Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.69
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.69! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.68 2016/08/07 00:28:39 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.41 raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: 'usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.160.6.56 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 255: col2 => 'Value'}],
1.160.6.37 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.160.6.40 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.160.6.40 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.160.6.20 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.160.6.28 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.160.6.37 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.160.6.35 raeburn 294: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.160.6.37 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
307: { text => 'Institutional directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
1.160.6.37 raeburn 311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
1.30 raeburn 313: },
314: 'contacts' =>
315: { text => 'Contact Information',
1.67 raeburn 316: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
1.160.6.37 raeburn 319: print => \&print_contacts,
320: modify => \&modify_contacts,
1.30 raeburn 321: },
322: 'usercreation' =>
323: { text => 'User creation',
1.67 raeburn 324: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
1.34 raeburn 327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
1.30 raeburn 329: {col1 => 'Context',
1.43 raeburn 330: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
1.30 raeburn 333: },
1.160.6.34 raeburn 334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
1.160.6.37 raeburn 343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
1.160.6.34 raeburn 345: },
1.69 raeburn 346: 'usermodification' =>
1.33 raeburn 347: { text => 'User modification',
1.67 raeburn 348: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 349: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in author context'},
1.33 raeburn 351: {col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
1.33 raeburn 355: },
1.69 raeburn 356: 'scantron' =>
1.95 www 357: { text => 'Bubblesheet format file',
1.67 raeburn 358: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
1.160.6.37 raeburn 362: print => \&print_scantron,
363: modify => \&modify_scantron,
1.46 raeburn 364: },
1.86 raeburn 365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
1.102 raeburn 369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
1.160.6.30 raeburn 371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
1.160.6.39 raeburn 373: col2 => ''},
1.160.6.46 raeburn 374: {col1 => 'Available templates',
375: col2 => ''},
1.160.6.39 raeburn 376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
1.160.6.37 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.86 raeburn 380: },
1.160.6.5 raeburn 381: 'requestauthor' =>
1.160.6.34 raeburn 382: {text => 'Request Authoring Space',
1.160.6.5 raeburn 383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
1.160.6.37 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.160.6.5 raeburn 390: },
1.69 raeburn 391: 'coursecategories' =>
1.120 raeburn 392: { text => 'Cataloging of courses/communities',
1.67 raeburn 393: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
1.57 raeburn 397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
1.160.6.37 raeburn 401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
1.69 raeburn 403: },
404: 'serverstatuses' =>
1.77 raeburn 405: {text => 'Access to server status pages',
1.69 raeburn 406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
1.160.6.37 raeburn 411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
1.69 raeburn 413: },
1.160.6.39 raeburn 414: 'coursedefaults' =>
1.160.6.16 raeburn 415: {text => 'Course/Community defaults',
416: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 417: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
418: col2 => 'Value',},
419: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 420: col2 => 'Value',},],
1.160.6.37 raeburn 421: print => \&print_coursedefaults,
422: modify => \&modify_coursedefaults,
423: },
1.160.6.39 raeburn 424: 'selfenrollment' =>
1.160.6.37 raeburn 425: {text => 'Self-enrollment in Course/Community',
426: help => 'Domain_Configuration_Selfenrollment',
427: header => [{col1 => 'Configuration Rights',
428: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
429: {col1 => 'Defaults',
430: col2 => 'Value'},
431: {col1 => 'Self-enrollment validation (optional)',
432: col2 => 'Value'},],
433: print => \&print_selfenrollment,
434: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 435: },
1.141 raeburn 436: 'usersessions' =>
1.145 raeburn 437: {text => 'User session hosting/offloading',
1.137 raeburn 438: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 439: header => [{col1 => 'Domain server',
440: col2 => 'Servers to offload sessions to when busy'},
441: {col1 => 'Hosting of users from other domains',
1.137 raeburn 442: col2 => 'Rules'},
443: {col1 => "Hosting domain's own users elsewhere",
444: col2 => 'Rules'}],
1.160.6.37 raeburn 445: print => \&print_usersessions,
446: modify => \&modify_usersessions,
1.137 raeburn 447: },
1.150 raeburn 448: 'loadbalancing' =>
1.160.6.7 raeburn 449: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 450: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 451: header => [{col1 => 'Balancers',
1.150 raeburn 452: col2 => 'Default destinations',
1.160.6.13 raeburn 453: col3 => 'User affiliation',
1.150 raeburn 454: col4 => 'Overrides'},
455: ],
1.160.6.37 raeburn 456: print => \&print_loadbalancing,
457: modify => \&modify_loadbalancing,
1.150 raeburn 458: },
1.3 raeburn 459: );
1.110 raeburn 460: if (keys(%servers) > 1) {
461: $prefs{'login'} = { text => 'Log-in page options',
462: help => 'Domain_Configuration_Login_Page',
463: header => [{col1 => 'Log-in Service',
464: col2 => 'Server Setting',},
465: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 466: col2 => ''},
467: {col1 => 'Log-in Help',
1.160.6.56 raeburn 468: col2 => 'Value'},
469: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 470: col2 => 'Value'}],
1.160.6.37 raeburn 471: print => \&print_login,
472: modify => \&modify_login,
1.110 raeburn 473: };
474: }
1.160.6.13 raeburn 475:
1.6 raeburn 476: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 477: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 478: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 479: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 480: text=>"Settings to display/modify"});
1.9 raeburn 481: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 482:
1.3 raeburn 483: if ($phase eq 'process') {
1.160.6.27 raeburn 484: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
485: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 486: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 487: $r->rflush();
1.160.6.27 raeburn 488: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 489: }
1.30 raeburn 490: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 491: my $js = &recaptcha_js().
1.160.6.40 raeburn 492: &toggle_display_js();
1.160.6.7 raeburn 493: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 494: my ($othertitle,$usertypes,$types) =
495: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 496: $js .= &lonbalance_targets_js($dom,$types,\%servers,
497: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 498: &new_spares_js().
499: &common_domprefs_js().
500: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 501: }
1.160.6.30 raeburn 502: if (grep(/^requestcourses$/,@actions)) {
503: my $javascript_validations;
504: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
505: $js .= <<END;
506: <script type="text/javascript">
507: $javascript_validations
508: </script>
509: $coursebrowserjs
510: END
511: }
1.150 raeburn 512: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 513: } else {
1.160.6.11 raeburn 514: # check if domconfig user exists for the domain.
515: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 516: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 517: &config_check($dom,$confname,$servadm);
518: unless ($configuserok eq 'ok') {
519: &Apache::lonconfigsettings::print_header($r,$phase,$context);
520: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
521: $confname).
522: '<br />'
523: );
524: if ($switchserver) {
525: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
526: '<br />'.
527: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
528: '<br />'.
529: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
530: '<br />'.
531: &mt('To do that now, use the following link: [_1]',$switchserver)
532: );
533: } else {
534: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
535: '<br />'.
536: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
537: );
538: }
539: $r->print(&Apache::loncommon::end_page());
540: return OK;
541: }
1.21 raeburn 542: if (keys(%domconfig) == 0) {
543: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 544: my @ids=&Apache::lonnet::current_machine_ids();
545: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 546: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 547: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 548: my $custom_img_count = 0;
549: foreach my $img (@loginimages) {
550: if ($designhash{$dom.'.login.'.$img} ne '') {
551: $custom_img_count ++;
552: }
553: }
554: foreach my $role (@roles) {
555: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
556: $custom_img_count ++;
557: }
558: }
559: if ($custom_img_count > 0) {
1.94 raeburn 560: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 561: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 562: $r->print(
563: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
564: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
565: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
566: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
567: if ($switch_server) {
1.30 raeburn 568: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 569: }
1.91 raeburn 570: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 571: return OK;
572: }
573: }
574: }
1.91 raeburn 575: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 576: }
577: return OK;
578: }
579:
580: sub process_changes {
1.160.6.24 raeburn 581: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 582: my %domconfig;
583: if (ref($values) eq 'HASH') {
584: %domconfig = %{$values};
585: }
1.3 raeburn 586: my $output;
587: if ($action eq 'login') {
1.160.6.24 raeburn 588: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 589: } elsif ($action eq 'rolecolors') {
1.9 raeburn 590: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 591: $lastactref,%domconfig);
1.3 raeburn 592: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 593: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 594: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 595: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 596: } elsif ($action eq 'autoupdate') {
597: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 598: } elsif ($action eq 'autocreate') {
599: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 600: } elsif ($action eq 'directorysrch') {
601: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 602: } elsif ($action eq 'usercreation') {
1.28 raeburn 603: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 604: } elsif ($action eq 'selfcreation') {
605: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 606: } elsif ($action eq 'usermodification') {
607: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 608: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 609: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 610: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 611: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 612: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 613: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 614: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 615: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 616: } elsif ($action eq 'serverstatuses') {
617: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 618: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 619: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 620: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 621: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 622: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 623: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 624: } elsif ($action eq 'selfenrollment') {
625: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 626: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 627: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 628: } elsif ($action eq 'loadbalancing') {
629: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 630: }
631: return $output;
632: }
633:
634: sub print_config_box {
1.9 raeburn 635: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 636: my $rowtotal = 0;
1.49 raeburn 637: my $output;
638: if ($action eq 'coursecategories') {
639: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 640: } elsif ($action eq 'defaults') {
641: $output = &defaults_javascript($settings);
1.91 raeburn 642: }
1.160.6.40 raeburn 643: $output .=
1.30 raeburn 644: '<table class="LC_nested_outer">
1.3 raeburn 645: <tr>
1.66 raeburn 646: <th align="left" valign="middle"><span class="LC_nobreak">'.
647: &mt($item->{text}).' '.
648: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
649: '</tr>';
1.30 raeburn 650: $rowtotal ++;
1.110 raeburn 651: my $numheaders = 1;
652: if (ref($item->{'header'}) eq 'ARRAY') {
653: $numheaders = scalar(@{$item->{'header'}});
654: }
655: if ($numheaders > 1) {
1.64 raeburn 656: my $colspan = '';
1.145 raeburn 657: my $rightcolspan = '';
1.160.6.42 raeburn 658: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.56 raeburn 659: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 660: $colspan = ' colspan="2"';
661: }
1.145 raeburn 662: if ($action eq 'usersessions') {
663: $rightcolspan = ' colspan="3"';
664: }
1.30 raeburn 665: $output .= '
1.3 raeburn 666: <tr>
667: <td>
668: <table class="LC_nested">
669: <tr class="LC_info_row">
1.59 bisitz 670: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 671: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 672: </tr>';
1.69 raeburn 673: $rowtotal ++;
1.160.6.37 raeburn 674: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 675: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.40 raeburn 676: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 677: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 678: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 679: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 680: } elsif ($action eq 'login') {
1.160.6.56 raeburn 681: if ($numheaders == 4) {
1.160.6.5 raeburn 682: $colspan = ' colspan="2"';
683: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
684: } else {
685: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
686: }
1.160.6.37 raeburn 687: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 688: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 689: } elsif ($action eq 'rolecolors') {
1.30 raeburn 690: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 691: }
1.30 raeburn 692: $output .= '
1.6 raeburn 693: </table>
694: </td>
695: </tr>
696: <tr>
697: <td>
698: <table class="LC_nested">
699: <tr class="LC_info_row">
1.160.6.37 raeburn 700: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 701: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 702: </tr>';
703: $rowtotal ++;
1.160.6.37 raeburn 704: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
705: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 706: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
707: if ($action eq 'coursecategories') {
708: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
709: $colspan = ' colspan="2"';
710: } else {
711: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
712: }
713: $output .= '
1.63 raeburn 714: </table>
715: </td>
716: </tr>
717: <tr>
718: <td>
719: <table class="LC_nested">
720: <tr class="LC_info_row">
721: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 722: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 723: </tr>'."\n";
724: if ($action eq 'coursecategories') {
725: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
726: } else {
727: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
728: }
1.63 raeburn 729: $rowtotal ++;
1.160.6.57 raeburn 730: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
731: ($action eq 'defaults')) {
1.160.6.37 raeburn 732: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 733: } elsif ($action eq 'login') {
1.160.6.56 raeburn 734: if ($numheaders == 4) {
1.160.6.5 raeburn 735: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
736: </table>
737: </td>
738: </tr>
739: <tr>
740: <td>
741: <table class="LC_nested">
742: <tr class="LC_info_row">
743: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 744: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 745: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
746: $rowtotal ++;
747: } else {
748: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
749: }
1.160.6.56 raeburn 750: $output .= '
751: </table>
752: </td>
753: </tr>
754: <tr>
755: <td>
756: <table class="LC_nested">
757: <tr class="LC_info_row">';
758: if ($numheaders == 4) {
759: $output .= '
760: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
761: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
762: </tr>';
763: } else {
764: $output .= '
765: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
766: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
767: </tr>';
768: }
769: $rowtotal ++;
770: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 771: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 772: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
773: $rowtotal ++;
774: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
782: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
783: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 784: &textbookcourses_javascript($settings).
785: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
786: </table>
787: </td>
788: </tr>
789: <tr>
790: <td>
791: <table class="LC_nested">
792: <tr class="LC_info_row">
793: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
794: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
795: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 796: </table>
797: </td>
798: </tr>
799: <tr>
800: <td>
801: <table class="LC_nested">
802: <tr class="LC_info_row">
1.160.6.46 raeburn 803: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
804: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 805: </tr>'.
806: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 807: } elsif ($action eq 'requestauthor') {
808: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 809: $rowtotal ++;
1.122 jms 810: } elsif ($action eq 'rolecolors') {
1.30 raeburn 811: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.69 raeburn 819: <td class="LC_left_item"'.$colspan.' valign="top">'.
820: &mt($item->{'header'}->[2]->{'col1'}).'</td>
821: <td class="LC_right_item" valign="top">'.
822: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 823: </tr>'.
1.30 raeburn 824: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 825: </table>
826: </td>
827: </tr>
828: <tr>
829: <td>
830: <table class="LC_nested">
831: <tr class="LC_info_row">
1.59 bisitz 832: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
833: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 834: </tr>'.
1.30 raeburn 835: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
836: $rowtotal += 2;
1.6 raeburn 837: }
1.3 raeburn 838: } else {
1.30 raeburn 839: $output .= '
1.3 raeburn 840: <tr>
841: <td>
842: <table class="LC_nested">
1.30 raeburn 843: <tr class="LC_info_row">';
1.24 raeburn 844: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 845: $output .= '
1.59 bisitz 846: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 847: } elsif ($action eq 'serverstatuses') {
848: $output .= '
849: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
850: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
851:
1.6 raeburn 852: } else {
1.30 raeburn 853: $output .= '
1.69 raeburn 854: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
855: }
1.72 raeburn 856: if (defined($item->{'header'}->[0]->{'col3'})) {
857: $output .= '<td class="LC_left_item" valign="top">'.
858: &mt($item->{'header'}->[0]->{'col2'});
859: if ($action eq 'serverstatuses') {
860: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
861: }
1.69 raeburn 862: } else {
863: $output .= '<td class="LC_right_item" valign="top">'.
864: &mt($item->{'header'}->[0]->{'col2'});
865: }
866: $output .= '</td>';
867: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 868: if (defined($item->{'header'}->[0]->{'col4'})) {
869: $output .= '<td class="LC_left_item" valign="top">'.
870: &mt($item->{'header'}->[0]->{'col3'});
871: } else {
872: $output .= '<td class="LC_right_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col3'});
874: }
1.69 raeburn 875: if ($action eq 'serverstatuses') {
876: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
877: }
878: $output .= '</td>';
1.6 raeburn 879: }
1.150 raeburn 880: if ($item->{'header'}->[0]->{'col4'}) {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col4'});
883: }
1.69 raeburn 884: $output .= '</tr>';
1.48 raeburn 885: $rowtotal ++;
1.160.6.5 raeburn 886: if ($action eq 'quotas') {
1.86 raeburn 887: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 888: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 889: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 890: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 891: } elsif ($action eq 'scantron') {
892: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 893: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 894: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 895: }
1.3 raeburn 896: }
1.30 raeburn 897: $output .= '
1.3 raeburn 898: </table>
899: </td>
900: </tr>
1.30 raeburn 901: </table><br />';
902: return ($output,$rowtotal);
1.1 raeburn 903: }
904:
1.3 raeburn 905: sub print_login {
1.160.6.5 raeburn 906: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 907: my ($css_class,$datatable);
1.6 raeburn 908: my %choices = &login_choices();
1.110 raeburn 909:
1.160.6.5 raeburn 910: if ($caller eq 'service') {
1.149 raeburn 911: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 912: my $choice = $choices{'disallowlogin'};
913: $css_class = ' class="LC_odd_row"';
1.128 raeburn 914: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 915: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 916: '<th>'.$choices{'server'}.'</th>'.
917: '<th>'.$choices{'serverpath'}.'</th>'.
918: '<th>'.$choices{'custompath'}.'</th>'.
919: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 920: my %disallowed;
921: if (ref($settings) eq 'HASH') {
922: if (ref($settings->{'loginvia'}) eq 'HASH') {
923: %disallowed = %{$settings->{'loginvia'}};
924: }
925: }
926: foreach my $lonhost (sort(keys(%servers))) {
927: my $direct = 'selected="selected"';
1.128 raeburn 928: if (ref($disallowed{$lonhost}) eq 'HASH') {
929: if ($disallowed{$lonhost}{'server'} ne '') {
930: $direct = '';
931: }
1.110 raeburn 932: }
1.115 raeburn 933: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 934: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 935: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
936: '</option>';
1.160.6.13 raeburn 937: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 938: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 939: my $selected = '';
1.128 raeburn 940: if (ref($disallowed{$lonhost}) eq 'HASH') {
941: if ($hostid eq $disallowed{$lonhost}{'server'}) {
942: $selected = 'selected="selected"';
943: }
1.110 raeburn 944: }
945: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
946: $servers{$hostid}.'</option>';
947: }
1.128 raeburn 948: $datatable .= '</select></td>'.
949: '<td><select name="'.$lonhost.'_serverpath">';
950: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
951: my $pathname = $path;
952: if ($path eq 'custom') {
953: $pathname = &mt('Custom Path').' ->';
954: }
955: my $selected = '';
956: if (ref($disallowed{$lonhost}) eq 'HASH') {
957: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
958: $selected = 'selected="selected"';
959: }
960: } elsif ($path eq '') {
961: $selected = 'selected="selected"';
962: }
963: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
964: }
965: $datatable .= '</select></td>';
966: my ($custom,$exempt);
967: if (ref($disallowed{$lonhost}) eq 'HASH') {
968: $custom = $disallowed{$lonhost}{'custompath'};
969: $exempt = $disallowed{$lonhost}{'exempt'};
970: }
971: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
972: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
973: '</tr>';
1.110 raeburn 974: }
975: $datatable .= '</table></td></tr>';
976: return $datatable;
1.160.6.5 raeburn 977: } elsif ($caller eq 'page') {
978: my %defaultchecked = (
979: 'coursecatalog' => 'on',
1.160.6.14 raeburn 980: 'helpdesk' => 'on',
1.160.6.5 raeburn 981: 'adminmail' => 'off',
982: 'newuser' => 'off',
983: );
1.160.6.14 raeburn 984: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 985: my (%checkedon,%checkedoff);
1.42 raeburn 986: foreach my $item (@toggles) {
1.160.6.5 raeburn 987: if ($defaultchecked{$item} eq 'on') {
988: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 989: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 990: } elsif ($defaultchecked{$item} eq 'off') {
991: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 992: $checkedon{$item} = ' ';
993: }
1.1 raeburn 994: }
1.160.6.5 raeburn 995: my @images = ('img','logo','domlogo','login');
996: my @logintext = ('textcol','bgcol');
997: my @bgs = ('pgbg','mainbg','sidebg');
998: my @links = ('link','alink','vlink');
999: my %designhash = &Apache::loncommon::get_domainconf($dom);
1000: my %defaultdesign = %Apache::loncommon::defaultdesign;
1001: my (%is_custom,%designs);
1002: my %defaults = (
1003: font => $defaultdesign{'login.font'},
1004: );
1.6 raeburn 1005: foreach my $item (@images) {
1.160.6.5 raeburn 1006: $defaults{$item} = $defaultdesign{'login.'.$item};
1007: $defaults{'showlogo'}{$item} = 1;
1008: }
1009: foreach my $item (@bgs) {
1010: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1011: }
1.41 raeburn 1012: foreach my $item (@logintext) {
1.160.6.5 raeburn 1013: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1014: }
1.160.6.5 raeburn 1015: foreach my $item (@links) {
1016: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1017: }
1.160.6.5 raeburn 1018: if (ref($settings) eq 'HASH') {
1019: foreach my $item (@toggles) {
1020: if ($settings->{$item} eq '1') {
1021: $checkedon{$item} = ' checked="checked" ';
1022: $checkedoff{$item} = ' ';
1023: } elsif ($settings->{$item} eq '0') {
1024: $checkedoff{$item} = ' checked="checked" ';
1025: $checkedon{$item} = ' ';
1026: }
1.6 raeburn 1027: }
1.160.6.5 raeburn 1028: foreach my $item (@images) {
1029: if (defined($settings->{$item})) {
1030: $designs{$item} = $settings->{$item};
1031: $is_custom{$item} = 1;
1032: }
1033: if (defined($settings->{'showlogo'}{$item})) {
1034: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1035: }
1036: }
1037: foreach my $item (@logintext) {
1038: if ($settings->{$item} ne '') {
1039: $designs{'logintext'}{$item} = $settings->{$item};
1040: $is_custom{$item} = 1;
1041: }
1042: }
1043: if ($settings->{'font'} ne '') {
1044: $designs{'font'} = $settings->{'font'};
1045: $is_custom{'font'} = 1;
1046: }
1047: foreach my $item (@bgs) {
1048: if ($settings->{$item} ne '') {
1049: $designs{'bgs'}{$item} = $settings->{$item};
1050: $is_custom{$item} = 1;
1051: }
1052: }
1053: foreach my $item (@links) {
1054: if ($settings->{$item} ne '') {
1055: $designs{'links'}{$item} = $settings->{$item};
1056: $is_custom{$item} = 1;
1057: }
1058: }
1059: } else {
1060: if ($designhash{$dom.'.login.font'} ne '') {
1061: $designs{'font'} = $designhash{$dom.'.login.font'};
1062: $is_custom{'font'} = 1;
1063: }
1064: foreach my $item (@images) {
1065: if ($designhash{$dom.'.login.'.$item} ne '') {
1066: $designs{$item} = $designhash{$dom.'.login.'.$item};
1067: $is_custom{$item} = 1;
1068: }
1069: }
1070: foreach my $item (@bgs) {
1071: if ($designhash{$dom.'.login.'.$item} ne '') {
1072: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1073: $is_custom{$item} = 1;
1074: }
1075: }
1076: foreach my $item (@links) {
1077: if ($designhash{$dom.'.login.'.$item} ne '') {
1078: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1079: $is_custom{$item} = 1;
1080: }
1.6 raeburn 1081: }
1082: }
1.160.6.5 raeburn 1083: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1084: logo => 'Institution Logo',
1085: domlogo => 'Domain Logo',
1086: login => 'Login box');
1087: my $itemcount = 1;
1088: foreach my $item (@toggles) {
1089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1090: $datatable .=
1091: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1092: '</td><td>'.
1093: '<span class="LC_nobreak"><label><input type="radio" name="'.
1094: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1095: '</label> <label><input type="radio" name="'.$item.'"'.
1096: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1097: '</tr>';
1098: $itemcount ++;
1.6 raeburn 1099: }
1.160.6.5 raeburn 1100: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1101: $datatable .= '</tr></table></td></tr>';
1102: } elsif ($caller eq 'help') {
1103: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1104: my $switchserver = &check_switchserver($dom,$confname);
1105: my $itemcount = 1;
1106: $defaulturl = '/adm/loginproblems.html';
1107: $defaulttype = 'default';
1108: %lt = &Apache::lonlocal::texthash (
1109: del => 'Delete?',
1110: rep => 'Replace:',
1111: upl => 'Upload:',
1112: default => 'Default',
1113: custom => 'Custom',
1114: );
1115: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1116: my @currlangs;
1117: if (ref($settings) eq 'HASH') {
1118: if (ref($settings->{'helpurl'}) eq 'HASH') {
1119: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1120: next if ($settings->{'helpurl'}{$key} eq '');
1121: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1122: $type{$key} = 'custom';
1123: unless ($key eq 'nolang') {
1124: push(@currlangs,$key);
1125: }
1126: }
1127: } elsif ($settings->{'helpurl'} ne '') {
1128: $type{'nolang'} = 'custom';
1129: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1130: }
1131: }
1.160.6.5 raeburn 1132: foreach my $lang ('nolang',sort(@currlangs)) {
1133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1134: $datatable .= '<tr'.$css_class.'>';
1135: if ($url{$lang} eq '') {
1136: $url{$lang} = $defaulturl;
1137: }
1138: if ($type{$lang} eq '') {
1139: $type{$lang} = $defaulttype;
1140: }
1141: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1142: if ($lang eq 'nolang') {
1143: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1144: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1145: } else {
1146: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1147: $langchoices{$lang},
1148: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1149: }
1150: $datatable .= '</span></td>'."\n".
1151: '<td class="LC_left_item">';
1152: if ($type{$lang} eq 'custom') {
1153: $datatable .= '<span class="LC_nobreak"><label>'.
1154: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1155: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1156: } else {
1157: $datatable .= $lt{'upl'};
1158: }
1159: $datatable .='<br />';
1160: if ($switchserver) {
1161: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1162: } else {
1163: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1164: }
1.160.6.5 raeburn 1165: $datatable .= '</td></tr>';
1166: $itemcount ++;
1.6 raeburn 1167: }
1.160.6.5 raeburn 1168: my @addlangs;
1169: foreach my $lang (sort(keys(%langchoices))) {
1170: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1171: push(@addlangs,$lang);
1172: }
1173: if (@addlangs > 0) {
1174: my %toadd;
1175: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1176: $toadd{''} = &mt('Select');
1177: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1178: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1179: &mt('Add log-in help page for a specific language:').' '.
1180: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1181: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1182: if ($switchserver) {
1183: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1184: } else {
1185: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1186: }
1.160.6.5 raeburn 1187: $datatable .= '</td></tr>';
1188: $itemcount ++;
1.6 raeburn 1189: }
1.160.6.5 raeburn 1190: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1191: } elsif ($caller eq 'headtag') {
1192: my %domservers = &Apache::lonnet::get_servers($dom);
1193: my $choice = $choices{'headtag'};
1194: $css_class = ' class="LC_odd_row"';
1195: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1196: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1197: '<th>'.$choices{'current'}.'</th>'.
1198: '<th>'.$choices{'action'}.'</th>'.
1199: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1200: my (%currurls,%currexempt);
1201: if (ref($settings) eq 'HASH') {
1202: if (ref($settings->{'headtag'}) eq 'HASH') {
1203: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1204: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1205: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1206: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1207: }
1208: }
1209: }
1210: }
1211: my %lt = &Apache::lonlocal::texthash(
1212: del => 'Delete?',
1213: rep => 'Replace:',
1214: upl => 'Upload:',
1215: curr => 'View contents',
1216: none => 'None',
1217: );
1218: my $switchserver = &check_switchserver($dom,$confname);
1219: foreach my $lonhost (sort(keys(%domservers))) {
1220: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1221: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1222: if ($currurls{$lonhost}) {
1223: $datatable .= '<td class="LC_right_item"><a href="'.
1224: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1225: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1226: '">'.$lt{'curr'}.'</a></td>'.
1227: '<td><span class="LC_nobreak"><label>'.
1228: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1229: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1230: } else {
1231: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1232: }
1233: $datatable .='<br />';
1234: if ($switchserver) {
1235: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1236: } else {
1237: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1238: }
1239: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1240: }
1241: $datatable .= '</table></td></tr>';
1.1 raeburn 1242: }
1.6 raeburn 1243: return $datatable;
1244: }
1245:
1246: sub login_choices {
1247: my %choices =
1248: &Apache::lonlocal::texthash (
1.116 bisitz 1249: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1250: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1251: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1252: disallowlogin => "Login page requests redirected",
1253: hostid => "Server",
1.128 raeburn 1254: server => "Redirect to:",
1255: serverpath => "Path",
1256: custompath => "Custom",
1257: exempt => "Exempt IP(s)",
1.110 raeburn 1258: directlogin => "No redirect",
1259: newuser => "Link to create a user account",
1260: img => "Header",
1261: logo => "Main Logo",
1262: domlogo => "Domain Logo",
1263: login => "Log-in Header",
1264: textcol => "Text color",
1265: bgcol => "Box color",
1266: bgs => "Background colors",
1267: links => "Link colors",
1268: font => "Font color",
1269: pgbg => "Header",
1270: mainbg => "Page",
1271: sidebg => "Login box",
1272: link => "Link",
1273: alink => "Active link",
1274: vlink => "Visited link",
1.160.6.56 raeburn 1275: headtag => "Custom markup",
1276: action => "Action",
1277: current => "Current",
1.6 raeburn 1278: );
1279: return %choices;
1280: }
1281:
1282: sub print_rolecolors {
1.30 raeburn 1283: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1284: my %choices = &color_font_choices();
1285: my @bgs = ('pgbg','tabbg','sidebg');
1286: my @links = ('link','alink','vlink');
1287: my @images = ('img');
1288: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1289: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1290: my %defaultdesign = %Apache::loncommon::defaultdesign;
1291: my (%is_custom,%designs);
1.160.6.22 raeburn 1292: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1293: if (ref($settings) eq 'HASH') {
1294: if (ref($settings->{$role}) eq 'HASH') {
1295: if ($settings->{$role}->{'img'} ne '') {
1296: $designs{'img'} = $settings->{$role}->{'img'};
1297: $is_custom{'img'} = 1;
1298: }
1299: if ($settings->{$role}->{'font'} ne '') {
1300: $designs{'font'} = $settings->{$role}->{'font'};
1301: $is_custom{'font'} = 1;
1302: }
1.97 tempelho 1303: if ($settings->{$role}->{'fontmenu'} ne '') {
1304: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1305: $is_custom{'fontmenu'} = 1;
1306: }
1.6 raeburn 1307: foreach my $item (@bgs) {
1308: if ($settings->{$role}->{$item} ne '') {
1309: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1310: $is_custom{$item} = 1;
1311: }
1312: }
1313: foreach my $item (@links) {
1314: if ($settings->{$role}->{$item} ne '') {
1315: $designs{'links'}{$item} = $settings->{$role}->{$item};
1316: $is_custom{$item} = 1;
1317: }
1318: }
1319: }
1320: } else {
1321: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1322: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1323: $is_custom{'img'} = 1;
1324: }
1.97 tempelho 1325: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1326: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1327: $is_custom{'fontmenu'} = 1;
1328: }
1.6 raeburn 1329: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1330: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1331: $is_custom{'font'} = 1;
1332: }
1333: foreach my $item (@bgs) {
1334: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1335: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1336: $is_custom{$item} = 1;
1337:
1338: }
1339: }
1340: foreach my $item (@links) {
1341: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1342: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: }
1347: my $itemcount = 1;
1.30 raeburn 1348: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1349: $datatable .= '</tr></table></td></tr>';
1350: return $datatable;
1351: }
1352:
1.160.6.22 raeburn 1353: sub role_defaults {
1354: my ($role,$bgs,$links,$images,$logintext) = @_;
1355: my %defaults;
1356: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1357: return %defaults;
1358: }
1359: my %defaultdesign = %Apache::loncommon::defaultdesign;
1360: if ($role eq 'login') {
1361: %defaults = (
1362: font => $defaultdesign{$role.'.font'},
1363: );
1364: if (ref($logintext) eq 'ARRAY') {
1365: foreach my $item (@{$logintext}) {
1366: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1367: }
1368: }
1369: foreach my $item (@{$images}) {
1370: $defaults{'showlogo'}{$item} = 1;
1371: }
1372: } else {
1373: %defaults = (
1374: img => $defaultdesign{$role.'.img'},
1375: font => $defaultdesign{$role.'.font'},
1376: fontmenu => $defaultdesign{$role.'.fontmenu'},
1377: );
1378: }
1379: foreach my $item (@{$bgs}) {
1380: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1381: }
1382: foreach my $item (@{$links}) {
1383: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1384: }
1385: foreach my $item (@{$images}) {
1386: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1387: }
1388: return %defaults;
1389: }
1390:
1.6 raeburn 1391: sub display_color_options {
1.9 raeburn 1392: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1393: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1394: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1395: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1396: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1397: '<td>'.$choices->{'font'}.'</td>';
1398: if (!$is_custom->{'font'}) {
1.30 raeburn 1399: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1400: } else {
1401: $datatable .= '<td> </td>';
1402: }
1.160.6.9 raeburn 1403: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1404:
1.8 raeburn 1405: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1406: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1407: ' value="'.$current_color.'" /> '.
1408: ' </td></tr>';
1.107 raeburn 1409: unless ($role eq 'login') {
1410: $datatable .= '<tr'.$css_class.'>'.
1411: '<td>'.$choices->{'fontmenu'}.'</td>';
1412: if (!$is_custom->{'fontmenu'}) {
1413: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1414: } else {
1415: $datatable .= '<td> </td>';
1416: }
1.160.6.22 raeburn 1417: $current_color = $designs->{'fontmenu'} ?
1418: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1419: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1420: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1421: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1422: ' value="'.$current_color.'" /> '.
1423: ' </td></tr>';
1.97 tempelho 1424: }
1.9 raeburn 1425: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1426: foreach my $img (@{$images}) {
1.18 albertel 1427: $itemcount ++;
1.6 raeburn 1428: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1429: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1430: '<td>'.$choices->{$img};
1.41 raeburn 1431: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1432: if ($role eq 'login') {
1433: if ($img eq 'login') {
1434: $login_hdr_pick =
1.135 bisitz 1435: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1436: $logincolors =
1437: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1438: $designs,$defaults);
1.70 raeburn 1439: } elsif ($img ne 'domlogo') {
1440: $datatable.= &logo_display_options($img,$defaults,$designs);
1441: }
1442: }
1443: $datatable .= '</td>';
1.6 raeburn 1444: if ($designs->{$img} ne '') {
1445: $imgfile = $designs->{$img};
1.18 albertel 1446: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1447: } else {
1448: $imgfile = $defaults->{$img};
1449: }
1450: if ($imgfile) {
1.9 raeburn 1451: my ($showfile,$fullsize);
1452: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1453: my $urldir = $1;
1454: my $filename = $2;
1455: my @info = &Apache::lonnet::stat_file($designs->{$img});
1456: if (@info) {
1457: my $thumbfile = 'tn-'.$filename;
1458: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1459: if (@thumb) {
1460: $showfile = $urldir.'/'.$thumbfile;
1461: } else {
1462: $showfile = $imgfile;
1463: }
1464: } else {
1465: $showfile = '';
1466: }
1467: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1468: $showfile = $imgfile;
1.6 raeburn 1469: my $imgdir = $1;
1470: my $filename = $2;
1.159 raeburn 1471: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1472: $showfile = "/$imgdir/tn-".$filename;
1473: } else {
1.159 raeburn 1474: my $input = $londocroot.$imgfile;
1475: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1476: if (!-e $output) {
1.9 raeburn 1477: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1478: my ($fullwidth,$fullheight) = &check_dimensions($input);
1479: if ($fullwidth ne '' && $fullheight ne '') {
1480: if ($fullwidth > $width && $fullheight > $height) {
1481: my $size = $width.'x'.$height;
1482: system("convert -sample $size $input $output");
1.159 raeburn 1483: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1484: }
1485: }
1.6 raeburn 1486: }
1487: }
1.16 raeburn 1488: }
1.6 raeburn 1489: if ($showfile) {
1.40 raeburn 1490: if ($showfile =~ m{^/(adm|res)/}) {
1491: if ($showfile =~ m{^/res/}) {
1492: my $local_showfile =
1493: &Apache::lonnet::filelocation('',$showfile);
1494: &Apache::lonnet::repcopy($local_showfile);
1495: }
1496: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1497: }
1498: if ($imgfile) {
1499: if ($imgfile =~ m{^/(adm|res)/}) {
1500: if ($imgfile =~ m{^/res/}) {
1501: my $local_imgfile =
1502: &Apache::lonnet::filelocation('',$imgfile);
1503: &Apache::lonnet::repcopy($local_imgfile);
1504: }
1505: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1506: } else {
1507: $fullsize = $imgfile;
1508: }
1509: }
1.41 raeburn 1510: $datatable .= '<td>';
1511: if ($img eq 'login') {
1.135 bisitz 1512: $datatable .= $login_hdr_pick;
1513: }
1.41 raeburn 1514: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1515: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1516: } else {
1.160.6.22 raeburn 1517: $datatable .= '<td> </td><td class="LC_left_item">'.
1518: &mt('Upload:').'<br />';
1.6 raeburn 1519: }
1520: } else {
1.160.6.22 raeburn 1521: $datatable .= '<td> </td><td class="LC_left_item">'.
1522: &mt('Upload:').'<br />';
1.6 raeburn 1523: }
1.9 raeburn 1524: if ($switchserver) {
1525: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1526: } else {
1.135 bisitz 1527: if ($img ne 'login') { # suppress file selection for Log-in header
1528: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1529: }
1.9 raeburn 1530: }
1531: $datatable .= '</td></tr>';
1.6 raeburn 1532: }
1533: $itemcount ++;
1534: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1535: $datatable .= '<tr'.$css_class.'>'.
1536: '<td>'.$choices->{'bgs'}.'</td>';
1537: my $bgs_def;
1538: foreach my $item (@{$bgs}) {
1539: if (!$is_custom->{$item}) {
1.70 raeburn 1540: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1541: }
1542: }
1543: if ($bgs_def) {
1.8 raeburn 1544: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1545: } else {
1546: $datatable .= '<td> </td>';
1547: }
1548: $datatable .= '<td class="LC_right_item">'.
1549: '<table border="0"><tr>';
1.160.6.13 raeburn 1550:
1.6 raeburn 1551: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1552: $datatable .= '<td align="center">'.$choices->{$item};
1553: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1554: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1555: $datatable .= ' ';
1.6 raeburn 1556: }
1.160.6.9 raeburn 1557: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1558: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1559: }
1560: $datatable .= '</tr></table></td></tr>';
1561: $itemcount ++;
1562: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1563: $datatable .= '<tr'.$css_class.'>'.
1564: '<td>'.$choices->{'links'}.'</td>';
1565: my $links_def;
1566: foreach my $item (@{$links}) {
1567: if (!$is_custom->{$item}) {
1.30 raeburn 1568: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1569: }
1570: }
1571: if ($links_def) {
1.8 raeburn 1572: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1573: } else {
1574: $datatable .= '<td> </td>';
1575: }
1576: $datatable .= '<td class="LC_right_item">'.
1577: '<table border="0"><tr>';
1578: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1579: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1580: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1581: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1582: $datatable.=' ';
1.6 raeburn 1583: }
1.160.6.9 raeburn 1584: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1585: '" /></td>';
1586: }
1.30 raeburn 1587: $$rowtotal += $itemcount;
1.3 raeburn 1588: return $datatable;
1589: }
1590:
1.70 raeburn 1591: sub logo_display_options {
1592: my ($img,$defaults,$designs) = @_;
1593: my $checkedon;
1594: if (ref($defaults) eq 'HASH') {
1595: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1596: if ($defaults->{'showlogo'}{$img}) {
1597: $checkedon = 'checked="checked" ';
1598: }
1599: }
1600: }
1601: if (ref($designs) eq 'HASH') {
1602: if (ref($designs->{'showlogo'}) eq 'HASH') {
1603: if (defined($designs->{'showlogo'}{$img})) {
1604: if ($designs->{'showlogo'}{$img} == 0) {
1605: $checkedon = '';
1606: } elsif ($designs->{'showlogo'}{$img} == 1) {
1607: $checkedon = 'checked="checked" ';
1608: }
1609: }
1610: }
1611: }
1612: return '<br /><label> <input type="checkbox" name="'.
1613: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1614: &mt('show').'</label>'."\n";
1615: }
1616:
1.41 raeburn 1617: sub login_header_options {
1.135 bisitz 1618: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1619: my $output = '';
1.41 raeburn 1620: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1621: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1622: if (!$is_custom->{'textcol'}) {
1623: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1624: ' ';
1625: }
1626: if (!$is_custom->{'bgcol'}) {
1627: $output .= $choices->{'bgcol'}.': '.
1628: '<span id="css_'.$role.'_font" style="background-color: '.
1629: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1630: }
1631: $output .= '<br />';
1632: }
1633: $output .='<br />';
1634: return $output;
1635: }
1636:
1637: sub login_text_colors {
1.160.6.22 raeburn 1638: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1639: my $color_menu = '<table border="0"><tr>';
1640: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1641: $color_menu .= '<td align="center">'.$choices->{$item};
1642: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1643: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1644: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1645: }
1646: $color_menu .= '</tr></table><br />';
1647: return $color_menu;
1648: }
1649:
1650: sub image_changes {
1651: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1652: my $output;
1.135 bisitz 1653: if ($img eq 'login') {
1654: # suppress image for Log-in header
1655: } elsif (!$is_custom) {
1.70 raeburn 1656: if ($img ne 'domlogo') {
1.41 raeburn 1657: $output .= &mt('Default image:').'<br />';
1658: } else {
1659: $output .= &mt('Default in use:').'<br />';
1660: }
1661: }
1.135 bisitz 1662: if ($img eq 'login') { # suppress image for Log-in header
1663: $output .= '<td>'.$logincolors;
1.41 raeburn 1664: } else {
1.135 bisitz 1665: if ($img_import) {
1666: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1667: }
1668: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1669: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1670: if ($is_custom) {
1671: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1672: '<input type="checkbox" name="'.
1673: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1674: '</label> '.&mt('Replace:').'</span><br />';
1675: } else {
1.160.6.22 raeburn 1676: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1677: }
1.41 raeburn 1678: }
1679: return $output;
1680: }
1681:
1.3 raeburn 1682: sub print_quotas {
1.86 raeburn 1683: my ($dom,$settings,$rowtotal,$action) = @_;
1684: my $context;
1685: if ($action eq 'quotas') {
1686: $context = 'tools';
1687: } else {
1688: $context = $action;
1689: }
1.160.6.20 raeburn 1690: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1691: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1692: my $typecount = 0;
1.101 raeburn 1693: my ($css_class,%titles);
1.86 raeburn 1694: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1695: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1696: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1697: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1698: %titles = &courserequest_titles();
1.160.6.5 raeburn 1699: } elsif ($context eq 'requestauthor') {
1700: @usertools = ('author');
1701: @options = ('norequest','approval','automatic');
1702: %titles = &authorrequest_titles();
1.86 raeburn 1703: } else {
1.160.6.4 raeburn 1704: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1705: %titles = &tool_titles();
1.86 raeburn 1706: }
1.26 raeburn 1707: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1708: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1709: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1710: unless (($context eq 'requestcourses') ||
1711: ($context eq 'requestauthor')) {
1.86 raeburn 1712: if (ref($settings) eq 'HASH') {
1713: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1714: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1715: } else {
1716: $currdefquota = $settings->{$type};
1717: }
1.160.6.20 raeburn 1718: if (ref($settings->{authorquota}) eq 'HASH') {
1719: $currauthorquota = $settings->{authorquota}->{$type};
1720: }
1.78 raeburn 1721: }
1.72 raeburn 1722: }
1.3 raeburn 1723: if (defined($usertypes->{$type})) {
1724: $typecount ++;
1725: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1726: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1727: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1728: '<td class="LC_left_item">';
1.101 raeburn 1729: if ($context eq 'requestcourses') {
1730: $datatable .= '<table><tr>';
1731: }
1732: my %cell;
1.72 raeburn 1733: foreach my $item (@usertools) {
1.101 raeburn 1734: if ($context eq 'requestcourses') {
1735: my ($curroption,$currlimit);
1736: if (ref($settings) eq 'HASH') {
1737: if (ref($settings->{$item}) eq 'HASH') {
1738: $curroption = $settings->{$item}->{$type};
1739: if ($curroption =~ /^autolimit=(\d*)$/) {
1740: $currlimit = $1;
1741: }
1742: }
1743: }
1744: if (!$curroption) {
1745: $curroption = 'norequest';
1746: }
1747: $datatable .= '<th>'.$titles{$item}.'</th>';
1748: foreach my $option (@options) {
1749: my $val = $option;
1750: if ($option eq 'norequest') {
1751: $val = 0;
1752: }
1753: if ($option eq 'validate') {
1754: my $canvalidate = 0;
1755: if (ref($validations{$item}) eq 'HASH') {
1756: if ($validations{$item}{$type}) {
1757: $canvalidate = 1;
1758: }
1759: }
1760: next if (!$canvalidate);
1761: }
1762: my $checked = '';
1763: if ($option eq $curroption) {
1764: $checked = ' checked="checked"';
1765: } elsif ($option eq 'autolimit') {
1766: if ($curroption =~ /^autolimit/) {
1767: $checked = ' checked="checked"';
1768: }
1769: }
1770: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1771: '<input type="radio" name="crsreq_'.$item.
1772: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1773: $titles{$option}.'</label>';
1.101 raeburn 1774: if ($option eq 'autolimit') {
1.127 raeburn 1775: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1776: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1777: 'value="'.$currlimit.'" />';
1.101 raeburn 1778: }
1.127 raeburn 1779: $cell{$item} .= '</span> ';
1.103 raeburn 1780: if ($option eq 'autolimit') {
1.127 raeburn 1781: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1782: }
1.101 raeburn 1783: }
1.160.6.5 raeburn 1784: } elsif ($context eq 'requestauthor') {
1785: my $curroption;
1786: if (ref($settings) eq 'HASH') {
1787: $curroption = $settings->{$type};
1788: }
1789: if (!$curroption) {
1790: $curroption = 'norequest';
1791: }
1792: foreach my $option (@options) {
1793: my $val = $option;
1794: if ($option eq 'norequest') {
1795: $val = 0;
1796: }
1797: my $checked = '';
1798: if ($option eq $curroption) {
1799: $checked = ' checked="checked"';
1800: }
1801: $datatable .= '<span class="LC_nobreak"><label>'.
1802: '<input type="radio" name="authorreq_'.$type.
1803: '" value="'.$val.'"'.$checked.' />'.
1804: $titles{$option}.'</label></span> ';
1805: }
1.101 raeburn 1806: } else {
1807: my $checked = 'checked="checked" ';
1808: if (ref($settings) eq 'HASH') {
1809: if (ref($settings->{$item}) eq 'HASH') {
1810: if ($settings->{$item}->{$type} == 0) {
1811: $checked = '';
1812: } elsif ($settings->{$item}->{$type} == 1) {
1813: $checked = 'checked="checked" ';
1814: }
1.78 raeburn 1815: }
1.72 raeburn 1816: }
1.101 raeburn 1817: $datatable .= '<span class="LC_nobreak"><label>'.
1818: '<input type="checkbox" name="'.$context.'_'.$item.
1819: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1820: '</label></span> ';
1.72 raeburn 1821: }
1.101 raeburn 1822: }
1823: if ($context eq 'requestcourses') {
1824: $datatable .= '</tr><tr>';
1825: foreach my $item (@usertools) {
1.106 raeburn 1826: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1827: }
1828: $datatable .= '</tr></table>';
1.72 raeburn 1829: }
1.86 raeburn 1830: $datatable .= '</td>';
1.160.6.5 raeburn 1831: unless (($context eq 'requestcourses') ||
1832: ($context eq 'requestauthor')) {
1.86 raeburn 1833: $datatable .=
1.160.6.20 raeburn 1834: '<td class="LC_right_item">'.
1835: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1836: '<input type="text" name="quota_'.$type.
1.72 raeburn 1837: '" value="'.$currdefquota.
1.160.6.20 raeburn 1838: '" size="5" /></span>'.(' ' x 2).
1839: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1840: '<input type="text" name="authorquota_'.$type.
1841: '" value="'.$currauthorquota.
1842: '" size="5" /></span></td>';
1.86 raeburn 1843: }
1844: $datatable .= '</tr>';
1.3 raeburn 1845: }
1846: }
1847: }
1.160.6.5 raeburn 1848: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1849: $defaultquota = '20';
1.160.6.20 raeburn 1850: $authorquota = '500';
1.86 raeburn 1851: if (ref($settings) eq 'HASH') {
1852: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1853: $defaultquota = $settings->{'defaultquota'}->{'default'};
1854: } elsif (defined($settings->{'default'})) {
1855: $defaultquota = $settings->{'default'};
1856: }
1.160.6.20 raeburn 1857: if (ref($settings->{'authorquota'}) eq 'HASH') {
1858: $authorquota = $settings->{'authorquota'}->{'default'};
1859: }
1.3 raeburn 1860: }
1861: }
1862: $typecount ++;
1863: $css_class = $typecount%2?' class="LC_odd_row"':'';
1864: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1865: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1866: '<td class="LC_left_item">';
1.101 raeburn 1867: if ($context eq 'requestcourses') {
1868: $datatable .= '<table><tr>';
1869: }
1870: my %defcell;
1.72 raeburn 1871: foreach my $item (@usertools) {
1.101 raeburn 1872: if ($context eq 'requestcourses') {
1873: my ($curroption,$currlimit);
1874: if (ref($settings) eq 'HASH') {
1875: if (ref($settings->{$item}) eq 'HASH') {
1876: $curroption = $settings->{$item}->{'default'};
1877: if ($curroption =~ /^autolimit=(\d*)$/) {
1878: $currlimit = $1;
1879: }
1880: }
1881: }
1882: if (!$curroption) {
1883: $curroption = 'norequest';
1884: }
1885: $datatable .= '<th>'.$titles{$item}.'</th>';
1886: foreach my $option (@options) {
1887: my $val = $option;
1888: if ($option eq 'norequest') {
1889: $val = 0;
1890: }
1891: if ($option eq 'validate') {
1892: my $canvalidate = 0;
1893: if (ref($validations{$item}) eq 'HASH') {
1894: if ($validations{$item}{'default'}) {
1895: $canvalidate = 1;
1896: }
1897: }
1898: next if (!$canvalidate);
1899: }
1900: my $checked = '';
1901: if ($option eq $curroption) {
1902: $checked = ' checked="checked"';
1903: } elsif ($option eq 'autolimit') {
1904: if ($curroption =~ /^autolimit/) {
1905: $checked = ' checked="checked"';
1906: }
1907: }
1908: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1909: '<input type="radio" name="crsreq_'.$item.
1910: '_default" value="'.$val.'"'.$checked.' />'.
1911: $titles{$option}.'</label>';
1912: if ($option eq 'autolimit') {
1.127 raeburn 1913: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1914: $item.'_limit_default" size="1" '.
1915: 'value="'.$currlimit.'" />';
1916: }
1.127 raeburn 1917: $defcell{$item} .= '</span> ';
1.104 raeburn 1918: if ($option eq 'autolimit') {
1.127 raeburn 1919: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1920: }
1.101 raeburn 1921: }
1.160.6.5 raeburn 1922: } elsif ($context eq 'requestauthor') {
1923: my $curroption;
1924: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1925: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1926: }
1927: if (!$curroption) {
1928: $curroption = 'norequest';
1929: }
1930: foreach my $option (@options) {
1931: my $val = $option;
1932: if ($option eq 'norequest') {
1933: $val = 0;
1934: }
1935: my $checked = '';
1936: if ($option eq $curroption) {
1937: $checked = ' checked="checked"';
1938: }
1939: $datatable .= '<span class="LC_nobreak"><label>'.
1940: '<input type="radio" name="authorreq_default"'.
1941: ' value="'.$val.'"'.$checked.' />'.
1942: $titles{$option}.'</label></span> ';
1943: }
1.101 raeburn 1944: } else {
1945: my $checked = 'checked="checked" ';
1946: if (ref($settings) eq 'HASH') {
1947: if (ref($settings->{$item}) eq 'HASH') {
1948: if ($settings->{$item}->{'default'} == 0) {
1949: $checked = '';
1950: } elsif ($settings->{$item}->{'default'} == 1) {
1951: $checked = 'checked="checked" ';
1952: }
1.78 raeburn 1953: }
1.72 raeburn 1954: }
1.101 raeburn 1955: $datatable .= '<span class="LC_nobreak"><label>'.
1956: '<input type="checkbox" name="'.$context.'_'.$item.
1957: '" value="default" '.$checked.'/>'.$titles{$item}.
1958: '</label></span> ';
1959: }
1960: }
1961: if ($context eq 'requestcourses') {
1962: $datatable .= '</tr><tr>';
1963: foreach my $item (@usertools) {
1.106 raeburn 1964: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1965: }
1.101 raeburn 1966: $datatable .= '</tr></table>';
1.72 raeburn 1967: }
1.86 raeburn 1968: $datatable .= '</td>';
1.160.6.5 raeburn 1969: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1970: $datatable .= '<td class="LC_right_item">'.
1971: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1972: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1973: $defaultquota.'" size="5" /></span>'.(' ' x2).
1974: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1975: '<input type="text" name="authorquota" value="'.
1976: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1977: }
1978: $datatable .= '</tr>';
1.72 raeburn 1979: $typecount ++;
1980: $css_class = $typecount%2?' class="LC_odd_row"':'';
1981: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1982: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1983: if ($context eq 'requestcourses') {
1.109 raeburn 1984: $datatable .= &mt('(overrides affiliation, if set)').
1985: '</td>'.
1986: '<td class="LC_left_item">'.
1987: '<table><tr>';
1.101 raeburn 1988: } else {
1.109 raeburn 1989: $datatable .= &mt('(overrides affiliation, if checked)').
1990: '</td>'.
1991: '<td class="LC_left_item" colspan="2">'.
1992: '<br />';
1.101 raeburn 1993: }
1994: my %advcell;
1.72 raeburn 1995: foreach my $item (@usertools) {
1.101 raeburn 1996: if ($context eq 'requestcourses') {
1997: my ($curroption,$currlimit);
1998: if (ref($settings) eq 'HASH') {
1999: if (ref($settings->{$item}) eq 'HASH') {
2000: $curroption = $settings->{$item}->{'_LC_adv'};
2001: if ($curroption =~ /^autolimit=(\d*)$/) {
2002: $currlimit = $1;
2003: }
2004: }
2005: }
2006: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2007: my $checked = '';
2008: if ($curroption eq '') {
2009: $checked = ' checked="checked"';
2010: }
2011: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2012: '<input type="radio" name="crsreq_'.$item.
2013: '__LC_adv" value=""'.$checked.' />'.
2014: &mt('No override set').'</label></span> ';
1.101 raeburn 2015: foreach my $option (@options) {
2016: my $val = $option;
2017: if ($option eq 'norequest') {
2018: $val = 0;
2019: }
2020: if ($option eq 'validate') {
2021: my $canvalidate = 0;
2022: if (ref($validations{$item}) eq 'HASH') {
2023: if ($validations{$item}{'_LC_adv'}) {
2024: $canvalidate = 1;
2025: }
2026: }
2027: next if (!$canvalidate);
2028: }
2029: my $checked = '';
1.104 raeburn 2030: if ($val eq $curroption) {
1.101 raeburn 2031: $checked = ' checked="checked"';
2032: } elsif ($option eq 'autolimit') {
2033: if ($curroption =~ /^autolimit/) {
2034: $checked = ' checked="checked"';
2035: }
2036: }
2037: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2038: '<input type="radio" name="crsreq_'.$item.
2039: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2040: $titles{$option}.'</label>';
2041: if ($option eq 'autolimit') {
1.127 raeburn 2042: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2043: $item.'_limit__LC_adv" size="1" '.
2044: 'value="'.$currlimit.'" />';
2045: }
1.127 raeburn 2046: $advcell{$item} .= '</span> ';
1.104 raeburn 2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2049: }
1.101 raeburn 2050: }
1.160.6.5 raeburn 2051: } elsif ($context eq 'requestauthor') {
2052: my $curroption;
2053: if (ref($settings) eq 'HASH') {
2054: $curroption = $settings->{'_LC_adv'};
2055: }
2056: my $checked = '';
2057: if ($curroption eq '') {
2058: $checked = ' checked="checked"';
2059: }
2060: $datatable .= '<span class="LC_nobreak"><label>'.
2061: '<input type="radio" name="authorreq__LC_adv"'.
2062: ' value=""'.$checked.' />'.
2063: &mt('No override set').'</label></span> ';
2064: foreach my $option (@options) {
2065: my $val = $option;
2066: if ($option eq 'norequest') {
2067: $val = 0;
2068: }
2069: my $checked = '';
2070: if ($val eq $curroption) {
2071: $checked = ' checked="checked"';
2072: }
2073: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2074: '<input type="radio" name="authorreq__LC_adv"'.
2075: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2076: $titles{$option}.'</label></span> ';
2077: }
1.101 raeburn 2078: } else {
2079: my $checked = 'checked="checked" ';
2080: if (ref($settings) eq 'HASH') {
2081: if (ref($settings->{$item}) eq 'HASH') {
2082: if ($settings->{$item}->{'_LC_adv'} == 0) {
2083: $checked = '';
2084: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2085: $checked = 'checked="checked" ';
2086: }
1.79 raeburn 2087: }
1.72 raeburn 2088: }
1.101 raeburn 2089: $datatable .= '<span class="LC_nobreak"><label>'.
2090: '<input type="checkbox" name="'.$context.'_'.$item.
2091: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2092: '</label></span> ';
2093: }
2094: }
2095: if ($context eq 'requestcourses') {
2096: $datatable .= '</tr><tr>';
2097: foreach my $item (@usertools) {
1.106 raeburn 2098: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2099: }
1.101 raeburn 2100: $datatable .= '</tr></table>';
1.72 raeburn 2101: }
1.98 raeburn 2102: $datatable .= '</td></tr>';
1.30 raeburn 2103: $$rowtotal += $typecount;
1.3 raeburn 2104: return $datatable;
2105: }
2106:
1.160.6.5 raeburn 2107: sub print_requestmail {
2108: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2109: my ($now,$datatable,%currapp);
1.102 raeburn 2110: $now = time;
2111: if (ref($settings) eq 'HASH') {
2112: if (ref($settings->{'notify'}) eq 'HASH') {
2113: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2114: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2115: }
2116: }
2117: }
1.160.6.16 raeburn 2118: my $numinrow = 2;
1.160.6.34 raeburn 2119: my $css_class;
2120: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2121: my $text;
2122: if ($action eq 'requestcourses') {
2123: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2124: } elsif ($action eq 'requestauthor') {
2125: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2126: } else {
1.160.6.34 raeburn 2127: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2128: }
1.160.6.34 raeburn 2129: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2130: ' <td>'.$text.'</td>'.
1.102 raeburn 2131: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2132: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2133: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2134: if ($numdc > 0) {
2135: $datatable .= $table;
1.102 raeburn 2136: } else {
2137: $datatable .= &mt('There are no active Domain Coordinators');
2138: }
2139: $datatable .='</td></tr>';
2140: return $datatable;
2141: }
2142:
1.160.6.30 raeburn 2143: sub print_studentcode {
2144: my ($settings,$rowtotal) = @_;
2145: my $rownum = 0;
2146: my ($output,%current);
2147: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2148: if (ref($settings) eq 'HASH') {
2149: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2150: foreach my $type (@crstypes) {
2151: $current{$type} = $settings->{'uniquecode'}{$type};
2152: }
1.160.6.30 raeburn 2153: }
2154: }
2155: $output .= '<tr>'.
2156: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2157: '<td class="LC_left_item">';
2158: foreach my $type (@crstypes) {
2159: my $check = ' ';
2160: if ($current{$type}) {
2161: $check = ' checked="checked" ';
2162: }
2163: $output .= '<span class="LC_nobreak"><label>'.
2164: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2165: &mt($type).'</label></span>'.(' 'x2).' ';
2166: }
2167: $output .= '</td></tr>';
2168: $$rowtotal ++;
2169: return $output;
2170: }
2171:
2172: sub print_textbookcourses {
1.160.6.46 raeburn 2173: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2174: my $rownum = 0;
2175: my $css_class;
2176: my $itemcount = 1;
2177: my $maxnum = 0;
2178: my $bookshash;
2179: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2180: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2181: }
2182: my %ordered;
2183: if (ref($bookshash) eq 'HASH') {
2184: foreach my $item (keys(%{$bookshash})) {
2185: if (ref($bookshash->{$item}) eq 'HASH') {
2186: my $num = $bookshash->{$item}{'order'};
2187: $ordered{$num} = $item;
2188: }
2189: }
2190: }
2191: my $confname = $dom.'-domainconfig';
2192: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2193: my $maxnum = scalar(keys(%ordered));
2194: my $datatable;
1.160.6.30 raeburn 2195: if (keys(%ordered)) {
2196: my @items = sort { $a <=> $b } keys(%ordered);
2197: for (my $i=0; $i<@items; $i++) {
2198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2199: my $key = $ordered{$items[$i]};
2200: my %coursehash=&Apache::lonnet::coursedescription($key);
2201: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2202: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2203: if (ref($bookshash->{$key}) eq 'HASH') {
2204: $subject = $bookshash->{$key}->{'subject'};
2205: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2206: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2207: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2208: $author = $bookshash->{$key}->{'author'};
2209: $image = $bookshash->{$key}->{'image'};
2210: if ($image ne '') {
2211: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2212: my $imagethumb = "$path/tn-".$imagefile;
2213: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2214: }
1.160.6.30 raeburn 2215: }
2216: }
1.160.6.46 raeburn 2217: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2218: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2219: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2220: for (my $k=0; $k<=$maxnum; $k++) {
2221: my $vpos = $k+1;
2222: my $selstr;
2223: if ($k == $i) {
2224: $selstr = ' selected="selected" ';
2225: }
2226: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2227: }
2228: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2229: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2230: &mt('Delete?').'</label></span></td>'.
2231: '<td colspan="2">'.
1.160.6.46 raeburn 2232: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2233: (' 'x2).
1.160.6.46 raeburn 2234: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2235: if ($type eq 'textbooks') {
2236: $datatable .= (' 'x2).
1.160.6.47 raeburn 2237: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2238: (' 'x2).
1.160.6.46 raeburn 2239: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2240: (' 'x2).
2241: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2242: if ($image) {
2243: $datatable .= '<span class="LC_nobreak">'.
2244: $imgsrc.
2245: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2246: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2247: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2248: }
2249: if ($switchserver) {
2250: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2251: } else {
2252: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2253: }
1.160.6.30 raeburn 2254: }
1.160.6.46 raeburn 2255: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2256: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2257: $coursetitle.'</span></td></tr>'."\n";
2258: $itemcount ++;
2259: }
2260: }
2261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2262: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2263: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2264: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2265: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2266: for (my $k=0; $k<$maxnum+1; $k++) {
2267: my $vpos = $k+1;
2268: my $selstr;
2269: if ($k == $maxnum) {
2270: $selstr = ' selected="selected" ';
2271: }
2272: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2273: }
2274: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2275: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2276: '<td colspan="2">'.
1.160.6.46 raeburn 2277: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2278: (' 'x2).
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2280: (' 'x2);
2281: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2282: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2283: (' 'x2).
2284: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2285: (' 'x2).
2286: '<span class="LC_nobreak">'.&mt('Image:').' ';
2287: if ($switchserver) {
2288: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2289: } else {
2290: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2291: }
1.160.6.30 raeburn 2292: }
2293: $datatable .= '</span>'."\n".
2294: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2295: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2296: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2297: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2298: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2299: '</span></td>'."\n".
2300: '</tr>'."\n";
2301: $itemcount ++;
2302: return $datatable;
2303: }
2304:
2305: sub textbookcourses_javascript {
1.160.6.46 raeburn 2306: my ($settings) = @_;
2307: return unless(ref($settings) eq 'HASH');
2308: my (%ordered,%total,%jstext);
2309: foreach my $type ('textbooks','templates') {
2310: $total{$type} = 0;
2311: if (ref($settings->{$type}) eq 'HASH') {
2312: foreach my $item (keys(%{$settings->{$type}})) {
2313: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2314: my $num = $settings->{$type}->{$item}{'order'};
2315: $ordered{$type}{$num} = $item;
2316: }
2317: }
2318: $total{$type} = scalar(keys(%{$settings->{$type}}));
2319: }
2320: my @jsarray = ();
2321: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2322: push(@jsarray,$ordered{$type}{$item});
2323: }
2324: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2325: }
2326: return <<"ENDSCRIPT";
2327: <script type="text/javascript">
2328: // <![CDATA[
1.160.6.46 raeburn 2329: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2330: var changedVal;
1.160.6.46 raeburn 2331: $jstext{'textbooks'};
2332: $jstext{'templates'};
2333: var newpos;
2334: var maxh;
2335: if (caller == 'textbooks') {
2336: newpos = 'textbooks_addbook_pos';
2337: maxh = 1 + $total{'textbooks'};
2338: } else {
2339: newpos = 'templates_addbook_pos';
2340: maxh = 1 + $total{'templates'};
2341: }
1.160.6.30 raeburn 2342: var current = new Array;
2343: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2344: if (item == newpos) {
2345: changedVal = newitemVal;
2346: } else {
2347: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2348: current[newitemVal] = newpos;
2349: }
1.160.6.46 raeburn 2350: if (caller == 'textbooks') {
2351: for (var i=0; i<textbooks.length; i++) {
2352: var elementName = 'textbooks_'+textbooks[i];
2353: if (elementName != item) {
2354: if (form.elements[elementName]) {
2355: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2356: current[currVal] = elementName;
2357: }
2358: }
2359: }
2360: }
2361: if (caller == 'templates') {
2362: for (var i=0; i<templates.length; i++) {
2363: var elementName = 'templates_'+templates[i];
2364: if (elementName != item) {
2365: if (form.elements[elementName]) {
2366: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2367: current[currVal] = elementName;
2368: }
1.160.6.30 raeburn 2369: }
2370: }
2371: }
2372: var oldVal;
2373: for (var j=0; j<maxh; j++) {
2374: if (current[j] == undefined) {
2375: oldVal = j;
2376: }
2377: }
2378: if (oldVal < changedVal) {
2379: for (var k=oldVal+1; k<=changedVal ; k++) {
2380: var elementName = current[k];
2381: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2382: }
2383: } else {
2384: for (var k=changedVal; k<oldVal; k++) {
2385: var elementName = current[k];
2386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2387: }
2388: }
2389: return;
2390: }
2391:
2392: // ]]>
2393: </script>
2394:
2395: ENDSCRIPT
2396: }
2397:
1.3 raeburn 2398: sub print_autoenroll {
1.30 raeburn 2399: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2400: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2401: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2402: if (ref($settings) eq 'HASH') {
2403: if (exists($settings->{'run'})) {
2404: if ($settings->{'run'} eq '0') {
2405: $runoff = ' checked="checked" ';
2406: $runon = ' ';
2407: } else {
2408: $runon = ' checked="checked" ';
2409: $runoff = ' ';
2410: }
2411: } else {
2412: if ($autorun) {
2413: $runon = ' checked="checked" ';
2414: $runoff = ' ';
2415: } else {
2416: $runoff = ' checked="checked" ';
2417: $runon = ' ';
2418: }
2419: }
1.129 raeburn 2420: if (exists($settings->{'co-owners'})) {
2421: if ($settings->{'co-owners'} eq '0') {
2422: $coownersoff = ' checked="checked" ';
2423: $coownerson = ' ';
2424: } else {
2425: $coownerson = ' checked="checked" ';
2426: $coownersoff = ' ';
2427: }
2428: } else {
2429: $coownersoff = ' checked="checked" ';
2430: $coownerson = ' ';
2431: }
1.3 raeburn 2432: if (exists($settings->{'sender_domain'})) {
2433: $defdom = $settings->{'sender_domain'};
2434: }
1.160.6.68 raeburn 2435: if (exists($settings->{'autofailsafe'})) {
2436: $failsafe = $settings->{'autofailsafe'};
2437: }
1.14 raeburn 2438: } else {
2439: if ($autorun) {
2440: $runon = ' checked="checked" ';
2441: $runoff = ' ';
2442: } else {
2443: $runoff = ' checked="checked" ';
2444: $runon = ' ';
2445: }
1.3 raeburn 2446: }
2447: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2448: my $notif_sender;
2449: if (ref($settings) eq 'HASH') {
2450: $notif_sender = $settings->{'sender_uname'};
2451: }
1.3 raeburn 2452: my $datatable='<tr class="LC_odd_row">'.
2453: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2454: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2455: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2456: $runon.' value="1" />'.&mt('Yes').'</label> '.
2457: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2458: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2459: '</tr><tr>'.
2460: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2461: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2462: &mt('username').': '.
2463: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2464: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2465: ': '.$domform.'</span></td></tr>'.
2466: '<tr class="LC_odd_row">'.
2467: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2468: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2469: '<input type="radio" name="autoassign_coowners"'.
2470: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2471: '<label><input type="radio" name="autoassign_coowners"'.
2472: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2473: '</tr><tr>'.
2474: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2475: '<td class="LC_right_item"><span class="LC_nobreak">'.
2476: '<input type="text" name="autoenroll_failsafe"'.
2477: ' value="'.$failsafe.'" size="4" /></td></tr>';
2478: $$rowtotal += 4;
1.3 raeburn 2479: return $datatable;
2480: }
2481:
2482: sub print_autoupdate {
1.30 raeburn 2483: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2484: my $datatable;
2485: if ($position eq 'top') {
2486: my $updateon = ' ';
2487: my $updateoff = ' checked="checked" ';
2488: my $classlistson = ' ';
2489: my $classlistsoff = ' checked="checked" ';
2490: if (ref($settings) eq 'HASH') {
2491: if ($settings->{'run'} eq '1') {
2492: $updateon = $updateoff;
2493: $updateoff = ' ';
2494: }
2495: if ($settings->{'classlists'} eq '1') {
2496: $classlistson = $classlistsoff;
2497: $classlistsoff = ' ';
2498: }
2499: }
2500: my %title = (
2501: run => 'Auto-update active?',
2502: classlists => 'Update information in classlists?',
2503: );
2504: $datatable = '<tr class="LC_odd_row">'.
2505: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2506: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2507: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2508: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2509: '<label><input type="radio" name="autoupdate_run"'.
2510: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2511: '</tr><tr>'.
2512: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2513: '<td class="LC_right_item"><span class="LC_nobreak">'.
2514: '<label><input type="radio" name="classlists"'.
2515: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2516: '<label><input type="radio" name="classlists"'.
2517: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2518: '</tr>';
1.30 raeburn 2519: $$rowtotal += 2;
1.131 raeburn 2520: } elsif ($position eq 'middle') {
2521: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2522: my $numinrow = 3;
2523: my $locknamesettings;
2524: $datatable .= &insttypes_row($settings,$types,$usertypes,
2525: $dom,$numinrow,$othertitle,
2526: 'lockablenames');
2527: $$rowtotal ++;
1.3 raeburn 2528: } else {
1.44 raeburn 2529: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2530: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2531: 'permanentemail','id');
1.33 raeburn 2532: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2533: my $numrows = 0;
1.26 raeburn 2534: if (ref($types) eq 'ARRAY') {
2535: if (@{$types} > 0) {
2536: $datatable =
2537: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2538: \@fields,$types,\$numrows);
1.30 raeburn 2539: $$rowtotal += @{$types};
1.26 raeburn 2540: }
1.3 raeburn 2541: }
2542: $datatable .=
2543: &usertype_update_row($settings,{'default' => $othertitle},
2544: \%fieldtitles,\@fields,['default'],
2545: \$numrows);
1.30 raeburn 2546: $$rowtotal ++;
1.3 raeburn 2547: }
2548: return $datatable;
2549: }
2550:
1.125 raeburn 2551: sub print_autocreate {
2552: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2553: my (%createon,%createoff,%currhash);
1.125 raeburn 2554: my @types = ('xml','req');
2555: if (ref($settings) eq 'HASH') {
2556: foreach my $item (@types) {
2557: $createoff{$item} = ' checked="checked" ';
2558: $createon{$item} = ' ';
2559: if (exists($settings->{$item})) {
2560: if ($settings->{$item}) {
2561: $createon{$item} = ' checked="checked" ';
2562: $createoff{$item} = ' ';
2563: }
2564: }
2565: }
1.160.6.16 raeburn 2566: if ($settings->{'xmldc'} ne '') {
2567: $currhash{$settings->{'xmldc'}} = 1;
2568: }
1.125 raeburn 2569: } else {
2570: foreach my $item (@types) {
2571: $createoff{$item} = ' checked="checked" ';
2572: $createon{$item} = ' ';
2573: }
2574: }
2575: $$rowtotal += 2;
1.160.6.16 raeburn 2576: my $numinrow = 2;
1.125 raeburn 2577: my $datatable='<tr class="LC_odd_row">'.
2578: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2579: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2580: '<input type="radio" name="autocreate_xml"'.
2581: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2582: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2583: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2584: '</td></tr><tr>'.
2585: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2586: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2587: '<input type="radio" name="autocreate_req"'.
2588: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2589: '<label><input type="radio" name="autocreate_req"'.
2590: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2591: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2592: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2593: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2594: if ($numdc > 1) {
1.160.6.50 raeburn 2595: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2596: '</td><td class="LC_left_item">';
1.125 raeburn 2597: } else {
1.160.6.50 raeburn 2598: $datatable .= &mt('Course creation processed as:').
2599: '</td><td class="LC_right_item">';
1.125 raeburn 2600: }
1.160.6.50 raeburn 2601: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2602: $$rowtotal += $rows;
1.125 raeburn 2603: return $datatable;
2604: }
2605:
1.23 raeburn 2606: sub print_directorysrch {
1.30 raeburn 2607: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2608: my $srchon = ' ';
2609: my $srchoff = ' checked="checked" ';
1.25 raeburn 2610: my ($exacton,$containson,$beginson);
1.24 raeburn 2611: my $localon = ' ';
2612: my $localoff = ' checked="checked" ';
1.23 raeburn 2613: if (ref($settings) eq 'HASH') {
2614: if ($settings->{'available'} eq '1') {
2615: $srchon = $srchoff;
2616: $srchoff = ' ';
2617: }
1.24 raeburn 2618: if ($settings->{'localonly'} eq '1') {
2619: $localon = $localoff;
2620: $localoff = ' ';
2621: }
1.25 raeburn 2622: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2623: foreach my $type (@{$settings->{'searchtypes'}}) {
2624: if ($type eq 'exact') {
2625: $exacton = ' checked="checked" ';
2626: } elsif ($type eq 'contains') {
2627: $containson = ' checked="checked" ';
2628: } elsif ($type eq 'begins') {
2629: $beginson = ' checked="checked" ';
2630: }
2631: }
2632: } else {
2633: if ($settings->{'searchtypes'} eq 'exact') {
2634: $exacton = ' checked="checked" ';
2635: } elsif ($settings->{'searchtypes'} eq 'contains') {
2636: $containson = ' checked="checked" ';
2637: } elsif ($settings->{'searchtypes'} eq 'specify') {
2638: $exacton = ' checked="checked" ';
2639: $containson = ' checked="checked" ';
2640: }
1.23 raeburn 2641: }
2642: }
2643: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2644: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2645:
2646: my $numinrow = 4;
1.26 raeburn 2647: my $cansrchrow = 0;
1.23 raeburn 2648: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2649: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2650: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2651: '<input type="radio" name="dirsrch_available"'.
2652: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2653: '<label><input type="radio" name="dirsrch_available"'.
2654: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2655: '</tr><tr>'.
1.30 raeburn 2656: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2657: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2658: '<input type="radio" name="dirsrch_localonly"'.
2659: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2660: '<label><input type="radio" name="dirsrch_localonly"'.
2661: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2662: '</tr>';
1.30 raeburn 2663: $$rowtotal += 2;
1.26 raeburn 2664: if (ref($usertypes) eq 'HASH') {
2665: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2666: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2667: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2668: $cansrchrow = 1;
2669: }
2670: }
2671: if ($cansrchrow) {
1.30 raeburn 2672: $$rowtotal ++;
1.26 raeburn 2673: $datatable .= '<tr>';
2674: } else {
2675: $datatable .= '<tr class="LC_odd_row">';
2676: }
1.30 raeburn 2677: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2678: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2679: foreach my $title (@{$titleorder}) {
2680: if (defined($searchtitles->{$title})) {
2681: my $check = ' ';
1.93 raeburn 2682: if (ref($settings) eq 'HASH') {
1.39 raeburn 2683: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2684: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2685: $check = ' checked="checked" ';
2686: }
1.25 raeburn 2687: }
2688: }
2689: $datatable .= '<td class="LC_left_item">'.
2690: '<span class="LC_nobreak"><label>'.
2691: '<input type="checkbox" name="searchby" '.
2692: 'value="'.$title.'"'.$check.'/>'.
2693: $searchtitles->{$title}.'</label></span></td>';
2694: }
2695: }
1.26 raeburn 2696: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2697: $$rowtotal ++;
1.26 raeburn 2698: if ($cansrchrow) {
2699: $datatable .= '<tr class="LC_odd_row">';
2700: } else {
2701: $datatable .= '<tr>';
2702: }
1.30 raeburn 2703: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2704: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2705: '<span class="LC_nobreak"><label>'.
2706: '<input type="checkbox" name="searchtypes" '.
2707: $exacton.' value="exact" />'.&mt('Exact match').
2708: '</label> '.
2709: '<label><input type="checkbox" name="searchtypes" '.
2710: $beginson.' value="begins" />'.&mt('Begins with').
2711: '</label> '.
2712: '<label><input type="checkbox" name="searchtypes" '.
2713: $containson.' value="contains" />'.&mt('Contains').
2714: '</label></span></td></tr>';
1.30 raeburn 2715: $$rowtotal ++;
1.25 raeburn 2716: return $datatable;
2717: }
2718:
1.28 raeburn 2719: sub print_contacts {
1.30 raeburn 2720: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2721: my $datatable;
2722: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2723: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2724: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2725: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2726: foreach my $type (@mailings) {
2727: $otheremails{$type} = '';
2728: }
1.134 raeburn 2729: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2730: if (ref($settings) eq 'HASH') {
2731: foreach my $item (@contacts) {
2732: if (exists($settings->{$item})) {
2733: $to{$item} = $settings->{$item};
2734: }
2735: }
2736: foreach my $type (@mailings) {
2737: if (exists($settings->{$type})) {
2738: if (ref($settings->{$type}) eq 'HASH') {
2739: foreach my $item (@contacts) {
2740: if ($settings->{$type}{$item}) {
2741: $checked{$type}{$item} = ' checked="checked" ';
2742: }
2743: }
2744: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2745: if ($type eq 'helpdeskmail') {
2746: $bccemails{$type} = $settings->{$type}{'bcc'};
2747: }
1.28 raeburn 2748: }
1.89 raeburn 2749: } elsif ($type eq 'lonstatusmail') {
2750: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2751: }
2752: }
2753: } else {
2754: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2755: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2756: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2757: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2758: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2759: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2760: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2761: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2762: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2763: }
2764: my ($titles,$short_titles) = &contact_titles();
2765: my $rownum = 0;
2766: my $css_class;
2767: foreach my $item (@contacts) {
1.69 raeburn 2768: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2769: $datatable .= '<tr'.$css_class.'>'.
2770: '<td><span class="LC_nobreak">'.$titles->{$item}.
2771: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2772: '<input type="text" name="'.$item.'" value="'.
2773: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2774: $rownum ++;
1.28 raeburn 2775: }
2776: foreach my $type (@mailings) {
1.69 raeburn 2777: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2778: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2779: '<td><span class="LC_nobreak">'.
2780: $titles->{$type}.': </span></td>'.
1.28 raeburn 2781: '<td class="LC_left_item">'.
2782: '<span class="LC_nobreak">';
2783: foreach my $item (@contacts) {
2784: $datatable .= '<label>'.
2785: '<input type="checkbox" name="'.$type.'"'.
2786: $checked{$type}{$item}.
2787: ' value="'.$item.'" />'.$short_titles->{$item}.
2788: '</label> ';
2789: }
2790: $datatable .= '</span><br />'.&mt('Others').': '.
2791: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2792: 'value="'.$otheremails{$type}.'" />';
2793: if ($type eq 'helpdeskmail') {
1.136 raeburn 2794: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2795: '<input type="text" name="'.$type.'_bcc" '.
2796: 'value="'.$bccemails{$type}.'" />';
2797: }
2798: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2799: $rownum ++;
1.28 raeburn 2800: }
1.160.6.23 raeburn 2801: my %choices;
2802: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2803: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2804: &mt('LON-CAPA core group - MSU'),600,500));
2805: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2806: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2807: &mt('LON-CAPA core group - MSU'),600,500));
2808: my @toggles = ('reporterrors','reportupdates');
2809: my %defaultchecked = ('reporterrors' => 'on',
2810: 'reportupdates' => 'on');
2811: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2812: \%choices,$rownum);
2813: $datatable .= $reports;
1.30 raeburn 2814: $$rowtotal += $rownum;
1.28 raeburn 2815: return $datatable;
2816: }
2817:
1.118 jms 2818: sub print_helpsettings {
1.160.6.5 raeburn 2819: my ($dom,$confname,$settings,$rowtotal) = @_;
2820: my ($datatable,$itemcount);
2821: $itemcount = 1;
2822: my (%choices,%defaultchecked,@toggles);
2823: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2824: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2825: &mt('LON-CAPA bug tracker'),600,500));
2826: %defaultchecked = ('submitbugs' => 'on');
2827: @toggles = ('submitbugs',);
1.122 jms 2828:
1.160.6.5 raeburn 2829: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2830: \%choices,$itemcount);
2831: return $datatable;
1.121 raeburn 2832: }
2833:
2834: sub radiobutton_prefs {
1.160.6.16 raeburn 2835: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2836: $additional,$align) = @_;
1.121 raeburn 2837: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2838: (ref($choices) eq 'HASH'));
2839:
2840: my (%checkedon,%checkedoff,$datatable,$css_class);
2841:
2842: foreach my $item (@{$toggles}) {
2843: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2844: $checkedon{$item} = ' checked="checked" ';
2845: $checkedoff{$item} = ' ';
1.121 raeburn 2846: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2847: $checkedoff{$item} = ' checked="checked" ';
2848: $checkedon{$item} = ' ';
2849: }
2850: }
2851: if (ref($settings) eq 'HASH') {
1.121 raeburn 2852: foreach my $item (@{$toggles}) {
1.118 jms 2853: if ($settings->{$item} eq '1') {
2854: $checkedon{$item} = ' checked="checked" ';
2855: $checkedoff{$item} = ' ';
2856: } elsif ($settings->{$item} eq '0') {
2857: $checkedoff{$item} = ' checked="checked" ';
2858: $checkedon{$item} = ' ';
2859: }
2860: }
1.121 raeburn 2861: }
1.160.6.16 raeburn 2862: if ($onclick) {
2863: $onclick = ' onclick="'.$onclick.'"';
2864: }
1.121 raeburn 2865: foreach my $item (@{$toggles}) {
1.118 jms 2866: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2867: $datatable .=
1.160.6.16 raeburn 2868: '<tr'.$css_class.'><td valign="top">'.
2869: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 2870: '</span></td>';
2871: if ($align eq 'left') {
2872: $datatable .= '<td class="LC_left_item">';
2873: } else {
2874: $datatable .= '<td class="LC_right_item">';
2875: }
2876: $datatable .=
2877: '<span class="LC_nobreak">'.
1.118 jms 2878: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2879: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2880: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2881: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2882: '</span>'.$additional.
2883: '</td>'.
1.118 jms 2884: '</tr>';
2885: $itemcount ++;
1.121 raeburn 2886: }
2887: return ($datatable,$itemcount);
2888: }
2889:
2890: sub print_coursedefaults {
1.139 raeburn 2891: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2892: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2893: my $itemcount = 1;
1.160.6.16 raeburn 2894: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2895: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2896: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2897: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 2898: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2899: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2900: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 2901: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.16 raeburn 2902: );
1.160.6.21 raeburn 2903: my %staticdefaults = (
2904: anonsurvey_threshold => 10,
2905: uploadquota => 500,
1.160.6.57 raeburn 2906: postsubmit => 60,
1.160.6.21 raeburn 2907: );
1.139 raeburn 2908: if ($position eq 'top') {
1.160.6.57 raeburn 2909: %defaultchecked = (
2910: 'uselcmath' => 'on',
2911: 'usejsme' => 'on',
1.160.6.64 raeburn 2912: 'canclone' => 'none',
1.160.6.57 raeburn 2913: );
2914: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2915: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 2916: \%choices,$itemcount);
1.160.6.64 raeburn 2917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2918: $datatable .=
2919: '<tr'.$css_class.'><td valign="top">'.
2920: '<span class="LC_nobreak">'.$choices{'canclone'}.
2921: '</span></td><td class="LC_left_item">';
2922: my $currcanclone = 'none';
2923: my $onclick;
2924: my @cloneoptions = ('none','domain');
2925: my %clonetitles = (
2926: none => 'No additional course requesters',
2927: domain => "Any course requester in course's domain",
2928: instcode => 'Course requests for official courses ...',
2929: );
2930: my (%codedefaults,@code_order,@posscodes);
2931: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
2932: \@code_order) eq 'ok') {
2933: if (@code_order > 0) {
2934: push(@cloneoptions,'instcode');
2935: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
2936: }
2937: }
2938: if (ref($settings) eq 'HASH') {
2939: if ($settings->{'canclone'}) {
2940: if (ref($settings->{'canclone'}) eq 'HASH') {
2941: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
2942: if (@code_order > 0) {
2943: $currcanclone = 'instcode';
2944: @posscodes = @{$settings->{'canclone'}{'instcode'}};
2945: }
2946: }
2947: } elsif ($settings->{'canclone'} eq 'domain') {
2948: $currcanclone = $settings->{'canclone'};
2949: }
2950: }
2951: }
2952: foreach my $option (@cloneoptions) {
2953: my ($checked,$additional);
2954: if ($currcanclone eq $option) {
2955: $checked = ' checked="checked"';
2956: }
2957: if ($option eq 'instcode') {
2958: if (@code_order) {
2959: my $show = 'none';
2960: if ($checked) {
2961: $show = 'block';
2962: }
2963: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
2964: &mt('Institutional codes for new and cloned course have identical:').
2965: '<br />';
2966: foreach my $item (@code_order) {
2967: my $codechk;
2968: if ($checked) {
2969: if (grep(/^\Q$item\E$/,@posscodes)) {
2970: $codechk = ' checked="checked"';
2971: }
2972: }
2973: $additional .= '<label>'.
2974: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
2975: $item.'</label>';
2976: }
2977: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
2978: }
2979: }
2980: $datatable .=
2981: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
2982: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
2983: '</label> '.$additional.'</span><br />';
2984: }
2985: $datatable .= '</td>'.
2986: '</tr>';
2987: $itemcount ++;
1.139 raeburn 2988: } else {
2989: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.57 raeburn 2990: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.160.6.16 raeburn 2991: my $currusecredits = 0;
1.160.6.57 raeburn 2992: my $postsubmitclient = 1;
1.160.6.30 raeburn 2993: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2994: if (ref($settings) eq 'HASH') {
2995: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2996: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2997: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2998: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2999: }
3000: }
1.160.6.16 raeburn 3001: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3002: foreach my $type (@types) {
3003: next if ($type eq 'community');
3004: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3005: if ($defcredits{$type} ne '') {
3006: $currusecredits = 1;
3007: }
3008: }
3009: }
3010: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3011: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3012: $postsubmitclient = 0;
3013: foreach my $type (@types) {
3014: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3015: }
3016: } else {
3017: foreach my $type (@types) {
3018: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3019: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3020: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3021: } else {
3022: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3023: }
3024: } else {
3025: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3026: }
3027: }
3028: }
3029: } else {
3030: foreach my $type (@types) {
3031: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3032: }
3033: }
1.160.6.58 raeburn 3034: } else {
3035: foreach my $type (@types) {
3036: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3037: }
1.139 raeburn 3038: }
3039: if (!$currdefresponder) {
1.160.6.21 raeburn 3040: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3041: } elsif ($currdefresponder < 1) {
3042: $currdefresponder = 1;
3043: }
1.160.6.21 raeburn 3044: foreach my $type (@types) {
3045: if ($curruploadquota{$type} eq '') {
3046: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3047: }
3048: }
1.139 raeburn 3049: $datatable .=
1.160.6.16 raeburn 3050: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3051: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3052: '</span></td>'.
3053: '<td class="LC_right_item"><span class="LC_nobreak">'.
3054: '<input type="text" name="anonsurvey_threshold"'.
3055: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3056: '</td></tr>'."\n";
3057: $itemcount ++;
3058: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3059: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3060: $choices{'uploadquota'}.
3061: '</span></td>'.
3062: '<td align="right" class="LC_right_item">'.
3063: '<table><tr>';
1.160.6.21 raeburn 3064: foreach my $type (@types) {
3065: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3066: '<input type="text" name="uploadquota_'.$type.'"'.
3067: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3068: }
3069: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3070: $itemcount ++;
1.160.6.40 raeburn 3071: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3072: my $display = 'none';
3073: if ($currusecredits) {
3074: $display = 'block';
3075: }
3076: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3077: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3078: foreach my $type (@types) {
3079: next if ($type eq 'community');
3080: $additional .= '<td align="center">'.&mt($type).'<br />'.
3081: '<input type="text" name="'.$type.'_credits"'.
3082: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3083: }
3084: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3085: %defaultchecked = ('coursecredits' => 'off');
3086: @toggles = ('coursecredits');
3087: my $current = {
3088: 'coursecredits' => $currusecredits,
3089: };
3090: (my $table,$itemcount) =
3091: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3092: \%choices,$itemcount,$onclick,$additional,'left');
3093: $datatable .= $table;
3094: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3095: my $display = 'none';
3096: if ($postsubmitclient) {
3097: $display = 'block';
3098: }
3099: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3100: &mt('Number of seconds submit is disabled').'<br />'.
3101: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3102: '<table><tr>';
1.160.6.57 raeburn 3103: foreach my $type (@types) {
3104: $additional .= '<td align="center">'.&mt($type).'<br />'.
3105: '<input type="text" name="'.$type.'_timeout" value="'.
3106: $deftimeout{$type}.'" size="5" /></td>';
3107: }
3108: $additional .= '</tr></table></div>'."\n";
3109: %defaultchecked = ('postsubmit' => 'on');
3110: @toggles = ('postsubmit');
3111: my $current = {
3112: 'postsubmit' => $postsubmitclient,
3113: };
3114: ($table,$itemcount) =
3115: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3116: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3117: $datatable .= $table;
1.160.6.37 raeburn 3118: }
3119: $$rowtotal += $itemcount;
3120: return $datatable;
3121: }
3122:
3123: sub print_selfenrollment {
3124: my ($position,$dom,$settings,$rowtotal) = @_;
3125: my ($css_class,$datatable);
3126: my $itemcount = 1;
3127: my @types = ('official','unofficial','community','textbook');
3128: if (($position eq 'top') || ($position eq 'middle')) {
3129: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3130: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3131: my @rows;
3132: my $key;
3133: if ($position eq 'top') {
3134: $key = 'admin';
3135: if (ref($rowsref) eq 'ARRAY') {
3136: @rows = @{$rowsref};
3137: }
3138: } elsif ($position eq 'middle') {
3139: $key = 'default';
3140: @rows = ('types','registered','approval','limit');
3141: }
3142: foreach my $row (@rows) {
3143: if (defined($titlesref->{$row})) {
3144: $itemcount ++;
3145: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3146: $datatable .= '<tr'.$css_class.'>'.
3147: '<td>'.$titlesref->{$row}.'</td>'.
3148: '<td class="LC_left_item">'.
3149: '<table><tr>';
3150: my (%current,%currentcap);
3151: if (ref($settings) eq 'HASH') {
3152: if (ref($settings->{$key}) eq 'HASH') {
3153: foreach my $type (@types) {
3154: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3155: $current{$type} = $settings->{$key}->{$type}->{$row};
3156: }
3157: if (($row eq 'limit') && ($key eq 'default')) {
3158: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3159: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3160: }
3161: }
3162: }
3163: }
3164: }
3165: my %roles = (
3166: '0' => &Apache::lonnet::plaintext('dc'),
3167: );
3168:
3169: foreach my $type (@types) {
3170: unless (($row eq 'registered') && ($key eq 'default')) {
3171: $datatable .= '<th>'.&mt($type).'</th>';
3172: }
3173: }
3174: unless (($row eq 'registered') && ($key eq 'default')) {
3175: $datatable .= '</tr><tr>';
3176: }
3177: foreach my $type (@types) {
3178: if ($type eq 'community') {
3179: $roles{'1'} = &mt('Community personnel');
3180: } else {
3181: $roles{'1'} = &mt('Course personnel');
3182: }
3183: $datatable .= '<td style="vertical-align: top">';
3184: if ($position eq 'top') {
3185: my %checked;
3186: if ($current{$type} eq '0') {
3187: $checked{'0'} = ' checked="checked"';
3188: } else {
3189: $checked{'1'} = ' checked="checked"';
3190: }
3191: foreach my $role ('1','0') {
3192: $datatable .= '<span class="LC_nobreak"><label>'.
3193: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3194: 'value="'.$role.'"'.$checked{$role}.' />'.
3195: $roles{$role}.'</label></span> ';
3196: }
3197: } else {
3198: if ($row eq 'types') {
3199: my %checked;
3200: if ($current{$type} =~ /^(all|dom)$/) {
3201: $checked{$1} = ' checked="checked"';
3202: } else {
3203: $checked{''} = ' checked="checked"';
3204: }
3205: foreach my $val ('','dom','all') {
3206: $datatable .= '<span class="LC_nobreak"><label>'.
3207: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3208: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3209: }
3210: } elsif ($row eq 'registered') {
3211: my %checked;
3212: if ($current{$type} eq '1') {
3213: $checked{'1'} = ' checked="checked"';
3214: } else {
3215: $checked{'0'} = ' checked="checked"';
3216: }
3217: foreach my $val ('0','1') {
3218: $datatable .= '<span class="LC_nobreak"><label>'.
3219: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3220: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3221: }
3222: } elsif ($row eq 'approval') {
3223: my %checked;
3224: if ($current{$type} =~ /^([12])$/) {
3225: $checked{$1} = ' checked="checked"';
3226: } else {
3227: $checked{'0'} = ' checked="checked"';
3228: }
3229: for my $val (0..2) {
3230: $datatable .= '<span class="LC_nobreak"><label>'.
3231: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3232: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3233: }
3234: } elsif ($row eq 'limit') {
3235: my %checked;
3236: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3237: $checked{$1} = ' checked="checked"';
3238: } else {
3239: $checked{'none'} = ' checked="checked"';
3240: }
3241: my $cap;
3242: if ($currentcap{$type} =~ /^\d+$/) {
3243: $cap = $currentcap{$type};
3244: }
3245: foreach my $val ('none','allstudents','selfenrolled') {
3246: $datatable .= '<span class="LC_nobreak"><label>'.
3247: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3248: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3249: }
3250: $datatable .= '<br />'.
3251: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3252: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3253: '</span>';
3254: }
3255: }
3256: $datatable .= '</td>';
3257: }
3258: $datatable .= '</tr>';
3259: }
3260: $datatable .= '</table></td></tr>';
3261: }
3262: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3263: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3264: }
3265: $$rowtotal += $itemcount;
3266: return $datatable;
3267: }
3268:
3269: sub print_validation_rows {
3270: my ($caller,$dom,$settings,$rowtotal) = @_;
3271: my ($itemsref,$namesref,$fieldsref);
3272: if ($caller eq 'selfenroll') {
3273: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3274: } elsif ($caller eq 'requestcourses') {
3275: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3276: }
3277: my %currvalidation;
3278: if (ref($settings) eq 'HASH') {
3279: if (ref($settings->{'validation'}) eq 'HASH') {
3280: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3281: }
1.160.6.39 raeburn 3282: }
3283: my $datatable;
3284: my $itemcount = 0;
3285: foreach my $item (@{$itemsref}) {
3286: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3287: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3288: $namesref->{$item}.
3289: '</span></td>'.
3290: '<td class="LC_left_item">';
3291: if (($item eq 'url') || ($item eq 'button')) {
3292: $datatable .= '<span class="LC_nobreak">'.
3293: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3294: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3295: } elsif ($item eq 'fields') {
3296: my @currfields;
3297: if (ref($currvalidation{$item}) eq 'ARRAY') {
3298: @currfields = @{$currvalidation{$item}};
3299: }
3300: foreach my $field (@{$fieldsref}) {
3301: my $check = '';
3302: if (grep(/^\Q$field\E$/,@currfields)) {
3303: $check = ' checked="checked"';
3304: }
3305: $datatable .= '<span class="LC_nobreak"><label>'.
3306: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3307: ' value="'.$field.'"'.$check.' />'.$field.
3308: '</label></span> ';
3309: }
3310: } elsif ($item eq 'markup') {
3311: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3312: $currvalidation{$item}.
1.160.6.37 raeburn 3313: '</textarea>';
1.160.6.39 raeburn 3314: }
3315: $datatable .= '</td></tr>'."\n";
3316: if (ref($rowtotal)) {
1.160.6.37 raeburn 3317: $itemcount ++;
3318: }
1.139 raeburn 3319: }
1.160.6.39 raeburn 3320: if ($caller eq 'requestcourses') {
3321: my %currhash;
1.160.6.51 raeburn 3322: if (ref($settings) eq 'HASH') {
3323: if (ref($settings->{'validation'}) eq 'HASH') {
3324: if ($settings->{'validation'}{'dc'} ne '') {
3325: $currhash{$settings->{'validation'}{'dc'}} = 1;
3326: }
1.160.6.39 raeburn 3327: }
3328: }
3329: my $numinrow = 2;
3330: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3331: 'validationdc',%currhash);
1.160.6.50 raeburn 3332: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3333: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3334: if ($numdc > 1) {
1.160.6.50 raeburn 3335: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3336: } else {
1.160.6.50 raeburn 3337: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3338: }
1.160.6.50 raeburn 3339: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3340: $itemcount ++;
3341: }
3342: if (ref($rowtotal)) {
3343: $$rowtotal += $itemcount;
3344: }
1.121 raeburn 3345: return $datatable;
1.118 jms 3346: }
3347:
1.137 raeburn 3348: sub print_usersessions {
3349: my ($position,$dom,$settings,$rowtotal) = @_;
3350: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3351: my (%by_ip,%by_location,@intdoms);
3352: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3353:
3354: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3355: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3356: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3357: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3358: my $itemcount = 1;
3359: if ($position eq 'top') {
1.152 raeburn 3360: if (keys(%serverhomes) > 1) {
1.145 raeburn 3361: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3362: my $curroffloadnow;
3363: if (ref($settings) eq 'HASH') {
3364: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3365: $curroffloadnow = $settings->{'offloadnow'};
3366: }
3367: }
3368: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3369: } else {
1.140 raeburn 3370: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3371: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3372: }
1.137 raeburn 3373: } else {
1.145 raeburn 3374: if (keys(%by_location) == 0) {
3375: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3376: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3377: } else {
3378: my %lt = &usersession_titles();
3379: my $numinrow = 5;
3380: my $prefix;
3381: my @types;
3382: if ($position eq 'bottom') {
3383: $prefix = 'remote';
3384: @types = ('version','excludedomain','includedomain');
3385: } else {
3386: $prefix = 'hosted';
3387: @types = ('excludedomain','includedomain');
3388: }
3389: my (%current,%checkedon,%checkedoff);
3390: my @lcversions = &Apache::lonnet::all_loncaparevs();
3391: my @locations = sort(keys(%by_location));
3392: foreach my $type (@types) {
3393: $checkedon{$type} = '';
3394: $checkedoff{$type} = ' checked="checked"';
3395: }
3396: if (ref($settings) eq 'HASH') {
3397: if (ref($settings->{$prefix}) eq 'HASH') {
3398: foreach my $key (keys(%{$settings->{$prefix}})) {
3399: $current{$key} = $settings->{$prefix}{$key};
3400: if ($key eq 'version') {
3401: if ($current{$key} ne '') {
3402: $checkedon{$key} = ' checked="checked"';
3403: $checkedoff{$key} = '';
3404: }
3405: } elsif (ref($current{$key}) eq 'ARRAY') {
3406: $checkedon{$key} = ' checked="checked"';
3407: $checkedoff{$key} = '';
3408: }
1.137 raeburn 3409: }
3410: }
3411: }
1.145 raeburn 3412: foreach my $type (@types) {
3413: next if ($type ne 'version' && !@locations);
3414: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3415: $datatable .= '<tr'.$css_class.'>
3416: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3417: <span class="LC_nobreak">
3418: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3419: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3420: if ($type eq 'version') {
3421: my $selector = '<select name="'.$prefix.'_version">';
3422: foreach my $version (@lcversions) {
3423: my $selected = '';
3424: if ($current{'version'} eq $version) {
3425: $selected = ' selected="selected"';
3426: }
3427: $selector .= ' <option value="'.$version.'"'.
3428: $selected.'>'.$version.'</option>';
3429: }
3430: $selector .= '</select> ';
3431: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3432: } else {
3433: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3434: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3435: ' />'.(' 'x2).
3436: '<input type="button" value="'.&mt('uncheck all').'" '.
3437: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3438: "\n".
3439: '</div><div><table>';
3440: my $rem;
3441: for (my $i=0; $i<@locations; $i++) {
3442: my ($showloc,$value,$checkedtype);
3443: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3444: my $ip = $by_location{$locations[$i]}->[0];
3445: if (ref($by_ip{$ip}) eq 'ARRAY') {
3446: $value = join(':',@{$by_ip{$ip}});
3447: $showloc = join(', ',@{$by_ip{$ip}});
3448: if (ref($current{$type}) eq 'ARRAY') {
3449: foreach my $loc (@{$by_ip{$ip}}) {
3450: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3451: $checkedtype = ' checked="checked"';
3452: last;
3453: }
3454: }
1.138 raeburn 3455: }
3456: }
3457: }
1.145 raeburn 3458: $rem = $i%($numinrow);
3459: if ($rem == 0) {
3460: if ($i > 0) {
3461: $datatable .= '</tr>';
3462: }
3463: $datatable .= '<tr>';
3464: }
3465: $datatable .= '<td class="LC_left_item">'.
3466: '<span class="LC_nobreak"><label>'.
3467: '<input type="checkbox" name="'.$prefix.'_'.$type.
3468: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3469: '</label></span></td>';
1.137 raeburn 3470: }
1.145 raeburn 3471: $rem = @locations%($numinrow);
3472: my $colsleft = $numinrow - $rem;
3473: if ($colsleft > 1 ) {
3474: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3475: ' </td>';
3476: } elsif ($colsleft == 1) {
3477: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3478: }
1.145 raeburn 3479: $datatable .= '</tr></table>';
1.137 raeburn 3480: }
1.145 raeburn 3481: $datatable .= '</td></tr>';
3482: $itemcount ++;
1.137 raeburn 3483: }
3484: }
3485: }
3486: $$rowtotal += $itemcount;
3487: return $datatable;
3488: }
3489:
1.138 raeburn 3490: sub build_location_hashes {
3491: my ($intdoms,$by_ip,$by_location) = @_;
3492: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3493: (ref($by_location) eq 'HASH'));
3494: my %iphost = &Apache::lonnet::get_iphost();
3495: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3496: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3497: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3498: foreach my $id (@{$iphost{$primary_ip}}) {
3499: my $intdom = &Apache::lonnet::internet_dom($id);
3500: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3501: push(@{$intdoms},$intdom);
3502: }
3503: }
3504: }
3505: foreach my $ip (keys(%iphost)) {
3506: if (ref($iphost{$ip}) eq 'ARRAY') {
3507: foreach my $id (@{$iphost{$ip}}) {
3508: my $location = &Apache::lonnet::internet_dom($id);
3509: if ($location) {
3510: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3511: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3512: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3513: push(@{$by_ip->{$ip}},$location);
3514: }
3515: } else {
3516: $by_ip->{$ip} = [$location];
3517: }
3518: }
3519: }
3520: }
3521: }
3522: foreach my $ip (sort(keys(%{$by_ip}))) {
3523: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3524: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3525: my $first = $by_ip->{$ip}->[0];
3526: if (ref($by_location->{$first}) eq 'ARRAY') {
3527: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3528: push(@{$by_location->{$first}},$ip);
3529: }
3530: } else {
3531: $by_location->{$first} = [$ip];
3532: }
3533: }
3534: }
3535: return;
3536: }
3537:
1.145 raeburn 3538: sub current_offloads_to {
3539: my ($dom,$settings,$servers) = @_;
3540: my (%spareid,%otherdomconfigs);
1.152 raeburn 3541: if (ref($servers) eq 'HASH') {
1.145 raeburn 3542: foreach my $lonhost (sort(keys(%{$servers}))) {
3543: my $gotspares;
1.152 raeburn 3544: if (ref($settings) eq 'HASH') {
3545: if (ref($settings->{'spares'}) eq 'HASH') {
3546: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3547: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3548: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3549: $gotspares = 1;
3550: }
1.145 raeburn 3551: }
3552: }
3553: unless ($gotspares) {
3554: my $gotspares;
3555: my $serverhomeID =
3556: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3557: my $serverhomedom =
3558: &Apache::lonnet::host_domain($serverhomeID);
3559: if ($serverhomedom ne $dom) {
3560: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3561: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3562: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3563: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3564: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3565: $gotspares = 1;
3566: }
3567: }
3568: } else {
3569: $otherdomconfigs{$serverhomedom} =
3570: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3571: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3572: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3573: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3574: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3575: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3576: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3577: $gotspares = 1;
3578: }
3579: }
3580: }
3581: }
3582: }
3583: }
3584: }
3585: unless ($gotspares) {
3586: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3587: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3588: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3589: } else {
3590: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3591: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3592: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3593: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3594: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3595: } else {
1.150 raeburn 3596: my %what = (
3597: spareid => 1,
3598: );
3599: my ($result,$returnhash) =
3600: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3601: if ($result eq 'ok') {
3602: if (ref($returnhash) eq 'HASH') {
3603: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3604: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3605: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3606: }
3607: }
1.145 raeburn 3608: }
3609: }
3610: }
3611: }
3612: }
3613: }
3614: return %spareid;
3615: }
3616:
3617: sub spares_row {
1.160.6.61 raeburn 3618: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 3619: my $css_class;
3620: my $numinrow = 4;
3621: my $itemcount = 1;
3622: my $datatable;
1.152 raeburn 3623: my %typetitles = &sparestype_titles();
3624: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3625: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3626: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3627: my ($othercontrol,$serverdom);
3628: if ($serverhome ne $server) {
3629: $serverdom = &Apache::lonnet::host_domain($serverhome);
3630: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3631: } else {
3632: $serverdom = &Apache::lonnet::host_domain($server);
3633: if ($serverdom ne $dom) {
3634: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3635: }
3636: }
3637: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 3638: my $checkednow;
3639: if (ref($curroffloadnow) eq 'HASH') {
3640: if ($curroffloadnow->{$server}) {
3641: $checkednow = ' checked="checked"';
3642: }
3643: }
1.145 raeburn 3644: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3645: $datatable .= '<tr'.$css_class.'>
3646: <td rowspan="2">
1.160.6.13 raeburn 3647: <span class="LC_nobreak">'.
3648: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 3649: ,'<b>'.$server.'</b>').'</span><br />'.
3650: '<span class="LC_nobreak">'."\n".
3651: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3652: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 3653: "\n";
1.145 raeburn 3654: my (%current,%canselect);
1.152 raeburn 3655: my @choices =
3656: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3657: foreach my $type ('primary','default') {
3658: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3659: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3660: my @spares = @{$spareid->{$server}{$type}};
3661: if (@spares > 0) {
1.152 raeburn 3662: if ($othercontrol) {
3663: $current{$type} = join(', ',@spares);
3664: } else {
3665: $current{$type} .= '<table>';
3666: my $numspares = scalar(@spares);
3667: for (my $i=0; $i<@spares; $i++) {
3668: my $rem = $i%($numinrow);
3669: if ($rem == 0) {
3670: if ($i > 0) {
3671: $current{$type} .= '</tr>';
3672: }
3673: $current{$type} .= '<tr>';
1.145 raeburn 3674: }
1.152 raeburn 3675: $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'".');" /> '.
3676: $spareid->{$server}{$type}[$i].
3677: '</label></td>'."\n";
3678: }
3679: my $rem = @spares%($numinrow);
3680: my $colsleft = $numinrow - $rem;
3681: if ($colsleft > 1 ) {
3682: $current{$type} .= '<td colspan="'.$colsleft.
3683: '" class="LC_left_item">'.
3684: ' </td>';
3685: } elsif ($colsleft == 1) {
3686: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3687: }
1.152 raeburn 3688: $current{$type} .= '</tr></table>';
1.150 raeburn 3689: }
1.145 raeburn 3690: }
3691: }
3692: if ($current{$type} eq '') {
3693: $current{$type} = &mt('None specified');
3694: }
1.152 raeburn 3695: if ($othercontrol) {
3696: if ($type eq 'primary') {
3697: $canselect{$type} = $othercontrol;
3698: }
3699: } else {
3700: $canselect{$type} =
3701: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3702: '<select name="newspare_'.$type.'_'.$server.'" '.
3703: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3704: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3705: if (@choices > 0) {
3706: foreach my $lonhost (@choices) {
3707: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3708: }
3709: }
3710: $canselect{$type} .= '</select>'."\n";
3711: }
3712: } else {
3713: $current{$type} = &mt('Could not be determined');
3714: if ($type eq 'primary') {
3715: $canselect{$type} = $othercontrol;
3716: }
1.145 raeburn 3717: }
1.152 raeburn 3718: if ($type eq 'default') {
3719: $datatable .= '<tr'.$css_class.'>';
3720: }
3721: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3722: '<td>'.$current{$type}.'</td>'."\n".
3723: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3724: }
3725: $itemcount ++;
3726: }
3727: }
3728: $$rowtotal += $itemcount;
3729: return $datatable;
3730: }
3731:
1.152 raeburn 3732: sub possible_newspares {
3733: my ($server,$currspares,$serverhomes,$altids) = @_;
3734: my $serverhostname = &Apache::lonnet::hostname($server);
3735: my %excluded;
3736: if ($serverhostname ne '') {
3737: %excluded = (
3738: $serverhostname => 1,
3739: );
3740: }
3741: if (ref($currspares) eq 'HASH') {
3742: foreach my $type (keys(%{$currspares})) {
3743: if (ref($currspares->{$type}) eq 'ARRAY') {
3744: if (@{$currspares->{$type}} > 0) {
3745: foreach my $curr (@{$currspares->{$type}}) {
3746: my $hostname = &Apache::lonnet::hostname($curr);
3747: $excluded{$hostname} = 1;
3748: }
3749: }
3750: }
3751: }
3752: }
3753: my @choices;
3754: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3755: if (keys(%{$serverhomes}) > 1) {
3756: foreach my $name (sort(keys(%{$serverhomes}))) {
3757: unless ($excluded{$name}) {
3758: if (exists($altids->{$serverhomes->{$name}})) {
3759: push(@choices,$altids->{$serverhomes->{$name}});
3760: } else {
3761: push(@choices,$serverhomes->{$name});
1.145 raeburn 3762: }
3763: }
3764: }
3765: }
3766: }
1.152 raeburn 3767: return sort(@choices);
1.145 raeburn 3768: }
3769:
1.150 raeburn 3770: sub print_loadbalancing {
3771: my ($dom,$settings,$rowtotal) = @_;
3772: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3773: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3774: my $numinrow = 1;
3775: my $datatable;
3776: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3777: my (%currbalancer,%currtargets,%currrules,%existing);
3778: if (ref($settings) eq 'HASH') {
3779: %existing = %{$settings};
3780: }
3781: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3782: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3783: \%currtargets,\%currrules);
1.150 raeburn 3784: } else {
3785: return;
3786: }
3787: my ($othertitle,$usertypes,$types) =
3788: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3789: my $rownum = 8;
1.150 raeburn 3790: if (ref($types) eq 'ARRAY') {
3791: $rownum += scalar(@{$types});
3792: }
1.160.6.7 raeburn 3793: my @css_class = ('LC_odd_row','LC_even_row');
3794: my $balnum = 0;
3795: my $islast;
3796: my (@toshow,$disabledtext);
3797: if (keys(%currbalancer) > 0) {
3798: @toshow = sort(keys(%currbalancer));
3799: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3800: push(@toshow,'');
3801: }
3802: } else {
3803: @toshow = ('');
3804: $disabledtext = &mt('No existing load balancer');
3805: }
3806: foreach my $lonhost (@toshow) {
3807: if ($balnum == scalar(@toshow)-1) {
3808: $islast = 1;
3809: } else {
3810: $islast = 0;
3811: }
3812: my $cssidx = $balnum%2;
3813: my $targets_div_style = 'display: none';
3814: my $disabled_div_style = 'display: block';
3815: my $homedom_div_style = 'display: none';
3816: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3817: '<td rowspan="'.$rownum.'" valign="top">'.
3818: '<p>';
3819: if ($lonhost eq '') {
3820: $datatable .= '<span class="LC_nobreak">';
3821: if (keys(%currbalancer) > 0) {
3822: $datatable .= &mt('Add balancer:');
3823: } else {
3824: $datatable .= &mt('Enable balancer:');
3825: }
3826: $datatable .= ' '.
3827: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3828: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3829: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3830: '<option value="" selected="selected">'.&mt('None').
3831: '</option>'."\n";
3832: foreach my $server (sort(keys(%servers))) {
3833: next if ($currbalancer{$server});
3834: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3835: }
3836: $datatable .=
3837: '</select>'."\n".
3838: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3839: } else {
3840: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3841: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3842: &mt('Stop balancing').'</label>'.
3843: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3844: $targets_div_style = 'display: block';
3845: $disabled_div_style = 'display: none';
3846: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3847: $homedom_div_style = 'display: block';
3848: }
3849: }
3850: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3851: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3852: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3853: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3854: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3855: my @sparestypes = ('primary','default');
3856: my %typetitles = &sparestype_titles();
3857: foreach my $sparetype (@sparestypes) {
3858: my $targettable;
3859: for (my $i=0; $i<$numspares; $i++) {
3860: my $checked;
3861: if (ref($currtargets{$lonhost}) eq 'HASH') {
3862: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3863: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3864: $checked = ' checked="checked"';
3865: }
3866: }
3867: }
3868: my ($chkboxval,$disabled);
3869: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3870: $chkboxval = $spares[$i];
3871: }
3872: if (exists($currbalancer{$spares[$i]})) {
3873: $disabled = ' disabled="disabled"';
3874: }
3875: $targettable .=
1.160.6.55 raeburn 3876: '<td><span class="LC_nobreak"><label>'.
3877: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3878: $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 3879: '</span></label></span></td>';
1.160.6.7 raeburn 3880: my $rem = $i%($numinrow);
3881: if ($rem == 0) {
3882: if (($i > 0) && ($i < $numspares-1)) {
3883: $targettable .= '</tr>';
3884: }
3885: if ($i < $numspares-1) {
3886: $targettable .= '<tr>';
1.150 raeburn 3887: }
3888: }
3889: }
1.160.6.7 raeburn 3890: if ($targettable ne '') {
3891: my $rem = $numspares%($numinrow);
3892: my $colsleft = $numinrow - $rem;
3893: if ($colsleft > 1 ) {
3894: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3895: ' </td>';
3896: } elsif ($colsleft == 1) {
3897: $targettable .= '<td class="LC_left_item"> </td>';
3898: }
3899: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3900: '<table><tr>'.$targettable.'</tr></table><br />';
3901: }
3902: }
3903: $datatable .= '</div></td></tr>'.
3904: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3905: $othertitle,$usertypes,$types,\%servers,
3906: \%currbalancer,$lonhost,
3907: $targets_div_style,$homedom_div_style,
3908: $css_class[$cssidx],$balnum,$islast);
3909: $$rowtotal += $rownum;
3910: $balnum ++;
3911: }
3912: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3913: return $datatable;
3914: }
3915:
3916: sub get_loadbalancers_config {
3917: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3918: return unless ((ref($servers) eq 'HASH') &&
3919: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3920: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3921: if (keys(%{$existing}) > 0) {
3922: my $oldlonhost;
3923: foreach my $key (sort(keys(%{$existing}))) {
3924: if ($key eq 'lonhost') {
3925: $oldlonhost = $existing->{'lonhost'};
3926: $currbalancer->{$oldlonhost} = 1;
3927: } elsif ($key eq 'targets') {
3928: if ($oldlonhost) {
3929: $currtargets->{$oldlonhost} = $existing->{'targets'};
3930: }
3931: } elsif ($key eq 'rules') {
3932: if ($oldlonhost) {
3933: $currrules->{$oldlonhost} = $existing->{'rules'};
3934: }
3935: } elsif (ref($existing->{$key}) eq 'HASH') {
3936: $currbalancer->{$key} = 1;
3937: $currtargets->{$key} = $existing->{$key}{'targets'};
3938: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3939: }
3940: }
1.160.6.7 raeburn 3941: } else {
3942: my ($balancerref,$targetsref) =
3943: &Apache::lonnet::get_lonbalancer_config($servers);
3944: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3945: foreach my $server (sort(keys(%{$balancerref}))) {
3946: $currbalancer->{$server} = 1;
3947: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3948: }
3949: }
3950: }
1.160.6.7 raeburn 3951: return;
1.150 raeburn 3952: }
3953:
3954: sub loadbalancing_rules {
3955: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3956: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3957: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3958: my $output;
1.160.6.7 raeburn 3959: my $num = 0;
3960: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3961: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3962: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3963: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3964: $num ++;
1.150 raeburn 3965: my $current;
3966: if (ref($currrules) eq 'HASH') {
3967: $current = $currrules->{$type};
3968: }
1.160.6.55 raeburn 3969: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 3970: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3971: $current = '';
3972: }
3973: }
3974: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3975: $servers,$currbalancer,$lonhost,$dom,
3976: $targets_div_style,$homedom_div_style,
3977: $css_class,$balnum,$num,$islast);
1.150 raeburn 3978: }
3979: }
3980: return $output;
3981: }
3982:
3983: sub loadbalancing_titles {
3984: my ($dom,$intdom,$usertypes,$types) = @_;
3985: my %othertypes = (
3986: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3987: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3988: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3989: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3990: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3991: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3992: );
1.160.6.26 raeburn 3993: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3994: if (ref($types) eq 'ARRAY') {
3995: unshift(@alltypes,@{$types},'default');
3996: }
3997: my %titles;
3998: foreach my $type (@alltypes) {
3999: if ($type =~ /^_LC_/) {
4000: $titles{$type} = $othertypes{$type};
4001: } elsif ($type eq 'default') {
4002: $titles{$type} = &mt('All users from [_1]',$dom);
4003: if (ref($types) eq 'ARRAY') {
4004: if (@{$types} > 0) {
4005: $titles{$type} = &mt('Other users from [_1]',$dom);
4006: }
4007: }
4008: } elsif (ref($usertypes) eq 'HASH') {
4009: $titles{$type} = $usertypes->{$type};
4010: }
4011: }
4012: return (\@alltypes,\%othertypes,\%titles);
4013: }
4014:
4015: sub loadbalance_rule_row {
1.160.6.7 raeburn 4016: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4017: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4018: my @rulenames;
1.150 raeburn 4019: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4020: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4021: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4022: } else {
1.160.6.26 raeburn 4023: @rulenames = ('default','homeserver');
4024: if ($type eq '_LC_external') {
4025: push(@rulenames,'externalbalancer');
4026: } else {
4027: push(@rulenames,'specific');
4028: }
4029: push(@rulenames,'none');
1.150 raeburn 4030: }
4031: my $style = $targets_div_style;
1.160.6.55 raeburn 4032: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4033: $style = $homedom_div_style;
4034: }
1.160.6.7 raeburn 4035: my $space;
4036: if ($islast && $num == 1) {
4037: $space = '<div display="inline-block"> </div>';
4038: }
4039: my $output =
4040: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4041: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4042: '<td valaign="top">'.$space.
4043: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4044: for (my $i=0; $i<@rulenames; $i++) {
4045: my $rule = $rulenames[$i];
4046: my ($checked,$extra);
4047: if ($rulenames[$i] eq 'default') {
4048: $rule = '';
4049: }
4050: if ($rulenames[$i] eq 'specific') {
4051: if (ref($servers) eq 'HASH') {
4052: my $default;
4053: if (($current ne '') && (exists($servers->{$current}))) {
4054: $checked = ' checked="checked"';
4055: }
4056: unless ($checked) {
4057: $default = ' selected="selected"';
4058: }
1.160.6.7 raeburn 4059: $extra =
4060: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4061: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4062: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4063: '<option value=""'.$default.'></option>'."\n";
4064: foreach my $server (sort(keys(%{$servers}))) {
4065: if (ref($currbalancer) eq 'HASH') {
4066: next if (exists($currbalancer->{$server}));
4067: }
1.150 raeburn 4068: my $selected;
1.160.6.7 raeburn 4069: if ($server eq $current) {
1.150 raeburn 4070: $selected = ' selected="selected"';
4071: }
1.160.6.7 raeburn 4072: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4073: }
4074: $extra .= '</select>';
4075: }
4076: } elsif ($rule eq $current) {
4077: $checked = ' checked="checked"';
4078: }
4079: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4080: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4081: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4082: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4083: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4084: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4085: $output .= $ruletitles{'particular'};
4086: } else {
4087: $output .= $ruletitles{$rulenames[$i]};
4088: }
4089: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4090: }
4091: $output .= '</div></td></tr>'."\n";
4092: return $output;
4093: }
4094:
4095: sub offloadtype_text {
4096: my %ruletitles = &Apache::lonlocal::texthash (
4097: 'default' => 'Offloads to default destinations',
4098: 'homeserver' => "Offloads to user's home server",
4099: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4100: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4101: 'none' => 'No offload',
1.160.6.26 raeburn 4102: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4103: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4104: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4105: );
4106: return %ruletitles;
4107: }
4108:
4109: sub sparestype_titles {
4110: my %typestitles = &Apache::lonlocal::texthash (
4111: 'primary' => 'primary',
4112: 'default' => 'default',
4113: );
4114: return %typestitles;
4115: }
4116:
1.28 raeburn 4117: sub contact_titles {
4118: my %titles = &Apache::lonlocal::texthash (
4119: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4120: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4121: 'errormail' => 'Error reports to be e-mailed to',
4122: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4123: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4124: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4125: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4126: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4127: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4128: );
4129: my %short_titles = &Apache::lonlocal::texthash (
4130: adminemail => 'Admin E-mail address',
4131: supportemail => 'Support E-mail',
4132: );
4133: return (\%titles,\%short_titles);
4134: }
4135:
1.72 raeburn 4136: sub tool_titles {
4137: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4138: aboutme => 'Personal web page',
1.86 raeburn 4139: blog => 'Blog',
1.160.6.4 raeburn 4140: webdav => 'WebDAV',
1.86 raeburn 4141: portfolio => 'Portfolio',
1.88 bisitz 4142: official => 'Official courses (with institutional codes)',
4143: unofficial => 'Unofficial courses',
1.98 raeburn 4144: community => 'Communities',
1.160.6.30 raeburn 4145: textbook => 'Textbook courses',
1.86 raeburn 4146: );
1.72 raeburn 4147: return %titles;
4148: }
4149:
1.101 raeburn 4150: sub courserequest_titles {
4151: my %titles = &Apache::lonlocal::texthash (
4152: official => 'Official',
4153: unofficial => 'Unofficial',
4154: community => 'Communities',
1.160.6.30 raeburn 4155: textbook => 'Textbook',
1.101 raeburn 4156: norequest => 'Not allowed',
1.104 raeburn 4157: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4158: validate => 'With validation',
4159: autolimit => 'Numerical limit',
1.103 raeburn 4160: unlimited => '(blank for unlimited)',
1.101 raeburn 4161: );
4162: return %titles;
4163: }
4164:
1.160.6.5 raeburn 4165: sub authorrequest_titles {
4166: my %titles = &Apache::lonlocal::texthash (
4167: norequest => 'Not allowed',
4168: approval => 'Approval by Dom. Coord.',
4169: automatic => 'Automatic approval',
4170: );
4171: return %titles;
4172: }
4173:
1.101 raeburn 4174: sub courserequest_conditions {
4175: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4176: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4177: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4178: );
4179: return %conditions;
4180: }
4181:
4182:
1.27 raeburn 4183: sub print_usercreation {
1.30 raeburn 4184: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4185: my $numinrow = 4;
1.28 raeburn 4186: my $datatable;
4187: if ($position eq 'top') {
1.30 raeburn 4188: $$rowtotal ++;
1.34 raeburn 4189: my $rowcount = 0;
1.32 raeburn 4190: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4191: if (ref($rules) eq 'HASH') {
4192: if (keys(%{$rules}) > 0) {
1.32 raeburn 4193: $datatable .= &user_formats_row('username',$settings,$rules,
4194: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4195: $$rowtotal ++;
1.32 raeburn 4196: $rowcount ++;
4197: }
4198: }
4199: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4200: if (ref($idrules) eq 'HASH') {
4201: if (keys(%{$idrules}) > 0) {
4202: $datatable .= &user_formats_row('id',$settings,$idrules,
4203: $idruleorder,$numinrow,$rowcount);
4204: $$rowtotal ++;
4205: $rowcount ++;
1.28 raeburn 4206: }
4207: }
1.39 raeburn 4208: if ($rowcount == 0) {
4209: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4210: $$rowtotal ++;
4211: $rowcount ++;
4212: }
1.34 raeburn 4213: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4214: my @creators = ('author','course','requestcrs');
1.37 raeburn 4215: my ($rules,$ruleorder) =
4216: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4217: my %lt = &usercreation_types();
4218: my %checked;
4219: if (ref($settings) eq 'HASH') {
4220: if (ref($settings->{'cancreate'}) eq 'HASH') {
4221: foreach my $item (@creators) {
4222: $checked{$item} = $settings->{'cancreate'}{$item};
4223: }
4224: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4225: foreach my $item (@creators) {
4226: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4227: $checked{$item} = 'none';
4228: }
4229: }
4230: }
4231: }
4232: my $rownum = 0;
4233: foreach my $item (@creators) {
4234: $rownum ++;
1.160.6.34 raeburn 4235: if ($checked{$item} eq '') {
4236: $checked{$item} = 'any';
1.34 raeburn 4237: }
4238: my $css_class;
4239: if ($rownum%2) {
4240: $css_class = '';
4241: } else {
4242: $css_class = ' class="LC_odd_row" ';
4243: }
4244: $datatable .= '<tr'.$css_class.'>'.
4245: '<td><span class="LC_nobreak">'.$lt{$item}.
4246: '</span></td><td align="right">';
1.160.6.34 raeburn 4247: my @options = ('any');
4248: if (ref($rules) eq 'HASH') {
4249: if (keys(%{$rules}) > 0) {
4250: push(@options,('official','unofficial'));
1.37 raeburn 4251: }
4252: }
1.160.6.34 raeburn 4253: push(@options,'none');
1.37 raeburn 4254: foreach my $option (@options) {
1.50 raeburn 4255: my $type = 'radio';
1.34 raeburn 4256: my $check = ' ';
1.160.6.34 raeburn 4257: if ($checked{$item} eq $option) {
4258: $check = ' checked="checked" ';
1.34 raeburn 4259: }
4260: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4261: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4262: $item.'" value="'.$option.'"'.$check.'/> '.
4263: $lt{$option}.'</label> </span>';
4264: }
4265: $datatable .= '</td></tr>';
4266: }
1.28 raeburn 4267: } else {
4268: my @contexts = ('author','course','domain');
4269: my @authtypes = ('int','krb4','krb5','loc');
4270: my %checked;
4271: if (ref($settings) eq 'HASH') {
4272: if (ref($settings->{'authtypes'}) eq 'HASH') {
4273: foreach my $item (@contexts) {
4274: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4275: foreach my $auth (@authtypes) {
4276: if ($settings->{'authtypes'}{$item}{$auth}) {
4277: $checked{$item}{$auth} = ' checked="checked" ';
4278: }
4279: }
4280: }
4281: }
1.27 raeburn 4282: }
1.35 raeburn 4283: } else {
4284: foreach my $item (@contexts) {
1.36 raeburn 4285: foreach my $auth (@authtypes) {
1.35 raeburn 4286: $checked{$item}{$auth} = ' checked="checked" ';
4287: }
4288: }
1.27 raeburn 4289: }
1.28 raeburn 4290: my %title = &context_names();
4291: my %authname = &authtype_names();
4292: my $rownum = 0;
4293: my $css_class;
4294: foreach my $item (@contexts) {
4295: if ($rownum%2) {
4296: $css_class = '';
4297: } else {
4298: $css_class = ' class="LC_odd_row" ';
4299: }
1.30 raeburn 4300: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4301: '<td>'.$title{$item}.
4302: '</td><td class="LC_left_item">'.
4303: '<span class="LC_nobreak">';
4304: foreach my $auth (@authtypes) {
4305: $datatable .= '<label>'.
4306: '<input type="checkbox" name="'.$item.'_auth" '.
4307: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4308: $authname{$auth}.'</label> ';
4309: }
4310: $datatable .= '</span></td></tr>';
4311: $rownum ++;
1.27 raeburn 4312: }
1.30 raeburn 4313: $$rowtotal += $rownum;
1.27 raeburn 4314: }
4315: return $datatable;
4316: }
4317:
1.160.6.34 raeburn 4318: sub print_selfcreation {
4319: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4320: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4321: if (ref($settings) eq 'HASH') {
4322: if (ref($settings->{'cancreate'}) eq 'HASH') {
4323: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4324: if (ref($createsettings) eq 'HASH') {
4325: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4326: @selfcreate = @{$createsettings->{'selfcreate'}};
4327: } elsif ($createsettings->{'selfcreate'} ne '') {
4328: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4329: @selfcreate = ('email','login','sso');
4330: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4331: @selfcreate = ($createsettings->{'selfcreate'});
4332: }
4333: }
4334: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4335: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4336: }
4337: }
4338: }
4339: }
4340: my %radiohash;
4341: my $numinrow = 4;
4342: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4343: if ($position eq 'top') {
4344: my %choices = &Apache::lonlocal::texthash (
4345: cancreate_login => 'Institutional Login',
4346: cancreate_sso => 'Institutional Single Sign On',
4347: );
4348: my @toggles = sort(keys(%choices));
4349: my %defaultchecked = (
4350: 'cancreate_login' => 'off',
4351: 'cancreate_sso' => 'off',
4352: );
1.160.6.35 raeburn 4353: my ($onclick,$itemcount);
1.160.6.34 raeburn 4354: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4355: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4356: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4357:
1.160.6.34 raeburn 4358: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4359:
4360: if (ref($usertypes) eq 'HASH') {
4361: if (keys(%{$usertypes}) > 0) {
4362: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4363: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4364: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4365: $$rowtotal ++;
4366: }
4367: }
1.160.6.44 raeburn 4368: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4369: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4370: $fieldtitles{'inststatus'} = &mt('Institutional status');
4371: my $rem;
4372: my $numperrow = 2;
4373: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4374: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4375: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4376: '<td class="LC_left_item">'."\n".
4377: '<table><tr><td>'."\n";
4378: for (my $i=0; $i<@fields; $i++) {
4379: $rem = $i%($numperrow);
4380: if ($rem == 0) {
4381: if ($i > 0) {
4382: $datatable .= '</tr>';
4383: }
4384: $datatable .= '<tr>';
4385: }
4386: my $currval;
1.160.6.51 raeburn 4387: if (ref($createsettings) eq 'HASH') {
4388: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4389: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4390: }
1.160.6.44 raeburn 4391: }
4392: $datatable .= '<td class="LC_left_item">'.
4393: '<span class="LC_nobreak">'.
4394: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4395: 'value="'.$currval.'" size="10" /> '.
4396: $fieldtitles{$fields[$i]}.'</span></td>';
4397: }
4398: my $colsleft = $numperrow - $rem;
4399: if ($colsleft > 1 ) {
4400: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4401: ' </td>';
4402: } elsif ($colsleft == 1) {
4403: $datatable .= '<td class="LC_left_item"> </td>';
4404: }
4405: $datatable .= '</tr></table></td></tr>';
4406: $$rowtotal ++;
1.160.6.34 raeburn 4407: } elsif ($position eq 'middle') {
4408: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4409: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4410: $usertypes->{'default'} = $othertitle;
4411: if (ref($types) eq 'ARRAY') {
4412: push(@{$types},'default');
4413: $usertypes->{'default'} = $othertitle;
4414: foreach my $status (@{$types}) {
4415: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4416: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4417: $$rowtotal ++;
1.160.6.34 raeburn 4418: }
4419: }
4420: } else {
1.160.6.40 raeburn 4421: my %choices = &Apache::lonlocal::texthash (
4422: cancreate_email => 'E-mail address as username',
4423: );
4424: my @toggles = sort(keys(%choices));
4425: my %defaultchecked = (
4426: 'cancreate_email' => 'off',
4427: );
4428: my $itemcount = 0;
4429: my $display = 'none';
4430: if (grep(/^\Qemail\E$/,@selfcreate)) {
4431: $display = 'block';
4432: }
4433: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4434: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4435: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4436: my $usertypes = {};
4437: my $order = [];
4438: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4439: $usertypes = $domdefaults{'inststatustypes'};
4440: $order = $domdefaults{'inststatusguest'};
4441: }
4442: if (ref($order) eq 'ARRAY') {
4443: push(@{$order},'default');
4444: if (@{$order} > 1) {
4445: $usertypes->{'default'} = &mt('Other users');
4446: $additional .= '<table><tr>';
4447: foreach my $status (@{$order}) {
4448: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4449: }
4450: $additional .= '</tr><tr>';
4451: foreach my $status (@{$order}) {
4452: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4453: }
1.160.6.40 raeburn 4454: $additional .= '</tr></table>';
1.160.6.34 raeburn 4455: } else {
1.160.6.40 raeburn 4456: $usertypes->{'default'} = &mt('All users');
4457: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4458: }
4459: }
1.160.6.40 raeburn 4460: $additional .= '</div>'."\n";
4461:
4462: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4463: \%choices,$$rowtotal,$onclick,$additional);
4464: $$rowtotal ++;
1.160.6.40 raeburn 4465: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4466: $$rowtotal ++;
1.160.6.35 raeburn 4467: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4468: $numinrow = 1;
1.160.6.40 raeburn 4469: if (ref($order) eq 'ARRAY') {
4470: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4471: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4472: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4473: $$rowtotal ++;
4474: }
4475: }
1.160.6.34 raeburn 4476: my ($emailrules,$emailruleorder) =
4477: &Apache::lonnet::inst_userrules($dom,'email');
4478: if (ref($emailrules) eq 'HASH') {
4479: if (keys(%{$emailrules}) > 0) {
4480: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4481: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4482: $$rowtotal ++;
4483: }
4484: }
1.160.6.35 raeburn 4485: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4486: }
4487: return $datatable;
4488: }
4489:
1.160.6.40 raeburn 4490: sub email_as_username {
4491: my ($rowtotal,$processing,$type) = @_;
4492: my %choices =
4493: &Apache::lonlocal::texthash (
4494: automatic => 'Automatic approval',
4495: approval => 'Queued for approval',
4496: );
4497: my $output;
4498: foreach my $option ('automatic','approval') {
4499: my $checked;
4500: if (ref($processing) eq 'HASH') {
4501: if ($type eq '') {
4502: if (!exists($processing->{'default'})) {
4503: if ($option eq 'automatic') {
4504: $checked = ' checked="checked"';
4505: }
4506: } else {
4507: if ($processing->{'default'} eq $option) {
4508: $checked = ' checked="checked"';
4509: }
4510: }
4511: } else {
4512: if (!exists($processing->{$type})) {
4513: if ($option eq 'automatic') {
4514: $checked = ' checked="checked"';
4515: }
4516: } else {
4517: if ($processing->{$type} eq $option) {
4518: $checked = ' checked="checked"';
4519: }
4520: }
4521: }
4522: } elsif ($option eq 'automatic') {
4523: $checked = ' checked="checked"';
4524: }
4525: my $name = 'cancreate_emailprocess';
4526: if (($type ne '') && ($type ne 'default')) {
4527: $name .= '_'.$type;
4528: }
4529: $output .= '<span class="LC_nobreak"><label>'.
4530: '<input type="radio" name="'.$name.'"'.
4531: $checked.' value="'.$option.'" />'.
4532: $choices{$option}.'</label></span>';
4533: if ($type eq '') {
4534: $output .= ' ';
4535: } else {
4536: $output .= '<br />';
4537: }
4538: }
4539: $$rowtotal ++;
4540: return $output;
4541: }
4542:
1.160.6.5 raeburn 4543: sub captcha_choice {
4544: my ($context,$settings,$itemcount) = @_;
1.160.6.69! raeburn 4545: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
! 4546: $vertext,$currver);
1.160.6.5 raeburn 4547: my %lt = &captcha_phrases();
4548: $keyentry = 'hidden';
4549: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4550: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4551: } elsif ($context eq 'login') {
4552: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4553: }
4554: if (ref($settings) eq 'HASH') {
4555: if ($settings->{'captcha'}) {
4556: $checked{$settings->{'captcha'}} = ' checked="checked"';
4557: } else {
4558: $checked{'original'} = ' checked="checked"';
4559: }
4560: if ($settings->{'captcha'} eq 'recaptcha') {
4561: $pubtext = $lt{'pub'};
4562: $privtext = $lt{'priv'};
4563: $keyentry = 'text';
1.160.6.69! raeburn 4564: $vertext = $lt{'ver'};
! 4565: $currver = $settings->{'recaptchaversion'};
! 4566: if ($currver ne '2') {
! 4567: $currver = 1;
! 4568: }
1.160.6.5 raeburn 4569: }
4570: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4571: $currpub = $settings->{'recaptchakeys'}{'public'};
4572: $currpriv = $settings->{'recaptchakeys'}{'private'};
4573: }
4574: } else {
4575: $checked{'original'} = ' checked="checked"';
4576: }
4577: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4578: my $output = '<tr'.$css_class.'>'.
4579: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4580: '<table><tr><td>'."\n";
4581: foreach my $option ('original','recaptcha','notused') {
4582: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4583: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4584: $lt{$option}.'</label></span>';
4585: unless ($option eq 'notused') {
4586: $output .= (' 'x2)."\n";
4587: }
4588: }
4589: #
4590: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4591: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4592: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4593: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4594: #
4595: $output .= '</td></tr>'."\n".
4596: '<tr><td>'."\n".
4597: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4598: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4599: $currpub.'" size="40" /></span><br />'."\n".
4600: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4601: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69! raeburn 4602: $currpriv.'" size="40" /></span><br />'.
! 4603: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
! 4604: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
! 4605: $currver.'" size="3" /></span><br />'.
! 4606: '</td></tr></table>'."\n".
1.160.6.5 raeburn 4607: '</td></tr>';
4608: return $output;
4609: }
4610:
1.32 raeburn 4611: sub user_formats_row {
4612: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4613: my $output;
4614: my %text = (
4615: 'username' => 'new usernames',
4616: 'id' => 'IDs',
1.45 raeburn 4617: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4618: );
4619: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4620: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4621: '<td><span class="LC_nobreak">';
4622: if ($type eq 'email') {
4623: $output .= &mt("Formats disallowed for $text{$type}: ");
4624: } else {
4625: $output .= &mt("Format rules to check for $text{$type}: ");
4626: }
4627: $output .= '</span></td>'.
4628: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4629: my $rem;
4630: if (ref($ruleorder) eq 'ARRAY') {
4631: for (my $i=0; $i<@{$ruleorder}; $i++) {
4632: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4633: my $rem = $i%($numinrow);
4634: if ($rem == 0) {
4635: if ($i > 0) {
4636: $output .= '</tr>';
4637: }
4638: $output .= '<tr>';
4639: }
4640: my $check = ' ';
1.39 raeburn 4641: if (ref($settings) eq 'HASH') {
4642: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4643: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4644: $check = ' checked="checked" ';
4645: }
1.27 raeburn 4646: }
4647: }
4648: $output .= '<td class="LC_left_item">'.
4649: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4650: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4651: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4652: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4653: }
4654: }
4655: $rem = @{$ruleorder}%($numinrow);
4656: }
4657: my $colsleft = $numinrow - $rem;
4658: if ($colsleft > 1 ) {
4659: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4660: ' </td>';
4661: } elsif ($colsleft == 1) {
4662: $output .= '<td class="LC_left_item"> </td>';
4663: }
4664: $output .= '</tr></table></td></tr>';
4665: return $output;
4666: }
4667:
1.34 raeburn 4668: sub usercreation_types {
4669: my %lt = &Apache::lonlocal::texthash (
4670: author => 'When adding a co-author',
4671: course => 'When adding a user to a course',
1.100 raeburn 4672: requestcrs => 'When requesting a course',
1.34 raeburn 4673: any => 'Any',
4674: official => 'Institutional only ',
4675: unofficial => 'Non-institutional only',
4676: none => 'None',
4677: );
4678: return %lt;
1.48 raeburn 4679: }
1.34 raeburn 4680:
1.160.6.34 raeburn 4681: sub selfcreation_types {
4682: my %lt = &Apache::lonlocal::texthash (
4683: selfcreate => 'User creates own account',
4684: any => 'Any',
4685: official => 'Institutional only ',
4686: unofficial => 'Non-institutional only',
4687: email => 'E-mail address',
4688: login => 'Institutional Login',
4689: sso => 'SSO',
4690: );
4691: }
4692:
1.28 raeburn 4693: sub authtype_names {
4694: my %lt = &Apache::lonlocal::texthash(
4695: int => 'Internal',
4696: krb4 => 'Kerberos 4',
4697: krb5 => 'Kerberos 5',
4698: loc => 'Local',
4699: );
4700: return %lt;
4701: }
4702:
4703: sub context_names {
4704: my %context_title = &Apache::lonlocal::texthash(
4705: author => 'Creating users when an Author',
4706: course => 'Creating users when in a course',
4707: domain => 'Creating users when a Domain Coordinator',
4708: );
4709: return %context_title;
4710: }
4711:
1.33 raeburn 4712: sub print_usermodification {
4713: my ($position,$dom,$settings,$rowtotal) = @_;
4714: my $numinrow = 4;
4715: my ($context,$datatable,$rowcount);
4716: if ($position eq 'top') {
4717: $rowcount = 0;
4718: $context = 'author';
4719: foreach my $role ('ca','aa') {
4720: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4721: $numinrow,$rowcount);
4722: $$rowtotal ++;
4723: $rowcount ++;
4724: }
1.160.6.37 raeburn 4725: } elsif ($position eq 'bottom') {
1.33 raeburn 4726: $context = 'course';
4727: $rowcount = 0;
4728: foreach my $role ('st','ep','ta','in','cr') {
4729: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4730: $numinrow,$rowcount);
4731: $$rowtotal ++;
4732: $rowcount ++;
4733: }
4734: }
4735: return $datatable;
4736: }
4737:
1.43 raeburn 4738: sub print_defaults {
1.160.6.40 raeburn 4739: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4740: my $rownum = 0;
4741: my ($datatable,$css_class);
1.160.6.40 raeburn 4742: if ($position eq 'top') {
4743: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4744: 'datelocale_def','portal_def');
4745: my %defaults;
4746: if (ref($settings) eq 'HASH') {
4747: %defaults = %{$settings};
1.43 raeburn 4748: } else {
1.160.6.40 raeburn 4749: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4750: foreach my $item (@items) {
4751: $defaults{$item} = $domdefaults{$item};
4752: }
1.43 raeburn 4753: }
1.160.6.40 raeburn 4754: my $titles = &defaults_titles($dom);
4755: foreach my $item (@items) {
4756: if ($rownum%2) {
4757: $css_class = '';
4758: } else {
4759: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4760: }
1.160.6.40 raeburn 4761: $datatable .= '<tr'.$css_class.'>'.
4762: '<td><span class="LC_nobreak">'.$titles->{$item}.
4763: '</span></td><td class="LC_right_item" colspan="3">';
4764: if ($item eq 'auth_def') {
4765: my @authtypes = ('internal','krb4','krb5','localauth');
4766: my %shortauth = (
4767: internal => 'int',
4768: krb4 => 'krb4',
4769: krb5 => 'krb5',
4770: localauth => 'loc'
4771: );
4772: my %authnames = &authtype_names();
4773: foreach my $auth (@authtypes) {
4774: my $checked = ' ';
4775: if ($defaults{$item} eq $auth) {
4776: $checked = ' checked="checked" ';
4777: }
4778: $datatable .= '<label><input type="radio" name="'.$item.
4779: '" value="'.$auth.'"'.$checked.'/>'.
4780: $authnames{$shortauth{$auth}}.'</label> ';
4781: }
4782: } elsif ($item eq 'timezone_def') {
4783: my $includeempty = 1;
4784: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4785: } elsif ($item eq 'datelocale_def') {
4786: my $includeempty = 1;
4787: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4788: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4789: my $includeempty = 1;
4790: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4791: } else {
4792: my $size;
4793: if ($item eq 'portal_def') {
4794: $size = ' size="25"';
4795: }
4796: $datatable .= '<input type="text" name="'.$item.'" value="'.
4797: $defaults{$item}.'"'.$size.' />';
4798: }
4799: $datatable .= '</td></tr>';
4800: $rownum ++;
4801: }
4802: } else {
4803: my (%defaults);
4804: if (ref($settings) eq 'HASH') {
4805: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4806: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4807: my $maxnum = @{$settings->{'inststatusorder'}};
4808: for (my $i=0; $i<$maxnum; $i++) {
4809: $css_class = $rownum%2?' class="LC_odd_row"':'';
4810: my $item = $settings->{'inststatusorder'}->[$i];
4811: my $title = $settings->{'inststatustypes'}->{$item};
4812: my $guestok;
4813: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4814: $guestok = 1;
4815: }
4816: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4817: $datatable .= '<tr'.$css_class.'>'.
4818: '<td><span class="LC_nobreak">'.
4819: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4820: for (my $k=0; $k<=$maxnum; $k++) {
4821: my $vpos = $k+1;
4822: my $selstr;
4823: if ($k == $i) {
4824: $selstr = ' selected="selected" ';
4825: }
4826: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4827: }
4828: my ($checkedon,$checkedoff);
4829: $checkedoff = ' checked="checked"';
4830: if ($guestok) {
4831: $checkedon = $checkedoff;
4832: $checkedoff = '';
4833: }
4834: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4835: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4836: &mt('delete').'</span></td>'.
4837: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4838: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4839: '</span></td>'.
4840: '<td class="LC_right_item"><span class="LC_nobreak">'.
4841: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4842: &mt('Yes').'</label>'.(' 'x2).
4843: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4844: &mt('No').'</label></span></td></tr>';
4845: }
4846: $css_class = $rownum%2?' class="LC_odd_row"':'';
4847: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4848: $datatable .= '<tr '.$css_class.'>'.
4849: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4850: for (my $k=0; $k<=$maxnum; $k++) {
4851: my $vpos = $k+1;
4852: my $selstr;
4853: if ($k == $maxnum) {
4854: $selstr = ' selected="selected" ';
4855: }
4856: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4857: }
4858: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 4859: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 4860: ' '.&mt('(new)').
4861: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4862: &mt('Name displayed:').
4863: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4864: '<td class="LC_right_item"><span class="LC_nobreak">'.
4865: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4866: &mt('Yes').'</label>'.(' 'x2).
4867: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4868: &mt('No').'</label></span></td></tr>';
4869: '</tr>'."\n";
4870: $rownum ++;
1.141 raeburn 4871: }
1.43 raeburn 4872: }
4873: }
4874: $$rowtotal += $rownum;
4875: return $datatable;
4876: }
4877:
1.160.6.5 raeburn 4878: sub get_languages_hash {
4879: my %langchoices;
4880: foreach my $id (&Apache::loncommon::languageids()) {
4881: my $code = &Apache::loncommon::supportedlanguagecode($id);
4882: if ($code ne '') {
4883: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4884: }
4885: }
4886: return %langchoices;
4887: }
4888:
1.43 raeburn 4889: sub defaults_titles {
1.141 raeburn 4890: my ($dom) = @_;
1.43 raeburn 4891: my %titles = &Apache::lonlocal::texthash (
4892: 'auth_def' => 'Default authentication type',
4893: 'auth_arg_def' => 'Default authentication argument',
4894: 'lang_def' => 'Default language',
1.54 raeburn 4895: 'timezone_def' => 'Default timezone',
1.68 raeburn 4896: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4897: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4898: );
1.141 raeburn 4899: if ($dom) {
4900: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4901: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4902: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4903: $protocol = 'http' if ($protocol ne 'https');
4904: if ($uint_dom) {
4905: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4906: $uint_dom);
4907: }
4908: }
1.43 raeburn 4909: return (\%titles);
4910: }
4911:
1.46 raeburn 4912: sub print_scantronformat {
4913: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4914: my $itemcount = 1;
1.60 raeburn 4915: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4916: %confhash);
1.46 raeburn 4917: my $switchserver = &check_switchserver($dom,$confname);
4918: my %lt = &Apache::lonlocal::texthash (
1.95 www 4919: default => 'Default bubblesheet format file error',
4920: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4921: );
4922: my %scantronfiles = (
4923: default => 'default.tab',
4924: custom => 'custom.tab',
4925: );
4926: foreach my $key (keys(%scantronfiles)) {
4927: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4928: .$scantronfiles{$key};
4929: }
4930: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4931: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4932: if (!$switchserver) {
4933: my $servadm = $r->dir_config('lonAdmEMail');
4934: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4935: if ($configuserok eq 'ok') {
4936: if ($author_ok eq 'ok') {
4937: my %legacyfile = (
4938: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4939: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4940: );
4941: my %md5chk;
4942: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4943: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4944: chomp($md5chk{$type});
1.46 raeburn 4945: }
4946: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4947: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4948: ($scantronurls{$type},my $error) =
1.46 raeburn 4949: &legacy_scantronformat($r,$dom,$confname,
4950: $type,$legacyfile{$type},
4951: $scantronurls{$type},
4952: $scantronfiles{$type});
1.60 raeburn 4953: if ($error ne '') {
4954: $error{$type} = $error;
4955: }
4956: }
4957: if (keys(%error) == 0) {
4958: $is_custom = 1;
4959: $confhash{'scantron'}{'scantronformat'} =
4960: $scantronurls{'custom'};
4961: my $putresult =
4962: &Apache::lonnet::put_dom('configuration',
4963: \%confhash,$dom);
4964: if ($putresult ne 'ok') {
4965: $error{'custom'} =
4966: '<span class="LC_error">'.
4967: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4968: }
1.46 raeburn 4969: }
4970: } else {
1.60 raeburn 4971: ($scantronurls{'default'},my $error) =
1.46 raeburn 4972: &legacy_scantronformat($r,$dom,$confname,
4973: 'default',$legacyfile{'default'},
4974: $scantronurls{'default'},
4975: $scantronfiles{'default'});
1.60 raeburn 4976: if ($error eq '') {
4977: $confhash{'scantron'}{'scantronformat'} = '';
4978: my $putresult =
4979: &Apache::lonnet::put_dom('configuration',
4980: \%confhash,$dom);
4981: if ($putresult ne 'ok') {
4982: $error{'default'} =
4983: '<span class="LC_error">'.
4984: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4985: }
4986: } else {
4987: $error{'default'} = $error;
4988: }
1.46 raeburn 4989: }
4990: }
4991: }
4992: } else {
1.95 www 4993: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4994: }
4995: }
4996: if (ref($settings) eq 'HASH') {
4997: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4998: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4999: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5000: $scantronurl = '';
5001: } else {
5002: $scantronurl = $settings->{'scantronformat'};
5003: }
5004: $is_custom = 1;
5005: } else {
5006: $scantronurl = $scantronurls{'default'};
5007: }
5008: } else {
1.60 raeburn 5009: if ($is_custom) {
5010: $scantronurl = $scantronurls{'custom'};
5011: } else {
5012: $scantronurl = $scantronurls{'default'};
5013: }
1.46 raeburn 5014: }
5015: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5016: $datatable .= '<tr'.$css_class.'>';
5017: if (!$is_custom) {
1.65 raeburn 5018: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5019: '<span class="LC_nobreak">';
1.46 raeburn 5020: if ($scantronurl) {
1.160.6.21 raeburn 5021: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5022: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5023: } else {
5024: $datatable = &mt('File unavailable for display');
5025: }
1.65 raeburn 5026: $datatable .= '</span></td>';
1.60 raeburn 5027: if (keys(%error) == 0) {
5028: $datatable .= '<td valign="bottom">';
5029: if (!$switchserver) {
5030: $datatable .= &mt('Upload:').'<br />';
5031: }
5032: } else {
5033: my $errorstr;
5034: foreach my $key (sort(keys(%error))) {
5035: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5036: }
5037: $datatable .= '<td>'.$errorstr;
5038: }
1.46 raeburn 5039: } else {
5040: if (keys(%error) > 0) {
5041: my $errorstr;
5042: foreach my $key (sort(keys(%error))) {
5043: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5044: }
1.60 raeburn 5045: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5046: } elsif ($scantronurl) {
1.160.6.26 raeburn 5047: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5048: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5049: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5050: $link.
5051: '<label><input type="checkbox" name="scantronformat_del"'.
5052: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5053: '<td><span class="LC_nobreak"> '.
5054: &mt('Replace:').'</span><br />';
1.46 raeburn 5055: }
5056: }
5057: if (keys(%error) == 0) {
5058: if ($switchserver) {
5059: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5060: } else {
1.65 raeburn 5061: $datatable .='<span class="LC_nobreak"> '.
5062: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5063: }
5064: }
5065: $datatable .= '</td></tr>';
5066: $$rowtotal ++;
5067: return $datatable;
5068: }
5069:
5070: sub legacy_scantronformat {
5071: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5072: my ($url,$error);
5073: my @statinfo = &Apache::lonnet::stat_file($newurl);
5074: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5075: (my $result,$url) =
5076: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5077: '','',$newfile);
5078: if ($result ne 'ok') {
1.130 raeburn 5079: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5080: }
5081: }
5082: return ($url,$error);
5083: }
1.43 raeburn 5084:
1.49 raeburn 5085: sub print_coursecategories {
1.57 raeburn 5086: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5087: my $datatable;
5088: if ($position eq 'top') {
1.160.6.42 raeburn 5089: my (%checked);
5090: my @catitems = ('unauth','auth');
5091: my @cattypes = ('std','domonly','codesrch','none');
5092: $checked{'unauth'} = 'std';
5093: $checked{'auth'} = 'std';
5094: if (ref($settings) eq 'HASH') {
5095: foreach my $type (@cattypes) {
5096: if ($type eq $settings->{'unauth'}) {
5097: $checked{'unauth'} = $type;
5098: }
5099: if ($type eq $settings->{'auth'}) {
5100: $checked{'auth'} = $type;
5101: }
5102: }
5103: }
5104: my %lt = &Apache::lonlocal::texthash (
5105: unauth => 'Catalog type for unauthenticated users',
5106: auth => 'Catalog type for authenticated users',
5107: none => 'No catalog',
5108: std => 'Standard catalog',
5109: domonly => 'Domain-only catalog',
5110: codesrch => "Code search form",
5111: );
5112: my $itemcount = 0;
5113: foreach my $item (@catitems) {
5114: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5115: $datatable .= '<tr '.$css_class.'>'.
5116: '<td>'.$lt{$item}.'</td>'.
5117: '<td class="LC_right_item"><span class="LC_nobreak">';
5118: foreach my $type (@cattypes) {
5119: my $ischecked;
5120: if ($checked{$item} eq $type) {
5121: $ischecked=' checked="checked"';
5122: }
5123: $datatable .= '<label>'.
5124: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5125: ' />'.$lt{$type}.'</label> ';
5126: }
5127: $datatable .= '</td></tr>';
5128: $itemcount ++;
5129: }
5130: $$rowtotal += $itemcount;
5131: } elsif ($position eq 'middle') {
1.57 raeburn 5132: my $toggle_cats_crs = ' ';
5133: my $toggle_cats_dom = ' checked="checked" ';
5134: my $can_cat_crs = ' ';
5135: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5136: my $toggle_catscomm_comm = ' ';
5137: my $toggle_catscomm_dom = ' checked="checked" ';
5138: my $can_catcomm_comm = ' ';
5139: my $can_catcomm_dom = ' checked="checked" ';
5140:
1.57 raeburn 5141: if (ref($settings) eq 'HASH') {
5142: if ($settings->{'togglecats'} eq 'crs') {
5143: $toggle_cats_crs = $toggle_cats_dom;
5144: $toggle_cats_dom = ' ';
5145: }
5146: if ($settings->{'categorize'} eq 'crs') {
5147: $can_cat_crs = $can_cat_dom;
5148: $can_cat_dom = ' ';
5149: }
1.120 raeburn 5150: if ($settings->{'togglecatscomm'} eq 'comm') {
5151: $toggle_catscomm_comm = $toggle_catscomm_dom;
5152: $toggle_catscomm_dom = ' ';
5153: }
5154: if ($settings->{'categorizecomm'} eq 'comm') {
5155: $can_catcomm_comm = $can_catcomm_dom;
5156: $can_catcomm_dom = ' ';
5157: }
1.57 raeburn 5158: }
5159: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5160: togglecats => 'Show/Hide a course in catalog',
5161: togglecatscomm => 'Show/Hide a community in catalog',
5162: categorize => 'Assign a category to a course',
5163: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5164: );
5165: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5166: dom => 'Set in Domain',
5167: crs => 'Set in Course',
5168: comm => 'Set in Community',
1.57 raeburn 5169: );
5170: $datatable = '<tr class="LC_odd_row">'.
5171: '<td>'.$title{'togglecats'}.'</td>'.
5172: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5173: '<input type="radio" name="togglecats"'.
5174: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5175: '<label><input type="radio" name="togglecats"'.
5176: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5177: '</tr><tr>'.
5178: '<td>'.$title{'categorize'}.'</td>'.
5179: '<td class="LC_right_item"><span class="LC_nobreak">'.
5180: '<label><input type="radio" name="categorize"'.
5181: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5182: '<label><input type="radio" name="categorize"'.
5183: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5184: '</tr><tr class="LC_odd_row">'.
5185: '<td>'.$title{'togglecatscomm'}.'</td>'.
5186: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5187: '<input type="radio" name="togglecatscomm"'.
5188: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5189: '<label><input type="radio" name="togglecatscomm"'.
5190: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5191: '</tr><tr>'.
5192: '<td>'.$title{'categorizecomm'}.'</td>'.
5193: '<td class="LC_right_item"><span class="LC_nobreak">'.
5194: '<label><input type="radio" name="categorizecomm"'.
5195: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5196: '<label><input type="radio" name="categorizecomm"'.
5197: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5198: '</tr>';
1.120 raeburn 5199: $$rowtotal += 4;
1.57 raeburn 5200: } else {
5201: my $css_class;
5202: my $itemcount = 1;
5203: my $cathash;
5204: if (ref($settings) eq 'HASH') {
5205: $cathash = $settings->{'cats'};
5206: }
5207: if (ref($cathash) eq 'HASH') {
5208: my (@cats,@trails,%allitems,%idx,@jsarray);
5209: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5210: \%allitems,\%idx,\@jsarray);
5211: my $maxdepth = scalar(@cats);
5212: my $colattrib = '';
5213: if ($maxdepth > 2) {
5214: $colattrib = ' colspan="2" ';
5215: }
5216: my @path;
5217: if (@cats > 0) {
5218: if (ref($cats[0]) eq 'ARRAY') {
5219: my $numtop = @{$cats[0]};
5220: my $maxnum = $numtop;
1.120 raeburn 5221: my %default_names = (
5222: instcode => &mt('Official courses'),
5223: communities => &mt('Communities'),
5224: );
5225:
5226: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5227: ($cathash->{'instcode::0'} eq '') ||
5228: (!grep(/^communities$/,@{$cats[0]})) ||
5229: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5230: $maxnum ++;
5231: }
5232: my $lastidx;
5233: for (my $i=0; $i<$numtop; $i++) {
5234: my $parent = $cats[0][$i];
5235: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5236: my $item = &escape($parent).'::0';
5237: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5238: $lastidx = $idx{$item};
5239: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5240: .'<select name="'.$item.'"'.$chgstr.'>';
5241: for (my $k=0; $k<=$maxnum; $k++) {
5242: my $vpos = $k+1;
5243: my $selstr;
5244: if ($k == $i) {
5245: $selstr = ' selected="selected" ';
5246: }
5247: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5248: }
1.160.6.29 raeburn 5249: $datatable .= '</select></span></td><td>';
1.120 raeburn 5250: if ($parent eq 'instcode' || $parent eq 'communities') {
5251: $datatable .= '<span class="LC_nobreak">'
5252: .$default_names{$parent}.'</span>';
5253: if ($parent eq 'instcode') {
5254: $datatable .= '<br /><span class="LC_nobreak">('
5255: .&mt('with institutional codes')
5256: .')</span></td><td'.$colattrib.'>';
5257: } else {
5258: $datatable .= '<table><tr><td>';
5259: }
5260: $datatable .= '<span class="LC_nobreak">'
5261: .'<label><input type="radio" name="'
5262: .$parent.'" value="1" checked="checked" />'
5263: .&mt('Display').'</label>';
5264: if ($parent eq 'instcode') {
5265: $datatable .= ' ';
5266: } else {
5267: $datatable .= '</span></td></tr><tr><td>'
5268: .'<span class="LC_nobreak">';
5269: }
5270: $datatable .= '<label><input type="radio" name="'
5271: .$parent.'" value="0" />'
5272: .&mt('Do not display').'</label></span>';
5273: if ($parent eq 'communities') {
5274: $datatable .= '</td></tr></table>';
5275: }
5276: $datatable .= '</td>';
1.57 raeburn 5277: } else {
5278: $datatable .= $parent
1.160.6.29 raeburn 5279: .' <span class="LC_nobreak"><label>'
5280: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5281: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5282: }
5283: my $depth = 1;
5284: push(@path,$parent);
5285: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5286: pop(@path);
5287: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5288: $itemcount ++;
5289: }
1.48 raeburn 5290: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5291: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5292: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5293: for (my $k=0; $k<=$maxnum; $k++) {
5294: my $vpos = $k+1;
5295: my $selstr;
1.57 raeburn 5296: if ($k == $numtop) {
1.48 raeburn 5297: $selstr = ' selected="selected" ';
5298: }
5299: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5300: }
1.59 bisitz 5301: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5302: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5303: .'</tr>'."\n";
1.48 raeburn 5304: $itemcount ++;
1.120 raeburn 5305: foreach my $default ('instcode','communities') {
5306: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5307: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5308: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5309: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5310: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5311: for (my $k=0; $k<=$maxnum; $k++) {
5312: my $vpos = $k+1;
5313: my $selstr;
5314: if ($k == $maxnum) {
5315: $selstr = ' selected="selected" ';
5316: }
5317: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5318: }
1.120 raeburn 5319: $datatable .= '</select></span></td>'.
5320: '<td><span class="LC_nobreak">'.
5321: $default_names{$default}.'</span>';
5322: if ($default eq 'instcode') {
5323: $datatable .= '<br /><span class="LC_nobreak">('
5324: .&mt('with institutional codes').')</span>';
5325: }
5326: $datatable .= '</td>'
5327: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5328: .&mt('Display').'</label> '
5329: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5330: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5331: }
5332: }
5333: }
1.57 raeburn 5334: } else {
5335: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5336: }
5337: } else {
1.160.6.42 raeburn 5338: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5339: .&initialize_categories($itemcount);
1.48 raeburn 5340: }
1.57 raeburn 5341: $$rowtotal += $itemcount;
1.48 raeburn 5342: }
5343: return $datatable;
5344: }
5345:
1.69 raeburn 5346: sub print_serverstatuses {
5347: my ($dom,$settings,$rowtotal) = @_;
5348: my $datatable;
5349: my @pages = &serverstatus_pages();
5350: my (%namedaccess,%machineaccess);
5351: foreach my $type (@pages) {
5352: $namedaccess{$type} = '';
5353: $machineaccess{$type}= '';
5354: }
5355: if (ref($settings) eq 'HASH') {
5356: foreach my $type (@pages) {
5357: if (exists($settings->{$type})) {
5358: if (ref($settings->{$type}) eq 'HASH') {
5359: foreach my $key (keys(%{$settings->{$type}})) {
5360: if ($key eq 'namedusers') {
5361: $namedaccess{$type} = $settings->{$type}->{$key};
5362: } elsif ($key eq 'machines') {
5363: $machineaccess{$type} = $settings->{$type}->{$key};
5364: }
5365: }
5366: }
5367: }
5368: }
5369: }
1.81 raeburn 5370: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5371: my $rownum = 0;
5372: my $css_class;
5373: foreach my $type (@pages) {
5374: $rownum ++;
5375: $css_class = $rownum%2?' class="LC_odd_row"':'';
5376: $datatable .= '<tr'.$css_class.'>'.
5377: '<td><span class="LC_nobreak">'.
5378: $titles->{$type}.'</span></td>'.
5379: '<td class="LC_left_item">'.
5380: '<input type="text" name="'.$type.'_namedusers" '.
5381: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5382: '<td class="LC_right_item">'.
5383: '<span class="LC_nobreak">'.
5384: '<input type="text" name="'.$type.'_machines" '.
5385: 'value="'.$machineaccess{$type}.'" size="10" />'.
5386: '</td></tr>'."\n";
5387: }
5388: $$rowtotal += $rownum;
5389: return $datatable;
5390: }
5391:
5392: sub serverstatus_pages {
5393: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5394: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5395: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5396: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5397: }
5398:
1.160.6.40 raeburn 5399: sub defaults_javascript {
5400: my ($settings) = @_;
1.160.6.51 raeburn 5401: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5402: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5403: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5404: if ($maxnum eq '') {
5405: $maxnum = 0;
5406: }
5407: $maxnum ++;
1.160.6.51 raeburn 5408: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5409: return <<"ENDSCRIPT";
5410: <script type="text/javascript">
5411: // <![CDATA[
5412: function reorderTypes(form,caller) {
5413: var changedVal;
5414: $jstext
5415: var newpos = 'addinststatus_pos';
5416: var current = new Array;
5417: var maxh = $maxnum;
5418: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5419: var oldVal;
5420: if (caller == newpos) {
5421: changedVal = newitemVal;
5422: } else {
5423: var curritem = 'inststatus_pos_'+caller;
5424: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5425: current[newitemVal] = newpos;
5426: }
5427: for (var i=0; i<inststatuses.length; i++) {
5428: if (inststatuses[i] != caller) {
5429: var elementName = 'inststatus_pos_'+inststatuses[i];
5430: if (form.elements[elementName]) {
5431: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5432: current[currVal] = elementName;
5433: }
5434: }
5435: }
5436: for (var j=0; j<maxh; j++) {
5437: if (current[j] == undefined) {
5438: oldVal = j;
5439: }
5440: }
5441: if (oldVal < changedVal) {
5442: for (var k=oldVal+1; k<=changedVal ; k++) {
5443: var elementName = current[k];
5444: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5445: }
5446: } else {
5447: for (var k=changedVal; k<oldVal; k++) {
5448: var elementName = current[k];
5449: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5450: }
5451: }
5452: return;
5453: }
5454:
5455: // ]]>
5456: </script>
5457:
5458: ENDSCRIPT
5459: }
5460: }
5461:
1.49 raeburn 5462: sub coursecategories_javascript {
5463: my ($settings) = @_;
1.57 raeburn 5464: my ($output,$jstext,$cathash);
1.49 raeburn 5465: if (ref($settings) eq 'HASH') {
1.57 raeburn 5466: $cathash = $settings->{'cats'};
5467: }
5468: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5469: my (@cats,@jsarray,%idx);
1.57 raeburn 5470: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5471: if (@jsarray > 0) {
5472: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5473: for (my $i=0; $i<@jsarray; $i++) {
5474: if (ref($jsarray[$i]) eq 'ARRAY') {
5475: my $catstr = join('","',@{$jsarray[$i]});
5476: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5477: }
5478: }
5479: }
5480: } else {
5481: $jstext = ' var categories = Array(1);'."\n".
5482: ' categories[0] = Array("instcode_pos");'."\n";
5483: }
1.160.6.42 raeburn 5484: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5485: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5486: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5487: &js_escape(\$instcode_reserved);
5488: &js_escape(\$communities_reserved);
5489: &js_escape(\$choose_again);
1.49 raeburn 5490: $output = <<"ENDSCRIPT";
5491: <script type="text/javascript">
1.109 raeburn 5492: // <![CDATA[
1.49 raeburn 5493: function reorderCats(form,parent,item,idx) {
5494: var changedVal;
5495: $jstext
5496: var newpos = 'addcategory_pos';
5497: if (parent == '') {
5498: var has_instcode = 0;
5499: var maxtop = categories[idx].length;
5500: for (var j=0; j<maxtop; j++) {
5501: if (categories[idx][j] == 'instcode::0') {
5502: has_instcode == 1;
5503: }
5504: }
5505: if (has_instcode == 0) {
5506: categories[idx][maxtop] = 'instcode_pos';
5507: }
5508: } else {
5509: newpos += '_'+parent;
5510: }
5511: var maxh = 1 + categories[idx].length;
5512: var current = new Array;
5513: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5514: if (item == newpos) {
5515: changedVal = newitemVal;
5516: } else {
5517: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5518: current[newitemVal] = newpos;
5519: }
5520: for (var i=0; i<categories[idx].length; i++) {
5521: var elementName = categories[idx][i];
5522: if (elementName != item) {
5523: if (form.elements[elementName]) {
5524: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5525: current[currVal] = elementName;
5526: }
5527: }
5528: }
5529: var oldVal;
5530: for (var j=0; j<maxh; j++) {
5531: if (current[j] == undefined) {
5532: oldVal = j;
5533: }
5534: }
5535: if (oldVal < changedVal) {
5536: for (var k=oldVal+1; k<=changedVal ; k++) {
5537: var elementName = current[k];
5538: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5539: }
5540: } else {
5541: for (var k=changedVal; k<oldVal; k++) {
5542: var elementName = current[k];
5543: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5544: }
5545: }
5546: return;
5547: }
1.120 raeburn 5548:
5549: function categoryCheck(form) {
5550: if (form.elements['addcategory_name'].value == 'instcode') {
5551: alert('$instcode_reserved\\n$choose_again');
5552: return false;
5553: }
5554: if (form.elements['addcategory_name'].value == 'communities') {
5555: alert('$communities_reserved\\n$choose_again');
5556: return false;
5557: }
5558: return true;
5559: }
5560:
1.109 raeburn 5561: // ]]>
1.49 raeburn 5562: </script>
5563:
5564: ENDSCRIPT
5565: return $output;
5566: }
5567:
1.48 raeburn 5568: sub initialize_categories {
5569: my ($itemcount) = @_;
1.120 raeburn 5570: my ($datatable,$css_class,$chgstr);
5571: my %default_names = (
5572: instcode => 'Official courses (with institutional codes)',
5573: communities => 'Communities',
5574: );
5575: my $select0 = ' selected="selected"';
5576: my $select1 = '';
5577: foreach my $default ('instcode','communities') {
5578: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5579: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5580: if ($default eq 'communities') {
5581: $select1 = $select0;
5582: $select0 = '';
5583: }
5584: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5585: .'<select name="'.$default.'_pos">'
5586: .'<option value="0"'.$select0.'>1</option>'
5587: .'<option value="1"'.$select1.'>2</option>'
5588: .'<option value="2">3</option></select> '
5589: .$default_names{$default}
5590: .'</span></td><td><span class="LC_nobreak">'
5591: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5592: .&mt('Display').'</label> <label>'
5593: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5594: .'</label></span></td></tr>';
1.120 raeburn 5595: $itemcount ++;
5596: }
1.48 raeburn 5597: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5598: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5599: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5600: .'<select name="addcategory_pos"'.$chgstr.'>'
5601: .'<option value="0">1</option>'
5602: .'<option value="1">2</option>'
5603: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5604: .&mt('Add category').'</td><td>'.&mt('Name:')
5605: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5606: return $datatable;
5607: }
5608:
5609: sub build_category_rows {
1.49 raeburn 5610: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5611: my ($text,$name,$item,$chgstr);
1.48 raeburn 5612: if (ref($cats) eq 'ARRAY') {
5613: my $maxdepth = scalar(@{$cats});
5614: if (ref($cats->[$depth]) eq 'HASH') {
5615: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5616: my $numchildren = @{$cats->[$depth]{$parent}};
5617: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5618: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5619: my ($idxnum,$parent_name,$parent_item);
5620: my $higher = $depth - 1;
5621: if ($higher == 0) {
5622: $parent_name = &escape($parent).'::'.$higher;
5623: } else {
5624: if (ref($path) eq 'ARRAY') {
5625: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5626: }
5627: }
5628: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5629: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5630: if ($j < $numchildren) {
1.48 raeburn 5631: $name = $cats->[$depth]{$parent}[$j];
5632: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5633: $idxnum = $idx->{$item};
5634: } else {
5635: $name = $parent_name;
5636: $item = $parent_item;
1.48 raeburn 5637: }
1.49 raeburn 5638: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5639: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5640: for (my $i=0; $i<=$numchildren; $i++) {
5641: my $vpos = $i+1;
5642: my $selstr;
5643: if ($j == $i) {
5644: $selstr = ' selected="selected" ';
5645: }
5646: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5647: }
5648: $text .= '</select> ';
5649: if ($j < $numchildren) {
5650: my $deeper = $depth+1;
5651: $text .= $name.' '
5652: .'<label><input type="checkbox" name="deletecategory" value="'
5653: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5654: if(ref($path) eq 'ARRAY') {
5655: push(@{$path},$name);
1.49 raeburn 5656: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5657: pop(@{$path});
5658: }
5659: } else {
1.59 bisitz 5660: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5661: if ($j == $numchildren) {
5662: $text .= $name;
5663: } else {
5664: $text .= $item;
5665: }
5666: $text .= '" value="" />';
5667: }
5668: $text .= '</td></tr>';
5669: }
5670: $text .= '</table></td>';
5671: } else {
5672: my $higher = $depth-1;
5673: if ($higher == 0) {
5674: $name = &escape($parent).'::'.$higher;
5675: } else {
5676: if (ref($path) eq 'ARRAY') {
5677: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5678: }
5679: }
5680: my $colspan;
5681: if ($parent ne 'instcode') {
5682: $colspan = $maxdepth - $depth - 1;
5683: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5684: }
5685: }
5686: }
5687: }
5688: return $text;
5689: }
5690:
1.33 raeburn 5691: sub modifiable_userdata_row {
1.160.6.35 raeburn 5692: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5693: my ($role,$rolename,$statustype);
5694: $role = $item;
1.160.6.34 raeburn 5695: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5696: if ($item =~ /^emailusername_(.+)$/) {
5697: $statustype = $1;
5698: $role = 'emailusername';
5699: if (ref($usertypes) eq 'HASH') {
5700: if ($usertypes->{$statustype}) {
5701: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5702: } else {
5703: $rolename = &mt('Data provided by user');
5704: }
5705: }
1.160.6.34 raeburn 5706: }
5707: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5708: if (ref($usertypes) eq 'HASH') {
5709: $rolename = $usertypes->{$role};
5710: } else {
5711: $rolename = $role;
5712: }
1.33 raeburn 5713: } else {
1.63 raeburn 5714: if ($role eq 'cr') {
5715: $rolename = &mt('Custom role');
5716: } else {
5717: $rolename = &Apache::lonnet::plaintext($role);
5718: }
1.33 raeburn 5719: }
1.160.6.34 raeburn 5720: my (@fields,%fieldtitles);
5721: if (ref($fieldsref) eq 'ARRAY') {
5722: @fields = @{$fieldsref};
5723: } else {
5724: @fields = ('lastname','firstname','middlename','generation',
5725: 'permanentemail','id');
5726: }
5727: if ((ref($titlesref) eq 'HASH')) {
5728: %fieldtitles = %{$titlesref};
5729: } else {
5730: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5731: }
1.33 raeburn 5732: my $output;
5733: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5734: $output = '<tr '.$css_class.'>'.
5735: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5736: '<td class="LC_left_item" colspan="2"><table>';
5737: my $rem;
5738: my %checks;
5739: if (ref($settings) eq 'HASH') {
5740: if (ref($settings->{$context}) eq 'HASH') {
5741: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5742: my $hashref = $settings->{$context}->{$role};
5743: if ($role eq 'emailusername') {
5744: if ($statustype) {
5745: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5746: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5747: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5748: foreach my $field (@fields) {
5749: if ($hashref->{$field}) {
5750: $checks{$field} = $hashref->{$field};
5751: }
5752: }
5753: }
5754: }
5755: }
5756: } else {
5757: if (ref($hashref) eq 'HASH') {
5758: foreach my $field (@fields) {
5759: if ($hashref->{$field}) {
5760: $checks{$field} = ' checked="checked" ';
5761: }
5762: }
1.33 raeburn 5763: }
5764: }
5765: }
5766: }
5767: }
1.160.6.39 raeburn 5768:
1.33 raeburn 5769: for (my $i=0; $i<@fields; $i++) {
5770: my $rem = $i%($numinrow);
5771: if ($rem == 0) {
5772: if ($i > 0) {
5773: $output .= '</tr>';
5774: }
5775: $output .= '<tr>';
5776: }
5777: my $check = ' ';
1.160.6.35 raeburn 5778: unless ($role eq 'emailusername') {
5779: if (exists($checks{$fields[$i]})) {
5780: $check = $checks{$fields[$i]}
5781: } else {
5782: if ($role eq 'st') {
5783: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5784: $check = ' checked="checked" ';
1.160.6.35 raeburn 5785: }
1.33 raeburn 5786: }
5787: }
5788: }
5789: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5790: '<span class="LC_nobreak">';
5791: if ($role eq 'emailusername') {
5792: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5793: $checks{$fields[$i]} = 'omit';
5794: }
5795: foreach my $option ('required','optional','omit') {
5796: my $checked='';
5797: if ($checks{$fields[$i]} eq $option) {
5798: $checked='checked="checked" ';
5799: }
5800: $output .= '<label>'.
5801: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5802: &mt($option).'</label>'.(' ' x2);
5803: }
5804: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5805: } else {
5806: $output .= '<label>'.
5807: '<input type="checkbox" name="canmodify_'.$role.'" '.
5808: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5809: '</label>';
5810: }
5811: $output .= '</span></td>';
1.33 raeburn 5812: $rem = @fields%($numinrow);
5813: }
5814: my $colsleft = $numinrow - $rem;
5815: if ($colsleft > 1 ) {
5816: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5817: ' </td>';
5818: } elsif ($colsleft == 1) {
5819: $output .= '<td class="LC_left_item"> </td>';
5820: }
5821: $output .= '</tr></table></td></tr>';
5822: return $output;
5823: }
1.28 raeburn 5824:
1.93 raeburn 5825: sub insttypes_row {
1.160.6.34 raeburn 5826: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5827: my %lt = &Apache::lonlocal::texthash (
5828: cansearch => 'Users allowed to search',
5829: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5830: lockablenames => 'User preference to lock name',
1.93 raeburn 5831: );
5832: my $showdom;
5833: if ($context eq 'cansearch') {
5834: $showdom = ' ('.$dom.')';
5835: }
1.160.6.5 raeburn 5836: my $class = 'LC_left_item';
5837: if ($context eq 'statustocreate') {
5838: $class = 'LC_right_item';
5839: }
1.160.6.34 raeburn 5840: my $css_class = ' class="LC_odd_row"';
5841: if ($rownum ne '') {
5842: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5843: }
5844: my $output = '<tr'.$css_class.'>'.
5845: '<td>'.$lt{$context}.$showdom.
5846: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5847: my $rem;
5848: if (ref($types) eq 'ARRAY') {
5849: for (my $i=0; $i<@{$types}; $i++) {
5850: if (defined($usertypes->{$types->[$i]})) {
5851: my $rem = $i%($numinrow);
5852: if ($rem == 0) {
5853: if ($i > 0) {
5854: $output .= '</tr>';
5855: }
5856: $output .= '<tr>';
1.23 raeburn 5857: }
1.26 raeburn 5858: my $check = ' ';
1.99 raeburn 5859: if (ref($settings) eq 'HASH') {
5860: if (ref($settings->{$context}) eq 'ARRAY') {
5861: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5862: $check = ' checked="checked" ';
5863: }
5864: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5865: $check = ' checked="checked" ';
5866: }
1.23 raeburn 5867: }
1.26 raeburn 5868: $output .= '<td class="LC_left_item">'.
5869: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5870: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5871: 'value="'.$types->[$i].'"'.$check.'/>'.
5872: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5873: }
5874: }
1.26 raeburn 5875: $rem = @{$types}%($numinrow);
1.23 raeburn 5876: }
5877: my $colsleft = $numinrow - $rem;
1.131 raeburn 5878: if (($rem == 0) && (@{$types} > 0)) {
5879: $output .= '<tr>';
5880: }
1.23 raeburn 5881: if ($colsleft > 1) {
1.25 raeburn 5882: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5883: } else {
1.25 raeburn 5884: $output .= '<td class="LC_left_item">';
1.23 raeburn 5885: }
5886: my $defcheck = ' ';
1.99 raeburn 5887: if (ref($settings) eq 'HASH') {
5888: if (ref($settings->{$context}) eq 'ARRAY') {
5889: if (grep(/^default$/,@{$settings->{$context}})) {
5890: $defcheck = ' checked="checked" ';
5891: }
5892: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5893: $defcheck = ' checked="checked" ';
5894: }
1.23 raeburn 5895: }
1.25 raeburn 5896: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5897: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5898: 'value="default"'.$defcheck.'/>'.
5899: $othertitle.'</label></span></td>'.
5900: '</tr></table></td></tr>';
5901: return $output;
1.23 raeburn 5902: }
5903:
5904: sub sorted_searchtitles {
5905: my %searchtitles = &Apache::lonlocal::texthash(
5906: 'uname' => 'username',
5907: 'lastname' => 'last name',
5908: 'lastfirst' => 'last name, first name',
5909: );
5910: my @titleorder = ('uname','lastname','lastfirst');
5911: return (\%searchtitles,\@titleorder);
5912: }
5913:
1.25 raeburn 5914: sub sorted_searchtypes {
5915: my %srchtypes_desc = (
5916: exact => 'is exact match',
5917: contains => 'contains ..',
5918: begins => 'begins with ..',
5919: );
5920: my @srchtypeorder = ('exact','begins','contains');
5921: return (\%srchtypes_desc,\@srchtypeorder);
5922: }
5923:
1.3 raeburn 5924: sub usertype_update_row {
5925: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5926: my $datatable;
5927: my $numinrow = 4;
5928: foreach my $type (@{$types}) {
5929: if (defined($usertypes->{$type})) {
5930: $$rownums ++;
5931: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5932: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5933: '</td><td class="LC_left_item"><table>';
5934: for (my $i=0; $i<@{$fields}; $i++) {
5935: my $rem = $i%($numinrow);
5936: if ($rem == 0) {
5937: if ($i > 0) {
5938: $datatable .= '</tr>';
5939: }
5940: $datatable .= '<tr>';
5941: }
5942: my $check = ' ';
1.39 raeburn 5943: if (ref($settings) eq 'HASH') {
5944: if (ref($settings->{'fields'}) eq 'HASH') {
5945: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5946: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5947: $check = ' checked="checked" ';
5948: }
1.3 raeburn 5949: }
5950: }
5951: }
5952:
5953: if ($i == @{$fields}-1) {
5954: my $colsleft = $numinrow - $rem;
5955: if ($colsleft > 1) {
5956: $datatable .= '<td colspan="'.$colsleft.'">';
5957: } else {
5958: $datatable .= '<td>';
5959: }
5960: } else {
5961: $datatable .= '<td>';
5962: }
1.8 raeburn 5963: $datatable .= '<span class="LC_nobreak"><label>'.
5964: '<input type="checkbox" name="updateable_'.$type.
5965: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5966: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5967: }
5968: $datatable .= '</tr></table></td></tr>';
5969: }
5970: }
5971: return $datatable;
1.1 raeburn 5972: }
5973:
5974: sub modify_login {
1.160.6.24 raeburn 5975: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5976: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5977: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5978: %title = ( coursecatalog => 'Display course catalog',
5979: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5980: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5981: newuser => 'Link for visitors to create a user account',
5982: loginheader => 'Log-in box header');
5983: @offon = ('off','on');
1.112 raeburn 5984: if (ref($domconfig{login}) eq 'HASH') {
5985: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5986: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5987: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5988: }
5989: }
5990: }
1.9 raeburn 5991: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5992: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5993: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5994: foreach my $item (@toggles) {
5995: $loginhash{login}{$item} = $env{'form.'.$item};
5996: }
1.41 raeburn 5997: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5998: if (ref($colchanges{'login'}) eq 'HASH') {
5999: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6000: \%loginhash);
6001: }
1.110 raeburn 6002:
1.149 raeburn 6003: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6004: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6005: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6006: if (keys(%servers) > 1) {
6007: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6008: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6009: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6010: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6011: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6012: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6013: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6014: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6015: $changes{'loginvia'}{$lonhost} = 1;
6016: } else {
6017: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6018: $changes{'loginvia'}{$lonhost} = 1;
6019: }
6020: } else {
6021: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6022: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6023: $changes{'loginvia'}{$lonhost} = 1;
6024: }
6025: }
6026: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6027: foreach my $item (@loginvia_attribs) {
6028: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6029: }
6030: } else {
6031: foreach my $item (@loginvia_attribs) {
6032: my $new = $env{'form.'.$lonhost.'_'.$item};
6033: if (($item eq 'serverpath') && ($new eq 'custom')) {
6034: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6035: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6036: $new = '/';
6037: }
6038: }
6039: if (($item eq 'custompath') &&
6040: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6041: $new = '';
6042: }
6043: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6044: $changes{'loginvia'}{$lonhost} = 1;
6045: }
6046: if ($item eq 'exempt') {
1.160.6.56 raeburn 6047: $new = &check_exempt_addresses($new);
1.128 raeburn 6048: }
6049: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6050: }
6051: }
1.112 raeburn 6052: } else {
1.128 raeburn 6053: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6054: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6055: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6056: foreach my $item (@loginvia_attribs) {
6057: my $new = $env{'form.'.$lonhost.'_'.$item};
6058: if (($item eq 'serverpath') && ($new eq 'custom')) {
6059: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6060: $new = '/';
6061: }
6062: }
6063: if (($item eq 'custompath') &&
6064: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6065: $new = '';
6066: }
6067: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6068: }
1.110 raeburn 6069: }
6070: }
6071: }
6072: }
1.119 raeburn 6073:
1.160.6.5 raeburn 6074: my $servadm = $r->dir_config('lonAdmEMail');
6075: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6076: if (ref($domconfig{'login'}) eq 'HASH') {
6077: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6078: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6079: if ($lang eq 'nolang') {
6080: push(@currlangs,$lang);
6081: } elsif (defined($langchoices{$lang})) {
6082: push(@currlangs,$lang);
6083: } else {
6084: next;
6085: }
6086: }
6087: }
6088: }
6089: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6090: if (@currlangs > 0) {
6091: foreach my $lang (@currlangs) {
6092: if (grep(/^\Q$lang\E$/,@delurls)) {
6093: $changes{'helpurl'}{$lang} = 1;
6094: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6095: $changes{'helpurl'}{$lang} = 1;
6096: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6097: push(@newlangs,$lang);
6098: } else {
6099: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6100: }
6101: }
6102: }
6103: unless (grep(/^nolang$/,@currlangs)) {
6104: if ($env{'form.loginhelpurl_nolang.filename'}) {
6105: $changes{'helpurl'}{'nolang'} = 1;
6106: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6107: push(@newlangs,'nolang');
6108: }
6109: }
6110: if ($env{'form.loginhelpurl_add_lang'}) {
6111: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6112: ($env{'form.loginhelpurl_add_file.filename'})) {
6113: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6114: $addedfile = $env{'form.loginhelpurl_add_lang'};
6115: }
6116: }
6117: if ((@newlangs > 0) || ($addedfile)) {
6118: my $error;
6119: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6120: if ($configuserok eq 'ok') {
6121: if ($switchserver) {
6122: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6123: } elsif ($author_ok eq 'ok') {
6124: my @allnew = @newlangs;
6125: if ($addedfile ne '') {
6126: push(@allnew,$addedfile);
6127: }
6128: foreach my $lang (@allnew) {
6129: my $formelem = 'loginhelpurl_'.$lang;
6130: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6131: $formelem = 'loginhelpurl_add_file';
6132: }
6133: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6134: "help/$lang",'','',$newfile{$lang});
6135: if ($result eq 'ok') {
6136: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6137: $changes{'helpurl'}{$lang} = 1;
6138: } else {
6139: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6140: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6141: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6142: (!grep(/^\Q$lang\E$/,@delurls))) {
6143:
6144: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6145: }
6146: }
6147: }
6148: } else {
6149: $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);
6150: }
6151: } else {
6152: $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);
6153: }
6154: if ($error) {
6155: &Apache::lonnet::logthis($error);
6156: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6157: }
6158: }
1.160.6.56 raeburn 6159:
6160: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6161: if (ref($domconfig{'login'}) eq 'HASH') {
6162: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6163: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6164: if ($domservers{$lonhost}) {
6165: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6166: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.67 raeburn 6167: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'}
1.160.6.56 raeburn 6168: }
6169: }
6170: }
6171: }
6172: }
6173: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6174: foreach my $lonhost (sort(keys(%domservers))) {
6175: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6176: $changes{'headtag'}{$lonhost} = 1;
6177: } else {
6178: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6179: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6180: }
6181: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6182: push(@newhosts,$lonhost);
6183: } elsif ($currheadtagurls{$lonhost}) {
6184: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6185: if ($currexempt{$lonhost}) {
6186: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6187: $changes{'headtag'}{$lonhost} = 1;
6188: }
6189: } elsif ($possexempt{$lonhost}) {
6190: $changes{'headtag'}{$lonhost} = 1;
6191: }
6192: if ($possexempt{$lonhost}) {
6193: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6194: }
6195: }
6196: }
6197: }
6198: if (@newhosts) {
6199: my $error;
6200: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6201: if ($configuserok eq 'ok') {
6202: if ($switchserver) {
6203: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6204: } elsif ($author_ok eq 'ok') {
6205: foreach my $lonhost (@newhosts) {
6206: my $formelem = 'loginheadtag_'.$lonhost;
6207: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6208: "login/headtag/$lonhost",'','',
6209: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6210: if ($result eq 'ok') {
6211: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6212: $changes{'headtag'}{$lonhost} = 1;
6213: if ($possexempt{$lonhost}) {
6214: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6215: }
6216: } else {
6217: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6218: $newheadtagurls{$lonhost},$result);
6219: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6220: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6221: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6222: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6223: }
6224: }
6225: }
6226: } else {
6227: $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);
6228: }
6229: } else {
6230: $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);
6231: }
6232: if ($error) {
6233: &Apache::lonnet::logthis($error);
6234: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6235: }
6236: }
6237:
1.160.6.5 raeburn 6238: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6239:
6240: my $defaulthelpfile = '/adm/loginproblems.html';
6241: my $defaulttext = &mt('Default in use');
6242:
1.1 raeburn 6243: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6244: $dom);
6245: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6246: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6247: my %defaultchecked = (
6248: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6249: 'helpdesk' => 'on',
1.42 raeburn 6250: 'adminmail' => 'off',
1.43 raeburn 6251: 'newuser' => 'off',
1.42 raeburn 6252: );
1.55 raeburn 6253: if (ref($domconfig{'login'}) eq 'HASH') {
6254: foreach my $item (@toggles) {
6255: if ($defaultchecked{$item} eq 'on') {
6256: if (($domconfig{'login'}{$item} eq '0') &&
6257: ($env{'form.'.$item} eq '1')) {
6258: $changes{$item} = 1;
6259: } elsif (($domconfig{'login'}{$item} eq '' ||
6260: $domconfig{'login'}{$item} eq '1') &&
6261: ($env{'form.'.$item} eq '0')) {
6262: $changes{$item} = 1;
6263: }
6264: } elsif ($defaultchecked{$item} eq 'off') {
6265: if (($domconfig{'login'}{$item} eq '1') &&
6266: ($env{'form.'.$item} eq '0')) {
6267: $changes{$item} = 1;
6268: } elsif (($domconfig{'login'}{$item} eq '' ||
6269: $domconfig{'login'}{$item} eq '0') &&
6270: ($env{'form.'.$item} eq '1')) {
6271: $changes{$item} = 1;
6272: }
1.42 raeburn 6273: }
6274: }
1.41 raeburn 6275: }
1.6 raeburn 6276: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6277: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6278: if (ref($lastactref) eq 'HASH') {
6279: $lastactref->{'domainconfig'} = 1;
6280: }
1.1 raeburn 6281: $resulttext = &mt('Changes made:').'<ul>';
6282: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6283: if ($item eq 'loginvia') {
1.112 raeburn 6284: if (ref($changes{$item}) eq 'HASH') {
6285: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6286: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6287: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6288: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6289: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6290: $protocol = 'http' if ($protocol ne 'https');
6291: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6292:
6293: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6294: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6295: } else {
6296: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6297: }
6298: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6299: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6300: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6301: }
6302: $resulttext .= '</li>';
6303: } else {
6304: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6305: }
1.112 raeburn 6306: } else {
1.128 raeburn 6307: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6308: }
6309: }
1.128 raeburn 6310: $resulttext .= '</ul></li>';
1.112 raeburn 6311: }
1.160.6.5 raeburn 6312: } elsif ($item eq 'helpurl') {
6313: if (ref($changes{$item}) eq 'HASH') {
6314: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6315: if (grep(/^\Q$lang\E$/,@delurls)) {
6316: my ($chg,$link);
6317: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6318: if ($lang eq 'nolang') {
6319: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6320: } else {
6321: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6322: }
6323: $resulttext .= '<li>'.$chg.'</li>';
6324: } else {
6325: my $chg;
6326: if ($lang eq 'nolang') {
6327: $chg = &mt('custom log-in help file for no preferred language');
6328: } else {
6329: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6330: }
6331: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6332: $loginhash{'login'}{'helpurl'}{$lang}.
6333: '?inhibitmenu=yes',$chg,600,500).
6334: '</li>';
6335: }
6336: }
6337: }
1.160.6.56 raeburn 6338: } elsif ($item eq 'headtag') {
6339: if (ref($changes{$item}) eq 'HASH') {
6340: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6341: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6342: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6343: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6344: $resulttext .= '<li><a href="'.
6345: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6346: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6347: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6348: if ($possexempt{$lonhost}) {
6349: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6350: } else {
6351: $resulttext .= &mt('included for any client IP');
6352: }
6353: $resulttext .= '</li>';
6354: }
6355: }
6356: }
1.160.6.5 raeburn 6357: } elsif ($item eq 'captcha') {
6358: if (ref($loginhash{'login'}) eq 'HASH') {
6359: my $chgtxt;
6360: if ($loginhash{'login'}{$item} eq 'notused') {
6361: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6362: } else {
6363: my %captchas = &captcha_phrases();
6364: if ($captchas{$loginhash{'login'}{$item}}) {
6365: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6366: } else {
6367: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6368: }
6369: }
6370: $resulttext .= '<li>'.$chgtxt.'</li>';
6371: }
6372: } elsif ($item eq 'recaptchakeys') {
6373: if (ref($loginhash{'login'}) eq 'HASH') {
6374: my ($privkey,$pubkey);
6375: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6376: $pubkey = $loginhash{'login'}{$item}{'public'};
6377: $privkey = $loginhash{'login'}{$item}{'private'};
6378: }
6379: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6380: if (!$pubkey) {
6381: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6382: } else {
6383: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6384: }
6385: if (!$privkey) {
6386: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6387: } else {
1.160.6.53 raeburn 6388: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6389: }
6390: $chgtxt .= '</ul>';
6391: $resulttext .= '<li>'.$chgtxt.'</li>';
6392: }
1.160.6.69! raeburn 6393: } elsif ($item eq 'recaptchaversion') {
! 6394: if (ref($loginhash{'login'}) eq 'HASH') {
! 6395: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
! 6396: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
! 6397: '</li>';
! 6398: }
! 6399: }
1.41 raeburn 6400: } else {
6401: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6402: }
1.1 raeburn 6403: }
1.6 raeburn 6404: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6405: } else {
6406: $resulttext = &mt('No changes made to log-in page settings');
6407: }
6408: } else {
1.11 albertel 6409: $resulttext = '<span class="LC_error">'.
6410: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6411: }
1.6 raeburn 6412: if ($errors) {
1.9 raeburn 6413: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6414: $errors.'</ul>';
6415: }
6416: return $resulttext;
6417: }
6418:
1.160.6.56 raeburn 6419: sub check_exempt_addresses {
6420: my ($iplist) = @_;
6421: $iplist =~ s/^\s+//;
6422: $iplist =~ s/\s+$//;
6423: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6424: my (@okips,$new);
6425: foreach my $ip (@poss_ips) {
6426: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6427: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6428: push(@okips,$ip);
6429: }
6430: }
6431: }
6432: if (@okips > 0) {
6433: $new = join(',',@okips);
6434: } else {
6435: $new = '';
6436: }
6437: return $new;
6438: }
6439:
1.6 raeburn 6440: sub color_font_choices {
6441: my %choices =
6442: &Apache::lonlocal::texthash (
6443: img => "Header",
6444: bgs => "Background colors",
6445: links => "Link colors",
1.55 raeburn 6446: images => "Images",
1.6 raeburn 6447: font => "Font color",
1.160.6.22 raeburn 6448: fontmenu => "Font menu",
1.76 raeburn 6449: pgbg => "Page",
1.6 raeburn 6450: tabbg => "Header",
6451: sidebg => "Border",
6452: link => "Link",
6453: alink => "Active link",
6454: vlink => "Visited link",
6455: );
6456: return %choices;
6457: }
6458:
6459: sub modify_rolecolors {
1.160.6.24 raeburn 6460: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6461: my ($resulttext,%rolehash);
6462: $rolehash{'rolecolors'} = {};
1.55 raeburn 6463: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6464: if ($domconfig{'rolecolors'} eq '') {
6465: $domconfig{'rolecolors'} = {};
6466: }
6467: }
1.9 raeburn 6468: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6469: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6470: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6471: $dom);
6472: if ($putresult eq 'ok') {
6473: if (keys(%changes) > 0) {
1.41 raeburn 6474: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6475: if (ref($lastactref) eq 'HASH') {
6476: $lastactref->{'domainconfig'} = 1;
6477: }
1.6 raeburn 6478: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6479: $rolehash{'rolecolors'});
6480: } else {
6481: $resulttext = &mt('No changes made to default color schemes');
6482: }
6483: } else {
1.11 albertel 6484: $resulttext = '<span class="LC_error">'.
6485: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6486: }
6487: if ($errors) {
6488: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6489: $errors.'</ul>';
6490: }
6491: return $resulttext;
6492: }
6493:
6494: sub modify_colors {
1.9 raeburn 6495: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6496: my (%changes,%choices);
1.51 raeburn 6497: my @bgs;
1.6 raeburn 6498: my @links = ('link','alink','vlink');
1.41 raeburn 6499: my @logintext;
1.6 raeburn 6500: my @images;
6501: my $servadm = $r->dir_config('lonAdmEMail');
6502: my $errors;
1.160.6.22 raeburn 6503: my %defaults;
1.6 raeburn 6504: foreach my $role (@{$roles}) {
6505: if ($role eq 'login') {
1.12 raeburn 6506: %choices = &login_choices();
1.41 raeburn 6507: @logintext = ('textcol','bgcol');
1.12 raeburn 6508: } else {
6509: %choices = &color_font_choices();
6510: }
6511: if ($role eq 'login') {
1.41 raeburn 6512: @images = ('img','logo','domlogo','login');
1.51 raeburn 6513: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6514: } else {
6515: @images = ('img');
1.160.6.22 raeburn 6516: @bgs = ('pgbg','tabbg','sidebg');
6517: }
6518: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6519: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6520: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6521: }
6522: if ($role eq 'login') {
6523: foreach my $item (@logintext) {
1.160.6.39 raeburn 6524: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6525: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6526: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6527: }
6528: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6529: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6530: }
6531: }
6532: } else {
1.160.6.39 raeburn 6533: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6534: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6535: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6536: }
6537: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6538: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6539: }
1.6 raeburn 6540: }
1.160.6.22 raeburn 6541: foreach my $item (@bgs) {
1.160.6.39 raeburn 6542: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6543: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6544: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6545: }
6546: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6547: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6548: }
6549: }
6550: foreach my $item (@links) {
1.160.6.39 raeburn 6551: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6552: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6553: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6554: }
6555: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6556: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6557: }
1.6 raeburn 6558: }
1.46 raeburn 6559: my ($configuserok,$author_ok,$switchserver) =
6560: &config_check($dom,$confname,$servadm);
1.9 raeburn 6561: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6562: if (ref($domconfig->{$role}) ne 'HASH') {
6563: $domconfig->{$role} = {};
6564: }
1.8 raeburn 6565: foreach my $img (@images) {
1.70 raeburn 6566: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6567: if (defined($env{'form.login_showlogo_'.$img})) {
6568: $confhash->{$role}{'showlogo'}{$img} = 1;
6569: } else {
6570: $confhash->{$role}{'showlogo'}{$img} = 0;
6571: }
6572: }
1.18 albertel 6573: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6574: && !defined($domconfig->{$role}{$img})
6575: && !$env{'form.'.$role.'_del_'.$img}
6576: && $env{'form.'.$role.'_import_'.$img}) {
6577: # import the old configured image from the .tab setting
6578: # if they haven't provided a new one
6579: $domconfig->{$role}{$img} =
6580: $env{'form.'.$role.'_import_'.$img};
6581: }
1.6 raeburn 6582: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6583: my $error;
1.6 raeburn 6584: if ($configuserok eq 'ok') {
1.9 raeburn 6585: if ($switchserver) {
1.12 raeburn 6586: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6587: } else {
6588: if ($author_ok eq 'ok') {
6589: my ($result,$logourl) =
6590: &publishlogo($r,'upload',$role.'_'.$img,
6591: $dom,$confname,$img,$width,$height);
6592: if ($result eq 'ok') {
6593: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6594: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6595: } else {
1.12 raeburn 6596: $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 6597: }
6598: } else {
1.46 raeburn 6599: $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 6600: }
6601: }
6602: } else {
1.46 raeburn 6603: $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 6604: }
6605: if ($error) {
1.8 raeburn 6606: &Apache::lonnet::logthis($error);
1.11 albertel 6607: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6608: }
6609: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6610: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6611: my $error;
6612: if ($configuserok eq 'ok') {
6613: # is confname an author?
6614: if ($switchserver eq '') {
6615: if ($author_ok eq 'ok') {
6616: my ($result,$logourl) =
6617: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6618: $dom,$confname,$img,$width,$height);
6619: if ($result eq 'ok') {
6620: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6621: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6622: }
6623: }
6624: }
6625: }
1.6 raeburn 6626: }
6627: }
6628: }
6629: if (ref($domconfig) eq 'HASH') {
6630: if (ref($domconfig->{$role}) eq 'HASH') {
6631: foreach my $img (@images) {
6632: if ($domconfig->{$role}{$img} ne '') {
6633: if ($env{'form.'.$role.'_del_'.$img}) {
6634: $confhash->{$role}{$img} = '';
1.12 raeburn 6635: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6636: } else {
1.9 raeburn 6637: if ($confhash->{$role}{$img} eq '') {
6638: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6639: }
1.6 raeburn 6640: }
6641: } else {
6642: if ($env{'form.'.$role.'_del_'.$img}) {
6643: $confhash->{$role}{$img} = '';
1.12 raeburn 6644: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6645: }
6646: }
1.70 raeburn 6647: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6648: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6649: if ($confhash->{$role}{'showlogo'}{$img} ne
6650: $domconfig->{$role}{'showlogo'}{$img}) {
6651: $changes{$role}{'showlogo'}{$img} = 1;
6652: }
6653: } else {
6654: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6655: $changes{$role}{'showlogo'}{$img} = 1;
6656: }
6657: }
6658: }
6659: }
1.6 raeburn 6660: if ($domconfig->{$role}{'font'} ne '') {
6661: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6662: $changes{$role}{'font'} = 1;
6663: }
6664: } else {
6665: if ($confhash->{$role}{'font'}) {
6666: $changes{$role}{'font'} = 1;
6667: }
6668: }
1.107 raeburn 6669: if ($role ne 'login') {
6670: if ($domconfig->{$role}{'fontmenu'} ne '') {
6671: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6672: $changes{$role}{'fontmenu'} = 1;
6673: }
6674: } else {
6675: if ($confhash->{$role}{'fontmenu'}) {
6676: $changes{$role}{'fontmenu'} = 1;
6677: }
1.97 tempelho 6678: }
6679: }
1.6 raeburn 6680: foreach my $item (@bgs) {
6681: if ($domconfig->{$role}{$item} ne '') {
6682: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6683: $changes{$role}{'bgs'}{$item} = 1;
6684: }
6685: } else {
6686: if ($confhash->{$role}{$item}) {
6687: $changes{$role}{'bgs'}{$item} = 1;
6688: }
6689: }
6690: }
6691: foreach my $item (@links) {
6692: if ($domconfig->{$role}{$item} ne '') {
6693: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6694: $changes{$role}{'links'}{$item} = 1;
6695: }
6696: } else {
6697: if ($confhash->{$role}{$item}) {
6698: $changes{$role}{'links'}{$item} = 1;
6699: }
6700: }
6701: }
1.41 raeburn 6702: foreach my $item (@logintext) {
6703: if ($domconfig->{$role}{$item} ne '') {
6704: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6705: $changes{$role}{'logintext'}{$item} = 1;
6706: }
6707: } else {
6708: if ($confhash->{$role}{$item}) {
6709: $changes{$role}{'logintext'}{$item} = 1;
6710: }
6711: }
6712: }
1.6 raeburn 6713: } else {
6714: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6715: \@logintext,$confhash,\%changes);
1.6 raeburn 6716: }
6717: } else {
6718: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6719: \@logintext,$confhash,\%changes);
1.6 raeburn 6720: }
6721: }
6722: return ($errors,%changes);
6723: }
6724:
1.46 raeburn 6725: sub config_check {
6726: my ($dom,$confname,$servadm) = @_;
6727: my ($configuserok,$author_ok,$switchserver,%currroles);
6728: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6729: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6730: $confname,$servadm);
6731: if ($configuserok eq 'ok') {
6732: $switchserver = &check_switchserver($dom,$confname);
6733: if ($switchserver eq '') {
6734: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6735: }
6736: }
6737: return ($configuserok,$author_ok,$switchserver);
6738: }
6739:
1.6 raeburn 6740: sub default_change_checker {
1.41 raeburn 6741: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6742: foreach my $item (@{$links}) {
6743: if ($confhash->{$role}{$item}) {
6744: $changes->{$role}{'links'}{$item} = 1;
6745: }
6746: }
6747: foreach my $item (@{$bgs}) {
6748: if ($confhash->{$role}{$item}) {
6749: $changes->{$role}{'bgs'}{$item} = 1;
6750: }
6751: }
1.41 raeburn 6752: foreach my $item (@{$logintext}) {
6753: if ($confhash->{$role}{$item}) {
6754: $changes->{$role}{'logintext'}{$item} = 1;
6755: }
6756: }
1.6 raeburn 6757: foreach my $img (@{$images}) {
6758: if ($env{'form.'.$role.'_del_'.$img}) {
6759: $confhash->{$role}{$img} = '';
1.12 raeburn 6760: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6761: }
1.70 raeburn 6762: if ($role eq 'login') {
6763: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6764: $changes->{$role}{'showlogo'}{$img} = 1;
6765: }
6766: }
1.6 raeburn 6767: }
6768: if ($confhash->{$role}{'font'}) {
6769: $changes->{$role}{'font'} = 1;
6770: }
1.48 raeburn 6771: }
1.6 raeburn 6772:
6773: sub display_colorchgs {
6774: my ($dom,$changes,$roles,$confhash) = @_;
6775: my (%choices,$resulttext);
6776: if (!grep(/^login$/,@{$roles})) {
6777: $resulttext = &mt('Changes made:').'<br />';
6778: }
6779: foreach my $role (@{$roles}) {
6780: if ($role eq 'login') {
6781: %choices = &login_choices();
6782: } else {
6783: %choices = &color_font_choices();
6784: }
6785: if (ref($changes->{$role}) eq 'HASH') {
6786: if ($role ne 'login') {
6787: $resulttext .= '<h4>'.&mt($role).'</h4>';
6788: }
6789: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6790: if ($role ne 'login') {
6791: $resulttext .= '<ul>';
6792: }
6793: if (ref($changes->{$role}{$key}) eq 'HASH') {
6794: if ($role ne 'login') {
6795: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6796: }
6797: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6798: if (($role eq 'login') && ($key eq 'showlogo')) {
6799: if ($confhash->{$role}{$key}{$item}) {
6800: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6801: } else {
6802: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6803: }
6804: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6805: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6806: } else {
1.12 raeburn 6807: my $newitem = $confhash->{$role}{$item};
6808: if ($key eq 'images') {
6809: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6810: }
6811: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6812: }
6813: }
6814: if ($role ne 'login') {
6815: $resulttext .= '</ul></li>';
6816: }
6817: } else {
6818: if ($confhash->{$role}{$key} eq '') {
6819: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6820: } else {
6821: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6822: }
6823: }
6824: if ($role ne 'login') {
6825: $resulttext .= '</ul>';
6826: }
6827: }
6828: }
6829: }
1.3 raeburn 6830: return $resulttext;
1.1 raeburn 6831: }
6832:
1.9 raeburn 6833: sub thumb_dimensions {
6834: return ('200','50');
6835: }
6836:
1.16 raeburn 6837: sub check_dimensions {
6838: my ($inputfile) = @_;
6839: my ($fullwidth,$fullheight);
6840: if ($inputfile =~ m|^[/\w.\-]+$|) {
6841: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6842: my $imageinfo = <PIPE>;
6843: if (!close(PIPE)) {
6844: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6845: }
6846: chomp($imageinfo);
6847: my ($fullsize) =
1.21 raeburn 6848: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6849: if ($fullsize) {
6850: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6851: }
6852: }
6853: }
6854: return ($fullwidth,$fullheight);
6855: }
6856:
1.9 raeburn 6857: sub check_configuser {
6858: my ($uhome,$dom,$confname,$servadm) = @_;
6859: my ($configuserok,%currroles);
6860: if ($uhome eq 'no_host') {
6861: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6862: my $configpass = &LONCAPA::Enrollment::create_password();
6863: $configuserok =
6864: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6865: $configpass,'','','','','',undef,$servadm);
6866: } else {
6867: $configuserok = 'ok';
6868: %currroles =
6869: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6870: }
6871: return ($configuserok,%currroles);
6872: }
6873:
6874: sub check_authorstatus {
6875: my ($dom,$confname,%currroles) = @_;
6876: my $author_ok;
1.40 raeburn 6877: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6878: my $start = time;
6879: my $end = 0;
6880: $author_ok =
6881: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6882: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6883: } else {
6884: $author_ok = 'ok';
6885: }
6886: return $author_ok;
6887: }
6888:
6889: sub publishlogo {
1.46 raeburn 6890: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6891: my ($output,$fname,$logourl);
6892: if ($action eq 'upload') {
6893: $fname=$env{'form.'.$formname.'.filename'};
6894: chop($env{'form.'.$formname});
6895: } else {
6896: ($fname) = ($formname =~ /([^\/]+)$/);
6897: }
1.46 raeburn 6898: if ($savefileas ne '') {
6899: $fname = $savefileas;
6900: }
1.9 raeburn 6901: $fname=&Apache::lonnet::clean_filename($fname);
6902: # See if there is anything left
6903: unless ($fname) { return ('error: no uploaded file'); }
6904: $fname="$subdir/$fname";
1.160.6.5 raeburn 6905: my $docroot=$r->dir_config('lonDocRoot');
6906: my $filepath="$docroot/priv";
6907: my $relpath = "$dom/$confname";
1.9 raeburn 6908: my ($fnamepath,$file,$fetchthumb);
6909: $file=$fname;
6910: if ($fname=~m|/|) {
6911: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6912: }
1.160.6.26 raeburn 6913: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6914: my $count;
1.160.6.5 raeburn 6915: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6916: $filepath.="/$parts[$count]";
6917: if ((-e $filepath)!=1) {
6918: mkdir($filepath,02770);
6919: }
6920: }
6921: # Check for bad extension and disallow upload
6922: if ($file=~/\.(\w+)$/ &&
6923: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6924: $output =
1.160.6.25 raeburn 6925: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6926: } elsif ($file=~/\.(\w+)$/ &&
6927: !defined(&Apache::loncommon::fileembstyle($1))) {
6928: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6929: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6930: $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 6931: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6932: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6933: } else {
6934: my $source = $filepath.'/'.$file;
6935: my $logfile;
6936: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6937: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6938: }
6939: print $logfile
6940: "\n================= Publish ".localtime()." ================\n".
6941: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6942: # Save the file
6943: if (!open(FH,'>'.$source)) {
6944: &Apache::lonnet::logthis('Failed to create '.$source);
6945: return (&mt('Failed to create file'));
6946: }
6947: if ($action eq 'upload') {
6948: if (!print FH ($env{'form.'.$formname})) {
6949: &Apache::lonnet::logthis('Failed to write to '.$source);
6950: return (&mt('Failed to write file'));
6951: }
6952: } else {
6953: my $original = &Apache::lonnet::filelocation('',$formname);
6954: if(!copy($original,$source)) {
6955: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6956: return (&mt('Failed to write file'));
6957: }
6958: }
6959: close(FH);
6960: chmod(0660, $source); # Permissions to rw-rw---.
6961:
6962: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6963: my $copyfile=$targetdir.'/'.$file;
6964:
6965: my @parts=split(/\//,$targetdir);
6966: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6967: for (my $count=5;$count<=$#parts;$count++) {
6968: $path.="/$parts[$count]";
6969: if (!-e $path) {
6970: print $logfile "\nCreating directory ".$path;
6971: mkdir($path,02770);
6972: }
6973: }
6974: my $versionresult;
6975: if (-e $copyfile) {
6976: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6977: } else {
6978: $versionresult = 'ok';
6979: }
6980: if ($versionresult eq 'ok') {
6981: if (copy($source,$copyfile)) {
6982: print $logfile "\nCopied original source to ".$copyfile."\n";
6983: $output = 'ok';
6984: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6985: push(@{$modified_urls},[$copyfile,$source]);
6986: my $metaoutput =
6987: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6988: unless ($registered_cleanup) {
6989: my $handlers = $r->get_handlers('PerlCleanupHandler');
6990: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6991: $registered_cleanup=1;
6992: }
1.9 raeburn 6993: } else {
6994: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6995: $output = &mt('Failed to copy file to RES space').", $!";
6996: }
6997: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6998: my $inputfile = $filepath.'/'.$file;
6999: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7000: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7001: if ($fullwidth ne '' && $fullheight ne '') {
7002: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7003: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7004: system("convert -sample $thumbsize $inputfile $outfile");
7005: chmod(0660, $filepath.'/tn-'.$file);
7006: if (-e $outfile) {
7007: my $copyfile=$targetdir.'/tn-'.$file;
7008: if (copy($outfile,$copyfile)) {
7009: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7010: my $thumb_metaoutput =
7011: &write_metadata($dom,$confname,$formname,
7012: $targetdir,'tn-'.$file,$logfile);
7013: push(@{$modified_urls},[$copyfile,$outfile]);
7014: unless ($registered_cleanup) {
7015: my $handlers = $r->get_handlers('PerlCleanupHandler');
7016: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7017: $registered_cleanup=1;
7018: }
1.16 raeburn 7019: } else {
7020: print $logfile "\nUnable to write ".$copyfile.
7021: ':'.$!."\n";
7022: }
7023: }
1.9 raeburn 7024: }
7025: }
7026: }
7027: } else {
7028: $output = $versionresult;
7029: }
7030: }
7031: return ($output,$logourl);
7032: }
7033:
7034: sub logo_versioning {
7035: my ($targetdir,$file,$logfile) = @_;
7036: my $target = $targetdir.'/'.$file;
7037: my ($maxversion,$fn,$extn,$output);
7038: $maxversion = 0;
7039: if ($file =~ /^(.+)\.(\w+)$/) {
7040: $fn=$1;
7041: $extn=$2;
7042: }
7043: opendir(DIR,$targetdir);
7044: while (my $filename=readdir(DIR)) {
7045: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7046: $maxversion=($1>$maxversion)?$1:$maxversion;
7047: }
7048: }
7049: $maxversion++;
7050: print $logfile "\nCreating old version ".$maxversion."\n";
7051: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7052: if (copy($target,$copyfile)) {
7053: print $logfile "Copied old target to ".$copyfile."\n";
7054: $copyfile=$copyfile.'.meta';
7055: if (copy($target.'.meta',$copyfile)) {
7056: print $logfile "Copied old target metadata to ".$copyfile."\n";
7057: $output = 'ok';
7058: } else {
7059: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7060: $output = &mt('Failed to copy old meta').", $!, ";
7061: }
7062: } else {
7063: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7064: $output = &mt('Failed to copy old target').", $!, ";
7065: }
7066: return $output;
7067: }
7068:
7069: sub write_metadata {
7070: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7071: my (%metadatafields,%metadatakeys,$output);
7072: $metadatafields{'title'}=$formname;
7073: $metadatafields{'creationdate'}=time;
7074: $metadatafields{'lastrevisiondate'}=time;
7075: $metadatafields{'copyright'}='public';
7076: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7077: $env{'user.domain'};
7078: $metadatafields{'authorspace'}=$confname.':'.$dom;
7079: $metadatafields{'domain'}=$dom;
7080: {
7081: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7082: my $mfh;
1.155 raeburn 7083: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7084: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7085: unless ($_=~/\./) {
7086: my $unikey=$_;
7087: $unikey=~/^([A-Za-z]+)/;
7088: my $tag=$1;
7089: $tag=~tr/A-Z/a-z/;
7090: print $mfh "\n\<$tag";
7091: foreach (split(/\,/,$metadatakeys{$unikey})) {
7092: my $value=$metadatafields{$unikey.'.'.$_};
7093: $value=~s/\"/\'\'/g;
7094: print $mfh ' '.$_.'="'.$value.'"';
7095: }
7096: print $mfh '>'.
7097: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7098: .'</'.$tag.'>';
7099: }
7100: }
7101: $output = 'ok';
7102: print $logfile "\nWrote metadata";
7103: close($mfh);
7104: } else {
7105: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7106: $output = &mt('Could not write metadata');
7107: }
7108: }
1.155 raeburn 7109: return $output;
7110: }
7111:
7112: sub notifysubscribed {
7113: foreach my $targetsource (@{$modified_urls}){
7114: next unless (ref($targetsource) eq 'ARRAY');
7115: my ($target,$source)=@{$targetsource};
7116: if ($source ne '') {
7117: if (open(my $logfh,'>>'.$source.'.log')) {
7118: print $logfh "\nCleanup phase: Notifications\n";
7119: my @subscribed=&subscribed_hosts($target);
7120: foreach my $subhost (@subscribed) {
7121: print $logfh "\nNotifying host ".$subhost.':';
7122: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7123: print $logfh $reply;
7124: }
7125: my @subscribedmeta=&subscribed_hosts("$target.meta");
7126: foreach my $subhost (@subscribedmeta) {
7127: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7128: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7129: $subhost);
7130: print $logfh $reply;
7131: }
7132: print $logfh "\n============ Done ============\n";
1.160 raeburn 7133: close($logfh);
1.155 raeburn 7134: }
7135: }
7136: }
7137: return OK;
7138: }
7139:
7140: sub subscribed_hosts {
7141: my ($target) = @_;
7142: my @subscribed;
7143: if (open(my $fh,"<$target.subscription")) {
7144: while (my $subline=<$fh>) {
7145: if ($subline =~ /^($match_lonid):/) {
7146: my $host = $1;
7147: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7148: unless (grep(/^\Q$host\E$/,@subscribed)) {
7149: push(@subscribed,$host);
7150: }
7151: }
7152: }
7153: }
7154: }
7155: return @subscribed;
1.9 raeburn 7156: }
7157:
7158: sub check_switchserver {
7159: my ($dom,$confname) = @_;
7160: my ($allowed,$switchserver);
7161: my $home = &Apache::lonnet::homeserver($confname,$dom);
7162: if ($home eq 'no_host') {
7163: $home = &Apache::lonnet::domain($dom,'primary');
7164: }
7165: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7166: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7167: if (!$allowed) {
1.160.6.11 raeburn 7168: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7169: }
7170: return $switchserver;
7171: }
7172:
1.1 raeburn 7173: sub modify_quotas {
1.160.6.30 raeburn 7174: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7175: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7176: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7177: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7178: $validationfieldsref);
1.86 raeburn 7179: if ($action eq 'quotas') {
7180: $context = 'tools';
1.160.6.26 raeburn 7181: } else {
1.86 raeburn 7182: $context = $action;
7183: }
7184: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7185: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7186: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7187: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7188: %titles = &courserequest_titles();
7189: $toolregexp = join('|',@usertools);
7190: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7191: $confname = $dom.'-domainconfig';
7192: my $servadm = $r->dir_config('lonAdmEMail');
7193: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7194: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7195: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7196: } elsif ($context eq 'requestauthor') {
7197: @usertools = ('author');
7198: %titles = &authorrequest_titles();
1.86 raeburn 7199: } else {
1.160.6.4 raeburn 7200: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7201: %titles = &tool_titles();
1.86 raeburn 7202: }
1.160.6.27 raeburn 7203: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7204: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7205: foreach my $key (keys(%env)) {
1.101 raeburn 7206: if ($context eq 'requestcourses') {
7207: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7208: my $item = $1;
7209: my $type = $2;
7210: if ($type =~ /^limit_(.+)/) {
7211: $limithash{$item}{$1} = $env{$key};
7212: } else {
7213: $confhash{$item}{$type} = $env{$key};
7214: }
7215: }
1.160.6.5 raeburn 7216: } elsif ($context eq 'requestauthor') {
7217: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7218: $confhash{$1} = $env{$key};
7219: }
1.101 raeburn 7220: } else {
1.86 raeburn 7221: if ($key =~ /^form\.quota_(.+)$/) {
7222: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7223: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7224: $confhash{'authorquota'}{$1} = $env{$key};
7225: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7226: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7227: }
1.72 raeburn 7228: }
7229: }
1.160.6.5 raeburn 7230: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7231: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7232: @approvalnotify = sort(@approvalnotify);
7233: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7234: my @crstypes = ('official','unofficial','community','textbook');
7235: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7236: foreach my $type (@hasuniquecode) {
7237: if (grep(/^\Q$type\E$/,@crstypes)) {
7238: $confhash{'uniquecode'}{$type} = 1;
7239: }
7240: }
1.160.6.46 raeburn 7241: my (%newbook,%allpos);
1.160.6.30 raeburn 7242: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7243: foreach my $type ('textbooks','templates') {
7244: @{$allpos{$type}} = ();
7245: my $invalid;
7246: if ($type eq 'textbooks') {
7247: $invalid = &mt('Invalid LON-CAPA course for textbook');
7248: } else {
7249: $invalid = &mt('Invalid LON-CAPA course for template');
7250: }
7251: if ($env{'form.'.$type.'_addbook'}) {
7252: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7253: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7254: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7255: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7256: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7257: } else {
7258: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7259: my $position = $env{'form.'.$type.'_addbook_pos'};
7260: $position =~ s/\D+//g;
7261: if ($position ne '') {
7262: $allpos{$type}[$position] = $newbook{$type};
7263: }
1.160.6.30 raeburn 7264: }
1.160.6.46 raeburn 7265: } else {
7266: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7267: }
7268: }
1.160.6.46 raeburn 7269: }
1.160.6.30 raeburn 7270: }
1.102 raeburn 7271: if (ref($domconfig{$action}) eq 'HASH') {
7272: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7273: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7274: $changes{'notify'}{'approval'} = 1;
7275: }
7276: } else {
1.144 raeburn 7277: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7278: $changes{'notify'}{'approval'} = 1;
7279: }
7280: }
1.160.6.30 raeburn 7281: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7282: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7283: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7284: unless ($confhash{'uniquecode'}{$crstype}) {
7285: $changes{'uniquecode'} = 1;
7286: }
7287: }
7288: unless ($changes{'uniquecode'}) {
7289: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7290: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7291: $changes{'uniquecode'} = 1;
7292: }
7293: }
7294: }
7295: } else {
7296: $changes{'uniquecode'} = 1;
7297: }
7298: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7299: $changes{'uniquecode'} = 1;
7300: }
7301: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7302: foreach my $type ('textbooks','templates') {
7303: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7304: my %deletions;
7305: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7306: if (@todelete) {
7307: map { $deletions{$_} = 1; } @todelete;
7308: }
7309: my %imgdeletions;
7310: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7311: if (@todeleteimages) {
7312: map { $imgdeletions{$_} = 1; } @todeleteimages;
7313: }
7314: my $maxnum = $env{'form.'.$type.'_maxnum'};
7315: for (my $i=0; $i<=$maxnum; $i++) {
7316: my $itemid = $env{'form.'.$type.'_id_'.$i};
7317: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7318: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7319: if ($deletions{$key}) {
7320: if ($domconfig{$action}{$type}{$key}{'image'}) {
7321: #FIXME need to obsolete item in RES space
7322: }
7323: next;
7324: } else {
7325: my $newpos = $env{'form.'.$itemid};
7326: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7327: foreach my $item ('subject','title','publisher','author') {
7328: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7329: ($type eq 'templates'));
1.160.6.46 raeburn 7330: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7331: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7332: $changes{$type}{$key} = 1;
7333: }
7334: }
7335: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7336: }
1.160.6.46 raeburn 7337: if ($imgdeletions{$key}) {
7338: $changes{$type}{$key} = 1;
7339: #FIXME need to obsolete item in RES space
7340: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7341: my ($cdom,$cnum) = split(/_/,$key);
7342: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7343: $cdom,$cnum,$type,$configuserok,
7344: $switchserver,$author_ok);
7345: if ($imgurl) {
7346: $confhash{$type}{$key}{'image'} = $imgurl;
7347: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7348: }
1.160.6.46 raeburn 7349: if ($error) {
7350: &Apache::lonnet::logthis($error);
7351: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7352: }
7353: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7354: $confhash{$type}{$key}{'image'} =
7355: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7356: }
7357: }
7358: }
7359: }
7360: }
7361: }
1.102 raeburn 7362: } else {
1.144 raeburn 7363: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7364: $changes{'notify'}{'approval'} = 1;
7365: }
1.160.6.30 raeburn 7366: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7367: $changes{'uniquecode'} = 1;
7368: }
7369: }
7370: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7371: foreach my $type ('textbooks','templates') {
7372: if ($newbook{$type}) {
7373: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7374: foreach my $item ('subject','title','publisher','author') {
7375: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7376: ($type eq 'template'));
1.160.6.46 raeburn 7377: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7378: if ($env{'form.'.$type.'_addbook_'.$item}) {
7379: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7380: }
7381: }
7382: if ($type eq 'textbooks') {
7383: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7384: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7385: my ($imageurl,$error) =
7386: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7387: $configuserok,$switchserver,$author_ok);
7388: if ($imageurl) {
7389: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7390: }
7391: if ($error) {
7392: &Apache::lonnet::logthis($error);
7393: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7394: }
7395: }
1.160.6.30 raeburn 7396: }
7397: }
1.160.6.46 raeburn 7398: if (@{$allpos{$type}} > 0) {
7399: my $idx = 0;
7400: foreach my $item (@{$allpos{$type}}) {
7401: if ($item ne '') {
7402: $confhash{$type}{$item}{'order'} = $idx;
7403: if (ref($domconfig{$action}) eq 'HASH') {
7404: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7405: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7406: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7407: $changes{$type}{$item} = 1;
7408: }
1.160.6.30 raeburn 7409: }
7410: }
7411: }
1.160.6.46 raeburn 7412: $idx ++;
1.160.6.30 raeburn 7413: }
7414: }
7415: }
7416: }
1.160.6.39 raeburn 7417: if (ref($validationitemsref) eq 'ARRAY') {
7418: foreach my $item (@{$validationitemsref}) {
7419: if ($item eq 'fields') {
7420: my @changed;
7421: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7422: if (@{$confhash{'validation'}{$item}} > 0) {
7423: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7424: }
1.160.6.65 raeburn 7425: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7426: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7427: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7428: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7429: $domconfig{'requestcourses'}{'validation'}{$item});
7430: } else {
7431: @changed = @{$confhash{'validation'}{$item}};
7432: }
1.160.6.39 raeburn 7433: } else {
7434: @changed = @{$confhash{'validation'}{$item}};
7435: }
7436: } else {
7437: @changed = @{$confhash{'validation'}{$item}};
7438: }
7439: if (@changed) {
7440: if ($confhash{'validation'}{$item}) {
7441: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7442: } else {
7443: $changes{'validation'}{$item} = &mt('None');
7444: }
7445: }
7446: } else {
7447: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7448: if ($item eq 'markup') {
7449: if ($env{'form.requestcourses_validation_'.$item}) {
7450: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7451: }
7452: }
1.160.6.65 raeburn 7453: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7454: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7455: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7456: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7457: }
7458: } else {
7459: if ($confhash{'validation'}{$item} ne '') {
7460: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7461: }
1.160.6.39 raeburn 7462: }
7463: } else {
7464: if ($confhash{'validation'}{$item} ne '') {
7465: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7466: }
7467: }
7468: }
7469: }
7470: }
7471: if ($env{'form.validationdc'}) {
7472: my $newval = $env{'form.validationdc'};
7473: my %domcoords = &get_active_dcs($dom);
7474: if (exists($domcoords{$newval})) {
7475: $confhash{'validation'}{'dc'} = $newval;
7476: }
7477: }
7478: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7479: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7480: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7481: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7482: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7483: if ($confhash{'validation'}{'dc'} eq '') {
7484: $changes{'validation'}{'dc'} = &mt('None');
7485: } else {
7486: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7487: }
1.160.6.39 raeburn 7488: }
1.160.6.65 raeburn 7489: } elsif ($confhash{'validation'}{'dc'} ne '') {
7490: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7491: }
7492: } elsif ($confhash{'validation'}{'dc'} ne '') {
7493: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7494: }
7495: } elsif ($confhash{'validation'}{'dc'} ne '') {
7496: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7497: }
1.160.6.65 raeburn 7498: } else {
7499: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7500: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7501: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7502: $changes{'validation'}{'dc'} = &mt('None');
7503: }
7504: }
1.160.6.39 raeburn 7505: }
7506: }
1.102 raeburn 7507: }
7508: } else {
1.86 raeburn 7509: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7510: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7511: }
1.72 raeburn 7512: foreach my $item (@usertools) {
7513: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7514: my $unset;
1.101 raeburn 7515: if ($context eq 'requestcourses') {
1.104 raeburn 7516: $unset = '0';
7517: if ($type eq '_LC_adv') {
7518: $unset = '';
7519: }
1.101 raeburn 7520: if ($confhash{$item}{$type} eq 'autolimit') {
7521: $confhash{$item}{$type} .= '=';
7522: unless ($limithash{$item}{$type} =~ /\D/) {
7523: $confhash{$item}{$type} .= $limithash{$item}{$type};
7524: }
7525: }
1.160.6.5 raeburn 7526: } elsif ($context eq 'requestauthor') {
7527: $unset = '0';
7528: if ($type eq '_LC_adv') {
7529: $unset = '';
7530: }
1.72 raeburn 7531: } else {
1.101 raeburn 7532: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7533: $confhash{$item}{$type} = 1;
7534: } else {
7535: $confhash{$item}{$type} = 0;
7536: }
1.72 raeburn 7537: }
1.86 raeburn 7538: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7539: if ($action eq 'requestauthor') {
7540: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7541: $changes{$type} = 1;
7542: }
7543: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7544: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7545: $changes{$item}{$type} = 1;
7546: }
7547: } else {
7548: if ($context eq 'requestcourses') {
1.104 raeburn 7549: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7550: $changes{$item}{$type} = 1;
7551: }
7552: } else {
7553: if (!$confhash{$item}{$type}) {
7554: $changes{$item}{$type} = 1;
7555: }
7556: }
7557: }
7558: } else {
7559: if ($context eq 'requestcourses') {
1.104 raeburn 7560: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7561: $changes{$item}{$type} = 1;
7562: }
1.160.6.5 raeburn 7563: } elsif ($context eq 'requestauthor') {
7564: if ($confhash{$type} ne $unset) {
7565: $changes{$type} = 1;
7566: }
1.72 raeburn 7567: } else {
7568: if (!$confhash{$item}{$type}) {
7569: $changes{$item}{$type} = 1;
7570: }
7571: }
7572: }
1.1 raeburn 7573: }
7574: }
1.160.6.5 raeburn 7575: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7576: if (ref($domconfig{'quotas'}) eq 'HASH') {
7577: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7578: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7579: if (exists($confhash{'defaultquota'}{$key})) {
7580: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7581: $changes{'defaultquota'}{$key} = 1;
7582: }
7583: } else {
7584: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7585: }
7586: }
1.86 raeburn 7587: } else {
7588: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7589: if (exists($confhash{'defaultquota'}{$key})) {
7590: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7591: $changes{'defaultquota'}{$key} = 1;
7592: }
7593: } else {
7594: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7595: }
1.1 raeburn 7596: }
7597: }
1.160.6.20 raeburn 7598: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7599: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7600: if (exists($confhash{'authorquota'}{$key})) {
7601: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7602: $changes{'authorquota'}{$key} = 1;
7603: }
7604: } else {
7605: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7606: }
7607: }
7608: }
1.1 raeburn 7609: }
1.86 raeburn 7610: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7611: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7612: if (ref($domconfig{'quotas'}) eq 'HASH') {
7613: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7614: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7615: $changes{'defaultquota'}{$key} = 1;
7616: }
7617: } else {
7618: if (!exists($domconfig{'quotas'}{$key})) {
7619: $changes{'defaultquota'}{$key} = 1;
7620: }
1.72 raeburn 7621: }
7622: } else {
1.86 raeburn 7623: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7624: }
1.1 raeburn 7625: }
7626: }
1.160.6.20 raeburn 7627: if (ref($confhash{'authorquota'}) eq 'HASH') {
7628: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7629: if (ref($domconfig{'quotas'}) eq 'HASH') {
7630: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7631: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7632: $changes{'authorquota'}{$key} = 1;
7633: }
7634: } else {
7635: $changes{'authorquota'}{$key} = 1;
7636: }
7637: } else {
7638: $changes{'authorquota'}{$key} = 1;
7639: }
7640: }
7641: }
1.1 raeburn 7642: }
1.72 raeburn 7643:
1.160.6.5 raeburn 7644: if ($context eq 'requestauthor') {
7645: $domdefaults{'requestauthor'} = \%confhash;
7646: } else {
7647: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7648: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7649: $domdefaults{$key} = $confhash{$key};
7650: }
1.160.6.5 raeburn 7651: }
1.72 raeburn 7652: }
1.160.6.5 raeburn 7653:
1.1 raeburn 7654: my %quotahash = (
1.86 raeburn 7655: $action => { %confhash }
1.1 raeburn 7656: );
7657: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7658: $dom);
7659: if ($putresult eq 'ok') {
7660: if (keys(%changes) > 0) {
1.72 raeburn 7661: my $cachetime = 24*60*60;
7662: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7663: if (ref($lastactref) eq 'HASH') {
7664: $lastactref->{'domdefaults'} = 1;
7665: }
1.1 raeburn 7666: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7667: unless (($context eq 'requestcourses') ||
7668: ($context eq 'requestauthor')) {
1.86 raeburn 7669: if (ref($changes{'defaultquota'}) eq 'HASH') {
7670: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7671: foreach my $type (@{$types},'default') {
7672: if (defined($changes{'defaultquota'}{$type})) {
7673: my $typetitle = $usertypes->{$type};
7674: if ($type eq 'default') {
7675: $typetitle = $othertitle;
7676: }
1.160.6.28 raeburn 7677: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7678: }
7679: }
1.86 raeburn 7680: $resulttext .= '</ul></li>';
1.72 raeburn 7681: }
1.160.6.20 raeburn 7682: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7683: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7684: foreach my $type (@{$types},'default') {
7685: if (defined($changes{'authorquota'}{$type})) {
7686: my $typetitle = $usertypes->{$type};
7687: if ($type eq 'default') {
7688: $typetitle = $othertitle;
7689: }
1.160.6.28 raeburn 7690: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7691: }
7692: }
7693: $resulttext .= '</ul></li>';
7694: }
1.72 raeburn 7695: }
1.80 raeburn 7696: my %newenv;
1.72 raeburn 7697: foreach my $item (@usertools) {
1.160.6.5 raeburn 7698: my (%haschgs,%inconf);
7699: if ($context eq 'requestauthor') {
7700: %haschgs = %changes;
7701: %inconf = %confhash;
7702: } else {
7703: if (ref($changes{$item}) eq 'HASH') {
7704: %haschgs = %{$changes{$item}};
7705: }
7706: if (ref($confhash{$item}) eq 'HASH') {
7707: %inconf = %{$confhash{$item}};
7708: }
7709: }
7710: if (keys(%haschgs) > 0) {
1.80 raeburn 7711: my $newacc =
7712: &Apache::lonnet::usertools_access($env{'user.name'},
7713: $env{'user.domain'},
1.86 raeburn 7714: $item,'reload',$context);
1.160.6.5 raeburn 7715: if (($context eq 'requestcourses') ||
7716: ($context eq 'requestauthor')) {
1.108 raeburn 7717: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7718: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7719: }
7720: } else {
7721: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7722: $newenv{'environment.availabletools.'.$item} = $newacc;
7723: }
1.80 raeburn 7724: }
1.160.6.5 raeburn 7725: unless ($context eq 'requestauthor') {
7726: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7727: }
1.72 raeburn 7728: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7729: if ($haschgs{$type}) {
1.72 raeburn 7730: my $typetitle = $usertypes->{$type};
7731: if ($type eq 'default') {
7732: $typetitle = $othertitle;
7733: } elsif ($type eq '_LC_adv') {
7734: $typetitle = 'LON-CAPA Advanced Users';
7735: }
1.160.6.5 raeburn 7736: if ($inconf{$type}) {
1.101 raeburn 7737: if ($context eq 'requestcourses') {
7738: my $cond;
1.160.6.5 raeburn 7739: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7740: if ($1 eq '') {
7741: $cond = &mt('(Automatic processing of any request).');
7742: } else {
7743: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7744: }
7745: } else {
1.160.6.5 raeburn 7746: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7747: }
7748: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7749: } elsif ($context eq 'requestauthor') {
7750: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7751: $titles{$inconf{$type}},$typetitle);
7752:
1.101 raeburn 7753: } else {
7754: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7755: }
1.72 raeburn 7756: } else {
1.104 raeburn 7757: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7758: if ($inconf{$type} eq '0') {
1.104 raeburn 7759: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7760: } else {
7761: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7762: }
7763: } else {
7764: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7765: }
1.72 raeburn 7766: }
7767: }
1.26 raeburn 7768: }
1.160.6.5 raeburn 7769: unless ($context eq 'requestauthor') {
7770: $resulttext .= '</ul></li>';
7771: }
1.26 raeburn 7772: }
1.1 raeburn 7773: }
1.160.6.5 raeburn 7774: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7775: if (ref($changes{'notify'}) eq 'HASH') {
7776: if ($changes{'notify'}{'approval'}) {
7777: if (ref($confhash{'notify'}) eq 'HASH') {
7778: if ($confhash{'notify'}{'approval'}) {
7779: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7780: } else {
1.160.6.5 raeburn 7781: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7782: }
7783: }
7784: }
7785: }
7786: }
1.160.6.30 raeburn 7787: if ($action eq 'requestcourses') {
7788: my @offon = ('off','on');
7789: if ($changes{'uniquecode'}) {
7790: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7791: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7792: $resulttext .= '<li>'.
7793: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7794: '</li>';
7795: } else {
7796: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7797: '</li>';
7798: }
7799: }
1.160.6.46 raeburn 7800: foreach my $type ('textbooks','templates') {
7801: if (ref($changes{$type}) eq 'HASH') {
7802: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7803: foreach my $key (sort(keys(%{$changes{$type}}))) {
7804: my %coursehash = &Apache::lonnet::coursedescription($key);
7805: my $coursetitle = $coursehash{'description'};
7806: my $position = $confhash{$type}{$key}{'order'} + 1;
7807: $resulttext .= '<li>';
1.160.6.47 raeburn 7808: foreach my $item ('subject','title','publisher','author') {
7809: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7810: ($type eq 'templates'));
1.160.6.46 raeburn 7811: my $name = $item.':';
7812: $name =~ s/^(\w)/\U$1/;
7813: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7814: }
7815: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7816: if ($type eq 'textbooks') {
7817: if ($confhash{$type}{$key}{'image'}) {
7818: $resulttext .= ' '.&mt('Image: [_1]',
7819: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7820: ' alt="Textbook cover" />').'<br />';
7821: }
7822: }
7823: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7824: }
1.160.6.46 raeburn 7825: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7826: }
7827: }
1.160.6.39 raeburn 7828: if (ref($changes{'validation'}) eq 'HASH') {
7829: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7830: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7831: foreach my $item (@{$validationitemsref}) {
7832: if (exists($changes{'validation'}{$item})) {
7833: if ($item eq 'markup') {
7834: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7835: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7836: } else {
7837: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7838: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7839: }
7840: }
7841: }
7842: if (exists($changes{'validation'}{'dc'})) {
7843: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7844: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7845: }
7846: }
7847: }
1.160.6.30 raeburn 7848: }
1.1 raeburn 7849: $resulttext .= '</ul>';
1.80 raeburn 7850: if (keys(%newenv)) {
7851: &Apache::lonnet::appenv(\%newenv);
7852: }
1.1 raeburn 7853: } else {
1.86 raeburn 7854: if ($context eq 'requestcourses') {
7855: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7856: } elsif ($context eq 'requestauthor') {
7857: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7858: } else {
1.90 weissno 7859: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7860: }
1.1 raeburn 7861: }
7862: } else {
1.11 albertel 7863: $resulttext = '<span class="LC_error">'.
7864: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7865: }
1.160.6.30 raeburn 7866: if ($errors) {
7867: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7868: '<ul>'.$errors.'</ul></p>';
7869: }
1.3 raeburn 7870: return $resulttext;
1.1 raeburn 7871: }
7872:
1.160.6.30 raeburn 7873: sub process_textbook_image {
1.160.6.46 raeburn 7874: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7875: my $filename = $env{'form.'.$caller.'.filename'};
7876: my ($error,$url);
7877: my ($width,$height) = (50,50);
7878: if ($configuserok eq 'ok') {
7879: if ($switchserver) {
7880: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7881: $switchserver);
7882: } elsif ($author_ok eq 'ok') {
7883: my ($result,$imageurl) =
7884: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7885: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7886: if ($result eq 'ok') {
7887: $url = $imageurl;
7888: } else {
7889: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7890: }
7891: } else {
7892: $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);
7893: }
7894: } else {
7895: $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);
7896: }
7897: return ($url,$error);
7898: }
7899:
1.3 raeburn 7900: sub modify_autoenroll {
1.160.6.24 raeburn 7901: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7902: my ($resulttext,%changes);
7903: my %currautoenroll;
7904: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7905: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7906: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7907: }
7908: }
7909: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7910: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7911: sender => 'Sender for notification messages',
1.160.6.68 raeburn 7912: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
7913: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 7914: my @offon = ('off','on');
1.17 raeburn 7915: my $sender_uname = $env{'form.sender_uname'};
7916: my $sender_domain = $env{'form.sender_domain'};
7917: if ($sender_domain eq '') {
7918: $sender_uname = '';
7919: } elsif ($sender_uname eq '') {
7920: $sender_domain = '';
7921: }
1.129 raeburn 7922: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 7923: my $failsafe = $env{'form.autoenroll_failsafe'};
7924: $failsafe =~ s{^\s+|\s+$}{}g;
7925: if ($failsafe =~ /\D/) {
7926: undef($failsafe);
7927: }
1.1 raeburn 7928: my %autoenrollhash = (
1.129 raeburn 7929: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7930: 'sender_uname' => $sender_uname,
7931: 'sender_domain' => $sender_domain,
7932: 'co-owners' => $coowners,
1.160.6.68 raeburn 7933: 'autofailsafe' => $failsafe,
1.1 raeburn 7934: }
7935: );
1.4 raeburn 7936: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7937: $dom);
1.1 raeburn 7938: if ($putresult eq 'ok') {
7939: if (exists($currautoenroll{'run'})) {
7940: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7941: $changes{'run'} = 1;
7942: }
7943: } elsif ($autorun) {
7944: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7945: $changes{'run'} = 1;
1.1 raeburn 7946: }
7947: }
1.17 raeburn 7948: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7949: $changes{'sender'} = 1;
7950: }
1.17 raeburn 7951: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7952: $changes{'sender'} = 1;
7953: }
1.129 raeburn 7954: if ($currautoenroll{'co-owners'} ne '') {
7955: if ($currautoenroll{'co-owners'} ne $coowners) {
7956: $changes{'coowners'} = 1;
7957: }
7958: } elsif ($coowners) {
7959: $changes{'coowners'} = 1;
1.160.6.68 raeburn 7960: }
7961: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
7962: $changes{'autofailsafe'} = 1;
7963: }
1.1 raeburn 7964: if (keys(%changes) > 0) {
7965: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7966: if ($changes{'run'}) {
1.1 raeburn 7967: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7968: }
7969: if ($changes{'sender'}) {
1.17 raeburn 7970: if ($sender_uname eq '' || $sender_domain eq '') {
7971: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7972: } else {
7973: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7974: }
1.1 raeburn 7975: }
1.129 raeburn 7976: if ($changes{'coowners'}) {
7977: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7978: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7979: if (ref($lastactref) eq 'HASH') {
7980: $lastactref->{'domainconfig'} = 1;
7981: }
1.129 raeburn 7982: }
1.160.6.68 raeburn 7983: if ($changes{'autofailsafe'}) {
7984: if ($failsafe ne '') {
7985: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
7986: } else {
7987: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
7988: }
7989: &Apache::lonnet::get_domain_defaults($dom,1);
7990: if (ref($lastactref) eq 'HASH') {
7991: $lastactref->{'domdefaults'} = 1;
7992: }
7993: }
1.1 raeburn 7994: $resulttext .= '</ul>';
7995: } else {
7996: $resulttext = &mt('No changes made to auto-enrollment settings');
7997: }
7998: } else {
1.11 albertel 7999: $resulttext = '<span class="LC_error">'.
8000: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8001: }
1.3 raeburn 8002: return $resulttext;
1.1 raeburn 8003: }
8004:
8005: sub modify_autoupdate {
1.3 raeburn 8006: my ($dom,%domconfig) = @_;
1.1 raeburn 8007: my ($resulttext,%currautoupdate,%fields,%changes);
8008: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8009: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8010: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8011: }
8012: }
8013: my @offon = ('off','on');
8014: my %title = &Apache::lonlocal::texthash (
8015: run => 'Auto-update:',
8016: classlists => 'Updates to user information in classlists?'
8017: );
1.44 raeburn 8018: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8019: my %fieldtitles = &Apache::lonlocal::texthash (
8020: id => 'Student/Employee ID',
1.20 raeburn 8021: permanentemail => 'E-mail address',
1.1 raeburn 8022: lastname => 'Last Name',
8023: firstname => 'First Name',
8024: middlename => 'Middle Name',
1.132 raeburn 8025: generation => 'Generation',
1.1 raeburn 8026: );
1.142 raeburn 8027: $othertitle = &mt('All users');
1.1 raeburn 8028: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8029: $othertitle = &mt('Other users');
1.1 raeburn 8030: }
8031: foreach my $key (keys(%env)) {
8032: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8033: my ($usertype,$item) = ($1,$2);
8034: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8035: if ($usertype eq 'default') {
8036: push(@{$fields{$1}},$2);
8037: } elsif (ref($types) eq 'ARRAY') {
8038: if (grep(/^\Q$usertype\E$/,@{$types})) {
8039: push(@{$fields{$1}},$2);
8040: }
8041: }
8042: }
1.1 raeburn 8043: }
8044: }
1.131 raeburn 8045: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8046: @lockablenames = sort(@lockablenames);
8047: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8048: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8049: if (@changed) {
8050: $changes{'lockablenames'} = 1;
8051: }
8052: } else {
8053: if (@lockablenames) {
8054: $changes{'lockablenames'} = 1;
8055: }
8056: }
1.1 raeburn 8057: my %updatehash = (
8058: autoupdate => { run => $env{'form.autoupdate_run'},
8059: classlists => $env{'form.classlists'},
8060: fields => {%fields},
1.131 raeburn 8061: lockablenames => \@lockablenames,
1.1 raeburn 8062: }
8063: );
8064: foreach my $key (keys(%currautoupdate)) {
8065: if (($key eq 'run') || ($key eq 'classlists')) {
8066: if (exists($updatehash{autoupdate}{$key})) {
8067: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8068: $changes{$key} = 1;
8069: }
8070: }
8071: } elsif ($key eq 'fields') {
8072: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8073: foreach my $item (@{$types},'default') {
1.1 raeburn 8074: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8075: my $change = 0;
8076: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8077: if (!exists($fields{$item})) {
8078: $change = 1;
1.132 raeburn 8079: last;
1.1 raeburn 8080: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8081: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8082: $change = 1;
1.132 raeburn 8083: last;
1.1 raeburn 8084: }
8085: }
8086: }
8087: if ($change) {
8088: push(@{$changes{$key}},$item);
8089: }
1.26 raeburn 8090: }
1.1 raeburn 8091: }
8092: }
1.131 raeburn 8093: } elsif ($key eq 'lockablenames') {
8094: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8095: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8096: if (@changed) {
8097: $changes{'lockablenames'} = 1;
8098: }
8099: } else {
8100: if (@lockablenames) {
8101: $changes{'lockablenames'} = 1;
8102: }
8103: }
8104: }
8105: }
8106: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8107: if (@lockablenames) {
8108: $changes{'lockablenames'} = 1;
1.1 raeburn 8109: }
8110: }
1.26 raeburn 8111: foreach my $item (@{$types},'default') {
8112: if (defined($fields{$item})) {
8113: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8114: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8115: my $change = 0;
8116: if (ref($fields{$item}) eq 'ARRAY') {
8117: foreach my $type (@{$fields{$item}}) {
8118: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8119: $change = 1;
8120: last;
8121: }
8122: }
8123: }
8124: if ($change) {
8125: push(@{$changes{'fields'}},$item);
8126: }
8127: } else {
1.26 raeburn 8128: push(@{$changes{'fields'}},$item);
8129: }
8130: } else {
8131: push(@{$changes{'fields'}},$item);
1.1 raeburn 8132: }
8133: }
8134: }
8135: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8136: $dom);
8137: if ($putresult eq 'ok') {
8138: if (keys(%changes) > 0) {
8139: $resulttext = &mt('Changes made:').'<ul>';
8140: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8141: if ($key eq 'lockablenames') {
8142: $resulttext .= '<li>';
8143: if (@lockablenames) {
8144: $usertypes->{'default'} = $othertitle;
8145: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8146: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8147: } else {
8148: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8149: }
8150: $resulttext .= '</li>';
8151: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8152: foreach my $item (@{$changes{$key}}) {
8153: my @newvalues;
8154: foreach my $type (@{$fields{$item}}) {
8155: push(@newvalues,$fieldtitles{$type});
8156: }
1.3 raeburn 8157: my $newvaluestr;
8158: if (@newvalues > 0) {
8159: $newvaluestr = join(', ',@newvalues);
8160: } else {
8161: $newvaluestr = &mt('none');
1.6 raeburn 8162: }
1.1 raeburn 8163: if ($item eq 'default') {
1.26 raeburn 8164: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8165: } else {
1.26 raeburn 8166: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8167: }
8168: }
8169: } else {
8170: my $newvalue;
8171: if ($key eq 'run') {
8172: $newvalue = $offon[$env{'form.autoupdate_run'}];
8173: } else {
8174: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8175: }
1.1 raeburn 8176: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8177: }
8178: }
8179: $resulttext .= '</ul>';
8180: } else {
1.3 raeburn 8181: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8182: }
8183: } else {
1.11 albertel 8184: $resulttext = '<span class="LC_error">'.
8185: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8186: }
1.3 raeburn 8187: return $resulttext;
1.1 raeburn 8188: }
8189:
1.125 raeburn 8190: sub modify_autocreate {
8191: my ($dom,%domconfig) = @_;
8192: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8193: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8194: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8195: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8196: }
8197: }
8198: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8199: req => 'Auto-creation of validated requests for official courses',
8200: xmldc => 'Identity of course creator of courses from XML files',
8201: );
8202: my @types = ('xml','req');
8203: foreach my $item (@types) {
8204: $newvals{$item} = $env{'form.autocreate_'.$item};
8205: $newvals{$item} =~ s/\D//g;
8206: $newvals{$item} = 0 if ($newvals{$item} eq '');
8207: }
8208: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8209: my %domcoords = &get_active_dcs($dom);
8210: unless (exists($domcoords{$newvals{'xmldc'}})) {
8211: $newvals{'xmldc'} = '';
8212: }
8213: %autocreatehash = (
8214: autocreate => { xml => $newvals{'xml'},
8215: req => $newvals{'req'},
8216: }
8217: );
8218: if ($newvals{'xmldc'} ne '') {
8219: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8220: }
8221: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8222: $dom);
8223: if ($putresult eq 'ok') {
8224: my @items = @types;
8225: if ($newvals{'xml'}) {
8226: push(@items,'xmldc');
8227: }
8228: foreach my $item (@items) {
8229: if (exists($currautocreate{$item})) {
8230: if ($currautocreate{$item} ne $newvals{$item}) {
8231: $changes{$item} = 1;
8232: }
8233: } elsif ($newvals{$item}) {
8234: $changes{$item} = 1;
8235: }
8236: }
8237: if (keys(%changes) > 0) {
8238: my @offon = ('off','on');
8239: $resulttext = &mt('Changes made:').'<ul>';
8240: foreach my $item (@types) {
8241: if ($changes{$item}) {
8242: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8243: $resulttext .= '<li>'.
8244: &mt("$title{$item} set to [_1]$newtxt [_2]",
8245: '<b>','</b>').
8246: '</li>';
1.125 raeburn 8247: }
8248: }
8249: if ($changes{'xmldc'}) {
8250: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8251: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8252: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8253: }
8254: $resulttext .= '</ul>';
8255: } else {
8256: $resulttext = &mt('No changes made to auto-creation settings');
8257: }
8258: } else {
8259: $resulttext = '<span class="LC_error">'.
8260: &mt('An error occurred: [_1]',$putresult).'</span>';
8261: }
8262: return $resulttext;
8263: }
8264:
1.23 raeburn 8265: sub modify_directorysrch {
8266: my ($dom,%domconfig) = @_;
8267: my ($resulttext,%changes);
8268: my %currdirsrch;
8269: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8270: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8271: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8272: }
8273: }
8274: my %title = ( available => 'Directory search available',
1.24 raeburn 8275: localonly => 'Other domains can search',
1.23 raeburn 8276: searchby => 'Search types',
8277: searchtypes => 'Search latitude');
8278: my @offon = ('off','on');
1.24 raeburn 8279: my @otherdoms = ('Yes','No');
1.23 raeburn 8280:
1.25 raeburn 8281: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8282: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8283: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8284:
1.44 raeburn 8285: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8286: if (keys(%{$usertypes}) == 0) {
8287: @cansearch = ('default');
8288: } else {
8289: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8290: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8291: if (!grep(/^\Q$type\E$/,@cansearch)) {
8292: push(@{$changes{'cansearch'}},$type);
8293: }
1.23 raeburn 8294: }
1.26 raeburn 8295: foreach my $type (@cansearch) {
8296: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8297: push(@{$changes{'cansearch'}},$type);
8298: }
1.23 raeburn 8299: }
1.26 raeburn 8300: } else {
8301: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8302: }
8303: }
8304:
8305: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8306: foreach my $by (@{$currdirsrch{'searchby'}}) {
8307: if (!grep(/^\Q$by\E$/,@searchby)) {
8308: push(@{$changes{'searchby'}},$by);
8309: }
8310: }
8311: foreach my $by (@searchby) {
8312: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8313: push(@{$changes{'searchby'}},$by);
8314: }
8315: }
8316: } else {
8317: push(@{$changes{'searchby'}},@searchby);
8318: }
1.25 raeburn 8319:
8320: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8321: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8322: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8323: push(@{$changes{'searchtypes'}},$type);
8324: }
8325: }
8326: foreach my $type (@searchtypes) {
8327: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8328: push(@{$changes{'searchtypes'}},$type);
8329: }
8330: }
8331: } else {
8332: if (exists($currdirsrch{'searchtypes'})) {
8333: foreach my $type (@searchtypes) {
8334: if ($type ne $currdirsrch{'searchtypes'}) {
8335: push(@{$changes{'searchtypes'}},$type);
8336: }
8337: }
8338: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8339: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8340: }
8341: } else {
8342: push(@{$changes{'searchtypes'}},@searchtypes);
8343: }
8344: }
8345:
1.23 raeburn 8346: my %dirsrch_hash = (
8347: directorysrch => { available => $env{'form.dirsrch_available'},
8348: cansearch => \@cansearch,
1.24 raeburn 8349: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8350: searchby => \@searchby,
1.25 raeburn 8351: searchtypes => \@searchtypes,
1.23 raeburn 8352: }
8353: );
8354: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8355: $dom);
8356: if ($putresult eq 'ok') {
8357: if (exists($currdirsrch{'available'})) {
8358: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8359: $changes{'available'} = 1;
8360: }
8361: } else {
8362: if ($env{'form.dirsrch_available'} eq '1') {
8363: $changes{'available'} = 1;
8364: }
8365: }
1.24 raeburn 8366: if (exists($currdirsrch{'localonly'})) {
8367: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8368: $changes{'localonly'} = 1;
8369: }
8370: } else {
8371: if ($env{'form.dirsrch_localonly'} eq '1') {
8372: $changes{'localonly'} = 1;
8373: }
8374: }
1.23 raeburn 8375: if (keys(%changes) > 0) {
8376: $resulttext = &mt('Changes made:').'<ul>';
8377: if ($changes{'available'}) {
8378: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8379: }
1.24 raeburn 8380: if ($changes{'localonly'}) {
8381: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8382: }
8383:
1.23 raeburn 8384: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8385: my $chgtext;
1.26 raeburn 8386: if (ref($usertypes) eq 'HASH') {
8387: if (keys(%{$usertypes}) > 0) {
8388: foreach my $type (@{$types}) {
8389: if (grep(/^\Q$type\E$/,@cansearch)) {
8390: $chgtext .= $usertypes->{$type}.'; ';
8391: }
8392: }
8393: if (grep(/^default$/,@cansearch)) {
8394: $chgtext .= $othertitle;
8395: } else {
8396: $chgtext =~ s/\; $//;
8397: }
1.160.6.13 raeburn 8398: $resulttext .=
8399: '<li>'.
8400: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8401: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8402: '</li>';
1.23 raeburn 8403: }
8404: }
8405: }
8406: if (ref($changes{'searchby'}) eq 'ARRAY') {
8407: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8408: my $chgtext;
8409: foreach my $type (@{$titleorder}) {
8410: if (grep(/^\Q$type\E$/,@searchby)) {
8411: if (defined($searchtitles->{$type})) {
8412: $chgtext .= $searchtitles->{$type}.'; ';
8413: }
8414: }
8415: }
8416: $chgtext =~ s/\; $//;
8417: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8418: }
1.25 raeburn 8419: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8420: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8421: my $chgtext;
8422: foreach my $type (@{$srchtypeorder}) {
8423: if (grep(/^\Q$type\E$/,@searchtypes)) {
8424: if (defined($srchtypes_desc->{$type})) {
8425: $chgtext .= $srchtypes_desc->{$type}.'; ';
8426: }
8427: }
8428: }
8429: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8430: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8431: }
8432: $resulttext .= '</ul>';
8433: } else {
8434: $resulttext = &mt('No changes made to institution directory search settings');
8435: }
8436: } else {
8437: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8438: &mt('An error occurred: [_1]',$putresult).'</span>';
8439: }
8440: return $resulttext;
8441: }
8442:
1.28 raeburn 8443: sub modify_contacts {
1.160.6.24 raeburn 8444: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8445: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8446: if (ref($domconfig{'contacts'}) eq 'HASH') {
8447: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8448: $currsetting{$key} = $domconfig{'contacts'}{$key};
8449: }
8450: }
1.134 raeburn 8451: my (%others,%to,%bcc);
1.28 raeburn 8452: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8453: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8454: 'requestsmail','updatesmail','idconflictsmail');
8455: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8456: foreach my $type (@mailings) {
8457: @{$newsetting{$type}} =
8458: &Apache::loncommon::get_env_multiple('form.'.$type);
8459: foreach my $item (@contacts) {
8460: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8461: $contacts_hash{contacts}{$type}{$item} = 1;
8462: } else {
8463: $contacts_hash{contacts}{$type}{$item} = 0;
8464: }
8465: }
8466: $others{$type} = $env{'form.'.$type.'_others'};
8467: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8468: if ($type eq 'helpdeskmail') {
8469: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8470: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8471: }
1.28 raeburn 8472: }
8473: foreach my $item (@contacts) {
8474: $to{$item} = $env{'form.'.$item};
8475: $contacts_hash{'contacts'}{$item} = $to{$item};
8476: }
1.160.6.23 raeburn 8477: foreach my $item (@toggles) {
8478: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8479: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8480: }
8481: }
1.28 raeburn 8482: if (keys(%currsetting) > 0) {
8483: foreach my $item (@contacts) {
8484: if ($to{$item} ne $currsetting{$item}) {
8485: $changes{$item} = 1;
8486: }
8487: }
8488: foreach my $type (@mailings) {
8489: foreach my $item (@contacts) {
8490: if (ref($currsetting{$type}) eq 'HASH') {
8491: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8492: push(@{$changes{$type}},$item);
8493: }
8494: } else {
8495: push(@{$changes{$type}},@{$newsetting{$type}});
8496: }
8497: }
8498: if ($others{$type} ne $currsetting{$type}{'others'}) {
8499: push(@{$changes{$type}},'others');
8500: }
1.134 raeburn 8501: if ($type eq 'helpdeskmail') {
8502: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8503: push(@{$changes{$type}},'bcc');
8504: }
8505: }
1.28 raeburn 8506: }
8507: } else {
8508: my %default;
8509: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8510: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8511: $default{'errormail'} = 'adminemail';
8512: $default{'packagesmail'} = 'adminemail';
8513: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8514: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8515: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8516: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8517: foreach my $item (@contacts) {
8518: if ($to{$item} ne $default{$item}) {
8519: $changes{$item} = 1;
1.160.6.23 raeburn 8520: }
1.28 raeburn 8521: }
8522: foreach my $type (@mailings) {
8523: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8524:
8525: push(@{$changes{$type}},@{$newsetting{$type}});
8526: }
8527: if ($others{$type} ne '') {
8528: push(@{$changes{$type}},'others');
1.134 raeburn 8529: }
8530: if ($type eq 'helpdeskmail') {
8531: if ($bcc{$type} ne '') {
8532: push(@{$changes{$type}},'bcc');
8533: }
8534: }
1.28 raeburn 8535: }
8536: }
1.160.6.23 raeburn 8537: foreach my $item (@toggles) {
8538: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8539: $changes{$item} = 1;
8540: } elsif ((!$env{'form.'.$item}) &&
8541: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8542: $changes{$item} = 1;
8543: }
8544: }
1.28 raeburn 8545: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8546: $dom);
8547: if ($putresult eq 'ok') {
8548: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8549: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8550: if (ref($lastactref) eq 'HASH') {
8551: $lastactref->{'domainconfig'} = 1;
8552: }
1.28 raeburn 8553: my ($titles,$short_titles) = &contact_titles();
8554: $resulttext = &mt('Changes made:').'<ul>';
8555: foreach my $item (@contacts) {
8556: if ($changes{$item}) {
8557: $resulttext .= '<li>'.$titles->{$item}.
8558: &mt(' set to: ').
8559: '<span class="LC_cusr_emph">'.
8560: $to{$item}.'</span></li>';
8561: }
8562: }
8563: foreach my $type (@mailings) {
8564: if (ref($changes{$type}) eq 'ARRAY') {
8565: $resulttext .= '<li>'.$titles->{$type}.': ';
8566: my @text;
8567: foreach my $item (@{$newsetting{$type}}) {
8568: push(@text,$short_titles->{$item});
8569: }
8570: if ($others{$type} ne '') {
8571: push(@text,$others{$type});
8572: }
8573: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8574: join(', ',@text).'</span>';
8575: if ($type eq 'helpdeskmail') {
8576: if ($bcc{$type} ne '') {
8577: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8578: }
8579: }
8580: $resulttext .= '</li>';
1.28 raeburn 8581: }
8582: }
1.160.6.23 raeburn 8583: my @offon = ('off','on');
8584: if ($changes{'reporterrors'}) {
8585: $resulttext .= '<li>'.
8586: &mt('E-mail error reports to [_1] set to "'.
8587: $offon[$env{'form.reporterrors'}].'".',
8588: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8589: &mt('LON-CAPA core group - MSU'),600,500)).
8590: '</li>';
8591: }
8592: if ($changes{'reportupdates'}) {
8593: $resulttext .= '<li>'.
8594: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8595: $offon[$env{'form.reportupdates'}].'".',
8596: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8597: &mt('LON-CAPA core group - MSU'),600,500)).
8598: '</li>';
8599: }
1.28 raeburn 8600: $resulttext .= '</ul>';
8601: } else {
1.34 raeburn 8602: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8603: }
8604: } else {
8605: $resulttext = '<span class="LC_error">'.
8606: &mt('An error occurred: [_1].',$putresult).'</span>';
8607: }
8608: return $resulttext;
8609: }
8610:
8611: sub modify_usercreation {
1.27 raeburn 8612: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8613: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8614: my $warningmsg;
1.27 raeburn 8615: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8616: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8617: if ($key eq 'cancreate') {
8618: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8619: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8620: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69! raeburn 8621: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
! 8622: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 8623: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8624: } else {
8625: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8626: }
1.50 raeburn 8627: }
1.43 raeburn 8628: }
1.160.6.34 raeburn 8629: } elsif ($key eq 'email_rule') {
8630: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8631: } else {
8632: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8633: }
8634: }
1.34 raeburn 8635: }
1.160.6.34 raeburn 8636: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8637: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8638: my @contexts = ('author','course','requestcrs');
8639: foreach my $item(@contexts) {
8640: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8641: }
1.34 raeburn 8642: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8643: foreach my $item (@contexts) {
1.160.6.34 raeburn 8644: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8645: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8646: }
1.27 raeburn 8647: }
1.34 raeburn 8648: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8649: foreach my $item (@contexts) {
1.43 raeburn 8650: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8651: if ($cancreate{$item} ne 'any') {
8652: push(@{$changes{'cancreate'}},$item);
8653: }
8654: } else {
8655: if ($cancreate{$item} ne 'none') {
8656: push(@{$changes{'cancreate'}},$item);
8657: }
1.27 raeburn 8658: }
8659: }
8660: } else {
1.43 raeburn 8661: foreach my $item (@contexts) {
1.34 raeburn 8662: push(@{$changes{'cancreate'}},$item);
8663: }
1.27 raeburn 8664: }
1.34 raeburn 8665:
1.27 raeburn 8666: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8667: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8668: if (!grep(/^\Q$type\E$/,@username_rule)) {
8669: push(@{$changes{'username_rule'}},$type);
8670: }
8671: }
8672: foreach my $type (@username_rule) {
8673: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8674: push(@{$changes{'username_rule'}},$type);
8675: }
8676: }
8677: } else {
8678: push(@{$changes{'username_rule'}},@username_rule);
8679: }
8680:
1.32 raeburn 8681: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8682: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8683: if (!grep(/^\Q$type\E$/,@id_rule)) {
8684: push(@{$changes{'id_rule'}},$type);
8685: }
8686: }
8687: foreach my $type (@id_rule) {
8688: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8689: push(@{$changes{'id_rule'}},$type);
8690: }
8691: }
8692: } else {
8693: push(@{$changes{'id_rule'}},@id_rule);
8694: }
8695:
1.43 raeburn 8696: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8697: my @authtypes = ('int','krb4','krb5','loc');
8698: my %authhash;
1.43 raeburn 8699: foreach my $item (@authen_contexts) {
1.28 raeburn 8700: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8701: foreach my $auth (@authtypes) {
8702: if (grep(/^\Q$auth\E$/,@authallowed)) {
8703: $authhash{$item}{$auth} = 1;
8704: } else {
8705: $authhash{$item}{$auth} = 0;
8706: }
8707: }
8708: }
8709: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8710: foreach my $item (@authen_contexts) {
1.28 raeburn 8711: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8712: foreach my $auth (@authtypes) {
8713: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8714: push(@{$changes{'authtypes'}},$item);
8715: last;
8716: }
8717: }
8718: }
8719: }
8720: } else {
1.43 raeburn 8721: foreach my $item (@authen_contexts) {
1.28 raeburn 8722: push(@{$changes{'authtypes'}},$item);
8723: }
8724: }
8725:
1.160.6.34 raeburn 8726: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8727: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8728: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8729: $save_usercreate{'id_rule'} = \@id_rule;
8730: $save_usercreate{'username_rule'} = \@username_rule,
8731: $save_usercreate{'authtypes'} = \%authhash;
8732:
1.27 raeburn 8733: my %usercreation_hash = (
1.160.6.34 raeburn 8734: usercreation => \%save_usercreate,
8735: );
1.27 raeburn 8736:
8737: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8738: $dom);
1.50 raeburn 8739:
1.160.6.34 raeburn 8740: if ($putresult eq 'ok') {
8741: if (keys(%changes) > 0) {
8742: $resulttext = &mt('Changes made:').'<ul>';
8743: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8744: my %lt = &usercreation_types();
8745: foreach my $type (@{$changes{'cancreate'}}) {
8746: my $chgtext = $lt{$type}.', ';
8747: if ($cancreate{$type} eq 'none') {
8748: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8749: } elsif ($cancreate{$type} eq 'any') {
8750: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8751: } elsif ($cancreate{$type} eq 'official') {
8752: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8753: } elsif ($cancreate{$type} eq 'unofficial') {
8754: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8755: }
8756: $resulttext .= '<li>'.$chgtext.'</li>';
8757: }
8758: }
8759: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8760: my ($rules,$ruleorder) =
8761: &Apache::lonnet::inst_userrules($dom,'username');
8762: my $chgtext = '<ul>';
8763: foreach my $type (@username_rule) {
8764: if (ref($rules->{$type}) eq 'HASH') {
8765: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8766: }
8767: }
8768: $chgtext .= '</ul>';
8769: if (@username_rule > 0) {
8770: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8771: } else {
8772: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8773: }
8774: }
8775: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8776: my ($idrules,$idruleorder) =
8777: &Apache::lonnet::inst_userrules($dom,'id');
8778: my $chgtext = '<ul>';
8779: foreach my $type (@id_rule) {
8780: if (ref($idrules->{$type}) eq 'HASH') {
8781: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8782: }
8783: }
8784: $chgtext .= '</ul>';
8785: if (@id_rule > 0) {
8786: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8787: } else {
8788: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8789: }
8790: }
8791: my %authname = &authtype_names();
8792: my %context_title = &context_names();
8793: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8794: my $chgtext = '<ul>';
8795: foreach my $type (@{$changes{'authtypes'}}) {
8796: my @allowed;
8797: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8798: foreach my $auth (@authtypes) {
8799: if ($authhash{$type}{$auth}) {
8800: push(@allowed,$authname{$auth});
8801: }
8802: }
8803: if (@allowed > 0) {
8804: $chgtext .= join(', ',@allowed).'</li>';
8805: } else {
8806: $chgtext .= &mt('none').'</li>';
8807: }
8808: }
8809: $chgtext .= '</ul>';
8810: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8811: $resulttext .= '</li>';
8812: }
8813: $resulttext .= '</ul>';
8814: } else {
8815: $resulttext = &mt('No changes made to user creation settings');
8816: }
8817: } else {
8818: $resulttext = '<span class="LC_error">'.
8819: &mt('An error occurred: [_1]',$putresult).'</span>';
8820: }
8821: if ($warningmsg ne '') {
8822: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8823: }
8824: return $resulttext;
8825: }
8826:
8827: sub modify_selfcreation {
8828: my ($dom,%domconfig) = @_;
8829: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8830: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8831: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8832: if (ref($types) eq 'ARRAY') {
8833: $usertypes->{'default'} = $othertitle;
8834: push(@{$types},'default');
8835: }
1.160.6.34 raeburn 8836: #
8837: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8838: #
8839: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8840: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8841: if ($key eq 'cancreate') {
8842: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8843: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8844: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8845: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69! raeburn 8846: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 8847: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8848: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8849: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8850: } else {
8851: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8852: }
8853: }
8854: }
8855: } elsif ($key eq 'email_rule') {
8856: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8857: } else {
8858: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8859: }
8860: }
8861: }
8862: #
8863: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8864: #
8865: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8866: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8867: if ($key eq 'selfcreate') {
8868: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8869: } else {
8870: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8871: }
8872: }
8873: }
8874:
8875: my @contexts = ('selfcreate');
8876: @{$cancreate{'selfcreate'}} = ();
8877: %{$cancreate{'emailusername'}} = ();
8878: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8879: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8880: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8881: my %selfcreatetypes = (
8882: sso => 'users authenticated by institutional single sign on',
8883: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8884: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8885: );
1.160.6.34 raeburn 8886: #
8887: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8888: # is permitted.
8889: #
1.160.6.40 raeburn 8890:
8891: my @statuses;
8892: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8893: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8894: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8895: }
8896: }
8897: push(@statuses,'default');
8898:
1.160.6.35 raeburn 8899: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8900: if ($item eq 'email') {
1.160.6.40 raeburn 8901: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8902: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8903: push(@contexts,'selfcreateprocessing');
8904: foreach my $type (@statuses) {
8905: if ($type eq 'default') {
8906: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8907: } else {
8908: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8909: }
8910: }
1.160.6.34 raeburn 8911: }
8912: } else {
8913: if ($env{'form.cancreate_'.$item}) {
8914: push(@{$cancreate{'selfcreate'}},$item);
8915: }
8916: }
8917: }
8918: my (@email_rule,%userinfo,%savecaptcha);
8919: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8920: #
1.160.6.35 raeburn 8921: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8922: # 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 8923: #
1.160.6.40 raeburn 8924:
1.160.6.48 raeburn 8925: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8926: push(@contexts,'emailusername');
1.160.6.35 raeburn 8927: if (ref($types) eq 'ARRAY') {
8928: foreach my $type (@{$types}) {
8929: if (ref($infofields) eq 'ARRAY') {
8930: foreach my $field (@{$infofields}) {
8931: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8932: $cancreate{'emailusername'}{$type}{$field} = $1;
8933: }
8934: }
1.160.6.34 raeburn 8935: }
8936: }
8937: }
8938: #
8939: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8940: # queued requests for self-creation of account using e-mail address as username
8941: #
8942:
8943: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8944: @approvalnotify = sort(@approvalnotify);
8945: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8946: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8947: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8948: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8949: push(@{$changes{'cancreate'}},'notify');
8950: }
8951: } else {
8952: if ($cancreate{'notify'}{'approval'}) {
8953: push(@{$changes{'cancreate'}},'notify');
8954: }
8955: }
8956: } elsif ($cancreate{'notify'}{'approval'}) {
8957: push(@{$changes{'cancreate'}},'notify');
8958: }
8959:
8960: #
8961: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8962: #
8963: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8964: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8965: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8966: if (@{$curr_usercreation{'email_rule'}} > 0) {
8967: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8968: if (!grep(/^\Q$type\E$/,@email_rule)) {
8969: push(@{$changes{'email_rule'}},$type);
8970: }
8971: }
8972: }
8973: if (@email_rule > 0) {
8974: foreach my $type (@email_rule) {
8975: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8976: push(@{$changes{'email_rule'}},$type);
8977: }
8978: }
8979: }
8980: } elsif (@email_rule > 0) {
8981: push(@{$changes{'email_rule'}},@email_rule);
8982: }
8983: }
8984: #
1.160.6.40 raeburn 8985: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8986: # institutional log-in.
8987: #
8988: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8989: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8990: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8991: ($domdefaults{'auth_def'} eq 'localauth'))) {
8992: $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.').' '.
8993: &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.');
8994: }
8995: }
8996: my @fields = ('lastname','firstname','middlename','generation',
8997: 'permanentemail','id');
1.160.6.44 raeburn 8998: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8999: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9000: #
9001: # Where usernames may created for institutional log-in and/or institutional single sign on:
9002: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9003: # may self-create accounts
9004: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9005: # which the user may supply, if institutional data is unavailable.
9006: #
9007: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9008: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9009: if (@{$types} > 1) {
1.160.6.34 raeburn 9010: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9011: push(@contexts,'statustocreate');
9012: } else {
9013: undef($cancreate{'statustocreate'});
9014: }
9015: foreach my $type (@{$types}) {
9016: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9017: foreach my $field (@fields) {
9018: if (grep(/^\Q$field\E$/,@modifiable)) {
9019: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9020: } else {
9021: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9022: }
9023: }
9024: }
9025: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9026: foreach my $type (@{$types}) {
9027: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9028: foreach my $field (@fields) {
9029: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9030: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9031: push(@{$changes{'selfcreate'}},$type);
9032: last;
9033: }
9034: }
9035: }
9036: }
9037: } else {
9038: foreach my $type (@{$types}) {
9039: push(@{$changes{'selfcreate'}},$type);
9040: }
9041: }
9042: }
1.160.6.44 raeburn 9043: foreach my $field (@shibfields) {
9044: if ($env{'form.shibenv_'.$field} ne '') {
9045: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9046: }
9047: }
9048: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9049: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9050: foreach my $field (@shibfields) {
9051: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9052: push(@{$changes{'cancreate'}},'shibenv');
9053: }
9054: }
9055: } else {
9056: foreach my $field (@shibfields) {
9057: if ($env{'form.shibenv_'.$field}) {
9058: push(@{$changes{'cancreate'}},'shibenv');
9059: last;
9060: }
9061: }
9062: }
9063: }
1.160.6.34 raeburn 9064: }
9065: foreach my $item (@contexts) {
9066: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9067: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9068: if (ref($cancreate{$item}) eq 'ARRAY') {
9069: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9070: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9071: push(@{$changes{'cancreate'}},$item);
9072: }
9073: }
9074: }
9075: }
9076: if (ref($cancreate{$item}) eq 'ARRAY') {
9077: foreach my $type (@{$cancreate{$item}}) {
9078: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9079: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9080: push(@{$changes{'cancreate'}},$item);
9081: }
9082: }
9083: }
9084: }
9085: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9086: if (ref($cancreate{$item}) eq 'HASH') {
9087: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9088: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9089: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9090: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9091: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9092: push(@{$changes{'cancreate'}},$item);
9093: }
9094: }
9095: }
1.160.6.40 raeburn 9096: } elsif ($item eq 'selfcreateprocessing') {
9097: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9098: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9099: push(@{$changes{'cancreate'}},$item);
9100: }
9101: }
1.160.6.35 raeburn 9102: } else {
9103: if (!$cancreate{$item}{$curr}) {
9104: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9105: push(@{$changes{'cancreate'}},$item);
9106: }
1.160.6.34 raeburn 9107: }
9108: }
9109: }
9110: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9111: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9112: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9113: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9114: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9115: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9116: push(@{$changes{'cancreate'}},$item);
9117: }
9118: }
9119: } else {
9120: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9121: push(@{$changes{'cancreate'}},$item);
9122: }
9123: }
9124: }
1.160.6.40 raeburn 9125: } elsif ($item eq 'selfcreateprocessing') {
9126: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9127: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9128: push(@{$changes{'cancreate'}},$item);
9129: }
9130: }
1.160.6.35 raeburn 9131: } else {
9132: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9133: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9134: push(@{$changes{'cancreate'}},$item);
9135: }
1.160.6.34 raeburn 9136: }
9137: }
9138: }
9139: }
9140: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9141: if (ref($cancreate{$item}) eq 'ARRAY') {
9142: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9143: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9144: push(@{$changes{'cancreate'}},$item);
9145: }
9146: }
9147: } elsif (ref($cancreate{$item}) eq 'HASH') {
9148: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9149: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9150: push(@{$changes{'cancreate'}},$item);
9151: }
9152: }
9153: }
9154: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9155: if (ref($cancreate{$item}) eq 'HASH') {
9156: foreach my $type (keys(%{$cancreate{$item}})) {
9157: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9158: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9159: if ($cancreate{$item}{$type}{$field}) {
9160: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9161: push(@{$changes{'cancreate'}},$item);
9162: }
9163: last;
9164: }
9165: }
9166: }
9167: }
1.160.6.34 raeburn 9168: }
9169: }
9170: }
9171: #
9172: # Populate %save_usercreate hash with updates to self-creation configuration.
9173: #
9174: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9175: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69! raeburn 9176: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 9177: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9178: if (ref($cancreate{'notify'}) eq 'HASH') {
9179: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9180: }
1.160.6.40 raeburn 9181: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9182: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9183: }
1.160.6.34 raeburn 9184: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9185: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9186: }
1.160.6.44 raeburn 9187: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9188: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9189: }
1.160.6.34 raeburn 9190: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9191: $save_usercreate{'emailrule'} = \@email_rule;
9192:
9193: my %userconfig_hash = (
9194: usercreation => \%save_usercreate,
9195: usermodification => \%save_usermodify,
9196: );
9197: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9198: $dom);
9199: #
9200: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9201: #
1.27 raeburn 9202: if ($putresult eq 'ok') {
9203: if (keys(%changes) > 0) {
9204: $resulttext = &mt('Changes made:').'<ul>';
9205: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9206: my %lt = &selfcreation_types();
1.34 raeburn 9207: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9208: my $chgtext;
1.45 raeburn 9209: if ($type eq 'selfcreate') {
1.50 raeburn 9210: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9211: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9212: } else {
1.160.6.34 raeburn 9213: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9214: '<ul>';
1.50 raeburn 9215: foreach my $case (@{$cancreate{$type}}) {
9216: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9217: }
9218: $chgtext .= '</ul>';
1.100 raeburn 9219: if (ref($cancreate{$type}) eq 'ARRAY') {
9220: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9221: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9222: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9223: $chgtext .= '<br />'.
9224: '<span class="LC_warning">'.
9225: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9226: '</span>';
1.100 raeburn 9227: }
9228: }
9229: }
9230: }
1.43 raeburn 9231: }
1.160.6.44 raeburn 9232: } elsif ($type eq 'shibenv') {
9233: if (keys(%{$cancreate{$type}}) == 0) {
9234: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9235: } else {
9236: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9237: '<ul>';
9238: foreach my $field (@shibfields) {
9239: next if ($cancreate{$type}{$field} eq '');
9240: if ($field eq 'inststatus') {
9241: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9242: } else {
9243: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9244: }
9245: }
9246: $chgtext .= '</ul>';
9247: }
1.93 raeburn 9248: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9249: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9250: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9251: if (@{$cancreate{'selfcreate'}} > 0) {
9252: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9253: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9254: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9255: $chgtext .= '<br />'.
9256: '<span class="LC_warning">'.
9257: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9258: '</span>';
9259: }
1.96 raeburn 9260: } elsif (ref($usertypes) eq 'HASH') {
9261: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9262: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9263: } else {
9264: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9265: }
9266: $chgtext .= '<ul>';
9267: foreach my $case (@{$cancreate{$type}}) {
9268: if ($case eq 'default') {
9269: $chgtext .= '<li>'.$othertitle.'</li>';
9270: } else {
9271: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9272: }
9273: }
1.100 raeburn 9274: $chgtext .= '</ul>';
9275: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9276: $chgtext .= '<br /><span class="LC_warning">'.
9277: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9278: '</span>';
1.100 raeburn 9279: }
9280: }
9281: } else {
9282: if (@{$cancreate{$type}} == 0) {
9283: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9284: } else {
9285: $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 9286: }
9287: }
9288: }
1.160.6.40 raeburn 9289: } elsif ($type eq 'selfcreateprocessing') {
9290: my %choices = &Apache::lonlocal::texthash (
9291: automatic => 'Automatic approval',
9292: approval => 'Queued for approval',
9293: );
9294: if (@statuses > 1) {
9295: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9296: '<ul>';
9297: foreach my $type (@statuses) {
9298: if ($type eq 'default') {
9299: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9300: } else {
9301: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9302: }
9303: }
9304: $chgtext .= '</ul>';
9305: } else {
9306: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9307: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9308: }
1.160.6.5 raeburn 9309: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9310: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9311: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9312: } else {
9313: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9314: if ($captchas{$savecaptcha{$type}}) {
9315: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9316: } else {
9317: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9318: }
9319: }
9320: } elsif ($type eq 'recaptchakeys') {
9321: my ($privkey,$pubkey);
1.160.6.34 raeburn 9322: if (ref($savecaptcha{$type}) eq 'HASH') {
9323: $pubkey = $savecaptcha{$type}{'public'};
9324: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9325: }
9326: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9327: if (!$pubkey) {
9328: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9329: } else {
9330: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9331: }
9332: if (!$privkey) {
9333: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9334: } else {
9335: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9336: }
9337: $chgtext .= '</ul>';
1.160.6.69! raeburn 9338: } elsif ($type eq 'recaptchaversion') {
! 9339: if ($savecaptcha{'captcha'} eq 'recaptcha') {
! 9340: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
! 9341: }
1.160.6.34 raeburn 9342: } elsif ($type eq 'emailusername') {
9343: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9344: if (ref($types) eq 'ARRAY') {
9345: foreach my $type (@{$types}) {
9346: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9347: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9348: $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 9349: '<ul>';
9350: foreach my $field (@{$infofields}) {
9351: if ($cancreate{'emailusername'}{$type}{$field}) {
9352: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9353: }
9354: }
1.160.6.50 raeburn 9355: $chgtext .= '</ul>';
9356: } else {
9357: $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 9358: }
9359: } else {
1.160.6.50 raeburn 9360: $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 9361: }
9362: }
9363: }
9364: }
9365: } elsif ($type eq 'notify') {
9366: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9367: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9368: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9369: if ($cancreate{'notify'}{'approval'}) {
9370: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9371: }
9372: }
1.43 raeburn 9373: }
1.34 raeburn 9374: }
1.160.6.34 raeburn 9375: if ($chgtext) {
9376: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9377: }
9378: }
9379: }
1.43 raeburn 9380: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9381: my ($emailrules,$emailruleorder) =
9382: &Apache::lonnet::inst_userrules($dom,'email');
9383: my $chgtext = '<ul>';
9384: foreach my $type (@email_rule) {
9385: if (ref($emailrules->{$type}) eq 'HASH') {
9386: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9387: }
9388: }
9389: $chgtext .= '</ul>';
9390: if (@email_rule > 0) {
1.160.6.34 raeburn 9391: $resulttext .= '<li>'.
9392: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9393: $chgtext.
9394: '</li>';
1.43 raeburn 9395: } else {
1.160.6.34 raeburn 9396: $resulttext .= '<li>'.
9397: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9398: '</li>';
1.43 raeburn 9399: }
9400: }
1.160.6.34 raeburn 9401: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9402: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9403: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9404: foreach my $type (@{$changes{'selfcreate'}}) {
9405: my $typename = $type;
9406: if (ref($usertypes) eq 'HASH') {
9407: if ($usertypes->{$type} ne '') {
9408: $typename = $usertypes->{$type};
1.28 raeburn 9409: }
9410: }
1.160.6.34 raeburn 9411: my @modifiable;
9412: $resulttext .= '<li>'.
9413: &mt('Self-creation of account by users with status: [_1]',
9414: '<span class="LC_cusr_emph">'.$typename.'</span>').
9415: ' - '.&mt('modifiable fields (if institutional data blank): ');
9416: foreach my $field (@fields) {
9417: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9418: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9419: }
9420: }
9421: if (@modifiable > 0) {
9422: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9423: } else {
1.160.6.34 raeburn 9424: $resulttext .= &mt('none');
1.43 raeburn 9425: }
1.160.6.34 raeburn 9426: $resulttext .= '</li>';
1.28 raeburn 9427: }
1.160.6.34 raeburn 9428: $resulttext .= '</ul></li>';
1.28 raeburn 9429: }
1.27 raeburn 9430: $resulttext .= '</ul>';
9431: } else {
1.160.6.34 raeburn 9432: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9433: }
9434: } else {
9435: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9436: &mt('An error occurred: [_1]',$putresult).'</span>';
9437: }
1.43 raeburn 9438: if ($warningmsg ne '') {
9439: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9440: }
1.23 raeburn 9441: return $resulttext;
9442: }
9443:
1.160.6.5 raeburn 9444: sub process_captcha {
9445: my ($container,$changes,$newsettings,$current) = @_;
9446: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9447: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9448: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9449: $newsettings->{'captcha'} = 'original';
9450: }
9451: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9452: if ($container eq 'cancreate') {
9453: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9454: push(@{$changes->{'cancreate'}},'captcha');
9455: } elsif (!defined($changes->{'cancreate'})) {
9456: $changes->{'cancreate'} = ['captcha'];
9457: }
9458: } else {
9459: $changes->{'captcha'} = 1;
9460: }
9461: }
1.160.6.69! raeburn 9462: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 9463: if ($newsettings->{'captcha'} eq 'recaptcha') {
9464: $newpub = $env{'form.'.$container.'_recaptchapub'};
9465: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9466: $newpub =~ s/[^\w\-]//g;
9467: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9468: $newsettings->{'recaptchakeys'} = {
9469: public => $newpub,
9470: private => $newpriv,
9471: };
1.160.6.69! raeburn 9472: $newversion = $env{'form.'.$container.'_recaptchaversion'};
! 9473: $newversion =~ s/\D//g;
! 9474: if ($newversion ne '2') {
! 9475: $newversion = 1;
! 9476: }
! 9477: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 9478: }
9479: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9480: $currpub = $current->{'recaptchakeys'}{'public'};
9481: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9482: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9483: $newsettings->{'recaptchakeys'} = {
9484: public => '',
9485: private => '',
9486: }
9487: }
1.160.6.5 raeburn 9488: }
1.160.6.69! raeburn 9489: if ($current->{'captcha'} eq 'recaptcha') {
! 9490: $currversion = $current->{'recaptchaversion'};
! 9491: if ($currversion ne '2') {
! 9492: $currversion = 1;
! 9493: }
! 9494: }
! 9495: if ($currversion ne $newversion) {
! 9496: if ($container eq 'cancreate') {
! 9497: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
! 9498: push(@{$changes->{'cancreate'}},'recaptchaversion');
! 9499: } elsif (!defined($changes->{'cancreate'})) {
! 9500: $changes->{'cancreate'} = ['recaptchaversion'];
! 9501: }
! 9502: } else {
! 9503: $changes->{'recaptchaversion'} = 1;
! 9504: }
! 9505: }
1.160.6.5 raeburn 9506: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9507: if ($container eq 'cancreate') {
9508: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9509: push(@{$changes->{'cancreate'}},'recaptchakeys');
9510: } elsif (!defined($changes->{'cancreate'})) {
9511: $changes->{'cancreate'} = ['recaptchakeys'];
9512: }
9513: } else {
9514: $changes->{'recaptchakeys'} = 1;
9515: }
9516: }
9517: return;
9518: }
9519:
1.33 raeburn 9520: sub modify_usermodification {
9521: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9522: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9523: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9524: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9525: if ($key eq 'selfcreate') {
9526: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9527: } else {
9528: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9529: }
1.33 raeburn 9530: }
9531: }
1.160.6.34 raeburn 9532: my @contexts = ('author','course');
1.33 raeburn 9533: my %context_title = (
9534: author => 'In author context',
9535: course => 'In course context',
9536: );
9537: my @fields = ('lastname','firstname','middlename','generation',
9538: 'permanentemail','id');
9539: my %roles = (
9540: author => ['ca','aa'],
9541: course => ['st','ep','ta','in','cr'],
9542: );
9543: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9544: foreach my $context (@contexts) {
9545: foreach my $role (@{$roles{$context}}) {
9546: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9547: foreach my $item (@fields) {
9548: if (grep(/^\Q$item\E$/,@modifiable)) {
9549: $modifyhash{$context}{$role}{$item} = 1;
9550: } else {
9551: $modifyhash{$context}{$role}{$item} = 0;
9552: }
9553: }
9554: }
9555: if (ref($curr_usermodification{$context}) eq 'HASH') {
9556: foreach my $role (@{$roles{$context}}) {
9557: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9558: foreach my $field (@fields) {
9559: if ($modifyhash{$context}{$role}{$field} ne
9560: $curr_usermodification{$context}{$role}{$field}) {
9561: push(@{$changes{$context}},$role);
9562: last;
9563: }
9564: }
9565: }
9566: }
9567: } else {
9568: foreach my $context (@contexts) {
9569: foreach my $role (@{$roles{$context}}) {
9570: push(@{$changes{$context}},$role);
9571: }
9572: }
9573: }
9574: }
9575: my %usermodification_hash = (
9576: usermodification => \%modifyhash,
9577: );
9578: my $putresult = &Apache::lonnet::put_dom('configuration',
9579: \%usermodification_hash,$dom);
9580: if ($putresult eq 'ok') {
9581: if (keys(%changes) > 0) {
9582: $resulttext = &mt('Changes made: ').'<ul>';
9583: foreach my $context (@contexts) {
9584: if (ref($changes{$context}) eq 'ARRAY') {
9585: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9586: if (ref($changes{$context}) eq 'ARRAY') {
9587: foreach my $role (@{$changes{$context}}) {
9588: my $rolename;
1.160.6.34 raeburn 9589: if ($role eq 'cr') {
9590: $rolename = &mt('Custom');
1.33 raeburn 9591: } else {
1.160.6.34 raeburn 9592: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9593: }
9594: my @modifiable;
1.160.6.34 raeburn 9595: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9596: foreach my $field (@fields) {
9597: if ($modifyhash{$context}{$role}{$field}) {
9598: push(@modifiable,$fieldtitles{$field});
9599: }
9600: }
9601: if (@modifiable > 0) {
9602: $resulttext .= join(', ',@modifiable);
9603: } else {
9604: $resulttext .= &mt('none');
9605: }
9606: $resulttext .= '</li>';
9607: }
9608: $resulttext .= '</ul></li>';
9609: }
9610: }
9611: }
9612: $resulttext .= '</ul>';
9613: } else {
9614: $resulttext = &mt('No changes made to user modification settings');
9615: }
9616: } else {
9617: $resulttext = '<span class="LC_error">'.
9618: &mt('An error occurred: [_1]',$putresult).'</span>';
9619: }
9620: return $resulttext;
9621: }
9622:
1.43 raeburn 9623: sub modify_defaults {
1.160.6.27 raeburn 9624: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9625: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9626: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9627: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9628: my @authtypes = ('internal','krb4','krb5','localauth');
9629: foreach my $item (@items) {
9630: $newvalues{$item} = $env{'form.'.$item};
9631: if ($item eq 'auth_def') {
9632: if ($newvalues{$item} ne '') {
9633: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9634: push(@errors,$item);
9635: }
9636: }
9637: } elsif ($item eq 'lang_def') {
9638: if ($newvalues{$item} ne '') {
9639: if ($newvalues{$item} =~ /^(\w+)/) {
9640: my $langcode = $1;
1.103 raeburn 9641: if ($langcode ne 'x_chef') {
9642: if (code2language($langcode) eq '') {
9643: push(@errors,$item);
9644: }
1.43 raeburn 9645: }
9646: } else {
9647: push(@errors,$item);
9648: }
9649: }
1.54 raeburn 9650: } elsif ($item eq 'timezone_def') {
9651: if ($newvalues{$item} ne '') {
1.62 raeburn 9652: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9653: push(@errors,$item);
9654: }
9655: }
1.68 raeburn 9656: } elsif ($item eq 'datelocale_def') {
9657: if ($newvalues{$item} ne '') {
9658: my @datelocale_ids = DateTime::Locale->ids();
9659: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9660: push(@errors,$item);
9661: }
9662: }
1.141 raeburn 9663: } elsif ($item eq 'portal_def') {
9664: if ($newvalues{$item} ne '') {
9665: 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])\/?$/) {
9666: push(@errors,$item);
9667: }
9668: }
1.43 raeburn 9669: }
9670: if (grep(/^\Q$item\E$/,@errors)) {
9671: $newvalues{$item} = $domdefaults{$item};
9672: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9673: $changes{$item} = 1;
9674: }
1.72 raeburn 9675: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9676: }
9677: my %defaults_hash = (
1.72 raeburn 9678: defaults => \%newvalues,
9679: );
1.43 raeburn 9680: my $title = &defaults_titles();
1.160.6.40 raeburn 9681:
9682: my $currinststatus;
9683: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9684: $currinststatus = $domconfig{'inststatus'};
9685: } else {
9686: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9687: $currinststatus = {
9688: inststatustypes => $usertypes,
9689: inststatusorder => $types,
9690: inststatusguest => [],
9691: };
9692: }
9693: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9694: my @allpos;
9695: my %guests;
9696: my %alltypes;
9697: my ($currtitles,$currguests,$currorder);
9698: if (ref($currinststatus) eq 'HASH') {
9699: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9700: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9701: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9702: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9703: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9704: }
9705: }
9706: unless (grep(/^\Q$type\E$/,@todelete)) {
9707: my $position = $env{'form.inststatus_pos_'.$type};
9708: $position =~ s/\D+//g;
9709: $allpos[$position] = $type;
9710: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9711: $alltypes{$type} =~ s/`//g;
9712: if ($env{'form.inststatus_guest_'.$type}) {
9713: $guests{$type} = 1;
9714: }
9715: }
9716: }
9717: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9718: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9719: }
9720: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9721: $currtitles =~ s/,$//;
9722: }
9723: }
9724: if ($env{'form.addinststatus'}) {
9725: my $newtype = $env{'form.addinststatus'};
9726: $newtype =~ s/\W//g;
9727: unless (exists($alltypes{$newtype})) {
9728: if ($env{'form.addinststatus_guest'}) {
9729: $guests{$newtype} = 1;
9730: }
9731: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9732: $alltypes{$newtype} =~ s/`//g;
9733: my $position = $env{'form.addinststatus_pos'};
9734: $position =~ s/\D+//g;
9735: if ($position ne '') {
9736: $allpos[$position] = $newtype;
9737: }
9738: }
9739: }
9740: my (@orderedstatus,@orderedguests);
9741: foreach my $type (@allpos) {
9742: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9743: push(@orderedstatus,$type);
9744: if ($guests{$type}) {
9745: push(@orderedguests,$type);
9746: }
9747: }
9748: }
9749: foreach my $type (keys(%alltypes)) {
9750: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9751: delete($alltypes{$type});
9752: }
9753: }
9754: $defaults_hash{'inststatus'} = {
9755: inststatustypes => \%alltypes,
9756: inststatusorder => \@orderedstatus,
9757: inststatusguest => \@orderedguests,
9758: };
9759: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9760: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9761: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9762: }
9763: }
9764: if ($currorder ne join(',',@orderedstatus)) {
9765: $changes{'inststatus'}{'inststatusorder'} = 1;
9766: }
9767: if ($currguests ne join(',',@orderedguests)) {
9768: $changes{'inststatus'}{'inststatusguest'} = 1;
9769: }
9770: my $newtitles;
9771: foreach my $item (@orderedstatus) {
9772: $newtitles .= $alltypes{$item}.',';
9773: }
9774: $newtitles =~ s/,$//;
9775: if ($currtitles ne $newtitles) {
9776: $changes{'inststatus'}{'inststatustypes'} = 1;
9777: }
1.43 raeburn 9778: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9779: $dom);
9780: if ($putresult eq 'ok') {
9781: if (keys(%changes) > 0) {
9782: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9783: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9784: 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";
9785: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9786: if ($item eq 'inststatus') {
9787: if (ref($changes{'inststatus'}) eq 'HASH') {
9788: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9789: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9790: foreach my $type (@orderedstatus) {
9791: $resulttext .= $alltypes{$type}.', ';
9792: }
9793: $resulttext =~ s/, $//;
9794: $resulttext .= '</li>';
9795: }
9796: if ($changes{'inststatus'}{'inststatusguest'}) {
9797: $resulttext .= '<li>';
9798: if (@orderedguests) {
9799: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9800: foreach my $type (@orderedguests) {
9801: $resulttext .= $alltypes{$type}.', ';
9802: }
9803: $resulttext =~ s/, $//;
9804: } else {
9805: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9806: }
9807: $resulttext .= '</li>';
9808: }
9809: }
9810: } else {
9811: my $value = $env{'form.'.$item};
9812: if ($value eq '') {
9813: $value = &mt('none');
9814: } elsif ($item eq 'auth_def') {
9815: my %authnames = &authtype_names();
9816: my %shortauth = (
9817: internal => 'int',
9818: krb4 => 'krb4',
9819: krb5 => 'krb5',
9820: localauth => 'loc',
9821: );
9822: $value = $authnames{$shortauth{$value}};
9823: }
9824: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9825: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9826: }
9827: }
9828: $resulttext .= '</ul>';
9829: $mailmsgtext .= "\n";
9830: my $cachetime = 24*60*60;
1.72 raeburn 9831: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9832: if (ref($lastactref) eq 'HASH') {
9833: $lastactref->{'domdefaults'} = 1;
9834: }
1.68 raeburn 9835: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9836: my $notify = 1;
9837: if (ref($domconfig{'contacts'}) eq 'HASH') {
9838: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9839: $notify = 0;
9840: }
9841: }
9842: if ($notify) {
9843: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9844: "LON-CAPA Domain Settings Change - $dom",
9845: $mailmsgtext);
9846: }
1.54 raeburn 9847: }
1.43 raeburn 9848: } else {
1.54 raeburn 9849: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9850: }
9851: } else {
9852: $resulttext = '<span class="LC_error">'.
9853: &mt('An error occurred: [_1]',$putresult).'</span>';
9854: }
9855: if (@errors > 0) {
9856: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9857: foreach my $item (@errors) {
9858: $resulttext .= ' "'.$title->{$item}.'",';
9859: }
9860: $resulttext =~ s/,$//;
9861: }
9862: return $resulttext;
9863: }
9864:
1.46 raeburn 9865: sub modify_scantron {
1.160.6.24 raeburn 9866: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9867: my ($resulttext,%confhash,%changes,$errors);
9868: my $custom = 'custom.tab';
9869: my $default = 'default.tab';
9870: my $servadm = $r->dir_config('lonAdmEMail');
9871: my ($configuserok,$author_ok,$switchserver) =
9872: &config_check($dom,$confname,$servadm);
9873: if ($env{'form.scantronformat.filename'} ne '') {
9874: my $error;
9875: if ($configuserok eq 'ok') {
9876: if ($switchserver) {
1.130 raeburn 9877: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9878: } else {
9879: if ($author_ok eq 'ok') {
9880: my ($result,$scantronurl) =
9881: &publishlogo($r,'upload','scantronformat',$dom,
9882: $confname,'scantron','','',$custom);
9883: if ($result eq 'ok') {
9884: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9885: $changes{'scantronformat'} = 1;
1.46 raeburn 9886: } else {
9887: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9888: }
9889: } else {
9890: $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);
9891: }
9892: }
9893: } else {
9894: $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);
9895: }
9896: if ($error) {
9897: &Apache::lonnet::logthis($error);
9898: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9899: }
9900: }
1.48 raeburn 9901: if (ref($domconfig{'scantron'}) eq 'HASH') {
9902: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9903: if ($env{'form.scantronformat_del'}) {
9904: $confhash{'scantron'}{'scantronformat'} = '';
9905: $changes{'scantronformat'} = 1;
1.46 raeburn 9906: }
9907: }
9908: }
9909: if (keys(%confhash) > 0) {
9910: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9911: $dom);
9912: if ($putresult eq 'ok') {
9913: if (keys(%changes) > 0) {
1.48 raeburn 9914: if (ref($confhash{'scantron'}) eq 'HASH') {
9915: $resulttext = &mt('Changes made:').'<ul>';
9916: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9917: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9918: } else {
1.130 raeburn 9919: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9920: }
1.48 raeburn 9921: $resulttext .= '</ul>';
9922: } else {
1.130 raeburn 9923: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9924: }
9925: $resulttext .= '</ul>';
9926: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9927: if (ref($lastactref) eq 'HASH') {
9928: $lastactref->{'domainconfig'} = 1;
9929: }
1.46 raeburn 9930: } else {
1.130 raeburn 9931: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9932: }
9933: } else {
9934: $resulttext = '<span class="LC_error">'.
9935: &mt('An error occurred: [_1]',$putresult).'</span>';
9936: }
9937: } else {
1.130 raeburn 9938: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9939: }
9940: if ($errors) {
9941: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9942: $errors.'</ul>';
9943: }
9944: return $resulttext;
9945: }
9946:
1.48 raeburn 9947: sub modify_coursecategories {
1.160.6.43 raeburn 9948: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9949: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9950: $cathash);
1.48 raeburn 9951: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9952: my @catitems = ('unauth','auth');
9953: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9954: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9955: $cathash = $domconfig{'coursecategories'}{'cats'};
9956: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9957: $changes{'togglecats'} = 1;
9958: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9959: }
9960: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9961: $changes{'categorize'} = 1;
9962: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9963: }
1.120 raeburn 9964: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9965: $changes{'togglecatscomm'} = 1;
9966: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9967: }
9968: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9969: $changes{'categorizecomm'} = 1;
9970: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9971: }
1.160.6.42 raeburn 9972: foreach my $item (@catitems) {
9973: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9974: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9975: $changes{$item} = 1;
9976: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9977: }
9978: }
9979: }
1.57 raeburn 9980: } else {
9981: $changes{'togglecats'} = 1;
9982: $changes{'categorize'} = 1;
1.124 raeburn 9983: $changes{'togglecatscomm'} = 1;
9984: $changes{'categorizecomm'} = 1;
1.87 raeburn 9985: $domconfig{'coursecategories'} = {
9986: togglecats => $env{'form.togglecats'},
9987: categorize => $env{'form.categorize'},
1.124 raeburn 9988: togglecatscomm => $env{'form.togglecatscomm'},
9989: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9990: };
1.160.6.42 raeburn 9991: foreach my $item (@catitems) {
9992: if ($env{'form.coursecat_'.$item} ne 'std') {
9993: $changes{$item} = 1;
9994: }
9995: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9996: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9997: }
9998: }
1.57 raeburn 9999: }
10000: if (ref($cathash) eq 'HASH') {
10001: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10002: push (@deletecategory,'instcode::0');
10003: }
1.120 raeburn 10004: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10005: push(@deletecategory,'communities::0');
10006: }
1.48 raeburn 10007: }
1.57 raeburn 10008: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10009: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10010: if (@deletecategory > 0) {
10011: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10012: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10013: foreach my $item (@deletecategory) {
1.57 raeburn 10014: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10015: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10016: $deletions{$item} = 1;
1.57 raeburn 10017: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10018: }
10019: }
10020: }
1.57 raeburn 10021: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10022: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10023: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10024: $reorderings{$item} = 1;
1.57 raeburn 10025: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10026: }
10027: if ($env{'form.addcategory_name_'.$item} ne '') {
10028: my $newcat = $env{'form.addcategory_name_'.$item};
10029: my $newdepth = $depth+1;
10030: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10031: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10032: $adds{$newitem} = 1;
10033: }
10034: if ($env{'form.subcat_'.$item} ne '') {
10035: my $newcat = $env{'form.subcat_'.$item};
10036: my $newdepth = $depth+1;
10037: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10038: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10039: $adds{$newitem} = 1;
10040: }
10041: }
10042: }
10043: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10044: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10045: my $newitem = 'instcode::0';
1.57 raeburn 10046: if ($cathash->{$newitem} eq '') {
10047: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10048: $adds{$newitem} = 1;
10049: }
10050: } else {
10051: my $newitem = 'instcode::0';
1.57 raeburn 10052: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10053: $adds{$newitem} = 1;
10054: }
10055: }
1.120 raeburn 10056: if ($env{'form.communities'} eq '1') {
10057: if (ref($cathash) eq 'HASH') {
10058: my $newitem = 'communities::0';
10059: if ($cathash->{$newitem} eq '') {
10060: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10061: $adds{$newitem} = 1;
10062: }
10063: } else {
10064: my $newitem = 'communities::0';
10065: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10066: $adds{$newitem} = 1;
10067: }
10068: }
1.48 raeburn 10069: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10070: if (($env{'form.addcategory_name'} ne 'instcode') &&
10071: ($env{'form.addcategory_name'} ne 'communities')) {
10072: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10073: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10074: $adds{$newitem} = 1;
10075: }
1.48 raeburn 10076: }
1.57 raeburn 10077: my $putresult;
1.48 raeburn 10078: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10079: if (keys(%deletions) > 0) {
10080: foreach my $key (keys(%deletions)) {
10081: if ($predelallitems{$key} ne '') {
10082: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10083: }
10084: }
10085: }
10086: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10087: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10088: if (ref($chkcats[0]) eq 'ARRAY') {
10089: my $depth = 0;
10090: my $chg = 0;
10091: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10092: my $name = $chkcats[0][$i];
10093: my $item;
10094: if ($name eq '') {
10095: $chg ++;
10096: } else {
10097: $item = &escape($name).'::0';
10098: if ($chg) {
1.57 raeburn 10099: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10100: }
10101: $depth ++;
1.57 raeburn 10102: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10103: $depth --;
10104: }
10105: }
10106: }
1.57 raeburn 10107: }
10108: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10109: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10110: if ($putresult eq 'ok') {
1.57 raeburn 10111: my %title = (
1.120 raeburn 10112: togglecats => 'Show/Hide a course in catalog',
10113: categorize => 'Assign a category to a course',
10114: togglecatscomm => 'Show/Hide a community in catalog',
10115: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10116: );
10117: my %level = (
1.120 raeburn 10118: dom => 'set in Domain ("Modify Course/Community")',
10119: crs => 'set in Course ("Course Configuration")',
10120: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10121: none => 'No catalog',
10122: std => 'Standard catalog',
10123: domonly => 'Domain-only catalog',
10124: codesrch => 'Code search form',
1.57 raeburn 10125: );
1.48 raeburn 10126: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10127: if ($changes{'togglecats'}) {
10128: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10129: }
10130: if ($changes{'categorize'}) {
10131: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10132: }
1.120 raeburn 10133: if ($changes{'togglecatscomm'}) {
10134: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10135: }
10136: if ($changes{'categorizecomm'}) {
10137: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10138: }
1.160.6.42 raeburn 10139: if ($changes{'unauth'}) {
10140: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10141: }
10142: if ($changes{'auth'}) {
10143: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10144: }
1.57 raeburn 10145: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10146: my $cathash;
10147: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10148: $cathash = $domconfig{'coursecategories'}{'cats'};
10149: } else {
10150: $cathash = {};
10151: }
10152: my (@cats,@trails,%allitems);
10153: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10154: if (keys(%deletions) > 0) {
10155: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10156: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10157: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10158: }
10159: $resulttext .= '</ul></li>';
10160: }
10161: if (keys(%reorderings) > 0) {
10162: my %sort_by_trail;
10163: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10164: foreach my $key (keys(%reorderings)) {
10165: if ($allitems{$key} ne '') {
10166: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10167: }
1.48 raeburn 10168: }
1.57 raeburn 10169: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10170: $resulttext .= '<li>'.$trails[$trail].'</li>';
10171: }
10172: $resulttext .= '</ul></li>';
1.48 raeburn 10173: }
1.57 raeburn 10174: if (keys(%adds) > 0) {
10175: my %sort_by_trail;
10176: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10177: foreach my $key (keys(%adds)) {
10178: if ($allitems{$key} ne '') {
10179: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10180: }
10181: }
10182: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10183: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10184: }
1.57 raeburn 10185: $resulttext .= '</ul></li>';
1.48 raeburn 10186: }
10187: }
10188: $resulttext .= '</ul>';
1.160.6.43 raeburn 10189: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10190: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10191: if ($changes{'auth'}) {
10192: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10193: }
10194: if ($changes{'unauth'}) {
10195: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10196: }
10197: my $cachetime = 24*60*60;
10198: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10199: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10200: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10201: }
10202: }
1.48 raeburn 10203: } else {
10204: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10205: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10206: }
10207: } else {
1.120 raeburn 10208: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10209: }
10210: return $resulttext;
10211: }
10212:
1.69 raeburn 10213: sub modify_serverstatuses {
10214: my ($dom,%domconfig) = @_;
10215: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10216: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10217: %currserverstatus = %{$domconfig{'serverstatuses'}};
10218: }
10219: my @pages = &serverstatus_pages();
10220: foreach my $type (@pages) {
10221: $newserverstatus{$type}{'namedusers'} = '';
10222: $newserverstatus{$type}{'machines'} = '';
10223: if (defined($env{'form.'.$type.'_namedusers'})) {
10224: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10225: my @okusers;
10226: foreach my $user (@users) {
10227: my ($uname,$udom) = split(/:/,$user);
10228: if (($udom =~ /^$match_domain$/) &&
10229: (&Apache::lonnet::domain($udom)) &&
10230: ($uname =~ /^$match_username$/)) {
10231: if (!grep(/^\Q$user\E/,@okusers)) {
10232: push(@okusers,$user);
10233: }
10234: }
10235: }
10236: if (@okusers > 0) {
10237: @okusers = sort(@okusers);
10238: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10239: }
10240: }
10241: if (defined($env{'form.'.$type.'_machines'})) {
10242: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10243: my @okmachines;
10244: foreach my $ip (@machines) {
10245: my @parts = split(/\./,$ip);
10246: next if (@parts < 4);
10247: my $badip = 0;
10248: for (my $i=0; $i<4; $i++) {
10249: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10250: $badip = 1;
10251: last;
10252: }
10253: }
10254: if (!$badip) {
10255: push(@okmachines,$ip);
10256: }
10257: }
10258: @okmachines = sort(@okmachines);
10259: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10260: }
10261: }
10262: my %serverstatushash = (
10263: serverstatuses => \%newserverstatus,
10264: );
10265: foreach my $type (@pages) {
1.83 raeburn 10266: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10267: my (@current,@new);
1.83 raeburn 10268: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10269: if ($currserverstatus{$type}{$setting} ne '') {
10270: @current = split(/,/,$currserverstatus{$type}{$setting});
10271: }
10272: }
10273: if ($newserverstatus{$type}{$setting} ne '') {
10274: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10275: }
10276: if (@current > 0) {
10277: if (@new > 0) {
10278: foreach my $item (@current) {
10279: if (!grep(/^\Q$item\E$/,@new)) {
10280: $changes{$type}{$setting} = 1;
1.82 raeburn 10281: last;
10282: }
10283: }
1.84 raeburn 10284: foreach my $item (@new) {
10285: if (!grep(/^\Q$item\E$/,@current)) {
10286: $changes{$type}{$setting} = 1;
10287: last;
1.82 raeburn 10288: }
10289: }
10290: } else {
1.83 raeburn 10291: $changes{$type}{$setting} = 1;
1.69 raeburn 10292: }
1.83 raeburn 10293: } elsif (@new > 0) {
10294: $changes{$type}{$setting} = 1;
1.69 raeburn 10295: }
10296: }
10297: }
10298: if (keys(%changes) > 0) {
1.81 raeburn 10299: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10300: my $putresult = &Apache::lonnet::put_dom('configuration',
10301: \%serverstatushash,$dom);
10302: if ($putresult eq 'ok') {
10303: $resulttext .= &mt('Changes made:').'<ul>';
10304: foreach my $type (@pages) {
1.84 raeburn 10305: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10306: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10307: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10308: if ($newserverstatus{$type}{'namedusers'} eq '') {
10309: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10310: } else {
10311: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10312: }
1.84 raeburn 10313: }
10314: if ($changes{$type}{'machines'}) {
1.69 raeburn 10315: if ($newserverstatus{$type}{'machines'} eq '') {
10316: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10317: } else {
10318: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10319: }
10320:
10321: }
10322: $resulttext .= '</ul></li>';
10323: }
10324: }
10325: $resulttext .= '</ul>';
10326: } else {
10327: $resulttext = '<span class="LC_error">'.
10328: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10329:
10330: }
10331: } else {
10332: $resulttext = &mt('No changes made to access to server status pages');
10333: }
10334: return $resulttext;
10335: }
10336:
1.118 jms 10337: sub modify_helpsettings {
1.122 jms 10338: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10339: my ($resulttext,$errors,%changes,%helphash);
10340: my %defaultchecked = ('submitbugs' => 'on');
10341: my @offon = ('off','on');
1.118 jms 10342: my @toggles = ('submitbugs');
10343: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10344: foreach my $item (@toggles) {
1.160.6.5 raeburn 10345: if ($defaultchecked{$item} eq 'on') {
10346: if ($domconfig{'helpsettings'}{$item} eq '') {
10347: if ($env{'form.'.$item} eq '0') {
10348: $changes{$item} = 1;
10349: }
10350: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10351: $changes{$item} = 1;
10352: }
10353: } elsif ($defaultchecked{$item} eq 'off') {
10354: if ($domconfig{'helpsettings'}{$item} eq '') {
10355: if ($env{'form.'.$item} eq '1') {
10356: $changes{$item} = 1;
10357: }
10358: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10359: $changes{$item} = 1;
10360: }
1.160.6.26 raeburn 10361: }
1.160.6.5 raeburn 10362: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10363: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10364: }
10365: }
1.118 jms 10366: }
1.123 jms 10367: my $putresult;
10368: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10369: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10370: if ($putresult eq 'ok') {
10371: $resulttext = &mt('Changes made:').'<ul>';
10372: foreach my $item (sort(keys(%changes))) {
10373: if ($item eq 'submitbugs') {
10374: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10375: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10376: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10377: }
10378: }
10379: $resulttext .= '</ul>';
10380: } else {
10381: $resulttext = &mt('No changes made to help settings');
10382: $errors .= '<li><span class="LC_error">'.
10383: &mt('An error occurred storing the settings: [_1]',
10384: $putresult).'</span></li>';
10385: }
1.118 jms 10386: }
10387: if ($errors) {
1.160.6.5 raeburn 10388: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10389: $errors.'</ul>';
10390: }
10391: return $resulttext;
10392: }
10393:
1.121 raeburn 10394: sub modify_coursedefaults {
1.160.6.27 raeburn 10395: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10396: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10397: my %defaultchecked = (
10398: 'uselcmath' => 'on',
10399: 'usejsme' => 'on'
10400: );
10401: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10402: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 10403: 'uploadquota_community','uploadquota_textbook');
10404: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10405: my %staticdefaults = (
10406: anonsurvey_threshold => 10,
10407: uploadquota => 500,
1.160.6.57 raeburn 10408: postsubmit => 60,
1.160.6.21 raeburn 10409: );
1.121 raeburn 10410:
10411: $defaultshash{'coursedefaults'} = {};
10412:
10413: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10414: if ($domconfig{'coursedefaults'} eq '') {
10415: $domconfig{'coursedefaults'} = {};
10416: }
10417: }
10418:
10419: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10420: foreach my $item (@toggles) {
10421: if ($defaultchecked{$item} eq 'on') {
10422: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10423: ($env{'form.'.$item} eq '0')) {
10424: $changes{$item} = 1;
1.160.6.16 raeburn 10425: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10426: $changes{$item} = 1;
10427: }
10428: } elsif ($defaultchecked{$item} eq 'off') {
10429: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10430: ($env{'form.'.$item} eq '1')) {
10431: $changes{$item} = 1;
10432: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10433: $changes{$item} = 1;
10434: }
10435: }
10436: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10437: }
1.160.6.21 raeburn 10438: foreach my $item (@numbers) {
10439: my ($currdef,$newdef);
1.160.6.26 raeburn 10440: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10441: if ($item eq 'anonsurvey_threshold') {
10442: $currdef = $domconfig{'coursedefaults'}{$item};
10443: $newdef =~ s/\D//g;
10444: if ($newdef eq '' || $newdef < 1) {
10445: $newdef = 1;
10446: }
10447: $defaultshash{'coursedefaults'}{$item} = $newdef;
10448: } else {
10449: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10450: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10451: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10452: }
10453: $newdef =~ s/[^\w.\-]//g;
10454: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10455: }
10456: if ($currdef ne $newdef) {
10457: my $staticdef;
10458: if ($item eq 'anonsurvey_threshold') {
10459: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10460: $changes{$item} = 1;
10461: }
10462: } else {
10463: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10464: $changes{'uploadquota'} = 1;
10465: }
10466: }
1.139 raeburn 10467: }
10468: }
1.160.6.64 raeburn 10469: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10470: my @currclonecode;
10471: if (ref($currclone) eq 'HASH') {
10472: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10473: @currclonecode = @{$currclone->{'instcode'}};
10474: }
10475: }
10476: my $newclone;
10477: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10478: $newclone = $env{'form.canclone'};
10479: }
10480: if ($newclone eq 'instcode') {
10481: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10482: my (%codedefaults,@code_order,@clonecode);
10483: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10484: \@code_order);
10485: foreach my $item (@code_order) {
10486: if (grep(/^\Q$item\E$/,@newcodes)) {
10487: push(@clonecode,$item);
10488: }
10489: }
10490: if (@clonecode) {
10491: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10492: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10493: if (@diffs) {
10494: $changes{'canclone'} = 1;
10495: }
10496: } else {
10497: $newclone eq '';
10498: }
10499: } elsif ($newclone ne '') {
10500: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10501: }
10502: if ($newclone ne $currclone) {
10503: $changes{'canclone'} = 1;
10504: }
1.160.6.57 raeburn 10505: my %credits;
10506: foreach my $type (@types) {
10507: unless ($type eq 'community') {
10508: $credits{$type} = $env{'form.'.$type.'_credits'};
10509: $credits{$type} =~ s/[^\d.]+//g;
10510: }
10511: }
10512: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10513: ($env{'form.coursecredits'} eq '1')) {
10514: $changes{'coursecredits'} = 1;
10515: foreach my $type (keys(%credits)) {
10516: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10517: }
10518: } else {
10519: if ($env{'form.coursecredits'} eq '1') {
10520: foreach my $type (@types) {
10521: unless ($type eq 'community') {
10522: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10523: $changes{'coursecredits'} = 1;
10524: }
10525: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10526: }
10527: }
10528: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10529: foreach my $type (@types) {
10530: unless ($type eq 'community') {
10531: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10532: $changes{'coursecredits'} = 1;
10533: last;
10534: }
10535: }
10536: }
10537: }
10538: }
10539: if ($env{'form.postsubmit'} eq '1') {
10540: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10541: my %currtimeout;
10542: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10543: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10544: $changes{'postsubmit'} = 1;
10545: }
10546: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10547: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10548: }
10549: } else {
10550: $changes{'postsubmit'} = 1;
10551: }
10552: foreach my $type (@types) {
10553: my $timeout = $env{'form.'.$type.'_timeout'};
10554: $timeout =~ s/\D//g;
10555: if ($timeout == $staticdefaults{'postsubmit'}) {
10556: $timeout = '';
10557: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10558: $timeout = '0';
10559: }
10560: unless ($timeout eq '') {
10561: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10562: }
10563: if (exists($currtimeout{$type})) {
10564: if ($timeout ne $currtimeout{$type}) {
10565: $changes{'postsubmit'} = 1;
10566: }
10567: } elsif ($timeout ne '') {
10568: $changes{'postsubmit'} = 1;
10569: }
10570: }
10571: } else {
10572: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10573: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10574: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10575: $changes{'postsubmit'} = 1;
10576: }
10577: } else {
10578: $changes{'postsubmit'} = 1;
10579: }
1.160.6.16 raeburn 10580: }
1.121 raeburn 10581: }
10582: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10583: $dom);
10584: if ($putresult eq 'ok') {
10585: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10586: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10587: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10588: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
10589: ($changes{'canclone'})) {
1.160.6.57 raeburn 10590: foreach my $item ('uselcmath','usejsme') {
10591: if ($changes{$item}) {
10592: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10593: }
1.160.6.16 raeburn 10594: }
10595: if ($changes{'coursecredits'}) {
10596: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10597: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10598: $domdefaults{$type.'credits'} =
10599: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10600: }
10601: }
10602: }
10603: if ($changes{'postsubmit'}) {
10604: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10605: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10606: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10607: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10608: $domdefaults{$type.'postsubtimeout'} =
10609: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10610: }
10611: }
1.160.6.16 raeburn 10612: }
10613: }
1.160.6.21 raeburn 10614: if ($changes{'uploadquota'}) {
10615: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10616: foreach my $type (@types) {
10617: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10618: }
10619: }
10620: }
1.160.6.64 raeburn 10621: if ($changes{'canclone'}) {
10622: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10623: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10624: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10625: if (@clonecodes) {
10626: $domdefaults{'canclone'} = join('+',@clonecodes);
10627: }
10628: }
10629: } else {
10630: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10631: }
10632: }
1.121 raeburn 10633: my $cachetime = 24*60*60;
10634: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10635: if (ref($lastactref) eq 'HASH') {
10636: $lastactref->{'domdefaults'} = 1;
10637: }
1.121 raeburn 10638: }
10639: $resulttext = &mt('Changes made:').'<ul>';
10640: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10641: if ($item eq 'uselcmath') {
1.121 raeburn 10642: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10643: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10644: } else {
1.160.6.57 raeburn 10645: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10646: }
10647: } elsif ($item eq 'usejsme') {
10648: if ($env{'form.'.$item} eq '1') {
10649: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10650: } else {
10651: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10652: }
1.139 raeburn 10653: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10654: $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 10655: } elsif ($item eq 'uploadquota') {
10656: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10657: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10658: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10659: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10660: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10661:
1.160.6.21 raeburn 10662: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10663: '</ul>'.
10664: '</li>';
10665: } else {
10666: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10667: }
1.160.6.57 raeburn 10668: } elsif ($item eq 'postsubmit') {
10669: if ($domdefaults{'postsubmit'} eq 'off') {
10670: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10671: } else {
10672: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10673: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10674: $resulttext .= &mt('durations:').'<ul>';
10675: foreach my $type (@types) {
10676: $resulttext .= '<li>';
10677: my $timeout;
10678: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10679: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10680: }
10681: my $display;
10682: if ($timeout eq '0') {
10683: $display = &mt('unlimited');
10684: } elsif ($timeout eq '') {
10685: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10686: } else {
10687: $display = &mt('[quant,_1,second]',$timeout);
10688: }
10689: if ($type eq 'community') {
10690: $resulttext .= &mt('Communities');
10691: } elsif ($type eq 'official') {
10692: $resulttext .= &mt('Official courses');
10693: } elsif ($type eq 'unofficial') {
10694: $resulttext .= &mt('Unofficial courses');
10695: } elsif ($type eq 'textbook') {
10696: $resulttext .= &mt('Textbook courses');
10697: }
10698: $resulttext .= ' -- '.$display.'</li>';
10699: }
10700: $resulttext .= '</ul>';
10701: }
10702: $resulttext .= '</li>';
10703: }
1.160.6.16 raeburn 10704: } elsif ($item eq 'coursecredits') {
10705: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10706: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10707: ($domdefaults{'unofficialcredits'} eq '') &&
10708: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10709: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10710: } else {
10711: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10712: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10713: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10714: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10715: '</ul>'.
10716: '</li>';
10717: }
10718: } else {
10719: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10720: }
1.160.6.64 raeburn 10721: } elsif ($item eq 'canclone') {
10722: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10723: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10724: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
10725: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
10726: }
10727: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
10728: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
10729: } else {
10730: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
10731: }
1.140 raeburn 10732: }
1.121 raeburn 10733: }
10734: $resulttext .= '</ul>';
10735: } else {
10736: $resulttext = &mt('No changes made to course defaults');
10737: }
10738: } else {
10739: $resulttext = '<span class="LC_error">'.
10740: &mt('An error occurred: [_1]',$putresult).'</span>';
10741: }
10742: return $resulttext;
10743: }
10744:
1.160.6.37 raeburn 10745: sub modify_selfenrollment {
10746: my ($dom,$lastactref,%domconfig) = @_;
10747: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10748: my @types = ('official','unofficial','community','textbook');
10749: my %titles = &tool_titles();
10750: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10751: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10752: $ordered{'default'} = ['types','registered','approval','limit'];
10753:
10754: my (%roles,%shown,%toplevel);
10755: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10756:
10757: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10758: if ($domconfig{'selfenrollment'} eq '') {
10759: $domconfig{'selfenrollment'} = {};
10760: }
10761: }
10762: %toplevel = (
10763: admin => 'Configuration Rights',
10764: default => 'Default settings',
10765: validation => 'Validation of self-enrollment requests',
10766: );
10767: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10768:
10769: if (ref($ordered{'admin'}) eq 'ARRAY') {
10770: foreach my $item (@{$ordered{'admin'}}) {
10771: foreach my $type (@types) {
10772: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10773: $selfenrollhash{'admin'}{$type}{$item} = 1;
10774: } else {
10775: $selfenrollhash{'admin'}{$type}{$item} = 0;
10776: }
10777: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10778: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10779: if ($selfenrollhash{'admin'}{$type}{$item} ne
10780: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10781: push(@{$changes{'admin'}{$type}},$item);
10782: }
10783: } else {
10784: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10785: push(@{$changes{'admin'}{$type}},$item);
10786: }
10787: }
10788: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10789: push(@{$changes{'admin'}{$type}},$item);
10790: }
10791: }
10792: }
10793: }
10794:
10795: foreach my $item (@{$ordered{'default'}}) {
10796: foreach my $type (@types) {
10797: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10798: if ($item eq 'types') {
10799: unless (($value eq 'all') || ($value eq 'dom')) {
10800: $value = '';
10801: }
10802: } elsif ($item eq 'registered') {
10803: unless ($value eq '1') {
10804: $value = 0;
10805: }
10806: } elsif ($item eq 'approval') {
10807: unless ($value =~ /^[012]$/) {
10808: $value = 0;
10809: }
10810: } else {
10811: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10812: $value = 'none';
10813: }
10814: }
10815: $selfenrollhash{'default'}{$type}{$item} = $value;
10816: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10817: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10818: if ($selfenrollhash{'default'}{$type}{$item} ne
10819: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10820: push(@{$changes{'default'}{$type}},$item);
10821: }
10822: } else {
10823: push(@{$changes{'default'}{$type}},$item);
10824: }
10825: } else {
10826: push(@{$changes{'default'}{$type}},$item);
10827: }
10828: if ($item eq 'limit') {
10829: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10830: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10831: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10832: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10833: }
10834: } else {
10835: $selfenrollhash{'default'}{$type}{'cap'} = '';
10836: }
10837: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10838: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10839: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10840: push(@{$changes{'default'}{$type}},'cap');
10841: }
10842: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10843: push(@{$changes{'default'}{$type}},'cap');
10844: }
10845: }
10846: }
10847: }
10848:
10849: foreach my $item (@{$itemsref}) {
10850: if ($item eq 'fields') {
10851: my @changed;
10852: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10853: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10854: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10855: }
10856: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10857: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10858: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10859: $domconfig{'selfenrollment'}{'validation'}{$item});
10860: } else {
10861: @changed = @{$selfenrollhash{'validation'}{$item}};
10862: }
10863: } else {
10864: @changed = @{$selfenrollhash{'validation'}{$item}};
10865: }
10866: if (@changed) {
10867: if ($selfenrollhash{'validation'}{$item}) {
10868: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10869: } else {
10870: $changes{'validation'}{$item} = &mt('None');
10871: }
10872: }
10873: } else {
10874: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10875: if ($item eq 'markup') {
10876: if ($env{'form.selfenroll_validation_'.$item}) {
10877: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10878: }
10879: }
10880: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10881: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10882: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10883: }
10884: }
10885: }
10886: }
10887:
10888: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10889: $dom);
10890: if ($putresult eq 'ok') {
10891: if (keys(%changes) > 0) {
10892: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10893: $resulttext = &mt('Changes made:').'<ul>';
10894: foreach my $key ('admin','default','validation') {
10895: if (ref($changes{$key}) eq 'HASH') {
10896: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10897: if ($key eq 'validation') {
10898: foreach my $item (@{$itemsref}) {
10899: if (exists($changes{$key}{$item})) {
10900: if ($item eq 'markup') {
10901: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10902: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10903: } else {
10904: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10905: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10906: }
10907: }
10908: }
10909: } else {
10910: foreach my $type (@types) {
10911: if ($type eq 'community') {
10912: $roles{'1'} = &mt('Community personnel');
10913: } else {
10914: $roles{'1'} = &mt('Course personnel');
10915: }
10916: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10917: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10918: if ($key eq 'admin') {
10919: my @mgrdc = ();
10920: if (ref($ordered{$key}) eq 'ARRAY') {
10921: foreach my $item (@{$ordered{'admin'}}) {
10922: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10923: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10924: push(@mgrdc,$item);
10925: }
10926: }
10927: }
10928: if (@mgrdc) {
10929: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10930: } else {
10931: delete($domdefaults{$type.'selfenrolladmdc'});
10932: }
10933: }
10934: } else {
10935: if (ref($ordered{$key}) eq 'ARRAY') {
10936: foreach my $item (@{$ordered{$key}}) {
10937: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10938: $domdefaults{$type.'selfenroll'.$item} =
10939: $selfenrollhash{$key}{$type}{$item};
10940: }
10941: }
10942: }
10943: }
10944: }
10945: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10946: foreach my $item (@{$ordered{$key}}) {
10947: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10948: $resulttext .= '<li>';
10949: if ($key eq 'admin') {
10950: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10951: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10952: } else {
10953: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10954: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10955: }
10956: $resulttext .= '</li>';
10957: }
10958: }
10959: $resulttext .= '</ul></li>';
10960: }
10961: }
10962: $resulttext .= '</ul></li>';
10963: }
10964: }
10965: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10966: my $cachetime = 24*60*60;
10967: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10968: if (ref($lastactref) eq 'HASH') {
10969: $lastactref->{'domdefaults'} = 1;
10970: }
10971: }
10972: }
10973: $resulttext .= '</ul>';
10974: } else {
10975: $resulttext = &mt('No changes made to self-enrollment settings');
10976: }
10977: } else {
10978: $resulttext = '<span class="LC_error">'.
10979: &mt('An error occurred: [_1]',$putresult).'</span>';
10980: }
10981: return $resulttext;
10982: }
10983:
1.137 raeburn 10984: sub modify_usersessions {
1.160.6.27 raeburn 10985: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10986: my @hostingtypes = ('version','excludedomain','includedomain');
10987: my @offloadtypes = ('primary','default');
10988: my %types = (
10989: remote => \@hostingtypes,
10990: hosted => \@hostingtypes,
10991: spares => \@offloadtypes,
10992: );
10993: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10994: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10995: my (%by_ip,%by_location,@intdoms);
10996: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10997: my @locations = sort(keys(%by_location));
1.137 raeburn 10998: my (%defaultshash,%changes);
10999: foreach my $prefix (@prefixes) {
11000: $defaultshash{'usersessions'}{$prefix} = {};
11001: }
1.160.6.27 raeburn 11002: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11003: my $resulttext;
1.138 raeburn 11004: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11005: foreach my $prefix (@prefixes) {
1.145 raeburn 11006: next if ($prefix eq 'spares');
11007: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11008: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11009: if ($type eq 'version') {
11010: my $value = $env{'form.'.$prefix.'_'.$type};
11011: my $okvalue;
11012: if ($value ne '') {
11013: if (grep(/^\Q$value\E$/,@lcversions)) {
11014: $okvalue = $value;
11015: }
11016: }
11017: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11018: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11019: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11020: if ($inuse == 0) {
11021: $changes{$prefix}{$type} = 1;
11022: } else {
11023: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11024: $changes{$prefix}{$type} = 1;
11025: }
11026: if ($okvalue ne '') {
11027: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11028: }
11029: }
11030: } else {
11031: if (($inuse == 1) && ($okvalue ne '')) {
11032: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11033: $changes{$prefix}{$type} = 1;
11034: }
11035: }
11036: } else {
11037: if (($inuse == 1) && ($okvalue ne '')) {
11038: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11039: $changes{$prefix}{$type} = 1;
11040: }
11041: }
11042: } else {
11043: if (($inuse == 1) && ($okvalue ne '')) {
11044: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11045: $changes{$prefix}{$type} = 1;
11046: }
11047: }
11048: } else {
11049: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11050: my @okvals;
11051: foreach my $val (@vals) {
1.138 raeburn 11052: if ($val =~ /:/) {
11053: my @items = split(/:/,$val);
11054: foreach my $item (@items) {
11055: if (ref($by_location{$item}) eq 'ARRAY') {
11056: push(@okvals,$item);
11057: }
11058: }
11059: } else {
11060: if (ref($by_location{$val}) eq 'ARRAY') {
11061: push(@okvals,$val);
11062: }
1.137 raeburn 11063: }
11064: }
11065: @okvals = sort(@okvals);
11066: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11067: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11068: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11069: if ($inuse == 0) {
11070: $changes{$prefix}{$type} = 1;
11071: } else {
11072: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11073: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11074: if (@changed > 0) {
11075: $changes{$prefix}{$type} = 1;
11076: }
11077: }
11078: } else {
11079: if ($inuse == 1) {
11080: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11081: $changes{$prefix}{$type} = 1;
11082: }
11083: }
11084: } else {
11085: if ($inuse == 1) {
11086: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11087: $changes{$prefix}{$type} = 1;
11088: }
11089: }
11090: } else {
11091: if ($inuse == 1) {
11092: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11093: $changes{$prefix}{$type} = 1;
11094: }
11095: }
11096: }
11097: }
11098: }
1.145 raeburn 11099:
11100: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11101: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11102: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11103: my $savespares;
11104:
11105: foreach my $lonhost (sort(keys(%servers))) {
11106: my $serverhomeID =
11107: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11108: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11109: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11110: my %spareschg;
11111: foreach my $type (@{$types{'spares'}}) {
11112: my @okspares;
11113: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11114: foreach my $server (@checked) {
1.152 raeburn 11115: if (&Apache::lonnet::hostname($server) ne '') {
11116: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11117: unless (grep(/^\Q$server\E$/,@okspares)) {
11118: push(@okspares,$server);
11119: }
1.145 raeburn 11120: }
11121: }
11122: }
11123: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11124: my $newspare;
1.152 raeburn 11125: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11126: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11127: $newspare = $new;
11128: }
11129: }
1.152 raeburn 11130: my @spares;
11131: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11132: @spares = sort(@okspares,$newspare);
11133: } else {
11134: @spares = sort(@okspares);
11135: }
11136: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11137: if (ref($spareid{$lonhost}) eq 'HASH') {
11138: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11139: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11140: if (@diffs > 0) {
11141: $spareschg{$type} = 1;
11142: }
11143: }
11144: }
11145: }
11146: if (keys(%spareschg) > 0) {
11147: $changes{'spares'}{$lonhost} = \%spareschg;
11148: }
11149: }
1.160.6.61 raeburn 11150: $defaultshash{'usersessions'}{'offloadnow'} = {};
11151: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11152: my @okoffload;
11153: if (@offloadnow) {
11154: foreach my $server (@offloadnow) {
11155: if (&Apache::lonnet::hostname($server) ne '') {
11156: unless (grep(/^\Q$server\E$/,@okoffload)) {
11157: push(@okoffload,$server);
11158: }
11159: }
11160: }
11161: if (@okoffload) {
11162: foreach my $lonhost (@okoffload) {
11163: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11164: }
11165: }
11166: }
1.145 raeburn 11167: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11168: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11169: if (ref($changes{'spares'}) eq 'HASH') {
11170: if (keys(%{$changes{'spares'}}) > 0) {
11171: $savespares = 1;
11172: }
11173: }
11174: } else {
11175: $savespares = 1;
11176: }
1.160.6.61 raeburn 11177: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11178: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11179: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11180: $changes{'offloadnow'} = 1;
11181: last;
11182: }
11183: }
11184: unless ($changes{'offloadnow'}) {
11185: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11186: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11187: $changes{'offloadnow'} = 1;
11188: last;
11189: }
11190: }
11191: }
11192: } elsif (@okoffload) {
11193: $changes{'offloadnow'} = 1;
11194: }
11195: } elsif (@okoffload) {
11196: $changes{'offloadnow'} = 1;
1.145 raeburn 11197: }
1.147 raeburn 11198: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11199: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11200: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11201: $dom);
11202: if ($putresult eq 'ok') {
11203: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11204: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11205: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11206: }
11207: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11208: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11209: }
1.160.6.61 raeburn 11210: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11211: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11212: }
1.137 raeburn 11213: }
11214: my $cachetime = 24*60*60;
11215: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11216: if (ref($lastactref) eq 'HASH') {
11217: $lastactref->{'domdefaults'} = 1;
11218: }
1.147 raeburn 11219: if (keys(%changes) > 0) {
11220: my %lt = &usersession_titles();
11221: $resulttext = &mt('Changes made:').'<ul>';
11222: foreach my $prefix (@prefixes) {
11223: if (ref($changes{$prefix}) eq 'HASH') {
11224: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11225: if ($prefix eq 'spares') {
11226: if (ref($changes{$prefix}) eq 'HASH') {
11227: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11228: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11229: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11230: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11231: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11232: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11233: foreach my $type (@{$types{$prefix}}) {
11234: if ($changes{$prefix}{$lonhost}{$type}) {
11235: my $offloadto = &mt('None');
11236: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11237: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11238: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11239: }
1.145 raeburn 11240: }
1.147 raeburn 11241: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11242: }
1.137 raeburn 11243: }
11244: }
1.147 raeburn 11245: $resulttext .= '</li>';
1.137 raeburn 11246: }
11247: }
1.147 raeburn 11248: } else {
11249: foreach my $type (@{$types{$prefix}}) {
11250: if (defined($changes{$prefix}{$type})) {
11251: my $newvalue;
11252: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11253: if (ref($defaultshash{'usersessions'}{$prefix})) {
11254: if ($type eq 'version') {
11255: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11256: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11257: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11258: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11259: }
1.145 raeburn 11260: }
11261: }
11262: }
1.147 raeburn 11263: if ($newvalue eq '') {
11264: if ($type eq 'version') {
11265: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11266: } else {
11267: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11268: }
1.145 raeburn 11269: } else {
1.147 raeburn 11270: if ($type eq 'version') {
11271: $newvalue .= ' '.&mt('(or later)');
11272: }
11273: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11274: }
1.137 raeburn 11275: }
11276: }
11277: }
1.147 raeburn 11278: $resulttext .= '</ul>';
1.137 raeburn 11279: }
11280: }
1.160.6.61 raeburn 11281: if ($changes{'offloadnow'}) {
11282: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11283: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11284: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11285: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11286: $resulttext .= '<li>'.$lonhost.'</li>';
11287: }
11288: $resulttext .= '</ul>';
11289: } else {
11290: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11291: }
11292: } else {
11293: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11294: }
11295: }
1.147 raeburn 11296: $resulttext .= '</ul>';
11297: } else {
11298: $resulttext = $nochgmsg;
1.137 raeburn 11299: }
11300: } else {
11301: $resulttext = '<span class="LC_error">'.
11302: &mt('An error occurred: [_1]',$putresult).'</span>';
11303: }
11304: } else {
1.147 raeburn 11305: $resulttext = $nochgmsg;
1.137 raeburn 11306: }
11307: return $resulttext;
11308: }
11309:
1.150 raeburn 11310: sub modify_loadbalancing {
11311: my ($dom,%domconfig) = @_;
11312: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11313: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11314: my ($othertitle,$usertypes,$types) =
11315: &Apache::loncommon::sorted_inst_types($dom);
11316: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11317: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11318: my @sparestypes = ('primary','default');
11319: my %typetitles = &sparestype_titles();
11320: my $resulttext;
1.160.6.7 raeburn 11321: my (%currbalancer,%currtargets,%currrules,%existing);
11322: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11323: %existing = %{$domconfig{'loadbalancing'}};
11324: }
11325: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11326: \%currtargets,\%currrules);
11327: my ($saveloadbalancing,%defaultshash,%changes);
11328: my ($alltypes,$othertypes,$titles) =
11329: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11330: my %ruletitles = &offloadtype_text();
11331: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11332: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11333: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11334: if ($balancer eq '') {
11335: next;
11336: }
11337: if (!exists($servers{$balancer})) {
11338: if (exists($currbalancer{$balancer})) {
11339: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11340: }
1.160.6.7 raeburn 11341: next;
11342: }
11343: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11344: push(@{$changes{'delete'}},$balancer);
11345: next;
11346: }
11347: if (!exists($currbalancer{$balancer})) {
11348: push(@{$changes{'add'}},$balancer);
11349: }
11350: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11351: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11352: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11353: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11354: $saveloadbalancing = 1;
11355: }
11356: foreach my $sparetype (@sparestypes) {
11357: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11358: my @offloadto;
11359: foreach my $target (@targets) {
11360: if (($servers{$target}) && ($target ne $balancer)) {
11361: if ($sparetype eq 'default') {
11362: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11363: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11364: }
11365: }
1.160.6.7 raeburn 11366: unless(grep(/^\Q$target\E$/,@offloadto)) {
11367: push(@offloadto,$target);
11368: }
1.150 raeburn 11369: }
1.160.6.7 raeburn 11370: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11371: }
11372: }
1.160.6.7 raeburn 11373: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11374: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11375: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11376: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11377: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11378: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11379: }
1.160.6.7 raeburn 11380: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11381: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11382: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11383: }
11384: }
11385: }
11386: } else {
1.160.6.7 raeburn 11387: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11388: foreach my $sparetype (@sparestypes) {
11389: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11390: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11391: $changes{'curr'}{$balancer}{'targets'} = 1;
11392: }
1.150 raeburn 11393: }
11394: }
1.160.6.7 raeburn 11395: }
1.150 raeburn 11396: }
11397: my $ishomedom;
1.160.6.7 raeburn 11398: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11399: $ishomedom = 1;
1.150 raeburn 11400: }
11401: if (ref($alltypes) eq 'ARRAY') {
11402: foreach my $type (@{$alltypes}) {
11403: my $rule;
1.160.6.7 raeburn 11404: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11405: (!$ishomedom)) {
1.160.6.7 raeburn 11406: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11407: }
11408: if ($rule eq 'specific') {
1.160.6.55 raeburn 11409: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11410: if (exists($servers{$specifiedhost})) {
11411: $rule = $specifiedhost;
11412: }
1.150 raeburn 11413: }
1.160.6.7 raeburn 11414: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11415: if (ref($currrules{$balancer}) eq 'HASH') {
11416: if ($rule ne $currrules{$balancer}{$type}) {
11417: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11418: }
11419: } elsif ($rule ne '') {
1.160.6.7 raeburn 11420: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11421: }
11422: }
11423: }
1.160.6.7 raeburn 11424: }
11425: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11426: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11427: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11428: $defaultshash{'loadbalancing'} = {};
11429: }
11430: my $putresult = &Apache::lonnet::put_dom('configuration',
11431: \%defaultshash,$dom);
11432: if ($putresult eq 'ok') {
11433: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11434: my %toupdate;
1.160.6.7 raeburn 11435: if (ref($changes{'delete'}) eq 'ARRAY') {
11436: foreach my $balancer (sort(@{$changes{'delete'}})) {
11437: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11438: $toupdate{$balancer} = 1;
1.150 raeburn 11439: }
1.160.6.7 raeburn 11440: }
11441: if (ref($changes{'add'}) eq 'ARRAY') {
11442: foreach my $balancer (sort(@{$changes{'add'}})) {
11443: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11444: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11445: }
11446: }
11447: if (ref($changes{'curr'}) eq 'HASH') {
11448: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11449: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11450: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11451: if ($changes{'curr'}{$balancer}{'targets'}) {
11452: my %offloadstr;
11453: foreach my $sparetype (@sparestypes) {
11454: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11455: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11456: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11457: }
11458: }
1.150 raeburn 11459: }
1.160.6.7 raeburn 11460: if (keys(%offloadstr) == 0) {
11461: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11462: } else {
1.160.6.7 raeburn 11463: my $showoffload;
11464: foreach my $sparetype (@sparestypes) {
11465: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11466: if (defined($offloadstr{$sparetype})) {
11467: $showoffload .= $offloadstr{$sparetype};
11468: } else {
11469: $showoffload .= &mt('None');
11470: }
11471: $showoffload .= (' 'x3);
11472: }
11473: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11474: }
11475: }
11476: }
1.160.6.7 raeburn 11477: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11478: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11479: foreach my $type (@{$alltypes}) {
11480: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11481: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11482: my $balancetext;
11483: if ($rule eq '') {
11484: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11485: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11486: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11487: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11488: foreach my $sparetype (@sparestypes) {
11489: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11490: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11491: }
11492: }
1.160.6.55 raeburn 11493: foreach my $item (@{$alltypes}) {
11494: next if ($item =~ /^_LC_ipchange/);
11495: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11496: if ($hasrule eq 'homeserver') {
11497: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11498: } else {
11499: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11500: if ($servers{$hasrule}) {
11501: $toupdate{$hasrule} = 1;
11502: }
11503: }
11504: }
11505: }
11506: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11507: $balancetext = $ruletitles{$rule};
11508: } else {
11509: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11510: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11511: if ($receiver) {
11512: $toupdate{$receiver};
11513: }
11514: }
11515: } else {
11516: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11517: }
1.160.6.7 raeburn 11518: } else {
11519: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11520: }
1.160.6.26 raeburn 11521: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11522: }
11523: }
11524: }
11525: }
1.160.6.54 raeburn 11526: if (keys(%toupdate)) {
11527: my %thismachine;
11528: my $updatedhere;
11529: my $cachetime = 60*60*24;
11530: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11531: foreach my $lonhost (keys(%toupdate)) {
11532: if ($thismachine{$lonhost}) {
11533: unless ($updatedhere) {
11534: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11535: $defaultshash{'loadbalancing'},
11536: $cachetime);
11537: $updatedhere = 1;
11538: }
11539: } else {
11540: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11541: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11542: }
11543: }
11544: }
1.150 raeburn 11545: }
1.160.6.7 raeburn 11546: }
11547: if ($resulttext ne '') {
11548: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11549: } else {
11550: $resulttext = $nochgmsg;
11551: }
11552: } else {
1.160.6.7 raeburn 11553: $resulttext = $nochgmsg;
1.150 raeburn 11554: }
11555: } else {
1.160.6.7 raeburn 11556: $resulttext = '<span class="LC_error">'.
11557: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11558: }
11559: } else {
1.160.6.7 raeburn 11560: $resulttext = $nochgmsg;
1.150 raeburn 11561: }
11562: return $resulttext;
11563: }
11564:
1.48 raeburn 11565: sub recurse_check {
11566: my ($chkcats,$categories,$depth,$name) = @_;
11567: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11568: my $chg = 0;
11569: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11570: my $category = $chkcats->[$depth]{$name}[$j];
11571: my $item;
11572: if ($category eq '') {
11573: $chg ++;
11574: } else {
11575: my $deeper = $depth + 1;
11576: $item = &escape($category).':'.&escape($name).':'.$depth;
11577: if ($chg) {
11578: $categories->{$item} -= $chg;
11579: }
11580: &recurse_check($chkcats,$categories,$deeper,$category);
11581: $deeper --;
11582: }
11583: }
11584: }
11585: return;
11586: }
11587:
11588: sub recurse_cat_deletes {
11589: my ($item,$coursecategories,$deletions) = @_;
11590: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11591: my $subdepth = $depth + 1;
11592: if (ref($coursecategories) eq 'HASH') {
11593: foreach my $subitem (keys(%{$coursecategories})) {
11594: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11595: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11596: delete($coursecategories->{$subitem});
11597: $deletions->{$subitem} = 1;
11598: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11599: }
1.48 raeburn 11600: }
11601: }
11602: return;
11603: }
11604:
1.125 raeburn 11605: sub get_active_dcs {
11606: my ($dom) = @_;
1.160.6.16 raeburn 11607: my $now = time;
11608: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11609: my %domcoords;
11610: my $numdcs = 0;
11611: foreach my $server (keys(%dompersonnel)) {
11612: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11613: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11614: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11615: }
11616: }
11617: return %domcoords;
11618: }
11619:
11620: sub active_dc_picker {
1.160.6.16 raeburn 11621: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11622: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11623: my @domcoord = keys(%domcoords);
11624: if (keys(%currhash)) {
11625: foreach my $dc (keys(%currhash)) {
11626: unless (exists($domcoords{$dc})) {
11627: push(@domcoord,$dc);
11628: }
11629: }
11630: }
11631: @domcoord = sort(@domcoord);
11632: my $numdcs = scalar(@domcoord);
11633: my $rows = 0;
11634: my $table;
1.125 raeburn 11635: if ($numdcs > 1) {
1.160.6.16 raeburn 11636: $table = '<table>';
11637: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11638: my $rem = $i%($numinrow);
11639: if ($rem == 0) {
11640: if ($i > 0) {
1.160.6.16 raeburn 11641: $table .= '</tr>';
1.125 raeburn 11642: }
1.160.6.16 raeburn 11643: $table .= '<tr>';
11644: $rows ++;
1.125 raeburn 11645: }
1.160.6.16 raeburn 11646: my $check = '';
11647: if ($inputtype eq 'radio') {
11648: if (keys(%currhash) == 0) {
11649: if (!$i) {
11650: $check = ' checked="checked"';
11651: }
11652: } elsif (exists($currhash{$domcoord[$i]})) {
11653: $check = ' checked="checked"';
11654: }
11655: } else {
11656: if (exists($currhash{$domcoord[$i]})) {
11657: $check = ' checked="checked"';
1.125 raeburn 11658: }
11659: }
1.160.6.16 raeburn 11660: if ($i == @domcoord - 1) {
1.125 raeburn 11661: my $colsleft = $numinrow - $rem;
11662: if ($colsleft > 1) {
1.160.6.16 raeburn 11663: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11664: } else {
1.160.6.16 raeburn 11665: $table .= '<td class="LC_left_item">';
1.125 raeburn 11666: }
11667: } else {
1.160.6.16 raeburn 11668: $table .= '<td class="LC_left_item">';
11669: }
11670: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11671: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11672: $table .= '<span class="LC_nobreak"><label>'.
11673: '<input type="'.$inputtype.'" name="'.$name.'"'.
11674: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11675: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11676: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11677: }
1.160.6.33 raeburn 11678: $table .= '</label></span></td>';
1.125 raeburn 11679: }
1.160.6.16 raeburn 11680: $table .= '</tr></table>';
11681: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11682: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11683: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11684: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11685: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11686: if ($user ne $dcname.':'.$dcdom) {
11687: $table .= ' ('.$dcname.':'.$dcdom.')';
11688: }
1.160.6.16 raeburn 11689: } else {
11690: my $check;
11691: if (exists($currhash{$domcoord[0]})) {
11692: $check = ' checked="checked"';
11693: }
1.160.6.50 raeburn 11694: $table = '<span class="LC_nobreak"><label>'.
11695: '<input type="checkbox" name="'.$name.'" '.
11696: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11697: if ($user ne $dcname.':'.$dcdom) {
11698: $table .= ' ('.$dcname.':'.$dcdom.')';
11699: }
11700: $table .= '</label></span>';
1.160.6.16 raeburn 11701: $rows ++;
11702: }
1.125 raeburn 11703: }
1.160.6.16 raeburn 11704: return ($numdcs,$table,$rows);
1.125 raeburn 11705: }
11706:
1.137 raeburn 11707: sub usersession_titles {
11708: return &Apache::lonlocal::texthash(
11709: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11710: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11711: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11712: version => 'LON-CAPA version requirement',
1.138 raeburn 11713: excludedomain => 'Allow all, but exclude specific domains',
11714: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11715: primary => 'Primary (checked first)',
1.154 raeburn 11716: default => 'Default',
1.137 raeburn 11717: );
11718: }
11719:
1.152 raeburn 11720: sub id_for_thisdom {
11721: my (%servers) = @_;
11722: my %altids;
11723: foreach my $server (keys(%servers)) {
11724: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11725: if ($serverhome ne $server) {
11726: $altids{$serverhome} = $server;
11727: }
11728: }
11729: return %altids;
11730: }
11731:
1.150 raeburn 11732: sub count_servers {
11733: my ($currbalancer,%servers) = @_;
11734: my (@spares,$numspares);
11735: foreach my $lonhost (sort(keys(%servers))) {
11736: next if ($currbalancer eq $lonhost);
11737: push(@spares,$lonhost);
11738: }
11739: if ($currbalancer) {
11740: $numspares = scalar(@spares);
11741: } else {
11742: $numspares = scalar(@spares) - 1;
11743: }
11744: return ($numspares,@spares);
11745: }
11746:
11747: sub lonbalance_targets_js {
1.160.6.7 raeburn 11748: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11749: my $select = &mt('Select');
11750: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11751: if (ref($servers) eq 'HASH') {
11752: $alltargets = join("','",sort(keys(%{$servers})));
11753: my @homedoms;
11754: foreach my $server (sort(keys(%{$servers}))) {
11755: if (&Apache::lonnet::host_domain($server) eq $dom) {
11756: push(@homedoms,'1');
11757: } else {
11758: push(@homedoms,'0');
11759: }
11760: }
11761: $allishome = join("','",@homedoms);
11762: }
11763: if (ref($types) eq 'ARRAY') {
11764: if (@{$types} > 0) {
11765: @alltypes = @{$types};
11766: }
11767: }
11768: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11769: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11770: my (%currbalancer,%currtargets,%currrules,%existing);
11771: if (ref($settings) eq 'HASH') {
11772: %existing = %{$settings};
11773: }
11774: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11775: \%currtargets,\%currrules);
11776: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11777: return <<"END";
11778:
11779: <script type="text/javascript">
11780: // <![CDATA[
11781:
1.160.6.7 raeburn 11782: currBalancers = new Array('$balancers');
11783:
11784: function toggleTargets(balnum) {
11785: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11786: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11787: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11788: var prevbalancer = prevhostitem.value;
11789: var baltotal = document.getElementById('loadbalancing_total').value;
11790: prevhostitem.value = balancer;
11791: if (prevbalancer != '') {
11792: var prevIdx = currBalancers.indexOf(prevbalancer);
11793: if (prevIdx != -1) {
11794: currBalancers.splice(prevIdx,1);
11795: }
11796: }
1.150 raeburn 11797: if (balancer == '') {
1.160.6.7 raeburn 11798: hideSpares(balnum);
1.150 raeburn 11799: } else {
1.160.6.7 raeburn 11800: var currIdx = currBalancers.indexOf(balancer);
11801: if (currIdx == -1) {
11802: currBalancers.push(balancer);
11803: }
1.150 raeburn 11804: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11805: var ishomedom = homedoms[lonhostitem.selectedIndex];
11806: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11807: }
1.160.6.7 raeburn 11808: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11809: return;
11810: }
11811:
1.160.6.7 raeburn 11812: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11813: var alltargets = new Array('$alltargets');
11814: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11815: var offloadtypes = new Array('primary','default');
11816:
1.160.6.7 raeburn 11817: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11818: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11819:
1.151 raeburn 11820: for (var i=0; i<offloadtypes.length; i++) {
11821: var count = 0;
11822: for (var j=0; j<alltargets.length; j++) {
11823: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11824: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11825: item.value = alltargets[j];
11826: item.style.textAlign='left';
11827: item.style.textFace='normal';
11828: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11829: if (currBalancers.indexOf(alltargets[j]) == -1) {
11830: item.disabled = '';
11831: } else {
11832: item.disabled = 'disabled';
11833: item.checked = false;
11834: }
1.151 raeburn 11835: count ++;
11836: }
1.150 raeburn 11837: }
11838: }
1.151 raeburn 11839: for (var k=0; k<insttypes.length; k++) {
11840: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11841: if (ishomedom == 1) {
1.160.6.7 raeburn 11842: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11843: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11844: } else {
1.160.6.7 raeburn 11845: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11846: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11847: }
11848: } else {
1.160.6.7 raeburn 11849: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11850: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11851: }
1.151 raeburn 11852: if ((insttypes[k] != '_LC_external') &&
11853: ((insttypes[k] != '_LC_internetdom') ||
11854: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11855: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11856: item.options.length = 0;
11857: item.options[0] = new Option("","",true,true);
11858: var idx = 0;
1.151 raeburn 11859: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11860: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11861: idx ++;
11862: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11863: }
11864: }
11865: }
11866: }
11867: return;
11868: }
11869:
1.160.6.7 raeburn 11870: function hideSpares(balnum) {
1.150 raeburn 11871: var alltargets = new Array('$alltargets');
11872: var insttypes = new Array('$allinsttypes');
11873: var offloadtypes = new Array('primary','default');
11874:
1.160.6.7 raeburn 11875: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11876: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11877:
11878: var total = alltargets.length - 1;
11879: for (var i=0; i<offloadtypes; i++) {
11880: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11881: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11882: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11883: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11884: }
1.150 raeburn 11885: }
11886: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11887: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11888: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11889: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11890: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11891: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11892: }
11893: }
11894: return;
11895: }
11896:
1.160.6.7 raeburn 11897: function checkOffloads(item,balnum,type) {
1.150 raeburn 11898: var alltargets = new Array('$alltargets');
11899: var offloadtypes = new Array('primary','default');
11900: if (item.checked) {
11901: var total = alltargets.length - 1;
11902: var other;
11903: if (type == offloadtypes[0]) {
1.151 raeburn 11904: other = offloadtypes[1];
1.150 raeburn 11905: } else {
1.151 raeburn 11906: other = offloadtypes[0];
1.150 raeburn 11907: }
11908: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11909: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11910: if (server == item.value) {
1.160.6.7 raeburn 11911: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11912: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11913: }
11914: }
11915: }
11916: }
11917: return;
11918: }
11919:
1.160.6.7 raeburn 11920: function singleServerToggle(balnum,type) {
11921: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11922: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11923: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11924: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11925:
11926: } else {
1.160.6.7 raeburn 11927: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11928: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11929: }
11930: return;
11931: }
11932:
1.160.6.7 raeburn 11933: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11934: if (type == '_LC_external') {
1.160.6.26 raeburn 11935: return;
1.150 raeburn 11936: }
1.160.6.7 raeburn 11937: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11938: for (var i=0; i<typesRules.length; i++) {
11939: if (formname.elements[typesRules[i]].checked) {
11940: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11941: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11942: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11943: } else {
1.160.6.7 raeburn 11944: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11945: }
11946: }
11947: }
11948: return;
11949: }
11950:
11951: function balancerDeleteChange(balnum) {
11952: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11953: var baltotal = document.getElementById('loadbalancing_total').value;
11954: var addtarget;
11955: var removetarget;
11956: var action = 'delete';
11957: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11958: var lonhost = hostitem.value;
11959: var currIdx = currBalancers.indexOf(lonhost);
11960: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11961: if (currIdx != -1) {
11962: currBalancers.splice(currIdx,1);
11963: }
11964: addtarget = lonhost;
11965: } else {
11966: if (currIdx == -1) {
11967: currBalancers.push(lonhost);
11968: }
11969: removetarget = lonhost;
11970: action = 'undelete';
11971: }
11972: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11973: }
11974: return;
11975: }
11976:
11977: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11978: if (baltotal > 1) {
11979: var offloadtypes = new Array('primary','default');
11980: var alltargets = new Array('$alltargets');
11981: var insttypes = new Array('$allinsttypes');
11982: for (var i=0; i<baltotal; i++) {
11983: if (i != balnum) {
11984: for (var j=0; j<offloadtypes.length; j++) {
11985: var total = alltargets.length - 1;
11986: for (var k=0; k<total; k++) {
11987: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11988: var server = serveritem.value;
11989: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11990: if (server == addtarget) {
11991: serveritem.disabled = '';
11992: }
11993: }
11994: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11995: if (server == removetarget) {
11996: serveritem.disabled = 'disabled';
11997: serveritem.checked = false;
11998: }
11999: }
12000: }
12001: }
12002: for (var j=0; j<insttypes.length; j++) {
12003: if (insttypes[j] != '_LC_external') {
12004: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12005: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12006: var currSel = singleserver.selectedIndex;
12007: var currVal = singleserver.options[currSel].value;
12008: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12009: var numoptions = singleserver.options.length;
12010: var needsnew = 1;
12011: for (var k=0; k<numoptions; k++) {
12012: if (singleserver.options[k] == addtarget) {
12013: needsnew = 0;
12014: break;
12015: }
12016: }
12017: if (needsnew == 1) {
12018: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12019: }
12020: }
12021: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12022: singleserver.options.length = 0;
12023: if ((currVal) && (currVal != removetarget)) {
12024: singleserver.options[0] = new Option("","",false,false);
12025: } else {
12026: singleserver.options[0] = new Option("","",true,true);
12027: }
12028: var idx = 0;
12029: for (var m=0; m<alltargets.length; m++) {
12030: if (currBalancers.indexOf(alltargets[m]) == -1) {
12031: idx ++;
12032: if (currVal == alltargets[m]) {
12033: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12034: } else {
12035: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12036: }
12037: }
12038: }
12039: }
12040: }
12041: }
12042: }
1.150 raeburn 12043: }
12044: }
12045: }
12046: return;
12047: }
12048:
1.152 raeburn 12049: // ]]>
12050: </script>
12051:
12052: END
12053: }
12054:
12055: sub new_spares_js {
12056: my @sparestypes = ('primary','default');
12057: my $types = join("','",@sparestypes);
12058: my $select = &mt('Select');
12059: return <<"END";
12060:
12061: <script type="text/javascript">
12062: // <![CDATA[
12063:
12064: function updateNewSpares(formname,lonhost) {
12065: var types = new Array('$types');
12066: var include = new Array();
12067: var exclude = new Array();
12068: for (var i=0; i<types.length; i++) {
12069: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12070: for (var j=0; j<spareboxes.length; j++) {
12071: if (formname.elements[spareboxes[j]].checked) {
12072: exclude.push(formname.elements[spareboxes[j]].value);
12073: } else {
12074: include.push(formname.elements[spareboxes[j]].value);
12075: }
12076: }
12077: }
12078: for (var i=0; i<types.length; i++) {
12079: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12080: var selIdx = newSpare.selectedIndex;
12081: var currnew = newSpare.options[selIdx].value;
12082: var okSpares = new Array();
12083: for (var j=0; j<newSpare.options.length; j++) {
12084: var possible = newSpare.options[j].value;
12085: if (possible != '') {
12086: if (exclude.indexOf(possible) == -1) {
12087: okSpares.push(possible);
12088: } else {
12089: if (currnew == possible) {
12090: selIdx = 0;
12091: }
12092: }
12093: }
12094: }
12095: for (var k=0; k<include.length; k++) {
12096: if (okSpares.indexOf(include[k]) == -1) {
12097: okSpares.push(include[k]);
12098: }
12099: }
12100: okSpares.sort();
12101: newSpare.options.length = 0;
12102: if (selIdx == 0) {
12103: newSpare.options[0] = new Option("$select","",true,true);
12104: } else {
12105: newSpare.options[0] = new Option("$select","",false,false);
12106: }
12107: for (var m=0; m<okSpares.length; m++) {
12108: var idx = m+1;
12109: var selThis = 0;
12110: if (selIdx != 0) {
12111: if (okSpares[m] == currnew) {
12112: selThis = 1;
12113: }
12114: }
12115: if (selThis == 1) {
12116: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12117: } else {
12118: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12119: }
12120: }
12121: }
12122: return;
12123: }
12124:
12125: function checkNewSpares(lonhost,type) {
12126: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12127: var chosen = newSpare.options[newSpare.selectedIndex].value;
12128: if (chosen != '') {
12129: var othertype;
12130: var othernewSpare;
12131: if (type == 'primary') {
12132: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12133: }
12134: if (type == 'default') {
12135: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12136: }
12137: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12138: othernewSpare.selectedIndex = 0;
12139: }
12140: }
12141: return;
12142: }
12143:
12144: // ]]>
12145: </script>
12146:
12147: END
12148:
12149: }
12150:
12151: sub common_domprefs_js {
12152: return <<"END";
12153:
12154: <script type="text/javascript">
12155: // <![CDATA[
12156:
1.150 raeburn 12157: function getIndicesByName(formname,item) {
1.152 raeburn 12158: var group = new Array();
1.150 raeburn 12159: for (var i=0;i<formname.elements.length;i++) {
12160: if (formname.elements[i].name == item) {
1.152 raeburn 12161: group.push(formname.elements[i].id);
1.150 raeburn 12162: }
12163: }
1.152 raeburn 12164: return group;
1.150 raeburn 12165: }
12166:
12167: // ]]>
12168: </script>
12169:
12170: END
1.152 raeburn 12171:
1.150 raeburn 12172: }
12173:
1.160.6.5 raeburn 12174: sub recaptcha_js {
12175: my %lt = &captcha_phrases();
12176: return <<"END";
12177:
12178: <script type="text/javascript">
12179: // <![CDATA[
12180:
12181: function updateCaptcha(caller,context) {
12182: var privitem;
12183: var pubitem;
12184: var privtext;
12185: var pubtext;
1.160.6.69! raeburn 12186: var versionitem;
! 12187: var versiontext;
1.160.6.5 raeburn 12188: if (document.getElementById(context+'_recaptchapub')) {
12189: pubitem = document.getElementById(context+'_recaptchapub');
12190: } else {
12191: return;
12192: }
12193: if (document.getElementById(context+'_recaptchapriv')) {
12194: privitem = document.getElementById(context+'_recaptchapriv');
12195: } else {
12196: return;
12197: }
12198: if (document.getElementById(context+'_recaptchapubtxt')) {
12199: pubtext = document.getElementById(context+'_recaptchapubtxt');
12200: } else {
12201: return;
12202: }
12203: if (document.getElementById(context+'_recaptchaprivtxt')) {
12204: privtext = document.getElementById(context+'_recaptchaprivtxt');
12205: } else {
12206: return;
12207: }
1.160.6.69! raeburn 12208: if (document.getElementById(context+'_recaptchaversion')) {
! 12209: versionitem = document.getElementById(context+'_recaptchaversion');
! 12210: } else {
! 12211: return;
! 12212: }
! 12213: if (document.getElementById(context+'_recaptchavertxt')) {
! 12214: versiontext = document.getElementById(context+'_recaptchavertxt');
! 12215: } else {
! 12216: return;
! 12217: }
1.160.6.5 raeburn 12218: if (caller.checked) {
12219: if (caller.value == 'recaptcha') {
12220: pubitem.type = 'text';
12221: privitem.type = 'text';
12222: pubitem.size = '40';
12223: privitem.size = '40';
12224: pubtext.innerHTML = "$lt{'pub'}";
12225: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69! raeburn 12226: versionitem.type = 'text';
! 12227: versionitem.size = '3';
! 12228: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 12229: } else {
12230: pubitem.type = 'hidden';
12231: privitem.type = 'hidden';
1.160.6.69! raeburn 12232: versionitem.type = 'hidden';
1.160.6.5 raeburn 12233: pubtext.innerHTML = '';
12234: privtext.innerHTML = '';
1.160.6.69! raeburn 12235: versiontext.innerHTML = '';
1.160.6.5 raeburn 12236: }
12237: }
12238: return;
12239: }
12240:
12241: // ]]>
12242: </script>
12243:
12244: END
12245:
12246: }
12247:
1.160.6.40 raeburn 12248: sub toggle_display_js {
1.160.6.16 raeburn 12249: return <<"END";
12250:
12251: <script type="text/javascript">
12252: // <![CDATA[
12253:
1.160.6.40 raeburn 12254: function toggleDisplay(domForm,caller) {
12255: if (document.getElementById(caller)) {
12256: var divitem = document.getElementById(caller);
12257: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12258: var checkval = 1;
12259: var dispval = 'block';
1.160.6.40 raeburn 12260: if (caller == 'emailoptions') {
12261: optionsElement = domForm.cancreate_email;
12262: }
1.160.6.57 raeburn 12263: if (caller == 'studentsubmission') {
12264: optionsElement = domForm.postsubmit;
12265: }
1.160.6.64 raeburn 12266: if (caller == 'cloneinstcode') {
12267: optionsElement = domForm.canclone;
12268: checkval = 'instcode';
12269: }
1.160.6.40 raeburn 12270: if (optionsElement.length) {
1.160.6.16 raeburn 12271: var currval;
1.160.6.40 raeburn 12272: for (var i=0; i<optionsElement.length; i++) {
12273: if (optionsElement[i].checked) {
12274: currval = optionsElement[i].value;
1.160.6.16 raeburn 12275: }
12276: }
1.160.6.64 raeburn 12277: if (currval == checkval) {
12278: divitem.style.display = dispval;
1.160.6.16 raeburn 12279: } else {
1.160.6.40 raeburn 12280: divitem.style.display = 'none';
1.160.6.16 raeburn 12281: }
12282: }
12283: }
12284: return;
12285: }
12286:
12287: // ]]>
12288: </script>
12289:
12290: END
12291:
12292: }
12293:
1.160.6.5 raeburn 12294: sub captcha_phrases {
12295: return &Apache::lonlocal::texthash (
12296: priv => 'Private key',
12297: pub => 'Public key',
12298: original => 'original (CAPTCHA)',
12299: recaptcha => 'successor (ReCAPTCHA)',
12300: notused => 'unused',
1.160.6.69! raeburn 12301: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 12302: );
12303: }
12304:
1.160.6.24 raeburn 12305: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12306: my ($dom,$cachekeys) = @_;
12307: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12308: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12309: my %thismachine;
12310: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12311: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12312: if (keys(%servers)) {
1.160.6.24 raeburn 12313: foreach my $server (keys(%servers)) {
12314: next if ($thismachine{$server});
1.160.6.27 raeburn 12315: my @cached;
12316: foreach my $name (@posscached) {
12317: if ($cachekeys->{$name}) {
12318: push(@cached,&escape($name).':'.&escape($dom));
12319: }
12320: }
12321: if (@cached) {
12322: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12323: }
1.160.6.24 raeburn 12324: }
12325: }
12326: return;
12327: }
12328:
1.3 raeburn 12329: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>