Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.49
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.49! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.48 2014/05/23 08:34:54 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',
253: col2 => 'Value'}],
1.160.6.37 raeburn 254: print => \&print_login,
255: modify => \&modify_login,
1.30 raeburn 256: },
1.43 raeburn 257: 'defaults' =>
1.160.6.40 raeburn 258: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 259: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 260: header => [{col1 => 'Setting',
1.160.6.40 raeburn 261: col2 => 'Value'},
262: {col1 => 'Institutional user types',
263: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 264: print => \&print_defaults,
265: modify => \&modify_defaults,
1.43 raeburn 266: },
1.30 raeburn 267: 'quotas' =>
1.160.6.20 raeburn 268: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 269: help => 'Domain_Configuration_Quotas',
1.77 raeburn 270: header => [{col1 => 'User affiliation',
1.72 raeburn 271: col2 => 'Available tools',
1.160.6.28 raeburn 272: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 273: print => \&print_quotas,
274: modify => \&modify_quotas,
1.30 raeburn 275: },
276: 'autoenroll' =>
277: { text => 'Auto-enrollment settings',
1.67 raeburn 278: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 279: header => [{col1 => 'Configuration setting',
280: col2 => 'Value(s)'}],
1.160.6.37 raeburn 281: print => \&print_autoenroll,
282: modify => \&modify_autoenroll,
1.30 raeburn 283: },
284: 'autoupdate' =>
285: { text => 'Auto-update settings',
1.67 raeburn 286: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',},
1.131 raeburn 289: {col1 => 'Setting',
290: col2 => 'Affiliation'},
1.43 raeburn 291: {col1 => 'User population',
1.160.6.35 raeburn 292: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 293: print => \&print_autoupdate,
294: modify => \&modify_autoupdate,
1.30 raeburn 295: },
1.125 raeburn 296: 'autocreate' =>
297: { text => 'Auto-course creation settings',
298: help => 'Domain_Configuration_Auto_Creation',
299: header => [{col1 => 'Configuration Setting',
300: col2 => 'Value',}],
1.160.6.37 raeburn 301: print => \&print_autocreate,
302: modify => \&modify_autocreate,
1.125 raeburn 303: },
1.30 raeburn 304: 'directorysrch' =>
305: { text => 'Institutional directory searches',
1.67 raeburn 306: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 307: header => [{col1 => 'Setting',
308: col2 => 'Value',}],
1.160.6.37 raeburn 309: print => \&print_directorysrch,
310: modify => \&modify_directorysrch,
1.30 raeburn 311: },
312: 'contacts' =>
313: { text => 'Contact Information',
1.67 raeburn 314: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 315: header => [{col1 => 'Setting',
316: col2 => 'Value',}],
1.160.6.37 raeburn 317: print => \&print_contacts,
318: modify => \&modify_contacts,
1.30 raeburn 319: },
320: 'usercreation' =>
321: { text => 'User creation',
1.67 raeburn 322: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 323: header => [{col1 => 'Format rule type',
324: col2 => 'Format rules in force'},
1.34 raeburn 325: {col1 => 'User account creation',
326: col2 => 'Usernames which may be created',},
1.30 raeburn 327: {col1 => 'Context',
1.43 raeburn 328: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 329: print => \&print_usercreation,
330: modify => \&modify_usercreation,
1.30 raeburn 331: },
1.160.6.34 raeburn 332: 'selfcreation' =>
333: { text => 'Users self-creating accounts',
334: help => 'Domain_Configuration_Self_Creation',
335: header => [{col1 => 'Self-creation with institutional username',
336: col2 => 'Enabled?'},
337: {col1 => 'Institutional user type (login/SSO self-creation)',
338: col2 => 'Information user can enter'},
339: {col1 => 'Self-creation with e-mail as username',
340: col2 => 'Settings'}],
1.160.6.37 raeburn 341: print => \&print_selfcreation,
342: modify => \&modify_selfcreation,
1.160.6.34 raeburn 343: },
1.69 raeburn 344: 'usermodification' =>
1.33 raeburn 345: { text => 'User modification',
1.67 raeburn 346: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 347: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 348: col2 => 'User information updatable in author context'},
1.33 raeburn 349: {col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 351: print => \&print_usermodification,
352: modify => \&modify_usermodification,
1.33 raeburn 353: },
1.69 raeburn 354: 'scantron' =>
1.95 www 355: { text => 'Bubblesheet format file',
1.67 raeburn 356: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 357: header => [ {col1 => 'Item',
358: col2 => '',
359: }],
1.160.6.37 raeburn 360: print => \&print_scantron,
361: modify => \&modify_scantron,
1.46 raeburn 362: },
1.86 raeburn 363: 'requestcourses' =>
364: {text => 'Request creation of courses',
365: help => 'Domain_Configuration_Request_Courses',
366: header => [{col1 => 'User affiliation',
1.102 raeburn 367: col2 => 'Availability/Processing of requests',},
368: {col1 => 'Setting',
1.160.6.30 raeburn 369: col2 => 'Value'},
370: {col1 => 'Available textbooks',
1.160.6.39 raeburn 371: col2 => ''},
1.160.6.46 raeburn 372: {col1 => 'Available templates',
373: col2 => ''},
1.160.6.39 raeburn 374: {col1 => 'Validation (not official courses)',
375: col2 => 'Value'},],
1.160.6.37 raeburn 376: print => \&print_quotas,
377: modify => \&modify_quotas,
1.86 raeburn 378: },
1.160.6.5 raeburn 379: 'requestauthor' =>
1.160.6.34 raeburn 380: {text => 'Request Authoring Space',
1.160.6.5 raeburn 381: help => 'Domain_Configuration_Request_Author',
382: header => [{col1 => 'User affiliation',
383: col2 => 'Availability/Processing of requests',},
384: {col1 => 'Setting',
385: col2 => 'Value'}],
1.160.6.37 raeburn 386: print => \&print_quotas,
387: modify => \&modify_quotas,
1.160.6.5 raeburn 388: },
1.69 raeburn 389: 'coursecategories' =>
1.120 raeburn 390: { text => 'Cataloging of courses/communities',
1.67 raeburn 391: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 392: header => [{col1 => 'Catalog type/availability',
393: col2 => '',},
394: {col1 => 'Category settings for standard catalog',
1.57 raeburn 395: col2 => '',},
396: {col1 => 'Categories',
397: col2 => '',
398: }],
1.160.6.37 raeburn 399: print => \&print_coursecategories,
400: modify => \&modify_coursecategories,
1.69 raeburn 401: },
402: 'serverstatuses' =>
1.77 raeburn 403: {text => 'Access to server status pages',
1.69 raeburn 404: help => 'Domain_Configuration_Server_Status',
405: header => [{col1 => 'Status Page',
406: col2 => 'Other named users',
407: col3 => 'Specific IPs',
408: }],
1.160.6.37 raeburn 409: print => \&print_serverstatuses,
410: modify => \&modify_serverstatuses,
1.69 raeburn 411: },
1.160.6.39 raeburn 412: 'coursedefaults' =>
1.160.6.16 raeburn 413: {text => 'Course/Community defaults',
414: help => 'Domain_Configuration_Course_Defaults',
1.160.6.49! raeburn 415: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 416: col2 => 'Value',},],
1.160.6.37 raeburn 417: print => \&print_coursedefaults,
418: modify => \&modify_coursedefaults,
419: },
1.160.6.39 raeburn 420: 'selfenrollment' =>
1.160.6.37 raeburn 421: {text => 'Self-enrollment in Course/Community',
422: help => 'Domain_Configuration_Selfenrollment',
423: header => [{col1 => 'Configuration Rights',
424: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
425: {col1 => 'Defaults',
426: col2 => 'Value'},
427: {col1 => 'Self-enrollment validation (optional)',
428: col2 => 'Value'},],
429: print => \&print_selfenrollment,
430: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 431: },
1.141 raeburn 432: 'usersessions' =>
1.145 raeburn 433: {text => 'User session hosting/offloading',
1.137 raeburn 434: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 435: header => [{col1 => 'Domain server',
436: col2 => 'Servers to offload sessions to when busy'},
437: {col1 => 'Hosting of users from other domains',
1.137 raeburn 438: col2 => 'Rules'},
439: {col1 => "Hosting domain's own users elsewhere",
440: col2 => 'Rules'}],
1.160.6.37 raeburn 441: print => \&print_usersessions,
442: modify => \&modify_usersessions,
1.137 raeburn 443: },
1.150 raeburn 444: 'loadbalancing' =>
1.160.6.7 raeburn 445: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 446: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 447: header => [{col1 => 'Balancers',
1.150 raeburn 448: col2 => 'Default destinations',
1.160.6.13 raeburn 449: col3 => 'User affiliation',
1.150 raeburn 450: col4 => 'Overrides'},
451: ],
1.160.6.37 raeburn 452: print => \&print_loadbalancing,
453: modify => \&modify_loadbalancing,
1.150 raeburn 454: },
1.3 raeburn 455: );
1.110 raeburn 456: if (keys(%servers) > 1) {
457: $prefs{'login'} = { text => 'Log-in page options',
458: help => 'Domain_Configuration_Login_Page',
459: header => [{col1 => 'Log-in Service',
460: col2 => 'Server Setting',},
461: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 462: col2 => ''},
463: {col1 => 'Log-in Help',
464: col2 => 'Value'}],
1.160.6.37 raeburn 465: print => \&print_login,
466: modify => \&modify_login,
1.110 raeburn 467: };
468: }
1.160.6.13 raeburn 469:
1.6 raeburn 470: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 471: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 472: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 473: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 474: text=>"Settings to display/modify"});
1.9 raeburn 475: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 476:
1.3 raeburn 477: if ($phase eq 'process') {
1.160.6.27 raeburn 478: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
479: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 480: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 481: $r->rflush();
1.160.6.27 raeburn 482: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 483: }
1.30 raeburn 484: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 485: my $js = &recaptcha_js().
1.160.6.40 raeburn 486: &toggle_display_js();
1.160.6.7 raeburn 487: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 488: my ($othertitle,$usertypes,$types) =
489: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 490: $js .= &lonbalance_targets_js($dom,$types,\%servers,
491: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 492: &new_spares_js().
493: &common_domprefs_js().
494: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 495: }
1.160.6.30 raeburn 496: if (grep(/^requestcourses$/,@actions)) {
497: my $javascript_validations;
498: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
499: $js .= <<END;
500: <script type="text/javascript">
501: $javascript_validations
502: </script>
503: $coursebrowserjs
504: END
505: }
1.150 raeburn 506: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 507: } else {
1.160.6.11 raeburn 508: # check if domconfig user exists for the domain.
509: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 510: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 511: &config_check($dom,$confname,$servadm);
512: unless ($configuserok eq 'ok') {
513: &Apache::lonconfigsettings::print_header($r,$phase,$context);
514: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
515: $confname).
516: '<br />'
517: );
518: if ($switchserver) {
519: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
520: '<br />'.
521: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
522: '<br />'.
523: &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).
524: '<br />'.
525: &mt('To do that now, use the following link: [_1]',$switchserver)
526: );
527: } else {
528: $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.').
529: '<br />'.
530: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
531: );
532: }
533: $r->print(&Apache::loncommon::end_page());
534: return OK;
535: }
1.21 raeburn 536: if (keys(%domconfig) == 0) {
537: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 538: my @ids=&Apache::lonnet::current_machine_ids();
539: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 540: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 541: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 542: my $custom_img_count = 0;
543: foreach my $img (@loginimages) {
544: if ($designhash{$dom.'.login.'.$img} ne '') {
545: $custom_img_count ++;
546: }
547: }
548: foreach my $role (@roles) {
549: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
550: $custom_img_count ++;
551: }
552: }
553: if ($custom_img_count > 0) {
1.94 raeburn 554: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 555: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 556: $r->print(
557: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
558: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
559: &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 />'.
560: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
561: if ($switch_server) {
1.30 raeburn 562: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 563: }
1.91 raeburn 564: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 565: return OK;
566: }
567: }
568: }
1.91 raeburn 569: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 570: }
571: return OK;
572: }
573:
574: sub process_changes {
1.160.6.24 raeburn 575: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 576: my %domconfig;
577: if (ref($values) eq 'HASH') {
578: %domconfig = %{$values};
579: }
1.3 raeburn 580: my $output;
581: if ($action eq 'login') {
1.160.6.24 raeburn 582: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 583: } elsif ($action eq 'rolecolors') {
1.9 raeburn 584: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 585: $lastactref,%domconfig);
1.3 raeburn 586: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 587: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 588: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 589: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 590: } elsif ($action eq 'autoupdate') {
591: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 592: } elsif ($action eq 'autocreate') {
593: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 594: } elsif ($action eq 'directorysrch') {
595: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 596: } elsif ($action eq 'usercreation') {
1.28 raeburn 597: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 598: } elsif ($action eq 'selfcreation') {
599: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 600: } elsif ($action eq 'usermodification') {
601: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 602: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 603: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 604: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 605: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 606: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 607: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 608: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 609: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 610: } elsif ($action eq 'serverstatuses') {
611: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 612: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 613: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 614: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 616: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 617: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 618: } elsif ($action eq 'selfenrollment') {
619: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 620: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 621: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 622: } elsif ($action eq 'loadbalancing') {
623: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 624: }
625: return $output;
626: }
627:
628: sub print_config_box {
1.9 raeburn 629: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 630: my $rowtotal = 0;
1.49 raeburn 631: my $output;
632: if ($action eq 'coursecategories') {
633: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 634: } elsif ($action eq 'defaults') {
635: $output = &defaults_javascript($settings);
1.91 raeburn 636: }
1.160.6.40 raeburn 637: $output .=
1.30 raeburn 638: '<table class="LC_nested_outer">
1.3 raeburn 639: <tr>
1.66 raeburn 640: <th align="left" valign="middle"><span class="LC_nobreak">'.
641: &mt($item->{text}).' '.
642: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
643: '</tr>';
1.30 raeburn 644: $rowtotal ++;
1.110 raeburn 645: my $numheaders = 1;
646: if (ref($item->{'header'}) eq 'ARRAY') {
647: $numheaders = scalar(@{$item->{'header'}});
648: }
649: if ($numheaders > 1) {
1.64 raeburn 650: my $colspan = '';
1.145 raeburn 651: my $rightcolspan = '';
1.160.6.42 raeburn 652: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.5 raeburn 653: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 654: $colspan = ' colspan="2"';
655: }
1.145 raeburn 656: if ($action eq 'usersessions') {
657: $rightcolspan = ' colspan="3"';
658: }
1.30 raeburn 659: $output .= '
1.3 raeburn 660: <tr>
661: <td>
662: <table class="LC_nested">
663: <tr class="LC_info_row">
1.59 bisitz 664: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 665: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 666: </tr>';
1.69 raeburn 667: $rowtotal ++;
1.160.6.37 raeburn 668: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.40 raeburn 669: ($action eq 'usermodification') || ($action eq 'defaults') ||
670: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 671: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 672: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 673: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 674: } elsif ($action eq 'login') {
1.160.6.5 raeburn 675: if ($numheaders == 3) {
676: $colspan = ' colspan="2"';
677: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
678: } else {
679: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
680: }
1.160.6.37 raeburn 681: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 682: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 683: } elsif ($action eq 'rolecolors') {
1.30 raeburn 684: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 685: }
1.30 raeburn 686: $output .= '
1.6 raeburn 687: </table>
688: </td>
689: </tr>
690: <tr>
691: <td>
692: <table class="LC_nested">
693: <tr class="LC_info_row">
1.160.6.37 raeburn 694: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 695: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 696: </tr>';
697: $rowtotal ++;
1.160.6.37 raeburn 698: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
699: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 700: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
701: if ($action eq 'coursecategories') {
702: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
703: $colspan = ' colspan="2"';
704: } else {
705: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
706: }
707: $output .= '
1.63 raeburn 708: </table>
709: </td>
710: </tr>
711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
715: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 716: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 717: </tr>'."\n";
718: if ($action eq 'coursecategories') {
719: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
720: } else {
721: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
722: }
1.63 raeburn 723: $rowtotal ++;
1.160.6.49! raeburn 724: } elsif (($action eq 'usermodification') || ($action eq 'defaults')) {
1.160.6.37 raeburn 725: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 726: } elsif ($action eq 'login') {
1.160.6.5 raeburn 727: if ($numheaders == 3) {
728: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
729: </table>
730: </td>
731: </tr>
732: <tr>
733: <td>
734: <table class="LC_nested">
735: <tr class="LC_info_row">
736: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 737: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 738: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
739: $rowtotal ++;
740: } else {
741: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
742: }
1.102 raeburn 743: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 744: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
745: &print_studentcode($settings,\$rowtotal).'
746: </table>
747: </td>
748: </tr>
749: <tr>
750: <td>
751: <table class="LC_nested">
752: <tr class="LC_info_row">
753: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
754: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 755: &textbookcourses_javascript($settings).
756: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
757: </table>
758: </td>
759: </tr>
760: <tr>
761: <td>
762: <table class="LC_nested">
763: <tr class="LC_info_row">
764: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
765: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
766: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 767: </table>
768: </td>
769: </tr>
770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
1.160.6.46 raeburn 774: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
775: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 776: </tr>'.
777: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 778: } elsif ($action eq 'requestauthor') {
779: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 780: } elsif ($action eq 'rolecolors') {
1.30 raeburn 781: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 782: </table>
783: </td>
784: </tr>
785: <tr>
786: <td>
787: <table class="LC_nested">
788: <tr class="LC_info_row">
1.69 raeburn 789: <td class="LC_left_item"'.$colspan.' valign="top">'.
790: &mt($item->{'header'}->[2]->{'col1'}).'</td>
791: <td class="LC_right_item" valign="top">'.
792: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 793: </tr>'.
1.30 raeburn 794: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 795: </table>
796: </td>
797: </tr>
798: <tr>
799: <td>
800: <table class="LC_nested">
801: <tr class="LC_info_row">
1.59 bisitz 802: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
803: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 804: </tr>'.
1.30 raeburn 805: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
806: $rowtotal += 2;
1.6 raeburn 807: }
1.3 raeburn 808: } else {
1.30 raeburn 809: $output .= '
1.3 raeburn 810: <tr>
811: <td>
812: <table class="LC_nested">
1.30 raeburn 813: <tr class="LC_info_row">';
1.24 raeburn 814: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 815: $output .= '
1.59 bisitz 816: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 817: } elsif ($action eq 'serverstatuses') {
818: $output .= '
819: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
820: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
821:
1.6 raeburn 822: } else {
1.30 raeburn 823: $output .= '
1.69 raeburn 824: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
825: }
1.72 raeburn 826: if (defined($item->{'header'}->[0]->{'col3'})) {
827: $output .= '<td class="LC_left_item" valign="top">'.
828: &mt($item->{'header'}->[0]->{'col2'});
829: if ($action eq 'serverstatuses') {
830: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
831: }
1.69 raeburn 832: } else {
833: $output .= '<td class="LC_right_item" valign="top">'.
834: &mt($item->{'header'}->[0]->{'col2'});
835: }
836: $output .= '</td>';
837: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 838: if (defined($item->{'header'}->[0]->{'col4'})) {
839: $output .= '<td class="LC_left_item" valign="top">'.
840: &mt($item->{'header'}->[0]->{'col3'});
841: } else {
842: $output .= '<td class="LC_right_item" valign="top">'.
843: &mt($item->{'header'}->[0]->{'col3'});
844: }
1.69 raeburn 845: if ($action eq 'serverstatuses') {
846: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
847: }
848: $output .= '</td>';
1.6 raeburn 849: }
1.150 raeburn 850: if ($item->{'header'}->[0]->{'col4'}) {
851: $output .= '<td class="LC_right_item" valign="top">'.
852: &mt($item->{'header'}->[0]->{'col4'});
853: }
1.69 raeburn 854: $output .= '</tr>';
1.48 raeburn 855: $rowtotal ++;
1.160.6.5 raeburn 856: if ($action eq 'quotas') {
1.86 raeburn 857: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 858: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 859: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 860: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 861: } elsif ($action eq 'scantron') {
862: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 863: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 864: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.160.6.49! raeburn 865: } elsif ($action eq 'coursedefaults') {
! 866: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 867: }
1.3 raeburn 868: }
1.30 raeburn 869: $output .= '
1.3 raeburn 870: </table>
871: </td>
872: </tr>
1.30 raeburn 873: </table><br />';
874: return ($output,$rowtotal);
1.1 raeburn 875: }
876:
1.3 raeburn 877: sub print_login {
1.160.6.5 raeburn 878: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 879: my ($css_class,$datatable);
1.6 raeburn 880: my %choices = &login_choices();
1.110 raeburn 881:
1.160.6.5 raeburn 882: if ($caller eq 'service') {
1.149 raeburn 883: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 884: my $choice = $choices{'disallowlogin'};
885: $css_class = ' class="LC_odd_row"';
1.128 raeburn 886: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 887: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 888: '<th>'.$choices{'server'}.'</th>'.
889: '<th>'.$choices{'serverpath'}.'</th>'.
890: '<th>'.$choices{'custompath'}.'</th>'.
891: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 892: my %disallowed;
893: if (ref($settings) eq 'HASH') {
894: if (ref($settings->{'loginvia'}) eq 'HASH') {
895: %disallowed = %{$settings->{'loginvia'}};
896: }
897: }
898: foreach my $lonhost (sort(keys(%servers))) {
899: my $direct = 'selected="selected"';
1.128 raeburn 900: if (ref($disallowed{$lonhost}) eq 'HASH') {
901: if ($disallowed{$lonhost}{'server'} ne '') {
902: $direct = '';
903: }
1.110 raeburn 904: }
1.115 raeburn 905: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 906: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 907: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
908: '</option>';
1.160.6.13 raeburn 909: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 910: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 911: my $selected = '';
1.128 raeburn 912: if (ref($disallowed{$lonhost}) eq 'HASH') {
913: if ($hostid eq $disallowed{$lonhost}{'server'}) {
914: $selected = 'selected="selected"';
915: }
1.110 raeburn 916: }
917: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
918: $servers{$hostid}.'</option>';
919: }
1.128 raeburn 920: $datatable .= '</select></td>'.
921: '<td><select name="'.$lonhost.'_serverpath">';
922: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
923: my $pathname = $path;
924: if ($path eq 'custom') {
925: $pathname = &mt('Custom Path').' ->';
926: }
927: my $selected = '';
928: if (ref($disallowed{$lonhost}) eq 'HASH') {
929: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
930: $selected = 'selected="selected"';
931: }
932: } elsif ($path eq '') {
933: $selected = 'selected="selected"';
934: }
935: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
936: }
937: $datatable .= '</select></td>';
938: my ($custom,$exempt);
939: if (ref($disallowed{$lonhost}) eq 'HASH') {
940: $custom = $disallowed{$lonhost}{'custompath'};
941: $exempt = $disallowed{$lonhost}{'exempt'};
942: }
943: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
944: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
945: '</tr>';
1.110 raeburn 946: }
947: $datatable .= '</table></td></tr>';
948: return $datatable;
1.160.6.5 raeburn 949: } elsif ($caller eq 'page') {
950: my %defaultchecked = (
951: 'coursecatalog' => 'on',
1.160.6.14 raeburn 952: 'helpdesk' => 'on',
1.160.6.5 raeburn 953: 'adminmail' => 'off',
954: 'newuser' => 'off',
955: );
1.160.6.14 raeburn 956: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 957: my (%checkedon,%checkedoff);
1.42 raeburn 958: foreach my $item (@toggles) {
1.160.6.5 raeburn 959: if ($defaultchecked{$item} eq 'on') {
960: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 961: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 962: } elsif ($defaultchecked{$item} eq 'off') {
963: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 964: $checkedon{$item} = ' ';
965: }
1.1 raeburn 966: }
1.160.6.5 raeburn 967: my @images = ('img','logo','domlogo','login');
968: my @logintext = ('textcol','bgcol');
969: my @bgs = ('pgbg','mainbg','sidebg');
970: my @links = ('link','alink','vlink');
971: my %designhash = &Apache::loncommon::get_domainconf($dom);
972: my %defaultdesign = %Apache::loncommon::defaultdesign;
973: my (%is_custom,%designs);
974: my %defaults = (
975: font => $defaultdesign{'login.font'},
976: );
1.6 raeburn 977: foreach my $item (@images) {
1.160.6.5 raeburn 978: $defaults{$item} = $defaultdesign{'login.'.$item};
979: $defaults{'showlogo'}{$item} = 1;
980: }
981: foreach my $item (@bgs) {
982: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 983: }
1.41 raeburn 984: foreach my $item (@logintext) {
1.160.6.5 raeburn 985: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 986: }
1.160.6.5 raeburn 987: foreach my $item (@links) {
988: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 989: }
1.160.6.5 raeburn 990: if (ref($settings) eq 'HASH') {
991: foreach my $item (@toggles) {
992: if ($settings->{$item} eq '1') {
993: $checkedon{$item} = ' checked="checked" ';
994: $checkedoff{$item} = ' ';
995: } elsif ($settings->{$item} eq '0') {
996: $checkedoff{$item} = ' checked="checked" ';
997: $checkedon{$item} = ' ';
998: }
1.6 raeburn 999: }
1.160.6.5 raeburn 1000: foreach my $item (@images) {
1001: if (defined($settings->{$item})) {
1002: $designs{$item} = $settings->{$item};
1003: $is_custom{$item} = 1;
1004: }
1005: if (defined($settings->{'showlogo'}{$item})) {
1006: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1007: }
1008: }
1009: foreach my $item (@logintext) {
1010: if ($settings->{$item} ne '') {
1011: $designs{'logintext'}{$item} = $settings->{$item};
1012: $is_custom{$item} = 1;
1013: }
1014: }
1015: if ($settings->{'font'} ne '') {
1016: $designs{'font'} = $settings->{'font'};
1017: $is_custom{'font'} = 1;
1018: }
1019: foreach my $item (@bgs) {
1020: if ($settings->{$item} ne '') {
1021: $designs{'bgs'}{$item} = $settings->{$item};
1022: $is_custom{$item} = 1;
1023: }
1024: }
1025: foreach my $item (@links) {
1026: if ($settings->{$item} ne '') {
1027: $designs{'links'}{$item} = $settings->{$item};
1028: $is_custom{$item} = 1;
1029: }
1030: }
1031: } else {
1032: if ($designhash{$dom.'.login.font'} ne '') {
1033: $designs{'font'} = $designhash{$dom.'.login.font'};
1034: $is_custom{'font'} = 1;
1035: }
1036: foreach my $item (@images) {
1037: if ($designhash{$dom.'.login.'.$item} ne '') {
1038: $designs{$item} = $designhash{$dom.'.login.'.$item};
1039: $is_custom{$item} = 1;
1040: }
1041: }
1042: foreach my $item (@bgs) {
1043: if ($designhash{$dom.'.login.'.$item} ne '') {
1044: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1045: $is_custom{$item} = 1;
1046: }
1047: }
1048: foreach my $item (@links) {
1049: if ($designhash{$dom.'.login.'.$item} ne '') {
1050: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1051: $is_custom{$item} = 1;
1052: }
1.6 raeburn 1053: }
1054: }
1.160.6.5 raeburn 1055: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1056: logo => 'Institution Logo',
1057: domlogo => 'Domain Logo',
1058: login => 'Login box');
1059: my $itemcount = 1;
1060: foreach my $item (@toggles) {
1061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1062: $datatable .=
1063: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1064: '</td><td>'.
1065: '<span class="LC_nobreak"><label><input type="radio" name="'.
1066: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1067: '</label> <label><input type="radio" name="'.$item.'"'.
1068: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1069: '</tr>';
1070: $itemcount ++;
1.6 raeburn 1071: }
1.160.6.5 raeburn 1072: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1073: $datatable .= '</tr></table></td></tr>';
1074: } elsif ($caller eq 'help') {
1075: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1076: my $switchserver = &check_switchserver($dom,$confname);
1077: my $itemcount = 1;
1078: $defaulturl = '/adm/loginproblems.html';
1079: $defaulttype = 'default';
1080: %lt = &Apache::lonlocal::texthash (
1081: del => 'Delete?',
1082: rep => 'Replace:',
1083: upl => 'Upload:',
1084: default => 'Default',
1085: custom => 'Custom',
1086: );
1087: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1088: my @currlangs;
1089: if (ref($settings) eq 'HASH') {
1090: if (ref($settings->{'helpurl'}) eq 'HASH') {
1091: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1092: next if ($settings->{'helpurl'}{$key} eq '');
1093: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1094: $type{$key} = 'custom';
1095: unless ($key eq 'nolang') {
1096: push(@currlangs,$key);
1097: }
1098: }
1099: } elsif ($settings->{'helpurl'} ne '') {
1100: $type{'nolang'} = 'custom';
1101: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1102: }
1103: }
1.160.6.5 raeburn 1104: foreach my $lang ('nolang',sort(@currlangs)) {
1105: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1106: $datatable .= '<tr'.$css_class.'>';
1107: if ($url{$lang} eq '') {
1108: $url{$lang} = $defaulturl;
1109: }
1110: if ($type{$lang} eq '') {
1111: $type{$lang} = $defaulttype;
1112: }
1113: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1114: if ($lang eq 'nolang') {
1115: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1116: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1117: } else {
1118: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1119: $langchoices{$lang},
1120: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1121: }
1122: $datatable .= '</span></td>'."\n".
1123: '<td class="LC_left_item">';
1124: if ($type{$lang} eq 'custom') {
1125: $datatable .= '<span class="LC_nobreak"><label>'.
1126: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1127: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1128: } else {
1129: $datatable .= $lt{'upl'};
1130: }
1131: $datatable .='<br />';
1132: if ($switchserver) {
1133: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1134: } else {
1135: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1136: }
1.160.6.5 raeburn 1137: $datatable .= '</td></tr>';
1138: $itemcount ++;
1.6 raeburn 1139: }
1.160.6.5 raeburn 1140: my @addlangs;
1141: foreach my $lang (sort(keys(%langchoices))) {
1142: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1143: push(@addlangs,$lang);
1144: }
1145: if (@addlangs > 0) {
1146: my %toadd;
1147: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1148: $toadd{''} = &mt('Select');
1149: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1150: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1151: &mt('Add log-in help page for a specific language:').' '.
1152: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1153: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1154: if ($switchserver) {
1155: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1156: } else {
1157: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1158: }
1.160.6.5 raeburn 1159: $datatable .= '</td></tr>';
1160: $itemcount ++;
1.6 raeburn 1161: }
1.160.6.5 raeburn 1162: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1163: }
1.6 raeburn 1164: return $datatable;
1165: }
1166:
1167: sub login_choices {
1168: my %choices =
1169: &Apache::lonlocal::texthash (
1.116 bisitz 1170: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1171: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1172: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1173: disallowlogin => "Login page requests redirected",
1174: hostid => "Server",
1.128 raeburn 1175: server => "Redirect to:",
1176: serverpath => "Path",
1177: custompath => "Custom",
1178: exempt => "Exempt IP(s)",
1.110 raeburn 1179: directlogin => "No redirect",
1180: newuser => "Link to create a user account",
1181: img => "Header",
1182: logo => "Main Logo",
1183: domlogo => "Domain Logo",
1184: login => "Log-in Header",
1185: textcol => "Text color",
1186: bgcol => "Box color",
1187: bgs => "Background colors",
1188: links => "Link colors",
1189: font => "Font color",
1190: pgbg => "Header",
1191: mainbg => "Page",
1192: sidebg => "Login box",
1193: link => "Link",
1194: alink => "Active link",
1195: vlink => "Visited link",
1.6 raeburn 1196: );
1197: return %choices;
1198: }
1199:
1200: sub print_rolecolors {
1.30 raeburn 1201: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1202: my %choices = &color_font_choices();
1203: my @bgs = ('pgbg','tabbg','sidebg');
1204: my @links = ('link','alink','vlink');
1205: my @images = ('img');
1206: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1207: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1208: my %defaultdesign = %Apache::loncommon::defaultdesign;
1209: my (%is_custom,%designs);
1.160.6.22 raeburn 1210: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1211: if (ref($settings) eq 'HASH') {
1212: if (ref($settings->{$role}) eq 'HASH') {
1213: if ($settings->{$role}->{'img'} ne '') {
1214: $designs{'img'} = $settings->{$role}->{'img'};
1215: $is_custom{'img'} = 1;
1216: }
1217: if ($settings->{$role}->{'font'} ne '') {
1218: $designs{'font'} = $settings->{$role}->{'font'};
1219: $is_custom{'font'} = 1;
1220: }
1.97 tempelho 1221: if ($settings->{$role}->{'fontmenu'} ne '') {
1222: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1223: $is_custom{'fontmenu'} = 1;
1224: }
1.6 raeburn 1225: foreach my $item (@bgs) {
1226: if ($settings->{$role}->{$item} ne '') {
1227: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1228: $is_custom{$item} = 1;
1229: }
1230: }
1231: foreach my $item (@links) {
1232: if ($settings->{$role}->{$item} ne '') {
1233: $designs{'links'}{$item} = $settings->{$role}->{$item};
1234: $is_custom{$item} = 1;
1235: }
1236: }
1237: }
1238: } else {
1239: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1240: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1241: $is_custom{'img'} = 1;
1242: }
1.97 tempelho 1243: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1244: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1245: $is_custom{'fontmenu'} = 1;
1246: }
1.6 raeburn 1247: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1248: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1249: $is_custom{'font'} = 1;
1250: }
1251: foreach my $item (@bgs) {
1252: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1253: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1254: $is_custom{$item} = 1;
1255:
1256: }
1257: }
1258: foreach my $item (@links) {
1259: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1260: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1261: $is_custom{$item} = 1;
1262: }
1263: }
1264: }
1265: my $itemcount = 1;
1.30 raeburn 1266: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1267: $datatable .= '</tr></table></td></tr>';
1268: return $datatable;
1269: }
1270:
1.160.6.22 raeburn 1271: sub role_defaults {
1272: my ($role,$bgs,$links,$images,$logintext) = @_;
1273: my %defaults;
1274: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1275: return %defaults;
1276: }
1277: my %defaultdesign = %Apache::loncommon::defaultdesign;
1278: if ($role eq 'login') {
1279: %defaults = (
1280: font => $defaultdesign{$role.'.font'},
1281: );
1282: if (ref($logintext) eq 'ARRAY') {
1283: foreach my $item (@{$logintext}) {
1284: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1285: }
1286: }
1287: foreach my $item (@{$images}) {
1288: $defaults{'showlogo'}{$item} = 1;
1289: }
1290: } else {
1291: %defaults = (
1292: img => $defaultdesign{$role.'.img'},
1293: font => $defaultdesign{$role.'.font'},
1294: fontmenu => $defaultdesign{$role.'.fontmenu'},
1295: );
1296: }
1297: foreach my $item (@{$bgs}) {
1298: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1299: }
1300: foreach my $item (@{$links}) {
1301: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1302: }
1303: foreach my $item (@{$images}) {
1304: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1305: }
1306: return %defaults;
1307: }
1308:
1.6 raeburn 1309: sub display_color_options {
1.9 raeburn 1310: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1311: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1312: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1313: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1314: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1315: '<td>'.$choices->{'font'}.'</td>';
1316: if (!$is_custom->{'font'}) {
1.30 raeburn 1317: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1318: } else {
1319: $datatable .= '<td> </td>';
1320: }
1.160.6.9 raeburn 1321: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1322:
1.8 raeburn 1323: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1324: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1325: ' value="'.$current_color.'" /> '.
1326: ' </td></tr>';
1.107 raeburn 1327: unless ($role eq 'login') {
1328: $datatable .= '<tr'.$css_class.'>'.
1329: '<td>'.$choices->{'fontmenu'}.'</td>';
1330: if (!$is_custom->{'fontmenu'}) {
1331: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1332: } else {
1333: $datatable .= '<td> </td>';
1334: }
1.160.6.22 raeburn 1335: $current_color = $designs->{'fontmenu'} ?
1336: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1337: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1338: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1339: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1340: ' value="'.$current_color.'" /> '.
1341: ' </td></tr>';
1.97 tempelho 1342: }
1.9 raeburn 1343: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1344: foreach my $img (@{$images}) {
1.18 albertel 1345: $itemcount ++;
1.6 raeburn 1346: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1347: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1348: '<td>'.$choices->{$img};
1.41 raeburn 1349: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1350: if ($role eq 'login') {
1351: if ($img eq 'login') {
1352: $login_hdr_pick =
1.135 bisitz 1353: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1354: $logincolors =
1355: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1356: $designs,$defaults);
1.70 raeburn 1357: } elsif ($img ne 'domlogo') {
1358: $datatable.= &logo_display_options($img,$defaults,$designs);
1359: }
1360: }
1361: $datatable .= '</td>';
1.6 raeburn 1362: if ($designs->{$img} ne '') {
1363: $imgfile = $designs->{$img};
1.18 albertel 1364: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1365: } else {
1366: $imgfile = $defaults->{$img};
1367: }
1368: if ($imgfile) {
1.9 raeburn 1369: my ($showfile,$fullsize);
1370: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1371: my $urldir = $1;
1372: my $filename = $2;
1373: my @info = &Apache::lonnet::stat_file($designs->{$img});
1374: if (@info) {
1375: my $thumbfile = 'tn-'.$filename;
1376: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1377: if (@thumb) {
1378: $showfile = $urldir.'/'.$thumbfile;
1379: } else {
1380: $showfile = $imgfile;
1381: }
1382: } else {
1383: $showfile = '';
1384: }
1385: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1386: $showfile = $imgfile;
1.6 raeburn 1387: my $imgdir = $1;
1388: my $filename = $2;
1.159 raeburn 1389: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1390: $showfile = "/$imgdir/tn-".$filename;
1391: } else {
1.159 raeburn 1392: my $input = $londocroot.$imgfile;
1393: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1394: if (!-e $output) {
1.9 raeburn 1395: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1396: my ($fullwidth,$fullheight) = &check_dimensions($input);
1397: if ($fullwidth ne '' && $fullheight ne '') {
1398: if ($fullwidth > $width && $fullheight > $height) {
1399: my $size = $width.'x'.$height;
1400: system("convert -sample $size $input $output");
1.159 raeburn 1401: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1402: }
1403: }
1.6 raeburn 1404: }
1405: }
1.16 raeburn 1406: }
1.6 raeburn 1407: if ($showfile) {
1.40 raeburn 1408: if ($showfile =~ m{^/(adm|res)/}) {
1409: if ($showfile =~ m{^/res/}) {
1410: my $local_showfile =
1411: &Apache::lonnet::filelocation('',$showfile);
1412: &Apache::lonnet::repcopy($local_showfile);
1413: }
1414: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1415: }
1416: if ($imgfile) {
1417: if ($imgfile =~ m{^/(adm|res)/}) {
1418: if ($imgfile =~ m{^/res/}) {
1419: my $local_imgfile =
1420: &Apache::lonnet::filelocation('',$imgfile);
1421: &Apache::lonnet::repcopy($local_imgfile);
1422: }
1423: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1424: } else {
1425: $fullsize = $imgfile;
1426: }
1427: }
1.41 raeburn 1428: $datatable .= '<td>';
1429: if ($img eq 'login') {
1.135 bisitz 1430: $datatable .= $login_hdr_pick;
1431: }
1.41 raeburn 1432: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1433: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1434: } else {
1.160.6.22 raeburn 1435: $datatable .= '<td> </td><td class="LC_left_item">'.
1436: &mt('Upload:').'<br />';
1.6 raeburn 1437: }
1438: } else {
1.160.6.22 raeburn 1439: $datatable .= '<td> </td><td class="LC_left_item">'.
1440: &mt('Upload:').'<br />';
1.6 raeburn 1441: }
1.9 raeburn 1442: if ($switchserver) {
1443: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1444: } else {
1.135 bisitz 1445: if ($img ne 'login') { # suppress file selection for Log-in header
1446: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1447: }
1.9 raeburn 1448: }
1449: $datatable .= '</td></tr>';
1.6 raeburn 1450: }
1451: $itemcount ++;
1452: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1453: $datatable .= '<tr'.$css_class.'>'.
1454: '<td>'.$choices->{'bgs'}.'</td>';
1455: my $bgs_def;
1456: foreach my $item (@{$bgs}) {
1457: if (!$is_custom->{$item}) {
1.70 raeburn 1458: $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 1459: }
1460: }
1461: if ($bgs_def) {
1.8 raeburn 1462: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1463: } else {
1464: $datatable .= '<td> </td>';
1465: }
1466: $datatable .= '<td class="LC_right_item">'.
1467: '<table border="0"><tr>';
1.160.6.13 raeburn 1468:
1.6 raeburn 1469: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1470: $datatable .= '<td align="center">'.$choices->{$item};
1471: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1472: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1473: $datatable .= ' ';
1.6 raeburn 1474: }
1.160.6.9 raeburn 1475: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1476: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1477: }
1478: $datatable .= '</tr></table></td></tr>';
1479: $itemcount ++;
1480: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1481: $datatable .= '<tr'.$css_class.'>'.
1482: '<td>'.$choices->{'links'}.'</td>';
1483: my $links_def;
1484: foreach my $item (@{$links}) {
1485: if (!$is_custom->{$item}) {
1.30 raeburn 1486: $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 1487: }
1488: }
1489: if ($links_def) {
1.8 raeburn 1490: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1491: } else {
1492: $datatable .= '<td> </td>';
1493: }
1494: $datatable .= '<td class="LC_right_item">'.
1495: '<table border="0"><tr>';
1496: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1497: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1498: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1499: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1500: $datatable.=' ';
1.6 raeburn 1501: }
1.160.6.9 raeburn 1502: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1503: '" /></td>';
1504: }
1.30 raeburn 1505: $$rowtotal += $itemcount;
1.3 raeburn 1506: return $datatable;
1507: }
1508:
1.70 raeburn 1509: sub logo_display_options {
1510: my ($img,$defaults,$designs) = @_;
1511: my $checkedon;
1512: if (ref($defaults) eq 'HASH') {
1513: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1514: if ($defaults->{'showlogo'}{$img}) {
1515: $checkedon = 'checked="checked" ';
1516: }
1517: }
1518: }
1519: if (ref($designs) eq 'HASH') {
1520: if (ref($designs->{'showlogo'}) eq 'HASH') {
1521: if (defined($designs->{'showlogo'}{$img})) {
1522: if ($designs->{'showlogo'}{$img} == 0) {
1523: $checkedon = '';
1524: } elsif ($designs->{'showlogo'}{$img} == 1) {
1525: $checkedon = 'checked="checked" ';
1526: }
1527: }
1528: }
1529: }
1530: return '<br /><label> <input type="checkbox" name="'.
1531: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1532: &mt('show').'</label>'."\n";
1533: }
1534:
1.41 raeburn 1535: sub login_header_options {
1.135 bisitz 1536: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1537: my $output = '';
1.41 raeburn 1538: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1539: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1540: if (!$is_custom->{'textcol'}) {
1541: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1542: ' ';
1543: }
1544: if (!$is_custom->{'bgcol'}) {
1545: $output .= $choices->{'bgcol'}.': '.
1546: '<span id="css_'.$role.'_font" style="background-color: '.
1547: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1548: }
1549: $output .= '<br />';
1550: }
1551: $output .='<br />';
1552: return $output;
1553: }
1554:
1555: sub login_text_colors {
1.160.6.22 raeburn 1556: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1557: my $color_menu = '<table border="0"><tr>';
1558: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1559: $color_menu .= '<td align="center">'.$choices->{$item};
1560: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1561: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1562: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1563: }
1564: $color_menu .= '</tr></table><br />';
1565: return $color_menu;
1566: }
1567:
1568: sub image_changes {
1569: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1570: my $output;
1.135 bisitz 1571: if ($img eq 'login') {
1572: # suppress image for Log-in header
1573: } elsif (!$is_custom) {
1.70 raeburn 1574: if ($img ne 'domlogo') {
1.41 raeburn 1575: $output .= &mt('Default image:').'<br />';
1576: } else {
1577: $output .= &mt('Default in use:').'<br />';
1578: }
1579: }
1.135 bisitz 1580: if ($img eq 'login') { # suppress image for Log-in header
1581: $output .= '<td>'.$logincolors;
1.41 raeburn 1582: } else {
1.135 bisitz 1583: if ($img_import) {
1584: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1585: }
1586: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1587: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1588: if ($is_custom) {
1589: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1590: '<input type="checkbox" name="'.
1591: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1592: '</label> '.&mt('Replace:').'</span><br />';
1593: } else {
1.160.6.22 raeburn 1594: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1595: }
1.41 raeburn 1596: }
1597: return $output;
1598: }
1599:
1.3 raeburn 1600: sub print_quotas {
1.86 raeburn 1601: my ($dom,$settings,$rowtotal,$action) = @_;
1602: my $context;
1603: if ($action eq 'quotas') {
1604: $context = 'tools';
1605: } else {
1606: $context = $action;
1607: }
1.160.6.20 raeburn 1608: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1609: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1610: my $typecount = 0;
1.101 raeburn 1611: my ($css_class,%titles);
1.86 raeburn 1612: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1613: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1614: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1615: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1616: %titles = &courserequest_titles();
1.160.6.5 raeburn 1617: } elsif ($context eq 'requestauthor') {
1618: @usertools = ('author');
1619: @options = ('norequest','approval','automatic');
1620: %titles = &authorrequest_titles();
1.86 raeburn 1621: } else {
1.160.6.4 raeburn 1622: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1623: %titles = &tool_titles();
1.86 raeburn 1624: }
1.26 raeburn 1625: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1626: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1627: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1628: unless (($context eq 'requestcourses') ||
1629: ($context eq 'requestauthor')) {
1.86 raeburn 1630: if (ref($settings) eq 'HASH') {
1631: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1632: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1633: } else {
1634: $currdefquota = $settings->{$type};
1635: }
1.160.6.20 raeburn 1636: if (ref($settings->{authorquota}) eq 'HASH') {
1637: $currauthorquota = $settings->{authorquota}->{$type};
1638: }
1.78 raeburn 1639: }
1.72 raeburn 1640: }
1.3 raeburn 1641: if (defined($usertypes->{$type})) {
1642: $typecount ++;
1643: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1644: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1645: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1646: '<td class="LC_left_item">';
1.101 raeburn 1647: if ($context eq 'requestcourses') {
1648: $datatable .= '<table><tr>';
1649: }
1650: my %cell;
1.72 raeburn 1651: foreach my $item (@usertools) {
1.101 raeburn 1652: if ($context eq 'requestcourses') {
1653: my ($curroption,$currlimit);
1654: if (ref($settings) eq 'HASH') {
1655: if (ref($settings->{$item}) eq 'HASH') {
1656: $curroption = $settings->{$item}->{$type};
1657: if ($curroption =~ /^autolimit=(\d*)$/) {
1658: $currlimit = $1;
1659: }
1660: }
1661: }
1662: if (!$curroption) {
1663: $curroption = 'norequest';
1664: }
1665: $datatable .= '<th>'.$titles{$item}.'</th>';
1666: foreach my $option (@options) {
1667: my $val = $option;
1668: if ($option eq 'norequest') {
1669: $val = 0;
1670: }
1671: if ($option eq 'validate') {
1672: my $canvalidate = 0;
1673: if (ref($validations{$item}) eq 'HASH') {
1674: if ($validations{$item}{$type}) {
1675: $canvalidate = 1;
1676: }
1677: }
1678: next if (!$canvalidate);
1679: }
1680: my $checked = '';
1681: if ($option eq $curroption) {
1682: $checked = ' checked="checked"';
1683: } elsif ($option eq 'autolimit') {
1684: if ($curroption =~ /^autolimit/) {
1685: $checked = ' checked="checked"';
1686: }
1687: }
1688: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1689: '<input type="radio" name="crsreq_'.$item.
1690: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1691: $titles{$option}.'</label>';
1.101 raeburn 1692: if ($option eq 'autolimit') {
1.127 raeburn 1693: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1694: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1695: 'value="'.$currlimit.'" />';
1.101 raeburn 1696: }
1.127 raeburn 1697: $cell{$item} .= '</span> ';
1.103 raeburn 1698: if ($option eq 'autolimit') {
1.127 raeburn 1699: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1700: }
1.101 raeburn 1701: }
1.160.6.5 raeburn 1702: } elsif ($context eq 'requestauthor') {
1703: my $curroption;
1704: if (ref($settings) eq 'HASH') {
1705: $curroption = $settings->{$type};
1706: }
1707: if (!$curroption) {
1708: $curroption = 'norequest';
1709: }
1710: foreach my $option (@options) {
1711: my $val = $option;
1712: if ($option eq 'norequest') {
1713: $val = 0;
1714: }
1715: my $checked = '';
1716: if ($option eq $curroption) {
1717: $checked = ' checked="checked"';
1718: }
1719: $datatable .= '<span class="LC_nobreak"><label>'.
1720: '<input type="radio" name="authorreq_'.$type.
1721: '" value="'.$val.'"'.$checked.' />'.
1722: $titles{$option}.'</label></span> ';
1723: }
1.101 raeburn 1724: } else {
1725: my $checked = 'checked="checked" ';
1726: if (ref($settings) eq 'HASH') {
1727: if (ref($settings->{$item}) eq 'HASH') {
1728: if ($settings->{$item}->{$type} == 0) {
1729: $checked = '';
1730: } elsif ($settings->{$item}->{$type} == 1) {
1731: $checked = 'checked="checked" ';
1732: }
1.78 raeburn 1733: }
1.72 raeburn 1734: }
1.101 raeburn 1735: $datatable .= '<span class="LC_nobreak"><label>'.
1736: '<input type="checkbox" name="'.$context.'_'.$item.
1737: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1738: '</label></span> ';
1.72 raeburn 1739: }
1.101 raeburn 1740: }
1741: if ($context eq 'requestcourses') {
1742: $datatable .= '</tr><tr>';
1743: foreach my $item (@usertools) {
1.106 raeburn 1744: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1745: }
1746: $datatable .= '</tr></table>';
1.72 raeburn 1747: }
1.86 raeburn 1748: $datatable .= '</td>';
1.160.6.5 raeburn 1749: unless (($context eq 'requestcourses') ||
1750: ($context eq 'requestauthor')) {
1.86 raeburn 1751: $datatable .=
1.160.6.20 raeburn 1752: '<td class="LC_right_item">'.
1753: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1754: '<input type="text" name="quota_'.$type.
1.72 raeburn 1755: '" value="'.$currdefquota.
1.160.6.20 raeburn 1756: '" size="5" /></span>'.(' ' x 2).
1757: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1758: '<input type="text" name="authorquota_'.$type.
1759: '" value="'.$currauthorquota.
1760: '" size="5" /></span></td>';
1.86 raeburn 1761: }
1762: $datatable .= '</tr>';
1.3 raeburn 1763: }
1764: }
1765: }
1.160.6.5 raeburn 1766: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1767: $defaultquota = '20';
1.160.6.20 raeburn 1768: $authorquota = '500';
1.86 raeburn 1769: if (ref($settings) eq 'HASH') {
1770: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1771: $defaultquota = $settings->{'defaultquota'}->{'default'};
1772: } elsif (defined($settings->{'default'})) {
1773: $defaultquota = $settings->{'default'};
1774: }
1.160.6.20 raeburn 1775: if (ref($settings->{'authorquota'}) eq 'HASH') {
1776: $authorquota = $settings->{'authorquota'}->{'default'};
1777: }
1.3 raeburn 1778: }
1779: }
1780: $typecount ++;
1781: $css_class = $typecount%2?' class="LC_odd_row"':'';
1782: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1783: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1784: '<td class="LC_left_item">';
1.101 raeburn 1785: if ($context eq 'requestcourses') {
1786: $datatable .= '<table><tr>';
1787: }
1788: my %defcell;
1.72 raeburn 1789: foreach my $item (@usertools) {
1.101 raeburn 1790: if ($context eq 'requestcourses') {
1791: my ($curroption,$currlimit);
1792: if (ref($settings) eq 'HASH') {
1793: if (ref($settings->{$item}) eq 'HASH') {
1794: $curroption = $settings->{$item}->{'default'};
1795: if ($curroption =~ /^autolimit=(\d*)$/) {
1796: $currlimit = $1;
1797: }
1798: }
1799: }
1800: if (!$curroption) {
1801: $curroption = 'norequest';
1802: }
1803: $datatable .= '<th>'.$titles{$item}.'</th>';
1804: foreach my $option (@options) {
1805: my $val = $option;
1806: if ($option eq 'norequest') {
1807: $val = 0;
1808: }
1809: if ($option eq 'validate') {
1810: my $canvalidate = 0;
1811: if (ref($validations{$item}) eq 'HASH') {
1812: if ($validations{$item}{'default'}) {
1813: $canvalidate = 1;
1814: }
1815: }
1816: next if (!$canvalidate);
1817: }
1818: my $checked = '';
1819: if ($option eq $curroption) {
1820: $checked = ' checked="checked"';
1821: } elsif ($option eq 'autolimit') {
1822: if ($curroption =~ /^autolimit/) {
1823: $checked = ' checked="checked"';
1824: }
1825: }
1826: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1827: '<input type="radio" name="crsreq_'.$item.
1828: '_default" value="'.$val.'"'.$checked.' />'.
1829: $titles{$option}.'</label>';
1830: if ($option eq 'autolimit') {
1.127 raeburn 1831: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1832: $item.'_limit_default" size="1" '.
1833: 'value="'.$currlimit.'" />';
1834: }
1.127 raeburn 1835: $defcell{$item} .= '</span> ';
1.104 raeburn 1836: if ($option eq 'autolimit') {
1.127 raeburn 1837: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1838: }
1.101 raeburn 1839: }
1.160.6.5 raeburn 1840: } elsif ($context eq 'requestauthor') {
1841: my $curroption;
1842: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1843: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1844: }
1845: if (!$curroption) {
1846: $curroption = 'norequest';
1847: }
1848: foreach my $option (@options) {
1849: my $val = $option;
1850: if ($option eq 'norequest') {
1851: $val = 0;
1852: }
1853: my $checked = '';
1854: if ($option eq $curroption) {
1855: $checked = ' checked="checked"';
1856: }
1857: $datatable .= '<span class="LC_nobreak"><label>'.
1858: '<input type="radio" name="authorreq_default"'.
1859: ' value="'.$val.'"'.$checked.' />'.
1860: $titles{$option}.'</label></span> ';
1861: }
1.101 raeburn 1862: } else {
1863: my $checked = 'checked="checked" ';
1864: if (ref($settings) eq 'HASH') {
1865: if (ref($settings->{$item}) eq 'HASH') {
1866: if ($settings->{$item}->{'default'} == 0) {
1867: $checked = '';
1868: } elsif ($settings->{$item}->{'default'} == 1) {
1869: $checked = 'checked="checked" ';
1870: }
1.78 raeburn 1871: }
1.72 raeburn 1872: }
1.101 raeburn 1873: $datatable .= '<span class="LC_nobreak"><label>'.
1874: '<input type="checkbox" name="'.$context.'_'.$item.
1875: '" value="default" '.$checked.'/>'.$titles{$item}.
1876: '</label></span> ';
1877: }
1878: }
1879: if ($context eq 'requestcourses') {
1880: $datatable .= '</tr><tr>';
1881: foreach my $item (@usertools) {
1.106 raeburn 1882: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1883: }
1.101 raeburn 1884: $datatable .= '</tr></table>';
1.72 raeburn 1885: }
1.86 raeburn 1886: $datatable .= '</td>';
1.160.6.5 raeburn 1887: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1888: $datatable .= '<td class="LC_right_item">'.
1889: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1890: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1891: $defaultquota.'" size="5" /></span>'.(' ' x2).
1892: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1893: '<input type="text" name="authorquota" value="'.
1894: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1895: }
1896: $datatable .= '</tr>';
1.72 raeburn 1897: $typecount ++;
1898: $css_class = $typecount%2?' class="LC_odd_row"':'';
1899: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1900: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1901: if ($context eq 'requestcourses') {
1.109 raeburn 1902: $datatable .= &mt('(overrides affiliation, if set)').
1903: '</td>'.
1904: '<td class="LC_left_item">'.
1905: '<table><tr>';
1.101 raeburn 1906: } else {
1.109 raeburn 1907: $datatable .= &mt('(overrides affiliation, if checked)').
1908: '</td>'.
1909: '<td class="LC_left_item" colspan="2">'.
1910: '<br />';
1.101 raeburn 1911: }
1912: my %advcell;
1.72 raeburn 1913: foreach my $item (@usertools) {
1.101 raeburn 1914: if ($context eq 'requestcourses') {
1915: my ($curroption,$currlimit);
1916: if (ref($settings) eq 'HASH') {
1917: if (ref($settings->{$item}) eq 'HASH') {
1918: $curroption = $settings->{$item}->{'_LC_adv'};
1919: if ($curroption =~ /^autolimit=(\d*)$/) {
1920: $currlimit = $1;
1921: }
1922: }
1923: }
1924: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1925: my $checked = '';
1926: if ($curroption eq '') {
1927: $checked = ' checked="checked"';
1928: }
1929: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1930: '<input type="radio" name="crsreq_'.$item.
1931: '__LC_adv" value=""'.$checked.' />'.
1932: &mt('No override set').'</label></span> ';
1.101 raeburn 1933: foreach my $option (@options) {
1934: my $val = $option;
1935: if ($option eq 'norequest') {
1936: $val = 0;
1937: }
1938: if ($option eq 'validate') {
1939: my $canvalidate = 0;
1940: if (ref($validations{$item}) eq 'HASH') {
1941: if ($validations{$item}{'_LC_adv'}) {
1942: $canvalidate = 1;
1943: }
1944: }
1945: next if (!$canvalidate);
1946: }
1947: my $checked = '';
1.104 raeburn 1948: if ($val eq $curroption) {
1.101 raeburn 1949: $checked = ' checked="checked"';
1950: } elsif ($option eq 'autolimit') {
1951: if ($curroption =~ /^autolimit/) {
1952: $checked = ' checked="checked"';
1953: }
1954: }
1955: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1956: '<input type="radio" name="crsreq_'.$item.
1957: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1958: $titles{$option}.'</label>';
1959: if ($option eq 'autolimit') {
1.127 raeburn 1960: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1961: $item.'_limit__LC_adv" size="1" '.
1962: 'value="'.$currlimit.'" />';
1963: }
1.127 raeburn 1964: $advcell{$item} .= '</span> ';
1.104 raeburn 1965: if ($option eq 'autolimit') {
1.127 raeburn 1966: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1967: }
1.101 raeburn 1968: }
1.160.6.5 raeburn 1969: } elsif ($context eq 'requestauthor') {
1970: my $curroption;
1971: if (ref($settings) eq 'HASH') {
1972: $curroption = $settings->{'_LC_adv'};
1973: }
1974: my $checked = '';
1975: if ($curroption eq '') {
1976: $checked = ' checked="checked"';
1977: }
1978: $datatable .= '<span class="LC_nobreak"><label>'.
1979: '<input type="radio" name="authorreq__LC_adv"'.
1980: ' value=""'.$checked.' />'.
1981: &mt('No override set').'</label></span> ';
1982: foreach my $option (@options) {
1983: my $val = $option;
1984: if ($option eq 'norequest') {
1985: $val = 0;
1986: }
1987: my $checked = '';
1988: if ($val eq $curroption) {
1989: $checked = ' checked="checked"';
1990: }
1991: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1992: '<input type="radio" name="authorreq__LC_adv"'.
1993: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1994: $titles{$option}.'</label></span> ';
1995: }
1.101 raeburn 1996: } else {
1997: my $checked = 'checked="checked" ';
1998: if (ref($settings) eq 'HASH') {
1999: if (ref($settings->{$item}) eq 'HASH') {
2000: if ($settings->{$item}->{'_LC_adv'} == 0) {
2001: $checked = '';
2002: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2003: $checked = 'checked="checked" ';
2004: }
1.79 raeburn 2005: }
1.72 raeburn 2006: }
1.101 raeburn 2007: $datatable .= '<span class="LC_nobreak"><label>'.
2008: '<input type="checkbox" name="'.$context.'_'.$item.
2009: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2010: '</label></span> ';
2011: }
2012: }
2013: if ($context eq 'requestcourses') {
2014: $datatable .= '</tr><tr>';
2015: foreach my $item (@usertools) {
1.106 raeburn 2016: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2017: }
1.101 raeburn 2018: $datatable .= '</tr></table>';
1.72 raeburn 2019: }
1.98 raeburn 2020: $datatable .= '</td></tr>';
1.30 raeburn 2021: $$rowtotal += $typecount;
1.3 raeburn 2022: return $datatable;
2023: }
2024:
1.160.6.5 raeburn 2025: sub print_requestmail {
2026: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2027: my ($now,$datatable,%currapp);
1.102 raeburn 2028: $now = time;
2029: if (ref($settings) eq 'HASH') {
2030: if (ref($settings->{'notify'}) eq 'HASH') {
2031: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2032: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2033: }
2034: }
2035: }
1.160.6.16 raeburn 2036: my $numinrow = 2;
1.160.6.34 raeburn 2037: my $css_class;
2038: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2039: my $text;
2040: if ($action eq 'requestcourses') {
2041: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2042: } elsif ($action eq 'requestauthor') {
2043: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2044: } else {
1.160.6.34 raeburn 2045: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2046: }
1.160.6.34 raeburn 2047: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2048: ' <td>'.$text.'</td>'.
1.102 raeburn 2049: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2050: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2051: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2052: if ($numdc > 0) {
2053: $datatable .= $table;
1.102 raeburn 2054: } else {
2055: $datatable .= &mt('There are no active Domain Coordinators');
2056: }
2057: $datatable .='</td></tr>';
2058: $$rowtotal += $rows;
2059: return $datatable;
2060: }
2061:
1.160.6.30 raeburn 2062: sub print_studentcode {
2063: my ($settings,$rowtotal) = @_;
2064: my $rownum = 0;
2065: my ($output,%current);
2066: my @crstypes = ('official','unofficial','community','textbook');
2067: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2068: foreach my $type (@crstypes) {
2069: $current{$type} = $settings->{'uniquecode'}{$type};
2070: }
2071: }
2072: $output .= '<tr>'.
2073: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2074: '<td class="LC_left_item">';
2075: foreach my $type (@crstypes) {
2076: my $check = ' ';
2077: if ($current{$type}) {
2078: $check = ' checked="checked" ';
2079: }
2080: $output .= '<span class="LC_nobreak"><label>'.
2081: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2082: &mt($type).'</label></span>'.(' 'x2).' ';
2083: }
2084: $output .= '</td></tr>';
2085: $$rowtotal ++;
2086: return $output;
2087: }
2088:
2089: sub print_textbookcourses {
1.160.6.46 raeburn 2090: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2091: my $rownum = 0;
2092: my $css_class;
2093: my $itemcount = 1;
2094: my $maxnum = 0;
2095: my $bookshash;
2096: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2097: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2098: }
2099: my %ordered;
2100: if (ref($bookshash) eq 'HASH') {
2101: foreach my $item (keys(%{$bookshash})) {
2102: if (ref($bookshash->{$item}) eq 'HASH') {
2103: my $num = $bookshash->{$item}{'order'};
2104: $ordered{$num} = $item;
2105: }
2106: }
2107: }
2108: my $confname = $dom.'-domainconfig';
2109: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2110: my $maxnum = scalar(keys(%ordered));
2111: my $datatable;
1.160.6.30 raeburn 2112: if (keys(%ordered)) {
2113: my @items = sort { $a <=> $b } keys(%ordered);
2114: for (my $i=0; $i<@items; $i++) {
2115: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2116: my $key = $ordered{$items[$i]};
2117: my %coursehash=&Apache::lonnet::coursedescription($key);
2118: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2119: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2120: if (ref($bookshash->{$key}) eq 'HASH') {
2121: $subject = $bookshash->{$key}->{'subject'};
2122: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2123: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2124: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2125: $author = $bookshash->{$key}->{'author'};
2126: $image = $bookshash->{$key}->{'image'};
2127: if ($image ne '') {
2128: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2129: my $imagethumb = "$path/tn-".$imagefile;
2130: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2131: }
1.160.6.30 raeburn 2132: }
2133: }
1.160.6.46 raeburn 2134: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2135: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2136: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2137: for (my $k=0; $k<=$maxnum; $k++) {
2138: my $vpos = $k+1;
2139: my $selstr;
2140: if ($k == $i) {
2141: $selstr = ' selected="selected" ';
2142: }
2143: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2144: }
2145: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2146: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2147: &mt('Delete?').'</label></span></td>'.
2148: '<td colspan="2">'.
1.160.6.46 raeburn 2149: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2150: (' 'x2).
1.160.6.46 raeburn 2151: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2152: if ($type eq 'textbooks') {
2153: $datatable .= (' 'x2).
1.160.6.47 raeburn 2154: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2155: (' 'x2).
1.160.6.46 raeburn 2156: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2157: (' 'x2).
2158: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2159: if ($image) {
2160: $datatable .= '<span class="LC_nobreak">'.
2161: $imgsrc.
2162: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2163: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2164: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2165: }
2166: if ($switchserver) {
2167: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2168: } else {
2169: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2170: }
1.160.6.30 raeburn 2171: }
1.160.6.46 raeburn 2172: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2173: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2174: $coursetitle.'</span></td></tr>'."\n";
2175: $itemcount ++;
2176: }
2177: }
2178: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2179: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2180: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2181: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2182: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2183: for (my $k=0; $k<$maxnum+1; $k++) {
2184: my $vpos = $k+1;
2185: my $selstr;
2186: if ($k == $maxnum) {
2187: $selstr = ' selected="selected" ';
2188: }
2189: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2190: }
2191: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2192: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2193: '<td colspan="2">'.
1.160.6.46 raeburn 2194: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2195: (' 'x2).
1.160.6.46 raeburn 2196: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2197: (' 'x2);
2198: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2199: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2200: (' 'x2).
2201: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2202: (' 'x2).
2203: '<span class="LC_nobreak">'.&mt('Image:').' ';
2204: if ($switchserver) {
2205: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2206: } else {
2207: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2208: }
1.160.6.30 raeburn 2209: }
2210: $datatable .= '</span>'."\n".
2211: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2212: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2213: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2214: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2215: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2216: '</span></td>'."\n".
2217: '</tr>'."\n";
2218: $itemcount ++;
2219: return $datatable;
2220: }
2221:
2222: sub textbookcourses_javascript {
1.160.6.46 raeburn 2223: my ($settings) = @_;
2224: return unless(ref($settings) eq 'HASH');
2225: my (%ordered,%total,%jstext);
2226: foreach my $type ('textbooks','templates') {
2227: $total{$type} = 0;
2228: if (ref($settings->{$type}) eq 'HASH') {
2229: foreach my $item (keys(%{$settings->{$type}})) {
2230: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2231: my $num = $settings->{$type}->{$item}{'order'};
2232: $ordered{$type}{$num} = $item;
2233: }
2234: }
2235: $total{$type} = scalar(keys(%{$settings->{$type}}));
2236: }
2237: my @jsarray = ();
2238: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2239: push(@jsarray,$ordered{$type}{$item});
2240: }
2241: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2242: }
2243: return <<"ENDSCRIPT";
2244: <script type="text/javascript">
2245: // <![CDATA[
1.160.6.46 raeburn 2246: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2247: var changedVal;
1.160.6.46 raeburn 2248: $jstext{'textbooks'};
2249: $jstext{'templates'};
2250: var newpos;
2251: var maxh;
2252: if (caller == 'textbooks') {
2253: newpos = 'textbooks_addbook_pos';
2254: maxh = 1 + $total{'textbooks'};
2255: } else {
2256: newpos = 'templates_addbook_pos';
2257: maxh = 1 + $total{'templates'};
2258: }
1.160.6.30 raeburn 2259: var current = new Array;
2260: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2261: if (item == newpos) {
2262: changedVal = newitemVal;
2263: } else {
2264: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2265: current[newitemVal] = newpos;
2266: }
1.160.6.46 raeburn 2267: if (caller == 'textbooks') {
2268: for (var i=0; i<textbooks.length; i++) {
2269: var elementName = 'textbooks_'+textbooks[i];
2270: if (elementName != item) {
2271: if (form.elements[elementName]) {
2272: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2273: current[currVal] = elementName;
2274: }
2275: }
2276: }
2277: }
2278: if (caller == 'templates') {
2279: for (var i=0; i<templates.length; i++) {
2280: var elementName = 'templates_'+templates[i];
2281: if (elementName != item) {
2282: if (form.elements[elementName]) {
2283: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2284: current[currVal] = elementName;
2285: }
1.160.6.30 raeburn 2286: }
2287: }
2288: }
2289: var oldVal;
2290: for (var j=0; j<maxh; j++) {
2291: if (current[j] == undefined) {
2292: oldVal = j;
2293: }
2294: }
2295: if (oldVal < changedVal) {
2296: for (var k=oldVal+1; k<=changedVal ; k++) {
2297: var elementName = current[k];
2298: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2299: }
2300: } else {
2301: for (var k=changedVal; k<oldVal; k++) {
2302: var elementName = current[k];
2303: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2304: }
2305: }
2306: return;
2307: }
2308:
2309: // ]]>
2310: </script>
2311:
2312: ENDSCRIPT
2313: }
2314:
1.3 raeburn 2315: sub print_autoenroll {
1.30 raeburn 2316: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2317: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2318: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2319: if (ref($settings) eq 'HASH') {
2320: if (exists($settings->{'run'})) {
2321: if ($settings->{'run'} eq '0') {
2322: $runoff = ' checked="checked" ';
2323: $runon = ' ';
2324: } else {
2325: $runon = ' checked="checked" ';
2326: $runoff = ' ';
2327: }
2328: } else {
2329: if ($autorun) {
2330: $runon = ' checked="checked" ';
2331: $runoff = ' ';
2332: } else {
2333: $runoff = ' checked="checked" ';
2334: $runon = ' ';
2335: }
2336: }
1.129 raeburn 2337: if (exists($settings->{'co-owners'})) {
2338: if ($settings->{'co-owners'} eq '0') {
2339: $coownersoff = ' checked="checked" ';
2340: $coownerson = ' ';
2341: } else {
2342: $coownerson = ' checked="checked" ';
2343: $coownersoff = ' ';
2344: }
2345: } else {
2346: $coownersoff = ' checked="checked" ';
2347: $coownerson = ' ';
2348: }
1.3 raeburn 2349: if (exists($settings->{'sender_domain'})) {
2350: $defdom = $settings->{'sender_domain'};
2351: }
1.14 raeburn 2352: } else {
2353: if ($autorun) {
2354: $runon = ' checked="checked" ';
2355: $runoff = ' ';
2356: } else {
2357: $runoff = ' checked="checked" ';
2358: $runon = ' ';
2359: }
1.3 raeburn 2360: }
2361: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2362: my $notif_sender;
2363: if (ref($settings) eq 'HASH') {
2364: $notif_sender = $settings->{'sender_uname'};
2365: }
1.3 raeburn 2366: my $datatable='<tr class="LC_odd_row">'.
2367: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2368: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2369: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2370: $runon.' value="1" />'.&mt('Yes').'</label> '.
2371: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2372: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2373: '</tr><tr>'.
2374: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2375: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2376: &mt('username').': '.
2377: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2378: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2379: ': '.$domform.'</span></td></tr>'.
2380: '<tr class="LC_odd_row">'.
2381: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2382: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2383: '<input type="radio" name="autoassign_coowners"'.
2384: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2385: '<label><input type="radio" name="autoassign_coowners"'.
2386: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2387: '</tr>';
2388: $$rowtotal += 3;
1.3 raeburn 2389: return $datatable;
2390: }
2391:
2392: sub print_autoupdate {
1.30 raeburn 2393: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2394: my $datatable;
2395: if ($position eq 'top') {
2396: my $updateon = ' ';
2397: my $updateoff = ' checked="checked" ';
2398: my $classlistson = ' ';
2399: my $classlistsoff = ' checked="checked" ';
2400: if (ref($settings) eq 'HASH') {
2401: if ($settings->{'run'} eq '1') {
2402: $updateon = $updateoff;
2403: $updateoff = ' ';
2404: }
2405: if ($settings->{'classlists'} eq '1') {
2406: $classlistson = $classlistsoff;
2407: $classlistsoff = ' ';
2408: }
2409: }
2410: my %title = (
2411: run => 'Auto-update active?',
2412: classlists => 'Update information in classlists?',
2413: );
2414: $datatable = '<tr class="LC_odd_row">'.
2415: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2416: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2417: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2418: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2419: '<label><input type="radio" name="autoupdate_run"'.
2420: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2421: '</tr><tr>'.
2422: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2423: '<td class="LC_right_item"><span class="LC_nobreak">'.
2424: '<label><input type="radio" name="classlists"'.
2425: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2426: '<label><input type="radio" name="classlists"'.
2427: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2428: '</tr>';
1.30 raeburn 2429: $$rowtotal += 2;
1.131 raeburn 2430: } elsif ($position eq 'middle') {
2431: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2432: my $numinrow = 3;
2433: my $locknamesettings;
2434: $datatable .= &insttypes_row($settings,$types,$usertypes,
2435: $dom,$numinrow,$othertitle,
2436: 'lockablenames');
2437: $$rowtotal ++;
1.3 raeburn 2438: } else {
1.44 raeburn 2439: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2440: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2441: 'permanentemail','id');
1.33 raeburn 2442: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2443: my $numrows = 0;
1.26 raeburn 2444: if (ref($types) eq 'ARRAY') {
2445: if (@{$types} > 0) {
2446: $datatable =
2447: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2448: \@fields,$types,\$numrows);
1.30 raeburn 2449: $$rowtotal += @{$types};
1.26 raeburn 2450: }
1.3 raeburn 2451: }
2452: $datatable .=
2453: &usertype_update_row($settings,{'default' => $othertitle},
2454: \%fieldtitles,\@fields,['default'],
2455: \$numrows);
1.30 raeburn 2456: $$rowtotal ++;
1.3 raeburn 2457: }
2458: return $datatable;
2459: }
2460:
1.125 raeburn 2461: sub print_autocreate {
2462: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2463: my (%createon,%createoff,%currhash);
1.125 raeburn 2464: my @types = ('xml','req');
2465: if (ref($settings) eq 'HASH') {
2466: foreach my $item (@types) {
2467: $createoff{$item} = ' checked="checked" ';
2468: $createon{$item} = ' ';
2469: if (exists($settings->{$item})) {
2470: if ($settings->{$item}) {
2471: $createon{$item} = ' checked="checked" ';
2472: $createoff{$item} = ' ';
2473: }
2474: }
2475: }
1.160.6.16 raeburn 2476: if ($settings->{'xmldc'} ne '') {
2477: $currhash{$settings->{'xmldc'}} = 1;
2478: }
1.125 raeburn 2479: } else {
2480: foreach my $item (@types) {
2481: $createoff{$item} = ' checked="checked" ';
2482: $createon{$item} = ' ';
2483: }
2484: }
2485: $$rowtotal += 2;
1.160.6.16 raeburn 2486: my $numinrow = 2;
1.125 raeburn 2487: my $datatable='<tr class="LC_odd_row">'.
2488: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2489: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2490: '<input type="radio" name="autocreate_xml"'.
2491: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2492: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2493: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2494: '</td></tr><tr>'.
2495: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2496: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2497: '<input type="radio" name="autocreate_req"'.
2498: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2499: '<label><input type="radio" name="autocreate_req"'.
2500: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2501: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2502: 'autocreate_xmldc',%currhash);
1.125 raeburn 2503: if ($numdc > 1) {
1.143 raeburn 2504: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2505: &mt('Course creation processed as: (choose Dom. Coord.)').
2506: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2507: } else {
1.143 raeburn 2508: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2509: }
1.160.6.16 raeburn 2510: $$rowtotal += $rows;
1.125 raeburn 2511: return $datatable;
2512: }
2513:
1.23 raeburn 2514: sub print_directorysrch {
1.30 raeburn 2515: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2516: my $srchon = ' ';
2517: my $srchoff = ' checked="checked" ';
1.25 raeburn 2518: my ($exacton,$containson,$beginson);
1.24 raeburn 2519: my $localon = ' ';
2520: my $localoff = ' checked="checked" ';
1.23 raeburn 2521: if (ref($settings) eq 'HASH') {
2522: if ($settings->{'available'} eq '1') {
2523: $srchon = $srchoff;
2524: $srchoff = ' ';
2525: }
1.24 raeburn 2526: if ($settings->{'localonly'} eq '1') {
2527: $localon = $localoff;
2528: $localoff = ' ';
2529: }
1.25 raeburn 2530: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2531: foreach my $type (@{$settings->{'searchtypes'}}) {
2532: if ($type eq 'exact') {
2533: $exacton = ' checked="checked" ';
2534: } elsif ($type eq 'contains') {
2535: $containson = ' checked="checked" ';
2536: } elsif ($type eq 'begins') {
2537: $beginson = ' checked="checked" ';
2538: }
2539: }
2540: } else {
2541: if ($settings->{'searchtypes'} eq 'exact') {
2542: $exacton = ' checked="checked" ';
2543: } elsif ($settings->{'searchtypes'} eq 'contains') {
2544: $containson = ' checked="checked" ';
2545: } elsif ($settings->{'searchtypes'} eq 'specify') {
2546: $exacton = ' checked="checked" ';
2547: $containson = ' checked="checked" ';
2548: }
1.23 raeburn 2549: }
2550: }
2551: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2552: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2553:
2554: my $numinrow = 4;
1.26 raeburn 2555: my $cansrchrow = 0;
1.23 raeburn 2556: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2557: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2558: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2559: '<input type="radio" name="dirsrch_available"'.
2560: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2561: '<label><input type="radio" name="dirsrch_available"'.
2562: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2563: '</tr><tr>'.
1.30 raeburn 2564: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2565: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2566: '<input type="radio" name="dirsrch_localonly"'.
2567: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2568: '<label><input type="radio" name="dirsrch_localonly"'.
2569: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2570: '</tr>';
1.30 raeburn 2571: $$rowtotal += 2;
1.26 raeburn 2572: if (ref($usertypes) eq 'HASH') {
2573: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2574: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2575: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2576: $cansrchrow = 1;
2577: }
2578: }
2579: if ($cansrchrow) {
1.30 raeburn 2580: $$rowtotal ++;
1.26 raeburn 2581: $datatable .= '<tr>';
2582: } else {
2583: $datatable .= '<tr class="LC_odd_row">';
2584: }
1.30 raeburn 2585: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2586: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2587: foreach my $title (@{$titleorder}) {
2588: if (defined($searchtitles->{$title})) {
2589: my $check = ' ';
1.93 raeburn 2590: if (ref($settings) eq 'HASH') {
1.39 raeburn 2591: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2592: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2593: $check = ' checked="checked" ';
2594: }
1.25 raeburn 2595: }
2596: }
2597: $datatable .= '<td class="LC_left_item">'.
2598: '<span class="LC_nobreak"><label>'.
2599: '<input type="checkbox" name="searchby" '.
2600: 'value="'.$title.'"'.$check.'/>'.
2601: $searchtitles->{$title}.'</label></span></td>';
2602: }
2603: }
1.26 raeburn 2604: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2605: $$rowtotal ++;
1.26 raeburn 2606: if ($cansrchrow) {
2607: $datatable .= '<tr class="LC_odd_row">';
2608: } else {
2609: $datatable .= '<tr>';
2610: }
1.30 raeburn 2611: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2612: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2613: '<span class="LC_nobreak"><label>'.
2614: '<input type="checkbox" name="searchtypes" '.
2615: $exacton.' value="exact" />'.&mt('Exact match').
2616: '</label> '.
2617: '<label><input type="checkbox" name="searchtypes" '.
2618: $beginson.' value="begins" />'.&mt('Begins with').
2619: '</label> '.
2620: '<label><input type="checkbox" name="searchtypes" '.
2621: $containson.' value="contains" />'.&mt('Contains').
2622: '</label></span></td></tr>';
1.30 raeburn 2623: $$rowtotal ++;
1.25 raeburn 2624: return $datatable;
2625: }
2626:
1.28 raeburn 2627: sub print_contacts {
1.30 raeburn 2628: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2629: my $datatable;
2630: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2631: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2632: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2633: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2634: foreach my $type (@mailings) {
2635: $otheremails{$type} = '';
2636: }
1.134 raeburn 2637: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2638: if (ref($settings) eq 'HASH') {
2639: foreach my $item (@contacts) {
2640: if (exists($settings->{$item})) {
2641: $to{$item} = $settings->{$item};
2642: }
2643: }
2644: foreach my $type (@mailings) {
2645: if (exists($settings->{$type})) {
2646: if (ref($settings->{$type}) eq 'HASH') {
2647: foreach my $item (@contacts) {
2648: if ($settings->{$type}{$item}) {
2649: $checked{$type}{$item} = ' checked="checked" ';
2650: }
2651: }
2652: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2653: if ($type eq 'helpdeskmail') {
2654: $bccemails{$type} = $settings->{$type}{'bcc'};
2655: }
1.28 raeburn 2656: }
1.89 raeburn 2657: } elsif ($type eq 'lonstatusmail') {
2658: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2659: }
2660: }
2661: } else {
2662: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2663: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2664: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2665: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2666: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2667: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2668: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2669: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2670: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2671: }
2672: my ($titles,$short_titles) = &contact_titles();
2673: my $rownum = 0;
2674: my $css_class;
2675: foreach my $item (@contacts) {
1.69 raeburn 2676: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2677: $datatable .= '<tr'.$css_class.'>'.
2678: '<td><span class="LC_nobreak">'.$titles->{$item}.
2679: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2680: '<input type="text" name="'.$item.'" value="'.
2681: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2682: $rownum ++;
1.28 raeburn 2683: }
2684: foreach my $type (@mailings) {
1.69 raeburn 2685: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2686: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2687: '<td><span class="LC_nobreak">'.
2688: $titles->{$type}.': </span></td>'.
1.28 raeburn 2689: '<td class="LC_left_item">'.
2690: '<span class="LC_nobreak">';
2691: foreach my $item (@contacts) {
2692: $datatable .= '<label>'.
2693: '<input type="checkbox" name="'.$type.'"'.
2694: $checked{$type}{$item}.
2695: ' value="'.$item.'" />'.$short_titles->{$item}.
2696: '</label> ';
2697: }
2698: $datatable .= '</span><br />'.&mt('Others').': '.
2699: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2700: 'value="'.$otheremails{$type}.'" />';
2701: if ($type eq 'helpdeskmail') {
1.136 raeburn 2702: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2703: '<input type="text" name="'.$type.'_bcc" '.
2704: 'value="'.$bccemails{$type}.'" />';
2705: }
2706: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2707: $rownum ++;
1.28 raeburn 2708: }
1.160.6.23 raeburn 2709: my %choices;
2710: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2711: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2712: &mt('LON-CAPA core group - MSU'),600,500));
2713: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2714: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2715: &mt('LON-CAPA core group - MSU'),600,500));
2716: my @toggles = ('reporterrors','reportupdates');
2717: my %defaultchecked = ('reporterrors' => 'on',
2718: 'reportupdates' => 'on');
2719: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2720: \%choices,$rownum);
2721: $datatable .= $reports;
1.30 raeburn 2722: $$rowtotal += $rownum;
1.28 raeburn 2723: return $datatable;
2724: }
2725:
1.118 jms 2726: sub print_helpsettings {
1.160.6.5 raeburn 2727: my ($dom,$confname,$settings,$rowtotal) = @_;
2728: my ($datatable,$itemcount);
2729: $itemcount = 1;
2730: my (%choices,%defaultchecked,@toggles);
2731: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2732: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2733: &mt('LON-CAPA bug tracker'),600,500));
2734: %defaultchecked = ('submitbugs' => 'on');
2735: @toggles = ('submitbugs',);
1.122 jms 2736:
1.160.6.5 raeburn 2737: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2738: \%choices,$itemcount);
2739: return $datatable;
1.121 raeburn 2740: }
2741:
2742: sub radiobutton_prefs {
1.160.6.16 raeburn 2743: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2744: $additional) = @_;
1.121 raeburn 2745: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2746: (ref($choices) eq 'HASH'));
2747:
2748: my (%checkedon,%checkedoff,$datatable,$css_class);
2749:
2750: foreach my $item (@{$toggles}) {
2751: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2752: $checkedon{$item} = ' checked="checked" ';
2753: $checkedoff{$item} = ' ';
1.121 raeburn 2754: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2755: $checkedoff{$item} = ' checked="checked" ';
2756: $checkedon{$item} = ' ';
2757: }
2758: }
2759: if (ref($settings) eq 'HASH') {
1.121 raeburn 2760: foreach my $item (@{$toggles}) {
1.118 jms 2761: if ($settings->{$item} eq '1') {
2762: $checkedon{$item} = ' checked="checked" ';
2763: $checkedoff{$item} = ' ';
2764: } elsif ($settings->{$item} eq '0') {
2765: $checkedoff{$item} = ' checked="checked" ';
2766: $checkedon{$item} = ' ';
2767: }
2768: }
1.121 raeburn 2769: }
1.160.6.16 raeburn 2770: if ($onclick) {
2771: $onclick = ' onclick="'.$onclick.'"';
2772: }
1.121 raeburn 2773: foreach my $item (@{$toggles}) {
1.118 jms 2774: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2775: $datatable .=
1.160.6.16 raeburn 2776: '<tr'.$css_class.'><td valign="top">'.
2777: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2778: '</span></td>'.
2779: '<td class="LC_right_item"><span class="LC_nobreak">'.
2780: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2781: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2782: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2783: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2784: '</span>'.$additional.
2785: '</td>'.
1.118 jms 2786: '</tr>';
2787: $itemcount ++;
1.121 raeburn 2788: }
2789: return ($datatable,$itemcount);
2790: }
2791:
2792: sub print_coursedefaults {
1.139 raeburn 2793: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2794: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2795: my $itemcount = 1;
1.160.6.16 raeburn 2796: my %choices = &Apache::lonlocal::texthash (
2797: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2798: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2799: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2800: coursecredits => 'Credits can be specified for courses',
2801: );
1.160.6.21 raeburn 2802: my %staticdefaults = (
2803: anonsurvey_threshold => 10,
2804: uploadquota => 500,
2805: );
1.139 raeburn 2806: if ($position eq 'top') {
2807: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2808: @toggles = ('canuse_pdfforms');
1.139 raeburn 2809: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2810: \%choices,$itemcount);
1.139 raeburn 2811: } else {
2812: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2813: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2814: %curruploadquota);
1.160.6.16 raeburn 2815: my $currusecredits = 0;
1.160.6.30 raeburn 2816: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2817: if (ref($settings) eq 'HASH') {
2818: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2819: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2820: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2821: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2822: }
2823: }
1.160.6.16 raeburn 2824: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2825: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2826: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2827: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2828: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2829: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2830: $currusecredits = 1;
2831: }
2832: }
1.139 raeburn 2833: }
2834: if (!$currdefresponder) {
1.160.6.21 raeburn 2835: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2836: } elsif ($currdefresponder < 1) {
2837: $currdefresponder = 1;
2838: }
1.160.6.21 raeburn 2839: foreach my $type (@types) {
2840: if ($curruploadquota{$type} eq '') {
2841: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2842: }
2843: }
1.139 raeburn 2844: $datatable .=
1.160.6.16 raeburn 2845: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2846: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2847: '</span></td>'.
2848: '<td class="LC_right_item"><span class="LC_nobreak">'.
2849: '<input type="text" name="anonsurvey_threshold"'.
2850: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2851: '</td></tr>'."\n";
2852: $itemcount ++;
2853: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2854: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2855: $choices{'uploadquota'}.
2856: '</span></td>'.
2857: '<td align="right" class="LC_right_item">'.
2858: '<table><tr>';
1.160.6.21 raeburn 2859: foreach my $type (@types) {
2860: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2861: '<input type="text" name="uploadquota_'.$type.'"'.
2862: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2863: }
2864: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2865: $itemcount ++;
1.160.6.40 raeburn 2866: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2867: my $display = 'none';
2868: if ($currusecredits) {
2869: $display = 'block';
2870: }
2871: my $additional = '<div id="credits" style="display: '.$display.'">'.
2872: '<span class="LC_nobreak">'.
2873: &mt('Default credits for official courses [_1]',
2874: '<input type="text" name="official_credits" value="'.
2875: $def_official_credits.'" size="3" />').
2876: '</span><br />'.
2877: '<span class="LC_nobreak">'.
2878: &mt('Default credits for unofficial courses [_1]',
2879: '<input type="text" name="unofficial_credits" value="'.
2880: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2881: '</span><br />'.
2882: '<span class="LC_nobreak">'.
2883: &mt('Default credits for textbook courses [_1]',
2884: '<input type="text" name="textbook_credits" value="'.
2885: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2886: '</span></div>'."\n";
2887: %defaultchecked = ('coursecredits' => 'off');
2888: @toggles = ('coursecredits');
2889: my $current = {
2890: 'coursecredits' => $currusecredits,
2891: };
2892: (my $table,$itemcount) =
2893: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2894: \%choices,$itemcount,$onclick,$additional);
2895: $datatable .= $table;
1.160.6.37 raeburn 2896: $itemcount ++;
2897: }
2898: $$rowtotal += $itemcount;
2899: return $datatable;
2900: }
2901:
2902: sub print_selfenrollment {
2903: my ($position,$dom,$settings,$rowtotal) = @_;
2904: my ($css_class,$datatable);
2905: my $itemcount = 1;
2906: my @types = ('official','unofficial','community','textbook');
2907: if (($position eq 'top') || ($position eq 'middle')) {
2908: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2909: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2910: my @rows;
2911: my $key;
2912: if ($position eq 'top') {
2913: $key = 'admin';
2914: if (ref($rowsref) eq 'ARRAY') {
2915: @rows = @{$rowsref};
2916: }
2917: } elsif ($position eq 'middle') {
2918: $key = 'default';
2919: @rows = ('types','registered','approval','limit');
2920: }
2921: foreach my $row (@rows) {
2922: if (defined($titlesref->{$row})) {
2923: $itemcount ++;
2924: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2925: $datatable .= '<tr'.$css_class.'>'.
2926: '<td>'.$titlesref->{$row}.'</td>'.
2927: '<td class="LC_left_item">'.
2928: '<table><tr>';
2929: my (%current,%currentcap);
2930: if (ref($settings) eq 'HASH') {
2931: if (ref($settings->{$key}) eq 'HASH') {
2932: foreach my $type (@types) {
2933: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2934: $current{$type} = $settings->{$key}->{$type}->{$row};
2935: }
2936: if (($row eq 'limit') && ($key eq 'default')) {
2937: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2938: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2939: }
2940: }
2941: }
2942: }
2943: }
2944: my %roles = (
2945: '0' => &Apache::lonnet::plaintext('dc'),
2946: );
2947:
2948: foreach my $type (@types) {
2949: unless (($row eq 'registered') && ($key eq 'default')) {
2950: $datatable .= '<th>'.&mt($type).'</th>';
2951: }
2952: }
2953: unless (($row eq 'registered') && ($key eq 'default')) {
2954: $datatable .= '</tr><tr>';
2955: }
2956: foreach my $type (@types) {
2957: if ($type eq 'community') {
2958: $roles{'1'} = &mt('Community personnel');
2959: } else {
2960: $roles{'1'} = &mt('Course personnel');
2961: }
2962: $datatable .= '<td style="vertical-align: top">';
2963: if ($position eq 'top') {
2964: my %checked;
2965: if ($current{$type} eq '0') {
2966: $checked{'0'} = ' checked="checked"';
2967: } else {
2968: $checked{'1'} = ' checked="checked"';
2969: }
2970: foreach my $role ('1','0') {
2971: $datatable .= '<span class="LC_nobreak"><label>'.
2972: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2973: 'value="'.$role.'"'.$checked{$role}.' />'.
2974: $roles{$role}.'</label></span> ';
2975: }
2976: } else {
2977: if ($row eq 'types') {
2978: my %checked;
2979: if ($current{$type} =~ /^(all|dom)$/) {
2980: $checked{$1} = ' checked="checked"';
2981: } else {
2982: $checked{''} = ' checked="checked"';
2983: }
2984: foreach my $val ('','dom','all') {
2985: $datatable .= '<span class="LC_nobreak"><label>'.
2986: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2987: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2988: }
2989: } elsif ($row eq 'registered') {
2990: my %checked;
2991: if ($current{$type} eq '1') {
2992: $checked{'1'} = ' checked="checked"';
2993: } else {
2994: $checked{'0'} = ' checked="checked"';
2995: }
2996: foreach my $val ('0','1') {
2997: $datatable .= '<span class="LC_nobreak"><label>'.
2998: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2999: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3000: }
3001: } elsif ($row eq 'approval') {
3002: my %checked;
3003: if ($current{$type} =~ /^([12])$/) {
3004: $checked{$1} = ' checked="checked"';
3005: } else {
3006: $checked{'0'} = ' checked="checked"';
3007: }
3008: for my $val (0..2) {
3009: $datatable .= '<span class="LC_nobreak"><label>'.
3010: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3011: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3012: }
3013: } elsif ($row eq 'limit') {
3014: my %checked;
3015: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3016: $checked{$1} = ' checked="checked"';
3017: } else {
3018: $checked{'none'} = ' checked="checked"';
3019: }
3020: my $cap;
3021: if ($currentcap{$type} =~ /^\d+$/) {
3022: $cap = $currentcap{$type};
3023: }
3024: foreach my $val ('none','allstudents','selfenrolled') {
3025: $datatable .= '<span class="LC_nobreak"><label>'.
3026: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3027: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3028: }
3029: $datatable .= '<br />'.
3030: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3031: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3032: '</span>';
3033: }
3034: }
3035: $datatable .= '</td>';
3036: }
3037: $datatable .= '</tr>';
3038: }
3039: $datatable .= '</table></td></tr>';
3040: }
3041: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3042: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3043: }
3044: $$rowtotal += $itemcount;
3045: return $datatable;
3046: }
3047:
3048: sub print_validation_rows {
3049: my ($caller,$dom,$settings,$rowtotal) = @_;
3050: my ($itemsref,$namesref,$fieldsref);
3051: if ($caller eq 'selfenroll') {
3052: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3053: } elsif ($caller eq 'requestcourses') {
3054: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3055: }
3056: my %currvalidation;
3057: if (ref($settings) eq 'HASH') {
3058: if (ref($settings->{'validation'}) eq 'HASH') {
3059: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3060: }
1.160.6.39 raeburn 3061: }
3062: my $datatable;
3063: my $itemcount = 0;
3064: foreach my $item (@{$itemsref}) {
3065: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3066: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3067: $namesref->{$item}.
3068: '</span></td>'.
3069: '<td class="LC_left_item">';
3070: if (($item eq 'url') || ($item eq 'button')) {
3071: $datatable .= '<span class="LC_nobreak">'.
3072: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3073: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3074: } elsif ($item eq 'fields') {
3075: my @currfields;
3076: if (ref($currvalidation{$item}) eq 'ARRAY') {
3077: @currfields = @{$currvalidation{$item}};
3078: }
3079: foreach my $field (@{$fieldsref}) {
3080: my $check = '';
3081: if (grep(/^\Q$field\E$/,@currfields)) {
3082: $check = ' checked="checked"';
3083: }
3084: $datatable .= '<span class="LC_nobreak"><label>'.
3085: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3086: ' value="'.$field.'"'.$check.' />'.$field.
3087: '</label></span> ';
3088: }
3089: } elsif ($item eq 'markup') {
3090: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3091: $currvalidation{$item}.
1.160.6.37 raeburn 3092: '</textarea>';
1.160.6.39 raeburn 3093: }
3094: $datatable .= '</td></tr>'."\n";
3095: if (ref($rowtotal)) {
1.160.6.37 raeburn 3096: $itemcount ++;
3097: }
1.139 raeburn 3098: }
1.160.6.39 raeburn 3099: if ($caller eq 'requestcourses') {
3100: my %currhash;
3101: if (ref($settings->{'validation'}) eq 'HASH') {
3102: if ($settings->{'validation'}{'dc'} ne '') {
3103: $currhash{$settings->{'validation'}{'dc'}} = 1;
3104: }
3105: }
3106: my $numinrow = 2;
3107: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3108: 'validationdc',%currhash);
3109: if ($numdc > 1) {
3110: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3111: &mt('Course creation processed as: (choose Dom. Coord.)').
3112: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3113: } else {
3114: $datatable .= $dctable.'</td></tr>';
3115: }
3116: $itemcount ++;
3117: }
3118: if (ref($rowtotal)) {
3119: $$rowtotal += $itemcount;
3120: }
1.121 raeburn 3121: return $datatable;
1.118 jms 3122: }
3123:
1.137 raeburn 3124: sub print_usersessions {
3125: my ($position,$dom,$settings,$rowtotal) = @_;
3126: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3127: my (%by_ip,%by_location,@intdoms);
3128: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3129:
3130: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3131: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3132: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3133: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3134: my $itemcount = 1;
3135: if ($position eq 'top') {
1.152 raeburn 3136: if (keys(%serverhomes) > 1) {
1.145 raeburn 3137: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3138: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3139: } else {
1.140 raeburn 3140: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3141: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3142: }
1.137 raeburn 3143: } else {
1.145 raeburn 3144: if (keys(%by_location) == 0) {
3145: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3146: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3147: } else {
3148: my %lt = &usersession_titles();
3149: my $numinrow = 5;
3150: my $prefix;
3151: my @types;
3152: if ($position eq 'bottom') {
3153: $prefix = 'remote';
3154: @types = ('version','excludedomain','includedomain');
3155: } else {
3156: $prefix = 'hosted';
3157: @types = ('excludedomain','includedomain');
3158: }
3159: my (%current,%checkedon,%checkedoff);
3160: my @lcversions = &Apache::lonnet::all_loncaparevs();
3161: my @locations = sort(keys(%by_location));
3162: foreach my $type (@types) {
3163: $checkedon{$type} = '';
3164: $checkedoff{$type} = ' checked="checked"';
3165: }
3166: if (ref($settings) eq 'HASH') {
3167: if (ref($settings->{$prefix}) eq 'HASH') {
3168: foreach my $key (keys(%{$settings->{$prefix}})) {
3169: $current{$key} = $settings->{$prefix}{$key};
3170: if ($key eq 'version') {
3171: if ($current{$key} ne '') {
3172: $checkedon{$key} = ' checked="checked"';
3173: $checkedoff{$key} = '';
3174: }
3175: } elsif (ref($current{$key}) eq 'ARRAY') {
3176: $checkedon{$key} = ' checked="checked"';
3177: $checkedoff{$key} = '';
3178: }
1.137 raeburn 3179: }
3180: }
3181: }
1.145 raeburn 3182: foreach my $type (@types) {
3183: next if ($type ne 'version' && !@locations);
3184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3185: $datatable .= '<tr'.$css_class.'>
3186: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3187: <span class="LC_nobreak">
3188: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3189: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3190: if ($type eq 'version') {
3191: my $selector = '<select name="'.$prefix.'_version">';
3192: foreach my $version (@lcversions) {
3193: my $selected = '';
3194: if ($current{'version'} eq $version) {
3195: $selected = ' selected="selected"';
3196: }
3197: $selector .= ' <option value="'.$version.'"'.
3198: $selected.'>'.$version.'</option>';
3199: }
3200: $selector .= '</select> ';
3201: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3202: } else {
3203: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3204: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3205: ' />'.(' 'x2).
3206: '<input type="button" value="'.&mt('uncheck all').'" '.
3207: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3208: "\n".
3209: '</div><div><table>';
3210: my $rem;
3211: for (my $i=0; $i<@locations; $i++) {
3212: my ($showloc,$value,$checkedtype);
3213: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3214: my $ip = $by_location{$locations[$i]}->[0];
3215: if (ref($by_ip{$ip}) eq 'ARRAY') {
3216: $value = join(':',@{$by_ip{$ip}});
3217: $showloc = join(', ',@{$by_ip{$ip}});
3218: if (ref($current{$type}) eq 'ARRAY') {
3219: foreach my $loc (@{$by_ip{$ip}}) {
3220: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3221: $checkedtype = ' checked="checked"';
3222: last;
3223: }
3224: }
1.138 raeburn 3225: }
3226: }
3227: }
1.145 raeburn 3228: $rem = $i%($numinrow);
3229: if ($rem == 0) {
3230: if ($i > 0) {
3231: $datatable .= '</tr>';
3232: }
3233: $datatable .= '<tr>';
3234: }
3235: $datatable .= '<td class="LC_left_item">'.
3236: '<span class="LC_nobreak"><label>'.
3237: '<input type="checkbox" name="'.$prefix.'_'.$type.
3238: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3239: '</label></span></td>';
1.137 raeburn 3240: }
1.145 raeburn 3241: $rem = @locations%($numinrow);
3242: my $colsleft = $numinrow - $rem;
3243: if ($colsleft > 1 ) {
3244: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3245: ' </td>';
3246: } elsif ($colsleft == 1) {
3247: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3248: }
1.145 raeburn 3249: $datatable .= '</tr></table>';
1.137 raeburn 3250: }
1.145 raeburn 3251: $datatable .= '</td></tr>';
3252: $itemcount ++;
1.137 raeburn 3253: }
3254: }
3255: }
3256: $$rowtotal += $itemcount;
3257: return $datatable;
3258: }
3259:
1.138 raeburn 3260: sub build_location_hashes {
3261: my ($intdoms,$by_ip,$by_location) = @_;
3262: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3263: (ref($by_location) eq 'HASH'));
3264: my %iphost = &Apache::lonnet::get_iphost();
3265: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3266: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3267: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3268: foreach my $id (@{$iphost{$primary_ip}}) {
3269: my $intdom = &Apache::lonnet::internet_dom($id);
3270: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3271: push(@{$intdoms},$intdom);
3272: }
3273: }
3274: }
3275: foreach my $ip (keys(%iphost)) {
3276: if (ref($iphost{$ip}) eq 'ARRAY') {
3277: foreach my $id (@{$iphost{$ip}}) {
3278: my $location = &Apache::lonnet::internet_dom($id);
3279: if ($location) {
3280: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3281: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3282: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3283: push(@{$by_ip->{$ip}},$location);
3284: }
3285: } else {
3286: $by_ip->{$ip} = [$location];
3287: }
3288: }
3289: }
3290: }
3291: }
3292: foreach my $ip (sort(keys(%{$by_ip}))) {
3293: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3294: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3295: my $first = $by_ip->{$ip}->[0];
3296: if (ref($by_location->{$first}) eq 'ARRAY') {
3297: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3298: push(@{$by_location->{$first}},$ip);
3299: }
3300: } else {
3301: $by_location->{$first} = [$ip];
3302: }
3303: }
3304: }
3305: return;
3306: }
3307:
1.145 raeburn 3308: sub current_offloads_to {
3309: my ($dom,$settings,$servers) = @_;
3310: my (%spareid,%otherdomconfigs);
1.152 raeburn 3311: if (ref($servers) eq 'HASH') {
1.145 raeburn 3312: foreach my $lonhost (sort(keys(%{$servers}))) {
3313: my $gotspares;
1.152 raeburn 3314: if (ref($settings) eq 'HASH') {
3315: if (ref($settings->{'spares'}) eq 'HASH') {
3316: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3317: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3318: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3319: $gotspares = 1;
3320: }
1.145 raeburn 3321: }
3322: }
3323: unless ($gotspares) {
3324: my $gotspares;
3325: my $serverhomeID =
3326: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3327: my $serverhomedom =
3328: &Apache::lonnet::host_domain($serverhomeID);
3329: if ($serverhomedom ne $dom) {
3330: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3331: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3332: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3333: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3334: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3335: $gotspares = 1;
3336: }
3337: }
3338: } else {
3339: $otherdomconfigs{$serverhomedom} =
3340: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3341: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3342: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3343: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3344: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3345: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3346: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3347: $gotspares = 1;
3348: }
3349: }
3350: }
3351: }
3352: }
3353: }
3354: }
3355: unless ($gotspares) {
3356: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3357: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3358: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3359: } else {
3360: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3361: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3362: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3363: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3364: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3365: } else {
1.150 raeburn 3366: my %what = (
3367: spareid => 1,
3368: );
3369: my ($result,$returnhash) =
3370: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3371: if ($result eq 'ok') {
3372: if (ref($returnhash) eq 'HASH') {
3373: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3374: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3375: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3376: }
3377: }
1.145 raeburn 3378: }
3379: }
3380: }
3381: }
3382: }
3383: }
3384: return %spareid;
3385: }
3386:
3387: sub spares_row {
1.152 raeburn 3388: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3389: my $css_class;
3390: my $numinrow = 4;
3391: my $itemcount = 1;
3392: my $datatable;
1.152 raeburn 3393: my %typetitles = &sparestype_titles();
3394: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3395: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3396: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3397: my ($othercontrol,$serverdom);
3398: if ($serverhome ne $server) {
3399: $serverdom = &Apache::lonnet::host_domain($serverhome);
3400: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3401: } else {
3402: $serverdom = &Apache::lonnet::host_domain($server);
3403: if ($serverdom ne $dom) {
3404: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3405: }
3406: }
3407: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3408: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3409: $datatable .= '<tr'.$css_class.'>
3410: <td rowspan="2">
1.160.6.13 raeburn 3411: <span class="LC_nobreak">'.
3412: &mt('[_1] when busy, offloads to:'
3413: ,'<b>'.$server.'</b>').
3414: "\n";
1.145 raeburn 3415: my (%current,%canselect);
1.152 raeburn 3416: my @choices =
3417: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3418: foreach my $type ('primary','default') {
3419: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3420: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3421: my @spares = @{$spareid->{$server}{$type}};
3422: if (@spares > 0) {
1.152 raeburn 3423: if ($othercontrol) {
3424: $current{$type} = join(', ',@spares);
3425: } else {
3426: $current{$type} .= '<table>';
3427: my $numspares = scalar(@spares);
3428: for (my $i=0; $i<@spares; $i++) {
3429: my $rem = $i%($numinrow);
3430: if ($rem == 0) {
3431: if ($i > 0) {
3432: $current{$type} .= '</tr>';
3433: }
3434: $current{$type} .= '<tr>';
1.145 raeburn 3435: }
1.152 raeburn 3436: $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'".');" /> '.
3437: $spareid->{$server}{$type}[$i].
3438: '</label></td>'."\n";
3439: }
3440: my $rem = @spares%($numinrow);
3441: my $colsleft = $numinrow - $rem;
3442: if ($colsleft > 1 ) {
3443: $current{$type} .= '<td colspan="'.$colsleft.
3444: '" class="LC_left_item">'.
3445: ' </td>';
3446: } elsif ($colsleft == 1) {
3447: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3448: }
1.152 raeburn 3449: $current{$type} .= '</tr></table>';
1.150 raeburn 3450: }
1.145 raeburn 3451: }
3452: }
3453: if ($current{$type} eq '') {
3454: $current{$type} = &mt('None specified');
3455: }
1.152 raeburn 3456: if ($othercontrol) {
3457: if ($type eq 'primary') {
3458: $canselect{$type} = $othercontrol;
3459: }
3460: } else {
3461: $canselect{$type} =
3462: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3463: '<select name="newspare_'.$type.'_'.$server.'" '.
3464: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3465: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3466: if (@choices > 0) {
3467: foreach my $lonhost (@choices) {
3468: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3469: }
3470: }
3471: $canselect{$type} .= '</select>'."\n";
3472: }
3473: } else {
3474: $current{$type} = &mt('Could not be determined');
3475: if ($type eq 'primary') {
3476: $canselect{$type} = $othercontrol;
3477: }
1.145 raeburn 3478: }
1.152 raeburn 3479: if ($type eq 'default') {
3480: $datatable .= '<tr'.$css_class.'>';
3481: }
3482: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3483: '<td>'.$current{$type}.'</td>'."\n".
3484: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3485: }
3486: $itemcount ++;
3487: }
3488: }
3489: $$rowtotal += $itemcount;
3490: return $datatable;
3491: }
3492:
1.152 raeburn 3493: sub possible_newspares {
3494: my ($server,$currspares,$serverhomes,$altids) = @_;
3495: my $serverhostname = &Apache::lonnet::hostname($server);
3496: my %excluded;
3497: if ($serverhostname ne '') {
3498: %excluded = (
3499: $serverhostname => 1,
3500: );
3501: }
3502: if (ref($currspares) eq 'HASH') {
3503: foreach my $type (keys(%{$currspares})) {
3504: if (ref($currspares->{$type}) eq 'ARRAY') {
3505: if (@{$currspares->{$type}} > 0) {
3506: foreach my $curr (@{$currspares->{$type}}) {
3507: my $hostname = &Apache::lonnet::hostname($curr);
3508: $excluded{$hostname} = 1;
3509: }
3510: }
3511: }
3512: }
3513: }
3514: my @choices;
3515: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3516: if (keys(%{$serverhomes}) > 1) {
3517: foreach my $name (sort(keys(%{$serverhomes}))) {
3518: unless ($excluded{$name}) {
3519: if (exists($altids->{$serverhomes->{$name}})) {
3520: push(@choices,$altids->{$serverhomes->{$name}});
3521: } else {
3522: push(@choices,$serverhomes->{$name});
1.145 raeburn 3523: }
3524: }
3525: }
3526: }
3527: }
1.152 raeburn 3528: return sort(@choices);
1.145 raeburn 3529: }
3530:
1.150 raeburn 3531: sub print_loadbalancing {
3532: my ($dom,$settings,$rowtotal) = @_;
3533: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3534: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3535: my $numinrow = 1;
3536: my $datatable;
3537: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3538: my (%currbalancer,%currtargets,%currrules,%existing);
3539: if (ref($settings) eq 'HASH') {
3540: %existing = %{$settings};
3541: }
3542: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3543: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3544: \%currtargets,\%currrules);
1.150 raeburn 3545: } else {
3546: return;
3547: }
3548: my ($othertitle,$usertypes,$types) =
3549: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3550: my $rownum = 8;
1.150 raeburn 3551: if (ref($types) eq 'ARRAY') {
3552: $rownum += scalar(@{$types});
3553: }
1.160.6.7 raeburn 3554: my @css_class = ('LC_odd_row','LC_even_row');
3555: my $balnum = 0;
3556: my $islast;
3557: my (@toshow,$disabledtext);
3558: if (keys(%currbalancer) > 0) {
3559: @toshow = sort(keys(%currbalancer));
3560: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3561: push(@toshow,'');
3562: }
3563: } else {
3564: @toshow = ('');
3565: $disabledtext = &mt('No existing load balancer');
3566: }
3567: foreach my $lonhost (@toshow) {
3568: if ($balnum == scalar(@toshow)-1) {
3569: $islast = 1;
3570: } else {
3571: $islast = 0;
3572: }
3573: my $cssidx = $balnum%2;
3574: my $targets_div_style = 'display: none';
3575: my $disabled_div_style = 'display: block';
3576: my $homedom_div_style = 'display: none';
3577: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3578: '<td rowspan="'.$rownum.'" valign="top">'.
3579: '<p>';
3580: if ($lonhost eq '') {
3581: $datatable .= '<span class="LC_nobreak">';
3582: if (keys(%currbalancer) > 0) {
3583: $datatable .= &mt('Add balancer:');
3584: } else {
3585: $datatable .= &mt('Enable balancer:');
3586: }
3587: $datatable .= ' '.
3588: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3589: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3590: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3591: '<option value="" selected="selected">'.&mt('None').
3592: '</option>'."\n";
3593: foreach my $server (sort(keys(%servers))) {
3594: next if ($currbalancer{$server});
3595: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3596: }
3597: $datatable .=
3598: '</select>'."\n".
3599: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3600: } else {
3601: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3602: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3603: &mt('Stop balancing').'</label>'.
3604: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3605: $targets_div_style = 'display: block';
3606: $disabled_div_style = 'display: none';
3607: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3608: $homedom_div_style = 'display: block';
3609: }
3610: }
3611: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3612: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3613: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3614: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3615: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3616: my @sparestypes = ('primary','default');
3617: my %typetitles = &sparestype_titles();
3618: foreach my $sparetype (@sparestypes) {
3619: my $targettable;
3620: for (my $i=0; $i<$numspares; $i++) {
3621: my $checked;
3622: if (ref($currtargets{$lonhost}) eq 'HASH') {
3623: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3624: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3625: $checked = ' checked="checked"';
3626: }
3627: }
3628: }
3629: my ($chkboxval,$disabled);
3630: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3631: $chkboxval = $spares[$i];
3632: }
3633: if (exists($currbalancer{$spares[$i]})) {
3634: $disabled = ' disabled="disabled"';
3635: }
3636: $targettable .=
3637: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3638: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3639: '</span></label></td>';
3640: my $rem = $i%($numinrow);
3641: if ($rem == 0) {
3642: if (($i > 0) && ($i < $numspares-1)) {
3643: $targettable .= '</tr>';
3644: }
3645: if ($i < $numspares-1) {
3646: $targettable .= '<tr>';
1.150 raeburn 3647: }
3648: }
3649: }
1.160.6.7 raeburn 3650: if ($targettable ne '') {
3651: my $rem = $numspares%($numinrow);
3652: my $colsleft = $numinrow - $rem;
3653: if ($colsleft > 1 ) {
3654: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3655: ' </td>';
3656: } elsif ($colsleft == 1) {
3657: $targettable .= '<td class="LC_left_item"> </td>';
3658: }
3659: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3660: '<table><tr>'.$targettable.'</tr></table><br />';
3661: }
3662: }
3663: $datatable .= '</div></td></tr>'.
3664: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3665: $othertitle,$usertypes,$types,\%servers,
3666: \%currbalancer,$lonhost,
3667: $targets_div_style,$homedom_div_style,
3668: $css_class[$cssidx],$balnum,$islast);
3669: $$rowtotal += $rownum;
3670: $balnum ++;
3671: }
3672: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3673: return $datatable;
3674: }
3675:
3676: sub get_loadbalancers_config {
3677: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3678: return unless ((ref($servers) eq 'HASH') &&
3679: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3680: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3681: if (keys(%{$existing}) > 0) {
3682: my $oldlonhost;
3683: foreach my $key (sort(keys(%{$existing}))) {
3684: if ($key eq 'lonhost') {
3685: $oldlonhost = $existing->{'lonhost'};
3686: $currbalancer->{$oldlonhost} = 1;
3687: } elsif ($key eq 'targets') {
3688: if ($oldlonhost) {
3689: $currtargets->{$oldlonhost} = $existing->{'targets'};
3690: }
3691: } elsif ($key eq 'rules') {
3692: if ($oldlonhost) {
3693: $currrules->{$oldlonhost} = $existing->{'rules'};
3694: }
3695: } elsif (ref($existing->{$key}) eq 'HASH') {
3696: $currbalancer->{$key} = 1;
3697: $currtargets->{$key} = $existing->{$key}{'targets'};
3698: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3699: }
3700: }
1.160.6.7 raeburn 3701: } else {
3702: my ($balancerref,$targetsref) =
3703: &Apache::lonnet::get_lonbalancer_config($servers);
3704: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3705: foreach my $server (sort(keys(%{$balancerref}))) {
3706: $currbalancer->{$server} = 1;
3707: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3708: }
3709: }
3710: }
1.160.6.7 raeburn 3711: return;
1.150 raeburn 3712: }
3713:
3714: sub loadbalancing_rules {
3715: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3716: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3717: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3718: my $output;
1.160.6.7 raeburn 3719: my $num = 0;
3720: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3721: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3722: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3723: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3724: $num ++;
1.150 raeburn 3725: my $current;
3726: if (ref($currrules) eq 'HASH') {
3727: $current = $currrules->{$type};
3728: }
1.160.6.26 raeburn 3729: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3730: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3731: $current = '';
3732: }
3733: }
3734: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3735: $servers,$currbalancer,$lonhost,$dom,
3736: $targets_div_style,$homedom_div_style,
3737: $css_class,$balnum,$num,$islast);
1.150 raeburn 3738: }
3739: }
3740: return $output;
3741: }
3742:
3743: sub loadbalancing_titles {
3744: my ($dom,$intdom,$usertypes,$types) = @_;
3745: my %othertypes = (
3746: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3747: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3748: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3749: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3750: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3751: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3752: );
1.160.6.26 raeburn 3753: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3754: if (ref($types) eq 'ARRAY') {
3755: unshift(@alltypes,@{$types},'default');
3756: }
3757: my %titles;
3758: foreach my $type (@alltypes) {
3759: if ($type =~ /^_LC_/) {
3760: $titles{$type} = $othertypes{$type};
3761: } elsif ($type eq 'default') {
3762: $titles{$type} = &mt('All users from [_1]',$dom);
3763: if (ref($types) eq 'ARRAY') {
3764: if (@{$types} > 0) {
3765: $titles{$type} = &mt('Other users from [_1]',$dom);
3766: }
3767: }
3768: } elsif (ref($usertypes) eq 'HASH') {
3769: $titles{$type} = $usertypes->{$type};
3770: }
3771: }
3772: return (\@alltypes,\%othertypes,\%titles);
3773: }
3774:
3775: sub loadbalance_rule_row {
1.160.6.7 raeburn 3776: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3777: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3778: my @rulenames;
1.150 raeburn 3779: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3780: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3781: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3782: } else {
1.160.6.26 raeburn 3783: @rulenames = ('default','homeserver');
3784: if ($type eq '_LC_external') {
3785: push(@rulenames,'externalbalancer');
3786: } else {
3787: push(@rulenames,'specific');
3788: }
3789: push(@rulenames,'none');
1.150 raeburn 3790: }
3791: my $style = $targets_div_style;
1.160.6.26 raeburn 3792: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3793: $style = $homedom_div_style;
3794: }
1.160.6.7 raeburn 3795: my $space;
3796: if ($islast && $num == 1) {
3797: $space = '<div display="inline-block"> </div>';
3798: }
3799: my $output =
3800: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3801: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3802: '<td valaign="top">'.$space.
3803: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3804: for (my $i=0; $i<@rulenames; $i++) {
3805: my $rule = $rulenames[$i];
3806: my ($checked,$extra);
3807: if ($rulenames[$i] eq 'default') {
3808: $rule = '';
3809: }
3810: if ($rulenames[$i] eq 'specific') {
3811: if (ref($servers) eq 'HASH') {
3812: my $default;
3813: if (($current ne '') && (exists($servers->{$current}))) {
3814: $checked = ' checked="checked"';
3815: }
3816: unless ($checked) {
3817: $default = ' selected="selected"';
3818: }
1.160.6.7 raeburn 3819: $extra =
3820: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3821: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3822: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3823: '<option value=""'.$default.'></option>'."\n";
3824: foreach my $server (sort(keys(%{$servers}))) {
3825: if (ref($currbalancer) eq 'HASH') {
3826: next if (exists($currbalancer->{$server}));
3827: }
1.150 raeburn 3828: my $selected;
1.160.6.7 raeburn 3829: if ($server eq $current) {
1.150 raeburn 3830: $selected = ' selected="selected"';
3831: }
1.160.6.7 raeburn 3832: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3833: }
3834: $extra .= '</select>';
3835: }
3836: } elsif ($rule eq $current) {
3837: $checked = ' checked="checked"';
3838: }
3839: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3840: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3841: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3842: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3843: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3844: '</label>'.$extra.'</span><br />'."\n";
3845: }
3846: $output .= '</div></td></tr>'."\n";
3847: return $output;
3848: }
3849:
3850: sub offloadtype_text {
3851: my %ruletitles = &Apache::lonlocal::texthash (
3852: 'default' => 'Offloads to default destinations',
3853: 'homeserver' => "Offloads to user's home server",
3854: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3855: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3856: 'none' => 'No offload',
1.160.6.26 raeburn 3857: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3858: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3859: );
3860: return %ruletitles;
3861: }
3862:
3863: sub sparestype_titles {
3864: my %typestitles = &Apache::lonlocal::texthash (
3865: 'primary' => 'primary',
3866: 'default' => 'default',
3867: );
3868: return %typestitles;
3869: }
3870:
1.28 raeburn 3871: sub contact_titles {
3872: my %titles = &Apache::lonlocal::texthash (
3873: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3874: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3875: 'errormail' => 'Error reports to be e-mailed to',
3876: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3877: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3878: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3879: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3880: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3881: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3882: );
3883: my %short_titles = &Apache::lonlocal::texthash (
3884: adminemail => 'Admin E-mail address',
3885: supportemail => 'Support E-mail',
3886: );
3887: return (\%titles,\%short_titles);
3888: }
3889:
1.72 raeburn 3890: sub tool_titles {
3891: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3892: aboutme => 'Personal web page',
1.86 raeburn 3893: blog => 'Blog',
1.160.6.4 raeburn 3894: webdav => 'WebDAV',
1.86 raeburn 3895: portfolio => 'Portfolio',
1.88 bisitz 3896: official => 'Official courses (with institutional codes)',
3897: unofficial => 'Unofficial courses',
1.98 raeburn 3898: community => 'Communities',
1.160.6.30 raeburn 3899: textbook => 'Textbook courses',
1.86 raeburn 3900: );
1.72 raeburn 3901: return %titles;
3902: }
3903:
1.101 raeburn 3904: sub courserequest_titles {
3905: my %titles = &Apache::lonlocal::texthash (
3906: official => 'Official',
3907: unofficial => 'Unofficial',
3908: community => 'Communities',
1.160.6.30 raeburn 3909: textbook => 'Textbook',
1.101 raeburn 3910: norequest => 'Not allowed',
1.104 raeburn 3911: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3912: validate => 'With validation',
3913: autolimit => 'Numerical limit',
1.103 raeburn 3914: unlimited => '(blank for unlimited)',
1.101 raeburn 3915: );
3916: return %titles;
3917: }
3918:
1.160.6.5 raeburn 3919: sub authorrequest_titles {
3920: my %titles = &Apache::lonlocal::texthash (
3921: norequest => 'Not allowed',
3922: approval => 'Approval by Dom. Coord.',
3923: automatic => 'Automatic approval',
3924: );
3925: return %titles;
3926: }
3927:
1.101 raeburn 3928: sub courserequest_conditions {
3929: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3930: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3931: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3932: );
3933: return %conditions;
3934: }
3935:
3936:
1.27 raeburn 3937: sub print_usercreation {
1.30 raeburn 3938: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3939: my $numinrow = 4;
1.28 raeburn 3940: my $datatable;
3941: if ($position eq 'top') {
1.30 raeburn 3942: $$rowtotal ++;
1.34 raeburn 3943: my $rowcount = 0;
1.32 raeburn 3944: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3945: if (ref($rules) eq 'HASH') {
3946: if (keys(%{$rules}) > 0) {
1.32 raeburn 3947: $datatable .= &user_formats_row('username',$settings,$rules,
3948: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3949: $$rowtotal ++;
1.32 raeburn 3950: $rowcount ++;
3951: }
3952: }
3953: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3954: if (ref($idrules) eq 'HASH') {
3955: if (keys(%{$idrules}) > 0) {
3956: $datatable .= &user_formats_row('id',$settings,$idrules,
3957: $idruleorder,$numinrow,$rowcount);
3958: $$rowtotal ++;
3959: $rowcount ++;
1.28 raeburn 3960: }
3961: }
1.39 raeburn 3962: if ($rowcount == 0) {
3963: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3964: $$rowtotal ++;
3965: $rowcount ++;
3966: }
1.34 raeburn 3967: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3968: my @creators = ('author','course','requestcrs');
1.37 raeburn 3969: my ($rules,$ruleorder) =
3970: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3971: my %lt = &usercreation_types();
3972: my %checked;
3973: if (ref($settings) eq 'HASH') {
3974: if (ref($settings->{'cancreate'}) eq 'HASH') {
3975: foreach my $item (@creators) {
3976: $checked{$item} = $settings->{'cancreate'}{$item};
3977: }
3978: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3979: foreach my $item (@creators) {
3980: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3981: $checked{$item} = 'none';
3982: }
3983: }
3984: }
3985: }
3986: my $rownum = 0;
3987: foreach my $item (@creators) {
3988: $rownum ++;
1.160.6.34 raeburn 3989: if ($checked{$item} eq '') {
3990: $checked{$item} = 'any';
1.34 raeburn 3991: }
3992: my $css_class;
3993: if ($rownum%2) {
3994: $css_class = '';
3995: } else {
3996: $css_class = ' class="LC_odd_row" ';
3997: }
3998: $datatable .= '<tr'.$css_class.'>'.
3999: '<td><span class="LC_nobreak">'.$lt{$item}.
4000: '</span></td><td align="right">';
1.160.6.34 raeburn 4001: my @options = ('any');
4002: if (ref($rules) eq 'HASH') {
4003: if (keys(%{$rules}) > 0) {
4004: push(@options,('official','unofficial'));
1.37 raeburn 4005: }
4006: }
1.160.6.34 raeburn 4007: push(@options,'none');
1.37 raeburn 4008: foreach my $option (@options) {
1.50 raeburn 4009: my $type = 'radio';
1.34 raeburn 4010: my $check = ' ';
1.160.6.34 raeburn 4011: if ($checked{$item} eq $option) {
4012: $check = ' checked="checked" ';
1.34 raeburn 4013: }
4014: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4015: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4016: $item.'" value="'.$option.'"'.$check.'/> '.
4017: $lt{$option}.'</label> </span>';
4018: }
4019: $datatable .= '</td></tr>';
4020: }
1.28 raeburn 4021: } else {
4022: my @contexts = ('author','course','domain');
4023: my @authtypes = ('int','krb4','krb5','loc');
4024: my %checked;
4025: if (ref($settings) eq 'HASH') {
4026: if (ref($settings->{'authtypes'}) eq 'HASH') {
4027: foreach my $item (@contexts) {
4028: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4029: foreach my $auth (@authtypes) {
4030: if ($settings->{'authtypes'}{$item}{$auth}) {
4031: $checked{$item}{$auth} = ' checked="checked" ';
4032: }
4033: }
4034: }
4035: }
1.27 raeburn 4036: }
1.35 raeburn 4037: } else {
4038: foreach my $item (@contexts) {
1.36 raeburn 4039: foreach my $auth (@authtypes) {
1.35 raeburn 4040: $checked{$item}{$auth} = ' checked="checked" ';
4041: }
4042: }
1.27 raeburn 4043: }
1.28 raeburn 4044: my %title = &context_names();
4045: my %authname = &authtype_names();
4046: my $rownum = 0;
4047: my $css_class;
4048: foreach my $item (@contexts) {
4049: if ($rownum%2) {
4050: $css_class = '';
4051: } else {
4052: $css_class = ' class="LC_odd_row" ';
4053: }
1.30 raeburn 4054: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4055: '<td>'.$title{$item}.
4056: '</td><td class="LC_left_item">'.
4057: '<span class="LC_nobreak">';
4058: foreach my $auth (@authtypes) {
4059: $datatable .= '<label>'.
4060: '<input type="checkbox" name="'.$item.'_auth" '.
4061: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4062: $authname{$auth}.'</label> ';
4063: }
4064: $datatable .= '</span></td></tr>';
4065: $rownum ++;
1.27 raeburn 4066: }
1.30 raeburn 4067: $$rowtotal += $rownum;
1.27 raeburn 4068: }
4069: return $datatable;
4070: }
4071:
1.160.6.34 raeburn 4072: sub print_selfcreation {
4073: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4074: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4075: if (ref($settings) eq 'HASH') {
4076: if (ref($settings->{'cancreate'}) eq 'HASH') {
4077: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4078: if (ref($createsettings) eq 'HASH') {
4079: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4080: @selfcreate = @{$createsettings->{'selfcreate'}};
4081: } elsif ($createsettings->{'selfcreate'} ne '') {
4082: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4083: @selfcreate = ('email','login','sso');
4084: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4085: @selfcreate = ($createsettings->{'selfcreate'});
4086: }
4087: }
4088: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4089: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4090: }
4091: }
4092: }
4093: }
4094: my %radiohash;
4095: my $numinrow = 4;
4096: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4097: if ($position eq 'top') {
4098: my %choices = &Apache::lonlocal::texthash (
4099: cancreate_login => 'Institutional Login',
4100: cancreate_sso => 'Institutional Single Sign On',
4101: );
4102: my @toggles = sort(keys(%choices));
4103: my %defaultchecked = (
4104: 'cancreate_login' => 'off',
4105: 'cancreate_sso' => 'off',
4106: );
1.160.6.35 raeburn 4107: my ($onclick,$itemcount);
1.160.6.34 raeburn 4108: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4109: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4110: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4111:
1.160.6.34 raeburn 4112: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4113:
4114: if (ref($usertypes) eq 'HASH') {
4115: if (keys(%{$usertypes}) > 0) {
4116: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4117: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4118: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4119: $$rowtotal ++;
4120: }
4121: }
1.160.6.44 raeburn 4122: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4123: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4124: $fieldtitles{'inststatus'} = &mt('Institutional status');
4125: my $rem;
4126: my $numperrow = 2;
4127: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4128: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4129: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4130: '<td class="LC_left_item">'."\n".
4131: '<table><tr><td>'."\n";
4132: for (my $i=0; $i<@fields; $i++) {
4133: $rem = $i%($numperrow);
4134: if ($rem == 0) {
4135: if ($i > 0) {
4136: $datatable .= '</tr>';
4137: }
4138: $datatable .= '<tr>';
4139: }
4140: my $currval;
4141: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4142: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4143: }
4144: $datatable .= '<td class="LC_left_item">'.
4145: '<span class="LC_nobreak">'.
4146: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4147: 'value="'.$currval.'" size="10" /> '.
4148: $fieldtitles{$fields[$i]}.'</span></td>';
4149: }
4150: my $colsleft = $numperrow - $rem;
4151: if ($colsleft > 1 ) {
4152: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4153: ' </td>';
4154: } elsif ($colsleft == 1) {
4155: $datatable .= '<td class="LC_left_item"> </td>';
4156: }
4157: $datatable .= '</tr></table></td></tr>';
4158: $$rowtotal ++;
1.160.6.34 raeburn 4159: } elsif ($position eq 'middle') {
4160: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4161: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4162: $usertypes->{'default'} = $othertitle;
4163: if (ref($types) eq 'ARRAY') {
4164: push(@{$types},'default');
4165: $usertypes->{'default'} = $othertitle;
4166: foreach my $status (@{$types}) {
4167: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4168: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4169: $$rowtotal ++;
1.160.6.34 raeburn 4170: }
4171: }
4172: } else {
1.160.6.40 raeburn 4173: my %choices = &Apache::lonlocal::texthash (
4174: cancreate_email => 'E-mail address as username',
4175: );
4176: my @toggles = sort(keys(%choices));
4177: my %defaultchecked = (
4178: 'cancreate_email' => 'off',
4179: );
4180: my $itemcount = 0;
4181: my $display = 'none';
4182: if (grep(/^\Qemail\E$/,@selfcreate)) {
4183: $display = 'block';
4184: }
4185: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4186: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4187: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4188: my $usertypes = {};
4189: my $order = [];
4190: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4191: $usertypes = $domdefaults{'inststatustypes'};
4192: $order = $domdefaults{'inststatusguest'};
4193: }
4194: if (ref($order) eq 'ARRAY') {
4195: push(@{$order},'default');
4196: if (@{$order} > 1) {
4197: $usertypes->{'default'} = &mt('Other users');
4198: $additional .= '<table><tr>';
4199: foreach my $status (@{$order}) {
4200: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4201: }
4202: $additional .= '</tr><tr>';
4203: foreach my $status (@{$order}) {
4204: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4205: }
1.160.6.40 raeburn 4206: $additional .= '</tr></table>';
1.160.6.34 raeburn 4207: } else {
1.160.6.40 raeburn 4208: $usertypes->{'default'} = &mt('All users');
4209: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4210: }
4211: }
1.160.6.40 raeburn 4212: $additional .= '</div>'."\n";
4213:
4214: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4215: \%choices,$$rowtotal,$onclick,$additional);
4216: $$rowtotal ++;
1.160.6.40 raeburn 4217: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4218: $$rowtotal ++;
1.160.6.35 raeburn 4219: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4220: $numinrow = 1;
1.160.6.40 raeburn 4221: if (ref($order) eq 'ARRAY') {
4222: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4223: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4224: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4225: $$rowtotal ++;
4226: }
4227: }
1.160.6.34 raeburn 4228: my ($emailrules,$emailruleorder) =
4229: &Apache::lonnet::inst_userrules($dom,'email');
4230: if (ref($emailrules) eq 'HASH') {
4231: if (keys(%{$emailrules}) > 0) {
4232: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4233: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4234: $$rowtotal ++;
4235: }
4236: }
1.160.6.35 raeburn 4237: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4238: }
4239: return $datatable;
4240: }
4241:
1.160.6.40 raeburn 4242: sub email_as_username {
4243: my ($rowtotal,$processing,$type) = @_;
4244: my %choices =
4245: &Apache::lonlocal::texthash (
4246: automatic => 'Automatic approval',
4247: approval => 'Queued for approval',
4248: );
4249: my $output;
4250: foreach my $option ('automatic','approval') {
4251: my $checked;
4252: if (ref($processing) eq 'HASH') {
4253: if ($type eq '') {
4254: if (!exists($processing->{'default'})) {
4255: if ($option eq 'automatic') {
4256: $checked = ' checked="checked"';
4257: }
4258: } else {
4259: if ($processing->{'default'} eq $option) {
4260: $checked = ' checked="checked"';
4261: }
4262: }
4263: } else {
4264: if (!exists($processing->{$type})) {
4265: if ($option eq 'automatic') {
4266: $checked = ' checked="checked"';
4267: }
4268: } else {
4269: if ($processing->{$type} eq $option) {
4270: $checked = ' checked="checked"';
4271: }
4272: }
4273: }
4274: } elsif ($option eq 'automatic') {
4275: $checked = ' checked="checked"';
4276: }
4277: my $name = 'cancreate_emailprocess';
4278: if (($type ne '') && ($type ne 'default')) {
4279: $name .= '_'.$type;
4280: }
4281: $output .= '<span class="LC_nobreak"><label>'.
4282: '<input type="radio" name="'.$name.'"'.
4283: $checked.' value="'.$option.'" />'.
4284: $choices{$option}.'</label></span>';
4285: if ($type eq '') {
4286: $output .= ' ';
4287: } else {
4288: $output .= '<br />';
4289: }
4290: }
4291: $$rowtotal ++;
4292: return $output;
4293: }
4294:
1.160.6.5 raeburn 4295: sub captcha_choice {
4296: my ($context,$settings,$itemcount) = @_;
4297: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4298: my %lt = &captcha_phrases();
4299: $keyentry = 'hidden';
4300: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4301: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4302: } elsif ($context eq 'login') {
4303: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4304: }
4305: if (ref($settings) eq 'HASH') {
4306: if ($settings->{'captcha'}) {
4307: $checked{$settings->{'captcha'}} = ' checked="checked"';
4308: } else {
4309: $checked{'original'} = ' checked="checked"';
4310: }
4311: if ($settings->{'captcha'} eq 'recaptcha') {
4312: $pubtext = $lt{'pub'};
4313: $privtext = $lt{'priv'};
4314: $keyentry = 'text';
4315: }
4316: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4317: $currpub = $settings->{'recaptchakeys'}{'public'};
4318: $currpriv = $settings->{'recaptchakeys'}{'private'};
4319: }
4320: } else {
4321: $checked{'original'} = ' checked="checked"';
4322: }
4323: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4324: my $output = '<tr'.$css_class.'>'.
4325: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4326: '<table><tr><td>'."\n";
4327: foreach my $option ('original','recaptcha','notused') {
4328: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4329: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4330: $lt{$option}.'</label></span>';
4331: unless ($option eq 'notused') {
4332: $output .= (' 'x2)."\n";
4333: }
4334: }
4335: #
4336: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4337: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4338: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4339: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4340: #
4341: $output .= '</td></tr>'."\n".
4342: '<tr><td>'."\n".
4343: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4344: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4345: $currpub.'" size="40" /></span><br />'."\n".
4346: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4347: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4348: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4349: '</td></tr>';
4350: return $output;
4351: }
4352:
1.32 raeburn 4353: sub user_formats_row {
4354: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4355: my $output;
4356: my %text = (
4357: 'username' => 'new usernames',
4358: 'id' => 'IDs',
1.45 raeburn 4359: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4360: );
4361: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4362: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4363: '<td><span class="LC_nobreak">';
4364: if ($type eq 'email') {
4365: $output .= &mt("Formats disallowed for $text{$type}: ");
4366: } else {
4367: $output .= &mt("Format rules to check for $text{$type}: ");
4368: }
4369: $output .= '</span></td>'.
4370: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4371: my $rem;
4372: if (ref($ruleorder) eq 'ARRAY') {
4373: for (my $i=0; $i<@{$ruleorder}; $i++) {
4374: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4375: my $rem = $i%($numinrow);
4376: if ($rem == 0) {
4377: if ($i > 0) {
4378: $output .= '</tr>';
4379: }
4380: $output .= '<tr>';
4381: }
4382: my $check = ' ';
1.39 raeburn 4383: if (ref($settings) eq 'HASH') {
4384: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4385: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4386: $check = ' checked="checked" ';
4387: }
1.27 raeburn 4388: }
4389: }
4390: $output .= '<td class="LC_left_item">'.
4391: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4392: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4393: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4394: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4395: }
4396: }
4397: $rem = @{$ruleorder}%($numinrow);
4398: }
4399: my $colsleft = $numinrow - $rem;
4400: if ($colsleft > 1 ) {
4401: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4402: ' </td>';
4403: } elsif ($colsleft == 1) {
4404: $output .= '<td class="LC_left_item"> </td>';
4405: }
4406: $output .= '</tr></table></td></tr>';
4407: return $output;
4408: }
4409:
1.34 raeburn 4410: sub usercreation_types {
4411: my %lt = &Apache::lonlocal::texthash (
4412: author => 'When adding a co-author',
4413: course => 'When adding a user to a course',
1.100 raeburn 4414: requestcrs => 'When requesting a course',
1.34 raeburn 4415: any => 'Any',
4416: official => 'Institutional only ',
4417: unofficial => 'Non-institutional only',
4418: none => 'None',
4419: );
4420: return %lt;
1.48 raeburn 4421: }
1.34 raeburn 4422:
1.160.6.34 raeburn 4423: sub selfcreation_types {
4424: my %lt = &Apache::lonlocal::texthash (
4425: selfcreate => 'User creates own account',
4426: any => 'Any',
4427: official => 'Institutional only ',
4428: unofficial => 'Non-institutional only',
4429: email => 'E-mail address',
4430: login => 'Institutional Login',
4431: sso => 'SSO',
4432: );
4433: }
4434:
1.28 raeburn 4435: sub authtype_names {
4436: my %lt = &Apache::lonlocal::texthash(
4437: int => 'Internal',
4438: krb4 => 'Kerberos 4',
4439: krb5 => 'Kerberos 5',
4440: loc => 'Local',
4441: );
4442: return %lt;
4443: }
4444:
4445: sub context_names {
4446: my %context_title = &Apache::lonlocal::texthash(
4447: author => 'Creating users when an Author',
4448: course => 'Creating users when in a course',
4449: domain => 'Creating users when a Domain Coordinator',
4450: );
4451: return %context_title;
4452: }
4453:
1.33 raeburn 4454: sub print_usermodification {
4455: my ($position,$dom,$settings,$rowtotal) = @_;
4456: my $numinrow = 4;
4457: my ($context,$datatable,$rowcount);
4458: if ($position eq 'top') {
4459: $rowcount = 0;
4460: $context = 'author';
4461: foreach my $role ('ca','aa') {
4462: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4463: $numinrow,$rowcount);
4464: $$rowtotal ++;
4465: $rowcount ++;
4466: }
1.160.6.37 raeburn 4467: } elsif ($position eq 'bottom') {
1.33 raeburn 4468: $context = 'course';
4469: $rowcount = 0;
4470: foreach my $role ('st','ep','ta','in','cr') {
4471: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4472: $numinrow,$rowcount);
4473: $$rowtotal ++;
4474: $rowcount ++;
4475: }
4476: }
4477: return $datatable;
4478: }
4479:
1.43 raeburn 4480: sub print_defaults {
1.160.6.40 raeburn 4481: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4482: my $rownum = 0;
4483: my ($datatable,$css_class);
1.160.6.40 raeburn 4484: if ($position eq 'top') {
4485: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4486: 'datelocale_def','portal_def');
4487: my %defaults;
4488: if (ref($settings) eq 'HASH') {
4489: %defaults = %{$settings};
1.43 raeburn 4490: } else {
1.160.6.40 raeburn 4491: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4492: foreach my $item (@items) {
4493: $defaults{$item} = $domdefaults{$item};
4494: }
1.43 raeburn 4495: }
1.160.6.40 raeburn 4496: my $titles = &defaults_titles($dom);
4497: foreach my $item (@items) {
4498: if ($rownum%2) {
4499: $css_class = '';
4500: } else {
4501: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4502: }
1.160.6.40 raeburn 4503: $datatable .= '<tr'.$css_class.'>'.
4504: '<td><span class="LC_nobreak">'.$titles->{$item}.
4505: '</span></td><td class="LC_right_item" colspan="3">';
4506: if ($item eq 'auth_def') {
4507: my @authtypes = ('internal','krb4','krb5','localauth');
4508: my %shortauth = (
4509: internal => 'int',
4510: krb4 => 'krb4',
4511: krb5 => 'krb5',
4512: localauth => 'loc'
4513: );
4514: my %authnames = &authtype_names();
4515: foreach my $auth (@authtypes) {
4516: my $checked = ' ';
4517: if ($defaults{$item} eq $auth) {
4518: $checked = ' checked="checked" ';
4519: }
4520: $datatable .= '<label><input type="radio" name="'.$item.
4521: '" value="'.$auth.'"'.$checked.'/>'.
4522: $authnames{$shortauth{$auth}}.'</label> ';
4523: }
4524: } elsif ($item eq 'timezone_def') {
4525: my $includeempty = 1;
4526: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4527: } elsif ($item eq 'datelocale_def') {
4528: my $includeempty = 1;
4529: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4530: } elsif ($item eq 'lang_def') {
4531: my %langchoices = &get_languages_hash();
4532: $langchoices{''} = 'No language preference';
4533: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4534: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4535: \%langchoices);
4536: } else {
4537: my $size;
4538: if ($item eq 'portal_def') {
4539: $size = ' size="25"';
4540: }
4541: $datatable .= '<input type="text" name="'.$item.'" value="'.
4542: $defaults{$item}.'"'.$size.' />';
4543: }
4544: $datatable .= '</td></tr>';
4545: $rownum ++;
4546: }
4547: } else {
4548: my (%defaults);
4549: if (ref($settings) eq 'HASH') {
4550: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4551: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4552: my $maxnum = @{$settings->{'inststatusorder'}};
4553: for (my $i=0; $i<$maxnum; $i++) {
4554: $css_class = $rownum%2?' class="LC_odd_row"':'';
4555: my $item = $settings->{'inststatusorder'}->[$i];
4556: my $title = $settings->{'inststatustypes'}->{$item};
4557: my $guestok;
4558: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4559: $guestok = 1;
4560: }
4561: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4562: $datatable .= '<tr'.$css_class.'>'.
4563: '<td><span class="LC_nobreak">'.
4564: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4565: for (my $k=0; $k<=$maxnum; $k++) {
4566: my $vpos = $k+1;
4567: my $selstr;
4568: if ($k == $i) {
4569: $selstr = ' selected="selected" ';
4570: }
4571: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4572: }
4573: my ($checkedon,$checkedoff);
4574: $checkedoff = ' checked="checked"';
4575: if ($guestok) {
4576: $checkedon = $checkedoff;
4577: $checkedoff = '';
4578: }
4579: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4580: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4581: &mt('delete').'</span></td>'.
4582: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4583: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4584: '</span></td>'.
4585: '<td class="LC_right_item"><span class="LC_nobreak">'.
4586: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4587: &mt('Yes').'</label>'.(' 'x2).
4588: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4589: &mt('No').'</label></span></td></tr>';
4590: }
4591: $css_class = $rownum%2?' class="LC_odd_row"':'';
4592: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4593: $datatable .= '<tr '.$css_class.'>'.
4594: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4595: for (my $k=0; $k<=$maxnum; $k++) {
4596: my $vpos = $k+1;
4597: my $selstr;
4598: if ($k == $maxnum) {
4599: $selstr = ' selected="selected" ';
4600: }
4601: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4602: }
4603: $datatable .= '</select> '.&mt('Internal ID:').
4604: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4605: ' '.&mt('(new)').
4606: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4607: &mt('Name displayed:').
4608: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4609: '<td class="LC_right_item"><span class="LC_nobreak">'.
4610: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4611: &mt('Yes').'</label>'.(' 'x2).
4612: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4613: &mt('No').'</label></span></td></tr>';
4614: '</tr>'."\n";
4615: $rownum ++;
1.141 raeburn 4616: }
1.43 raeburn 4617: }
4618: }
4619: $$rowtotal += $rownum;
4620: return $datatable;
4621: }
4622:
1.160.6.5 raeburn 4623: sub get_languages_hash {
4624: my %langchoices;
4625: foreach my $id (&Apache::loncommon::languageids()) {
4626: my $code = &Apache::loncommon::supportedlanguagecode($id);
4627: if ($code ne '') {
4628: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4629: }
4630: }
4631: return %langchoices;
4632: }
4633:
1.43 raeburn 4634: sub defaults_titles {
1.141 raeburn 4635: my ($dom) = @_;
1.43 raeburn 4636: my %titles = &Apache::lonlocal::texthash (
4637: 'auth_def' => 'Default authentication type',
4638: 'auth_arg_def' => 'Default authentication argument',
4639: 'lang_def' => 'Default language',
1.54 raeburn 4640: 'timezone_def' => 'Default timezone',
1.68 raeburn 4641: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4642: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4643: );
1.141 raeburn 4644: if ($dom) {
4645: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4646: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4647: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4648: $protocol = 'http' if ($protocol ne 'https');
4649: if ($uint_dom) {
4650: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4651: $uint_dom);
4652: }
4653: }
1.43 raeburn 4654: return (\%titles);
4655: }
4656:
1.46 raeburn 4657: sub print_scantronformat {
4658: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4659: my $itemcount = 1;
1.60 raeburn 4660: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4661: %confhash);
1.46 raeburn 4662: my $switchserver = &check_switchserver($dom,$confname);
4663: my %lt = &Apache::lonlocal::texthash (
1.95 www 4664: default => 'Default bubblesheet format file error',
4665: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4666: );
4667: my %scantronfiles = (
4668: default => 'default.tab',
4669: custom => 'custom.tab',
4670: );
4671: foreach my $key (keys(%scantronfiles)) {
4672: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4673: .$scantronfiles{$key};
4674: }
4675: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4676: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4677: if (!$switchserver) {
4678: my $servadm = $r->dir_config('lonAdmEMail');
4679: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4680: if ($configuserok eq 'ok') {
4681: if ($author_ok eq 'ok') {
4682: my %legacyfile = (
4683: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4684: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4685: );
4686: my %md5chk;
4687: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4688: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4689: chomp($md5chk{$type});
1.46 raeburn 4690: }
4691: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4692: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4693: ($scantronurls{$type},my $error) =
1.46 raeburn 4694: &legacy_scantronformat($r,$dom,$confname,
4695: $type,$legacyfile{$type},
4696: $scantronurls{$type},
4697: $scantronfiles{$type});
1.60 raeburn 4698: if ($error ne '') {
4699: $error{$type} = $error;
4700: }
4701: }
4702: if (keys(%error) == 0) {
4703: $is_custom = 1;
4704: $confhash{'scantron'}{'scantronformat'} =
4705: $scantronurls{'custom'};
4706: my $putresult =
4707: &Apache::lonnet::put_dom('configuration',
4708: \%confhash,$dom);
4709: if ($putresult ne 'ok') {
4710: $error{'custom'} =
4711: '<span class="LC_error">'.
4712: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4713: }
1.46 raeburn 4714: }
4715: } else {
1.60 raeburn 4716: ($scantronurls{'default'},my $error) =
1.46 raeburn 4717: &legacy_scantronformat($r,$dom,$confname,
4718: 'default',$legacyfile{'default'},
4719: $scantronurls{'default'},
4720: $scantronfiles{'default'});
1.60 raeburn 4721: if ($error eq '') {
4722: $confhash{'scantron'}{'scantronformat'} = '';
4723: my $putresult =
4724: &Apache::lonnet::put_dom('configuration',
4725: \%confhash,$dom);
4726: if ($putresult ne 'ok') {
4727: $error{'default'} =
4728: '<span class="LC_error">'.
4729: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4730: }
4731: } else {
4732: $error{'default'} = $error;
4733: }
1.46 raeburn 4734: }
4735: }
4736: }
4737: } else {
1.95 www 4738: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4739: }
4740: }
4741: if (ref($settings) eq 'HASH') {
4742: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4743: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4744: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4745: $scantronurl = '';
4746: } else {
4747: $scantronurl = $settings->{'scantronformat'};
4748: }
4749: $is_custom = 1;
4750: } else {
4751: $scantronurl = $scantronurls{'default'};
4752: }
4753: } else {
1.60 raeburn 4754: if ($is_custom) {
4755: $scantronurl = $scantronurls{'custom'};
4756: } else {
4757: $scantronurl = $scantronurls{'default'};
4758: }
1.46 raeburn 4759: }
4760: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4761: $datatable .= '<tr'.$css_class.'>';
4762: if (!$is_custom) {
1.65 raeburn 4763: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4764: '<span class="LC_nobreak">';
1.46 raeburn 4765: if ($scantronurl) {
1.160.6.21 raeburn 4766: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4767: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4768: } else {
4769: $datatable = &mt('File unavailable for display');
4770: }
1.65 raeburn 4771: $datatable .= '</span></td>';
1.60 raeburn 4772: if (keys(%error) == 0) {
4773: $datatable .= '<td valign="bottom">';
4774: if (!$switchserver) {
4775: $datatable .= &mt('Upload:').'<br />';
4776: }
4777: } else {
4778: my $errorstr;
4779: foreach my $key (sort(keys(%error))) {
4780: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4781: }
4782: $datatable .= '<td>'.$errorstr;
4783: }
1.46 raeburn 4784: } else {
4785: if (keys(%error) > 0) {
4786: my $errorstr;
4787: foreach my $key (sort(keys(%error))) {
4788: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4789: }
1.60 raeburn 4790: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4791: } elsif ($scantronurl) {
1.160.6.26 raeburn 4792: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4793: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4794: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4795: $link.
4796: '<label><input type="checkbox" name="scantronformat_del"'.
4797: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4798: '<td><span class="LC_nobreak"> '.
4799: &mt('Replace:').'</span><br />';
1.46 raeburn 4800: }
4801: }
4802: if (keys(%error) == 0) {
4803: if ($switchserver) {
4804: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4805: } else {
1.65 raeburn 4806: $datatable .='<span class="LC_nobreak"> '.
4807: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4808: }
4809: }
4810: $datatable .= '</td></tr>';
4811: $$rowtotal ++;
4812: return $datatable;
4813: }
4814:
4815: sub legacy_scantronformat {
4816: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4817: my ($url,$error);
4818: my @statinfo = &Apache::lonnet::stat_file($newurl);
4819: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4820: (my $result,$url) =
4821: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4822: '','',$newfile);
4823: if ($result ne 'ok') {
1.130 raeburn 4824: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4825: }
4826: }
4827: return ($url,$error);
4828: }
1.43 raeburn 4829:
1.49 raeburn 4830: sub print_coursecategories {
1.57 raeburn 4831: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4832: my $datatable;
4833: if ($position eq 'top') {
1.160.6.42 raeburn 4834: my (%checked);
4835: my @catitems = ('unauth','auth');
4836: my @cattypes = ('std','domonly','codesrch','none');
4837: $checked{'unauth'} = 'std';
4838: $checked{'auth'} = 'std';
4839: if (ref($settings) eq 'HASH') {
4840: foreach my $type (@cattypes) {
4841: if ($type eq $settings->{'unauth'}) {
4842: $checked{'unauth'} = $type;
4843: }
4844: if ($type eq $settings->{'auth'}) {
4845: $checked{'auth'} = $type;
4846: }
4847: }
4848: }
4849: my %lt = &Apache::lonlocal::texthash (
4850: unauth => 'Catalog type for unauthenticated users',
4851: auth => 'Catalog type for authenticated users',
4852: none => 'No catalog',
4853: std => 'Standard catalog',
4854: domonly => 'Domain-only catalog',
4855: codesrch => "Code search form",
4856: );
4857: my $itemcount = 0;
4858: foreach my $item (@catitems) {
4859: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4860: $datatable .= '<tr '.$css_class.'>'.
4861: '<td>'.$lt{$item}.'</td>'.
4862: '<td class="LC_right_item"><span class="LC_nobreak">';
4863: foreach my $type (@cattypes) {
4864: my $ischecked;
4865: if ($checked{$item} eq $type) {
4866: $ischecked=' checked="checked"';
4867: }
4868: $datatable .= '<label>'.
4869: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4870: ' />'.$lt{$type}.'</label> ';
4871: }
4872: $datatable .= '</td></tr>';
4873: $itemcount ++;
4874: }
4875: $$rowtotal += $itemcount;
4876: } elsif ($position eq 'middle') {
1.57 raeburn 4877: my $toggle_cats_crs = ' ';
4878: my $toggle_cats_dom = ' checked="checked" ';
4879: my $can_cat_crs = ' ';
4880: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4881: my $toggle_catscomm_comm = ' ';
4882: my $toggle_catscomm_dom = ' checked="checked" ';
4883: my $can_catcomm_comm = ' ';
4884: my $can_catcomm_dom = ' checked="checked" ';
4885:
1.57 raeburn 4886: if (ref($settings) eq 'HASH') {
4887: if ($settings->{'togglecats'} eq 'crs') {
4888: $toggle_cats_crs = $toggle_cats_dom;
4889: $toggle_cats_dom = ' ';
4890: }
4891: if ($settings->{'categorize'} eq 'crs') {
4892: $can_cat_crs = $can_cat_dom;
4893: $can_cat_dom = ' ';
4894: }
1.120 raeburn 4895: if ($settings->{'togglecatscomm'} eq 'comm') {
4896: $toggle_catscomm_comm = $toggle_catscomm_dom;
4897: $toggle_catscomm_dom = ' ';
4898: }
4899: if ($settings->{'categorizecomm'} eq 'comm') {
4900: $can_catcomm_comm = $can_catcomm_dom;
4901: $can_catcomm_dom = ' ';
4902: }
1.57 raeburn 4903: }
4904: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4905: togglecats => 'Show/Hide a course in catalog',
4906: togglecatscomm => 'Show/Hide a community in catalog',
4907: categorize => 'Assign a category to a course',
4908: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4909: );
4910: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4911: dom => 'Set in Domain',
4912: crs => 'Set in Course',
4913: comm => 'Set in Community',
1.57 raeburn 4914: );
4915: $datatable = '<tr class="LC_odd_row">'.
4916: '<td>'.$title{'togglecats'}.'</td>'.
4917: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4918: '<input type="radio" name="togglecats"'.
4919: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4920: '<label><input type="radio" name="togglecats"'.
4921: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4922: '</tr><tr>'.
4923: '<td>'.$title{'categorize'}.'</td>'.
4924: '<td class="LC_right_item"><span class="LC_nobreak">'.
4925: '<label><input type="radio" name="categorize"'.
4926: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4927: '<label><input type="radio" name="categorize"'.
4928: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4929: '</tr><tr class="LC_odd_row">'.
4930: '<td>'.$title{'togglecatscomm'}.'</td>'.
4931: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4932: '<input type="radio" name="togglecatscomm"'.
4933: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4934: '<label><input type="radio" name="togglecatscomm"'.
4935: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4936: '</tr><tr>'.
4937: '<td>'.$title{'categorizecomm'}.'</td>'.
4938: '<td class="LC_right_item"><span class="LC_nobreak">'.
4939: '<label><input type="radio" name="categorizecomm"'.
4940: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4941: '<label><input type="radio" name="categorizecomm"'.
4942: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4943: '</tr>';
1.120 raeburn 4944: $$rowtotal += 4;
1.57 raeburn 4945: } else {
4946: my $css_class;
4947: my $itemcount = 1;
4948: my $cathash;
4949: if (ref($settings) eq 'HASH') {
4950: $cathash = $settings->{'cats'};
4951: }
4952: if (ref($cathash) eq 'HASH') {
4953: my (@cats,@trails,%allitems,%idx,@jsarray);
4954: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4955: \%allitems,\%idx,\@jsarray);
4956: my $maxdepth = scalar(@cats);
4957: my $colattrib = '';
4958: if ($maxdepth > 2) {
4959: $colattrib = ' colspan="2" ';
4960: }
4961: my @path;
4962: if (@cats > 0) {
4963: if (ref($cats[0]) eq 'ARRAY') {
4964: my $numtop = @{$cats[0]};
4965: my $maxnum = $numtop;
1.120 raeburn 4966: my %default_names = (
4967: instcode => &mt('Official courses'),
4968: communities => &mt('Communities'),
4969: );
4970:
4971: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4972: ($cathash->{'instcode::0'} eq '') ||
4973: (!grep(/^communities$/,@{$cats[0]})) ||
4974: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4975: $maxnum ++;
4976: }
4977: my $lastidx;
4978: for (my $i=0; $i<$numtop; $i++) {
4979: my $parent = $cats[0][$i];
4980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4981: my $item = &escape($parent).'::0';
4982: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4983: $lastidx = $idx{$item};
4984: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4985: .'<select name="'.$item.'"'.$chgstr.'>';
4986: for (my $k=0; $k<=$maxnum; $k++) {
4987: my $vpos = $k+1;
4988: my $selstr;
4989: if ($k == $i) {
4990: $selstr = ' selected="selected" ';
4991: }
4992: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4993: }
1.160.6.29 raeburn 4994: $datatable .= '</select></span></td><td>';
1.120 raeburn 4995: if ($parent eq 'instcode' || $parent eq 'communities') {
4996: $datatable .= '<span class="LC_nobreak">'
4997: .$default_names{$parent}.'</span>';
4998: if ($parent eq 'instcode') {
4999: $datatable .= '<br /><span class="LC_nobreak">('
5000: .&mt('with institutional codes')
5001: .')</span></td><td'.$colattrib.'>';
5002: } else {
5003: $datatable .= '<table><tr><td>';
5004: }
5005: $datatable .= '<span class="LC_nobreak">'
5006: .'<label><input type="radio" name="'
5007: .$parent.'" value="1" checked="checked" />'
5008: .&mt('Display').'</label>';
5009: if ($parent eq 'instcode') {
5010: $datatable .= ' ';
5011: } else {
5012: $datatable .= '</span></td></tr><tr><td>'
5013: .'<span class="LC_nobreak">';
5014: }
5015: $datatable .= '<label><input type="radio" name="'
5016: .$parent.'" value="0" />'
5017: .&mt('Do not display').'</label></span>';
5018: if ($parent eq 'communities') {
5019: $datatable .= '</td></tr></table>';
5020: }
5021: $datatable .= '</td>';
1.57 raeburn 5022: } else {
5023: $datatable .= $parent
1.160.6.29 raeburn 5024: .' <span class="LC_nobreak"><label>'
5025: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5026: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5027: }
5028: my $depth = 1;
5029: push(@path,$parent);
5030: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5031: pop(@path);
5032: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5033: $itemcount ++;
5034: }
1.48 raeburn 5035: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5036: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5037: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5038: for (my $k=0; $k<=$maxnum; $k++) {
5039: my $vpos = $k+1;
5040: my $selstr;
1.57 raeburn 5041: if ($k == $numtop) {
1.48 raeburn 5042: $selstr = ' selected="selected" ';
5043: }
5044: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5045: }
1.59 bisitz 5046: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5047: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5048: .'</tr>'."\n";
1.48 raeburn 5049: $itemcount ++;
1.120 raeburn 5050: foreach my $default ('instcode','communities') {
5051: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5052: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5053: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5054: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5055: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5056: for (my $k=0; $k<=$maxnum; $k++) {
5057: my $vpos = $k+1;
5058: my $selstr;
5059: if ($k == $maxnum) {
5060: $selstr = ' selected="selected" ';
5061: }
5062: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5063: }
1.120 raeburn 5064: $datatable .= '</select></span></td>'.
5065: '<td><span class="LC_nobreak">'.
5066: $default_names{$default}.'</span>';
5067: if ($default eq 'instcode') {
5068: $datatable .= '<br /><span class="LC_nobreak">('
5069: .&mt('with institutional codes').')</span>';
5070: }
5071: $datatable .= '</td>'
5072: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5073: .&mt('Display').'</label> '
5074: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5075: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5076: }
5077: }
5078: }
1.57 raeburn 5079: } else {
5080: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5081: }
5082: } else {
1.160.6.42 raeburn 5083: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5084: .&initialize_categories($itemcount);
1.48 raeburn 5085: }
1.57 raeburn 5086: $$rowtotal += $itemcount;
1.48 raeburn 5087: }
5088: return $datatable;
5089: }
5090:
1.69 raeburn 5091: sub print_serverstatuses {
5092: my ($dom,$settings,$rowtotal) = @_;
5093: my $datatable;
5094: my @pages = &serverstatus_pages();
5095: my (%namedaccess,%machineaccess);
5096: foreach my $type (@pages) {
5097: $namedaccess{$type} = '';
5098: $machineaccess{$type}= '';
5099: }
5100: if (ref($settings) eq 'HASH') {
5101: foreach my $type (@pages) {
5102: if (exists($settings->{$type})) {
5103: if (ref($settings->{$type}) eq 'HASH') {
5104: foreach my $key (keys(%{$settings->{$type}})) {
5105: if ($key eq 'namedusers') {
5106: $namedaccess{$type} = $settings->{$type}->{$key};
5107: } elsif ($key eq 'machines') {
5108: $machineaccess{$type} = $settings->{$type}->{$key};
5109: }
5110: }
5111: }
5112: }
5113: }
5114: }
1.81 raeburn 5115: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5116: my $rownum = 0;
5117: my $css_class;
5118: foreach my $type (@pages) {
5119: $rownum ++;
5120: $css_class = $rownum%2?' class="LC_odd_row"':'';
5121: $datatable .= '<tr'.$css_class.'>'.
5122: '<td><span class="LC_nobreak">'.
5123: $titles->{$type}.'</span></td>'.
5124: '<td class="LC_left_item">'.
5125: '<input type="text" name="'.$type.'_namedusers" '.
5126: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5127: '<td class="LC_right_item">'.
5128: '<span class="LC_nobreak">'.
5129: '<input type="text" name="'.$type.'_machines" '.
5130: 'value="'.$machineaccess{$type}.'" size="10" />'.
5131: '</td></tr>'."\n";
5132: }
5133: $$rowtotal += $rownum;
5134: return $datatable;
5135: }
5136:
5137: sub serverstatus_pages {
5138: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5139: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5140: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5141: 'uniquecodes','diskusage');
1.69 raeburn 5142: }
5143:
1.160.6.40 raeburn 5144: sub defaults_javascript {
5145: my ($settings) = @_;
5146: my ($output,$jstext);
5147: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5148: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5149: if ($maxnum eq '') {
5150: $maxnum = 0;
5151: }
5152: $maxnum ++;
5153: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5154: return <<"ENDSCRIPT";
5155: <script type="text/javascript">
5156: // <![CDATA[
5157: function reorderTypes(form,caller) {
5158: var changedVal;
5159: $jstext
5160: var newpos = 'addinststatus_pos';
5161: var current = new Array;
5162: var maxh = $maxnum;
5163: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5164: var oldVal;
5165: if (caller == newpos) {
5166: changedVal = newitemVal;
5167: } else {
5168: var curritem = 'inststatus_pos_'+caller;
5169: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5170: current[newitemVal] = newpos;
5171: }
5172: for (var i=0; i<inststatuses.length; i++) {
5173: if (inststatuses[i] != caller) {
5174: var elementName = 'inststatus_pos_'+inststatuses[i];
5175: if (form.elements[elementName]) {
5176: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5177: current[currVal] = elementName;
5178: }
5179: }
5180: }
5181: for (var j=0; j<maxh; j++) {
5182: if (current[j] == undefined) {
5183: oldVal = j;
5184: }
5185: }
5186: if (oldVal < changedVal) {
5187: for (var k=oldVal+1; k<=changedVal ; k++) {
5188: var elementName = current[k];
5189: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5190: }
5191: } else {
5192: for (var k=changedVal; k<oldVal; k++) {
5193: var elementName = current[k];
5194: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5195: }
5196: }
5197: return;
5198: }
5199:
5200: // ]]>
5201: </script>
5202:
5203: ENDSCRIPT
5204: }
5205: }
5206:
1.49 raeburn 5207: sub coursecategories_javascript {
5208: my ($settings) = @_;
1.57 raeburn 5209: my ($output,$jstext,$cathash);
1.49 raeburn 5210: if (ref($settings) eq 'HASH') {
1.57 raeburn 5211: $cathash = $settings->{'cats'};
5212: }
5213: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5214: my (@cats,@jsarray,%idx);
1.57 raeburn 5215: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5216: if (@jsarray > 0) {
5217: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5218: for (my $i=0; $i<@jsarray; $i++) {
5219: if (ref($jsarray[$i]) eq 'ARRAY') {
5220: my $catstr = join('","',@{$jsarray[$i]});
5221: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5222: }
5223: }
5224: }
5225: } else {
5226: $jstext = ' var categories = Array(1);'."\n".
5227: ' categories[0] = Array("instcode_pos");'."\n";
5228: }
1.160.6.42 raeburn 5229: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5230: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5231: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5232: $output = <<"ENDSCRIPT";
5233: <script type="text/javascript">
1.109 raeburn 5234: // <![CDATA[
1.49 raeburn 5235: function reorderCats(form,parent,item,idx) {
5236: var changedVal;
5237: $jstext
5238: var newpos = 'addcategory_pos';
5239: if (parent == '') {
5240: var has_instcode = 0;
5241: var maxtop = categories[idx].length;
5242: for (var j=0; j<maxtop; j++) {
5243: if (categories[idx][j] == 'instcode::0') {
5244: has_instcode == 1;
5245: }
5246: }
5247: if (has_instcode == 0) {
5248: categories[idx][maxtop] = 'instcode_pos';
5249: }
5250: } else {
5251: newpos += '_'+parent;
5252: }
5253: var maxh = 1 + categories[idx].length;
5254: var current = new Array;
5255: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5256: if (item == newpos) {
5257: changedVal = newitemVal;
5258: } else {
5259: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5260: current[newitemVal] = newpos;
5261: }
5262: for (var i=0; i<categories[idx].length; i++) {
5263: var elementName = categories[idx][i];
5264: if (elementName != item) {
5265: if (form.elements[elementName]) {
5266: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5267: current[currVal] = elementName;
5268: }
5269: }
5270: }
5271: var oldVal;
5272: for (var j=0; j<maxh; j++) {
5273: if (current[j] == undefined) {
5274: oldVal = j;
5275: }
5276: }
5277: if (oldVal < changedVal) {
5278: for (var k=oldVal+1; k<=changedVal ; k++) {
5279: var elementName = current[k];
5280: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5281: }
5282: } else {
5283: for (var k=changedVal; k<oldVal; k++) {
5284: var elementName = current[k];
5285: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5286: }
5287: }
5288: return;
5289: }
1.120 raeburn 5290:
5291: function categoryCheck(form) {
5292: if (form.elements['addcategory_name'].value == 'instcode') {
5293: alert('$instcode_reserved\\n$choose_again');
5294: return false;
5295: }
5296: if (form.elements['addcategory_name'].value == 'communities') {
5297: alert('$communities_reserved\\n$choose_again');
5298: return false;
5299: }
5300: return true;
5301: }
5302:
1.109 raeburn 5303: // ]]>
1.49 raeburn 5304: </script>
5305:
5306: ENDSCRIPT
5307: return $output;
5308: }
5309:
1.48 raeburn 5310: sub initialize_categories {
5311: my ($itemcount) = @_;
1.120 raeburn 5312: my ($datatable,$css_class,$chgstr);
5313: my %default_names = (
5314: instcode => 'Official courses (with institutional codes)',
5315: communities => 'Communities',
5316: );
5317: my $select0 = ' selected="selected"';
5318: my $select1 = '';
5319: foreach my $default ('instcode','communities') {
5320: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5321: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5322: if ($default eq 'communities') {
5323: $select1 = $select0;
5324: $select0 = '';
5325: }
5326: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5327: .'<select name="'.$default.'_pos">'
5328: .'<option value="0"'.$select0.'>1</option>'
5329: .'<option value="1"'.$select1.'>2</option>'
5330: .'<option value="2">3</option></select> '
5331: .$default_names{$default}
5332: .'</span></td><td><span class="LC_nobreak">'
5333: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5334: .&mt('Display').'</label> <label>'
5335: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5336: .'</label></span></td></tr>';
1.120 raeburn 5337: $itemcount ++;
5338: }
1.48 raeburn 5339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5340: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5341: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5342: .'<select name="addcategory_pos"'.$chgstr.'>'
5343: .'<option value="0">1</option>'
5344: .'<option value="1">2</option>'
5345: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5346: .&mt('Add category').'</td><td>'.&mt('Name:')
5347: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5348: return $datatable;
5349: }
5350:
5351: sub build_category_rows {
1.49 raeburn 5352: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5353: my ($text,$name,$item,$chgstr);
1.48 raeburn 5354: if (ref($cats) eq 'ARRAY') {
5355: my $maxdepth = scalar(@{$cats});
5356: if (ref($cats->[$depth]) eq 'HASH') {
5357: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5358: my $numchildren = @{$cats->[$depth]{$parent}};
5359: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5360: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5361: my ($idxnum,$parent_name,$parent_item);
5362: my $higher = $depth - 1;
5363: if ($higher == 0) {
5364: $parent_name = &escape($parent).'::'.$higher;
5365: } else {
5366: if (ref($path) eq 'ARRAY') {
5367: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5368: }
5369: }
5370: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5371: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5372: if ($j < $numchildren) {
1.48 raeburn 5373: $name = $cats->[$depth]{$parent}[$j];
5374: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5375: $idxnum = $idx->{$item};
5376: } else {
5377: $name = $parent_name;
5378: $item = $parent_item;
1.48 raeburn 5379: }
1.49 raeburn 5380: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5381: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5382: for (my $i=0; $i<=$numchildren; $i++) {
5383: my $vpos = $i+1;
5384: my $selstr;
5385: if ($j == $i) {
5386: $selstr = ' selected="selected" ';
5387: }
5388: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5389: }
5390: $text .= '</select> ';
5391: if ($j < $numchildren) {
5392: my $deeper = $depth+1;
5393: $text .= $name.' '
5394: .'<label><input type="checkbox" name="deletecategory" value="'
5395: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5396: if(ref($path) eq 'ARRAY') {
5397: push(@{$path},$name);
1.49 raeburn 5398: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5399: pop(@{$path});
5400: }
5401: } else {
1.59 bisitz 5402: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5403: if ($j == $numchildren) {
5404: $text .= $name;
5405: } else {
5406: $text .= $item;
5407: }
5408: $text .= '" value="" />';
5409: }
5410: $text .= '</td></tr>';
5411: }
5412: $text .= '</table></td>';
5413: } else {
5414: my $higher = $depth-1;
5415: if ($higher == 0) {
5416: $name = &escape($parent).'::'.$higher;
5417: } else {
5418: if (ref($path) eq 'ARRAY') {
5419: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5420: }
5421: }
5422: my $colspan;
5423: if ($parent ne 'instcode') {
5424: $colspan = $maxdepth - $depth - 1;
5425: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5426: }
5427: }
5428: }
5429: }
5430: return $text;
5431: }
5432:
1.33 raeburn 5433: sub modifiable_userdata_row {
1.160.6.35 raeburn 5434: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5435: my ($role,$rolename,$statustype);
5436: $role = $item;
1.160.6.34 raeburn 5437: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5438: if ($item =~ /^emailusername_(.+)$/) {
5439: $statustype = $1;
5440: $role = 'emailusername';
5441: if (ref($usertypes) eq 'HASH') {
5442: if ($usertypes->{$statustype}) {
5443: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5444: } else {
5445: $rolename = &mt('Data provided by user');
5446: }
5447: }
1.160.6.34 raeburn 5448: }
5449: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5450: if (ref($usertypes) eq 'HASH') {
5451: $rolename = $usertypes->{$role};
5452: } else {
5453: $rolename = $role;
5454: }
1.33 raeburn 5455: } else {
1.63 raeburn 5456: if ($role eq 'cr') {
5457: $rolename = &mt('Custom role');
5458: } else {
5459: $rolename = &Apache::lonnet::plaintext($role);
5460: }
1.33 raeburn 5461: }
1.160.6.34 raeburn 5462: my (@fields,%fieldtitles);
5463: if (ref($fieldsref) eq 'ARRAY') {
5464: @fields = @{$fieldsref};
5465: } else {
5466: @fields = ('lastname','firstname','middlename','generation',
5467: 'permanentemail','id');
5468: }
5469: if ((ref($titlesref) eq 'HASH')) {
5470: %fieldtitles = %{$titlesref};
5471: } else {
5472: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5473: }
1.33 raeburn 5474: my $output;
5475: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5476: $output = '<tr '.$css_class.'>'.
5477: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5478: '<td class="LC_left_item" colspan="2"><table>';
5479: my $rem;
5480: my %checks;
5481: if (ref($settings) eq 'HASH') {
5482: if (ref($settings->{$context}) eq 'HASH') {
5483: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5484: my $hashref = $settings->{$context}->{$role};
5485: if ($role eq 'emailusername') {
5486: if ($statustype) {
5487: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5488: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5489: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5490: foreach my $field (@fields) {
5491: if ($hashref->{$field}) {
5492: $checks{$field} = $hashref->{$field};
5493: }
5494: }
5495: }
5496: }
5497: }
5498: } else {
5499: if (ref($hashref) eq 'HASH') {
5500: foreach my $field (@fields) {
5501: if ($hashref->{$field}) {
5502: $checks{$field} = ' checked="checked" ';
5503: }
5504: }
1.33 raeburn 5505: }
5506: }
5507: }
5508: }
5509: }
1.160.6.39 raeburn 5510:
1.33 raeburn 5511: for (my $i=0; $i<@fields; $i++) {
5512: my $rem = $i%($numinrow);
5513: if ($rem == 0) {
5514: if ($i > 0) {
5515: $output .= '</tr>';
5516: }
5517: $output .= '<tr>';
5518: }
5519: my $check = ' ';
1.160.6.35 raeburn 5520: unless ($role eq 'emailusername') {
5521: if (exists($checks{$fields[$i]})) {
5522: $check = $checks{$fields[$i]}
5523: } else {
5524: if ($role eq 'st') {
5525: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5526: $check = ' checked="checked" ';
1.160.6.35 raeburn 5527: }
1.33 raeburn 5528: }
5529: }
5530: }
5531: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5532: '<span class="LC_nobreak">';
5533: if ($role eq 'emailusername') {
5534: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5535: $checks{$fields[$i]} = 'omit';
5536: }
5537: foreach my $option ('required','optional','omit') {
5538: my $checked='';
5539: if ($checks{$fields[$i]} eq $option) {
5540: $checked='checked="checked" ';
5541: }
5542: $output .= '<label>'.
5543: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5544: &mt($option).'</label>'.(' ' x2);
5545: }
5546: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5547: } else {
5548: $output .= '<label>'.
5549: '<input type="checkbox" name="canmodify_'.$role.'" '.
5550: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5551: '</label>';
5552: }
5553: $output .= '</span></td>';
1.33 raeburn 5554: $rem = @fields%($numinrow);
5555: }
5556: my $colsleft = $numinrow - $rem;
5557: if ($colsleft > 1 ) {
5558: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5559: ' </td>';
5560: } elsif ($colsleft == 1) {
5561: $output .= '<td class="LC_left_item"> </td>';
5562: }
5563: $output .= '</tr></table></td></tr>';
5564: return $output;
5565: }
1.28 raeburn 5566:
1.93 raeburn 5567: sub insttypes_row {
1.160.6.34 raeburn 5568: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5569: my %lt = &Apache::lonlocal::texthash (
5570: cansearch => 'Users allowed to search',
5571: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5572: lockablenames => 'User preference to lock name',
1.93 raeburn 5573: );
5574: my $showdom;
5575: if ($context eq 'cansearch') {
5576: $showdom = ' ('.$dom.')';
5577: }
1.160.6.5 raeburn 5578: my $class = 'LC_left_item';
5579: if ($context eq 'statustocreate') {
5580: $class = 'LC_right_item';
5581: }
1.160.6.34 raeburn 5582: my $css_class = ' class="LC_odd_row"';
5583: if ($rownum ne '') {
5584: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5585: }
5586: my $output = '<tr'.$css_class.'>'.
5587: '<td>'.$lt{$context}.$showdom.
5588: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5589: my $rem;
5590: if (ref($types) eq 'ARRAY') {
5591: for (my $i=0; $i<@{$types}; $i++) {
5592: if (defined($usertypes->{$types->[$i]})) {
5593: my $rem = $i%($numinrow);
5594: if ($rem == 0) {
5595: if ($i > 0) {
5596: $output .= '</tr>';
5597: }
5598: $output .= '<tr>';
1.23 raeburn 5599: }
1.26 raeburn 5600: my $check = ' ';
1.99 raeburn 5601: if (ref($settings) eq 'HASH') {
5602: if (ref($settings->{$context}) eq 'ARRAY') {
5603: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5604: $check = ' checked="checked" ';
5605: }
5606: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5607: $check = ' checked="checked" ';
5608: }
1.23 raeburn 5609: }
1.26 raeburn 5610: $output .= '<td class="LC_left_item">'.
5611: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5612: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5613: 'value="'.$types->[$i].'"'.$check.'/>'.
5614: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5615: }
5616: }
1.26 raeburn 5617: $rem = @{$types}%($numinrow);
1.23 raeburn 5618: }
5619: my $colsleft = $numinrow - $rem;
1.131 raeburn 5620: if (($rem == 0) && (@{$types} > 0)) {
5621: $output .= '<tr>';
5622: }
1.23 raeburn 5623: if ($colsleft > 1) {
1.25 raeburn 5624: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5625: } else {
1.25 raeburn 5626: $output .= '<td class="LC_left_item">';
1.23 raeburn 5627: }
5628: my $defcheck = ' ';
1.99 raeburn 5629: if (ref($settings) eq 'HASH') {
5630: if (ref($settings->{$context}) eq 'ARRAY') {
5631: if (grep(/^default$/,@{$settings->{$context}})) {
5632: $defcheck = ' checked="checked" ';
5633: }
5634: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5635: $defcheck = ' checked="checked" ';
5636: }
1.23 raeburn 5637: }
1.25 raeburn 5638: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5639: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5640: 'value="default"'.$defcheck.'/>'.
5641: $othertitle.'</label></span></td>'.
5642: '</tr></table></td></tr>';
5643: return $output;
1.23 raeburn 5644: }
5645:
5646: sub sorted_searchtitles {
5647: my %searchtitles = &Apache::lonlocal::texthash(
5648: 'uname' => 'username',
5649: 'lastname' => 'last name',
5650: 'lastfirst' => 'last name, first name',
5651: );
5652: my @titleorder = ('uname','lastname','lastfirst');
5653: return (\%searchtitles,\@titleorder);
5654: }
5655:
1.25 raeburn 5656: sub sorted_searchtypes {
5657: my %srchtypes_desc = (
5658: exact => 'is exact match',
5659: contains => 'contains ..',
5660: begins => 'begins with ..',
5661: );
5662: my @srchtypeorder = ('exact','begins','contains');
5663: return (\%srchtypes_desc,\@srchtypeorder);
5664: }
5665:
1.3 raeburn 5666: sub usertype_update_row {
5667: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5668: my $datatable;
5669: my $numinrow = 4;
5670: foreach my $type (@{$types}) {
5671: if (defined($usertypes->{$type})) {
5672: $$rownums ++;
5673: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5674: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5675: '</td><td class="LC_left_item"><table>';
5676: for (my $i=0; $i<@{$fields}; $i++) {
5677: my $rem = $i%($numinrow);
5678: if ($rem == 0) {
5679: if ($i > 0) {
5680: $datatable .= '</tr>';
5681: }
5682: $datatable .= '<tr>';
5683: }
5684: my $check = ' ';
1.39 raeburn 5685: if (ref($settings) eq 'HASH') {
5686: if (ref($settings->{'fields'}) eq 'HASH') {
5687: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5688: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5689: $check = ' checked="checked" ';
5690: }
1.3 raeburn 5691: }
5692: }
5693: }
5694:
5695: if ($i == @{$fields}-1) {
5696: my $colsleft = $numinrow - $rem;
5697: if ($colsleft > 1) {
5698: $datatable .= '<td colspan="'.$colsleft.'">';
5699: } else {
5700: $datatable .= '<td>';
5701: }
5702: } else {
5703: $datatable .= '<td>';
5704: }
1.8 raeburn 5705: $datatable .= '<span class="LC_nobreak"><label>'.
5706: '<input type="checkbox" name="updateable_'.$type.
5707: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5708: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5709: }
5710: $datatable .= '</tr></table></td></tr>';
5711: }
5712: }
5713: return $datatable;
1.1 raeburn 5714: }
5715:
5716: sub modify_login {
1.160.6.24 raeburn 5717: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5718: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5719: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5720: %title = ( coursecatalog => 'Display course catalog',
5721: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5722: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5723: newuser => 'Link for visitors to create a user account',
5724: loginheader => 'Log-in box header');
5725: @offon = ('off','on');
1.112 raeburn 5726: if (ref($domconfig{login}) eq 'HASH') {
5727: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5728: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5729: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5730: }
5731: }
5732: }
1.9 raeburn 5733: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5734: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5735: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5736: foreach my $item (@toggles) {
5737: $loginhash{login}{$item} = $env{'form.'.$item};
5738: }
1.41 raeburn 5739: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5740: if (ref($colchanges{'login'}) eq 'HASH') {
5741: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5742: \%loginhash);
5743: }
1.110 raeburn 5744:
1.149 raeburn 5745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5746: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5747: if (keys(%servers) > 1) {
5748: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5749: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5750: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5751: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5752: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5753: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5754: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5755: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5756: $changes{'loginvia'}{$lonhost} = 1;
5757: } else {
5758: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5759: $changes{'loginvia'}{$lonhost} = 1;
5760: }
5761: } else {
5762: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5763: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5764: $changes{'loginvia'}{$lonhost} = 1;
5765: }
5766: }
5767: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5768: foreach my $item (@loginvia_attribs) {
5769: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5770: }
5771: } else {
5772: foreach my $item (@loginvia_attribs) {
5773: my $new = $env{'form.'.$lonhost.'_'.$item};
5774: if (($item eq 'serverpath') && ($new eq 'custom')) {
5775: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5776: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5777: $new = '/';
5778: }
5779: }
5780: if (($item eq 'custompath') &&
5781: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5782: $new = '';
5783: }
5784: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5785: $changes{'loginvia'}{$lonhost} = 1;
5786: }
5787: if ($item eq 'exempt') {
5788: $new =~ s/^\s+//;
5789: $new =~ s/\s+$//;
5790: my @poss_ips = split(/\s*[,:]\s*/,$new);
5791: my @okips;
5792: foreach my $ip (@poss_ips) {
5793: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5794: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5795: push(@okips,$ip);
5796: }
5797: }
5798: }
5799: if (@okips > 0) {
5800: $new = join(',',@okips);
5801: } else {
5802: $new = '';
5803: }
5804: }
5805: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5806: }
5807: }
1.112 raeburn 5808: } else {
1.128 raeburn 5809: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5810: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5811: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5812: foreach my $item (@loginvia_attribs) {
5813: my $new = $env{'form.'.$lonhost.'_'.$item};
5814: if (($item eq 'serverpath') && ($new eq 'custom')) {
5815: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5816: $new = '/';
5817: }
5818: }
5819: if (($item eq 'custompath') &&
5820: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5821: $new = '';
5822: }
5823: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5824: }
1.110 raeburn 5825: }
5826: }
5827: }
5828: }
1.119 raeburn 5829:
1.160.6.5 raeburn 5830: my $servadm = $r->dir_config('lonAdmEMail');
5831: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5832: if (ref($domconfig{'login'}) eq 'HASH') {
5833: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5834: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5835: if ($lang eq 'nolang') {
5836: push(@currlangs,$lang);
5837: } elsif (defined($langchoices{$lang})) {
5838: push(@currlangs,$lang);
5839: } else {
5840: next;
5841: }
5842: }
5843: }
5844: }
5845: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5846: if (@currlangs > 0) {
5847: foreach my $lang (@currlangs) {
5848: if (grep(/^\Q$lang\E$/,@delurls)) {
5849: $changes{'helpurl'}{$lang} = 1;
5850: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5851: $changes{'helpurl'}{$lang} = 1;
5852: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5853: push(@newlangs,$lang);
5854: } else {
5855: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5856: }
5857: }
5858: }
5859: unless (grep(/^nolang$/,@currlangs)) {
5860: if ($env{'form.loginhelpurl_nolang.filename'}) {
5861: $changes{'helpurl'}{'nolang'} = 1;
5862: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5863: push(@newlangs,'nolang');
5864: }
5865: }
5866: if ($env{'form.loginhelpurl_add_lang'}) {
5867: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5868: ($env{'form.loginhelpurl_add_file.filename'})) {
5869: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5870: $addedfile = $env{'form.loginhelpurl_add_lang'};
5871: }
5872: }
5873: if ((@newlangs > 0) || ($addedfile)) {
5874: my $error;
5875: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5876: if ($configuserok eq 'ok') {
5877: if ($switchserver) {
5878: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5879: } elsif ($author_ok eq 'ok') {
5880: my @allnew = @newlangs;
5881: if ($addedfile ne '') {
5882: push(@allnew,$addedfile);
5883: }
5884: foreach my $lang (@allnew) {
5885: my $formelem = 'loginhelpurl_'.$lang;
5886: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5887: $formelem = 'loginhelpurl_add_file';
5888: }
5889: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5890: "help/$lang",'','',$newfile{$lang});
5891: if ($result eq 'ok') {
5892: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5893: $changes{'helpurl'}{$lang} = 1;
5894: } else {
5895: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5896: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5897: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5898: (!grep(/^\Q$lang\E$/,@delurls))) {
5899:
5900: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5901: }
5902: }
5903: }
5904: } else {
5905: $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);
5906: }
5907: } else {
5908: $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);
5909: }
5910: if ($error) {
5911: &Apache::lonnet::logthis($error);
5912: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5913: }
5914: }
5915: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5916:
5917: my $defaulthelpfile = '/adm/loginproblems.html';
5918: my $defaulttext = &mt('Default in use');
5919:
1.1 raeburn 5920: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5921: $dom);
5922: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5923: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5924: my %defaultchecked = (
5925: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5926: 'helpdesk' => 'on',
1.42 raeburn 5927: 'adminmail' => 'off',
1.43 raeburn 5928: 'newuser' => 'off',
1.42 raeburn 5929: );
1.55 raeburn 5930: if (ref($domconfig{'login'}) eq 'HASH') {
5931: foreach my $item (@toggles) {
5932: if ($defaultchecked{$item} eq 'on') {
5933: if (($domconfig{'login'}{$item} eq '0') &&
5934: ($env{'form.'.$item} eq '1')) {
5935: $changes{$item} = 1;
5936: } elsif (($domconfig{'login'}{$item} eq '' ||
5937: $domconfig{'login'}{$item} eq '1') &&
5938: ($env{'form.'.$item} eq '0')) {
5939: $changes{$item} = 1;
5940: }
5941: } elsif ($defaultchecked{$item} eq 'off') {
5942: if (($domconfig{'login'}{$item} eq '1') &&
5943: ($env{'form.'.$item} eq '0')) {
5944: $changes{$item} = 1;
5945: } elsif (($domconfig{'login'}{$item} eq '' ||
5946: $domconfig{'login'}{$item} eq '0') &&
5947: ($env{'form.'.$item} eq '1')) {
5948: $changes{$item} = 1;
5949: }
1.42 raeburn 5950: }
5951: }
1.41 raeburn 5952: }
1.6 raeburn 5953: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5954: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5955: if (ref($lastactref) eq 'HASH') {
5956: $lastactref->{'domainconfig'} = 1;
5957: }
1.1 raeburn 5958: $resulttext = &mt('Changes made:').'<ul>';
5959: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5960: if ($item eq 'loginvia') {
1.112 raeburn 5961: if (ref($changes{$item}) eq 'HASH') {
5962: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5963: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5964: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5965: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5966: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5967: $protocol = 'http' if ($protocol ne 'https');
5968: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5969:
5970: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5971: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5972: } else {
5973: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5974: }
5975: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5976: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5977: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5978: }
5979: $resulttext .= '</li>';
5980: } else {
5981: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5982: }
1.112 raeburn 5983: } else {
1.128 raeburn 5984: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5985: }
5986: }
1.128 raeburn 5987: $resulttext .= '</ul></li>';
1.112 raeburn 5988: }
1.160.6.5 raeburn 5989: } elsif ($item eq 'helpurl') {
5990: if (ref($changes{$item}) eq 'HASH') {
5991: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5992: if (grep(/^\Q$lang\E$/,@delurls)) {
5993: my ($chg,$link);
5994: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5995: if ($lang eq 'nolang') {
5996: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5997: } else {
5998: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5999: }
6000: $resulttext .= '<li>'.$chg.'</li>';
6001: } else {
6002: my $chg;
6003: if ($lang eq 'nolang') {
6004: $chg = &mt('custom log-in help file for no preferred language');
6005: } else {
6006: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6007: }
6008: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6009: $loginhash{'login'}{'helpurl'}{$lang}.
6010: '?inhibitmenu=yes',$chg,600,500).
6011: '</li>';
6012: }
6013: }
6014: }
6015: } elsif ($item eq 'captcha') {
6016: if (ref($loginhash{'login'}) eq 'HASH') {
6017: my $chgtxt;
6018: if ($loginhash{'login'}{$item} eq 'notused') {
6019: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6020: } else {
6021: my %captchas = &captcha_phrases();
6022: if ($captchas{$loginhash{'login'}{$item}}) {
6023: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6024: } else {
6025: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6026: }
6027: }
6028: $resulttext .= '<li>'.$chgtxt.'</li>';
6029: }
6030: } elsif ($item eq 'recaptchakeys') {
6031: if (ref($loginhash{'login'}) eq 'HASH') {
6032: my ($privkey,$pubkey);
6033: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6034: $pubkey = $loginhash{'login'}{$item}{'public'};
6035: $privkey = $loginhash{'login'}{$item}{'private'};
6036: }
6037: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6038: if (!$pubkey) {
6039: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6040: } else {
6041: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6042: }
6043: if (!$privkey) {
6044: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6045: } else {
6046: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6047: }
6048: $chgtxt .= '</ul>';
6049: $resulttext .= '<li>'.$chgtxt.'</li>';
6050: }
1.41 raeburn 6051: } else {
6052: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6053: }
1.1 raeburn 6054: }
1.6 raeburn 6055: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6056: } else {
6057: $resulttext = &mt('No changes made to log-in page settings');
6058: }
6059: } else {
1.11 albertel 6060: $resulttext = '<span class="LC_error">'.
6061: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6062: }
1.6 raeburn 6063: if ($errors) {
1.9 raeburn 6064: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6065: $errors.'</ul>';
6066: }
6067: return $resulttext;
6068: }
6069:
6070: sub color_font_choices {
6071: my %choices =
6072: &Apache::lonlocal::texthash (
6073: img => "Header",
6074: bgs => "Background colors",
6075: links => "Link colors",
1.55 raeburn 6076: images => "Images",
1.6 raeburn 6077: font => "Font color",
1.160.6.22 raeburn 6078: fontmenu => "Font menu",
1.76 raeburn 6079: pgbg => "Page",
1.6 raeburn 6080: tabbg => "Header",
6081: sidebg => "Border",
6082: link => "Link",
6083: alink => "Active link",
6084: vlink => "Visited link",
6085: );
6086: return %choices;
6087: }
6088:
6089: sub modify_rolecolors {
1.160.6.24 raeburn 6090: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6091: my ($resulttext,%rolehash);
6092: $rolehash{'rolecolors'} = {};
1.55 raeburn 6093: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6094: if ($domconfig{'rolecolors'} eq '') {
6095: $domconfig{'rolecolors'} = {};
6096: }
6097: }
1.9 raeburn 6098: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6099: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6100: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6101: $dom);
6102: if ($putresult eq 'ok') {
6103: if (keys(%changes) > 0) {
1.41 raeburn 6104: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6105: if (ref($lastactref) eq 'HASH') {
6106: $lastactref->{'domainconfig'} = 1;
6107: }
1.6 raeburn 6108: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6109: $rolehash{'rolecolors'});
6110: } else {
6111: $resulttext = &mt('No changes made to default color schemes');
6112: }
6113: } else {
1.11 albertel 6114: $resulttext = '<span class="LC_error">'.
6115: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6116: }
6117: if ($errors) {
6118: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6119: $errors.'</ul>';
6120: }
6121: return $resulttext;
6122: }
6123:
6124: sub modify_colors {
1.9 raeburn 6125: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6126: my (%changes,%choices);
1.51 raeburn 6127: my @bgs;
1.6 raeburn 6128: my @links = ('link','alink','vlink');
1.41 raeburn 6129: my @logintext;
1.6 raeburn 6130: my @images;
6131: my $servadm = $r->dir_config('lonAdmEMail');
6132: my $errors;
1.160.6.22 raeburn 6133: my %defaults;
1.6 raeburn 6134: foreach my $role (@{$roles}) {
6135: if ($role eq 'login') {
1.12 raeburn 6136: %choices = &login_choices();
1.41 raeburn 6137: @logintext = ('textcol','bgcol');
1.12 raeburn 6138: } else {
6139: %choices = &color_font_choices();
6140: }
6141: if ($role eq 'login') {
1.41 raeburn 6142: @images = ('img','logo','domlogo','login');
1.51 raeburn 6143: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6144: } else {
6145: @images = ('img');
1.160.6.22 raeburn 6146: @bgs = ('pgbg','tabbg','sidebg');
6147: }
6148: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6149: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6150: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6151: }
6152: if ($role eq 'login') {
6153: foreach my $item (@logintext) {
1.160.6.39 raeburn 6154: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6155: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6156: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6157: }
6158: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6159: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6160: }
6161: }
6162: } else {
1.160.6.39 raeburn 6163: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6164: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6165: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6166: }
6167: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6168: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6169: }
1.6 raeburn 6170: }
1.160.6.22 raeburn 6171: foreach my $item (@bgs) {
1.160.6.39 raeburn 6172: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6173: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6174: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6175: }
6176: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6177: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6178: }
6179: }
6180: foreach my $item (@links) {
1.160.6.39 raeburn 6181: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6182: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6183: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6184: }
6185: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6186: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6187: }
1.6 raeburn 6188: }
1.46 raeburn 6189: my ($configuserok,$author_ok,$switchserver) =
6190: &config_check($dom,$confname,$servadm);
1.9 raeburn 6191: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6192: if (ref($domconfig->{$role}) ne 'HASH') {
6193: $domconfig->{$role} = {};
6194: }
1.8 raeburn 6195: foreach my $img (@images) {
1.70 raeburn 6196: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6197: if (defined($env{'form.login_showlogo_'.$img})) {
6198: $confhash->{$role}{'showlogo'}{$img} = 1;
6199: } else {
6200: $confhash->{$role}{'showlogo'}{$img} = 0;
6201: }
6202: }
1.18 albertel 6203: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6204: && !defined($domconfig->{$role}{$img})
6205: && !$env{'form.'.$role.'_del_'.$img}
6206: && $env{'form.'.$role.'_import_'.$img}) {
6207: # import the old configured image from the .tab setting
6208: # if they haven't provided a new one
6209: $domconfig->{$role}{$img} =
6210: $env{'form.'.$role.'_import_'.$img};
6211: }
1.6 raeburn 6212: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6213: my $error;
1.6 raeburn 6214: if ($configuserok eq 'ok') {
1.9 raeburn 6215: if ($switchserver) {
1.12 raeburn 6216: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6217: } else {
6218: if ($author_ok eq 'ok') {
6219: my ($result,$logourl) =
6220: &publishlogo($r,'upload',$role.'_'.$img,
6221: $dom,$confname,$img,$width,$height);
6222: if ($result eq 'ok') {
6223: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6224: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6225: } else {
1.12 raeburn 6226: $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 6227: }
6228: } else {
1.46 raeburn 6229: $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 6230: }
6231: }
6232: } else {
1.46 raeburn 6233: $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 6234: }
6235: if ($error) {
1.8 raeburn 6236: &Apache::lonnet::logthis($error);
1.11 albertel 6237: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6238: }
6239: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6240: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6241: my $error;
6242: if ($configuserok eq 'ok') {
6243: # is confname an author?
6244: if ($switchserver eq '') {
6245: if ($author_ok eq 'ok') {
6246: my ($result,$logourl) =
6247: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6248: $dom,$confname,$img,$width,$height);
6249: if ($result eq 'ok') {
6250: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6251: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6252: }
6253: }
6254: }
6255: }
1.6 raeburn 6256: }
6257: }
6258: }
6259: if (ref($domconfig) eq 'HASH') {
6260: if (ref($domconfig->{$role}) eq 'HASH') {
6261: foreach my $img (@images) {
6262: if ($domconfig->{$role}{$img} ne '') {
6263: if ($env{'form.'.$role.'_del_'.$img}) {
6264: $confhash->{$role}{$img} = '';
1.12 raeburn 6265: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6266: } else {
1.9 raeburn 6267: if ($confhash->{$role}{$img} eq '') {
6268: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6269: }
1.6 raeburn 6270: }
6271: } else {
6272: if ($env{'form.'.$role.'_del_'.$img}) {
6273: $confhash->{$role}{$img} = '';
1.12 raeburn 6274: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6275: }
6276: }
1.70 raeburn 6277: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6278: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6279: if ($confhash->{$role}{'showlogo'}{$img} ne
6280: $domconfig->{$role}{'showlogo'}{$img}) {
6281: $changes{$role}{'showlogo'}{$img} = 1;
6282: }
6283: } else {
6284: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6285: $changes{$role}{'showlogo'}{$img} = 1;
6286: }
6287: }
6288: }
6289: }
1.6 raeburn 6290: if ($domconfig->{$role}{'font'} ne '') {
6291: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6292: $changes{$role}{'font'} = 1;
6293: }
6294: } else {
6295: if ($confhash->{$role}{'font'}) {
6296: $changes{$role}{'font'} = 1;
6297: }
6298: }
1.107 raeburn 6299: if ($role ne 'login') {
6300: if ($domconfig->{$role}{'fontmenu'} ne '') {
6301: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6302: $changes{$role}{'fontmenu'} = 1;
6303: }
6304: } else {
6305: if ($confhash->{$role}{'fontmenu'}) {
6306: $changes{$role}{'fontmenu'} = 1;
6307: }
1.97 tempelho 6308: }
6309: }
1.6 raeburn 6310: foreach my $item (@bgs) {
6311: if ($domconfig->{$role}{$item} ne '') {
6312: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6313: $changes{$role}{'bgs'}{$item} = 1;
6314: }
6315: } else {
6316: if ($confhash->{$role}{$item}) {
6317: $changes{$role}{'bgs'}{$item} = 1;
6318: }
6319: }
6320: }
6321: foreach my $item (@links) {
6322: if ($domconfig->{$role}{$item} ne '') {
6323: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6324: $changes{$role}{'links'}{$item} = 1;
6325: }
6326: } else {
6327: if ($confhash->{$role}{$item}) {
6328: $changes{$role}{'links'}{$item} = 1;
6329: }
6330: }
6331: }
1.41 raeburn 6332: foreach my $item (@logintext) {
6333: if ($domconfig->{$role}{$item} ne '') {
6334: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6335: $changes{$role}{'logintext'}{$item} = 1;
6336: }
6337: } else {
6338: if ($confhash->{$role}{$item}) {
6339: $changes{$role}{'logintext'}{$item} = 1;
6340: }
6341: }
6342: }
1.6 raeburn 6343: } else {
6344: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6345: \@logintext,$confhash,\%changes);
1.6 raeburn 6346: }
6347: } else {
6348: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6349: \@logintext,$confhash,\%changes);
1.6 raeburn 6350: }
6351: }
6352: return ($errors,%changes);
6353: }
6354:
1.46 raeburn 6355: sub config_check {
6356: my ($dom,$confname,$servadm) = @_;
6357: my ($configuserok,$author_ok,$switchserver,%currroles);
6358: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6359: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6360: $confname,$servadm);
6361: if ($configuserok eq 'ok') {
6362: $switchserver = &check_switchserver($dom,$confname);
6363: if ($switchserver eq '') {
6364: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6365: }
6366: }
6367: return ($configuserok,$author_ok,$switchserver);
6368: }
6369:
1.6 raeburn 6370: sub default_change_checker {
1.41 raeburn 6371: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6372: foreach my $item (@{$links}) {
6373: if ($confhash->{$role}{$item}) {
6374: $changes->{$role}{'links'}{$item} = 1;
6375: }
6376: }
6377: foreach my $item (@{$bgs}) {
6378: if ($confhash->{$role}{$item}) {
6379: $changes->{$role}{'bgs'}{$item} = 1;
6380: }
6381: }
1.41 raeburn 6382: foreach my $item (@{$logintext}) {
6383: if ($confhash->{$role}{$item}) {
6384: $changes->{$role}{'logintext'}{$item} = 1;
6385: }
6386: }
1.6 raeburn 6387: foreach my $img (@{$images}) {
6388: if ($env{'form.'.$role.'_del_'.$img}) {
6389: $confhash->{$role}{$img} = '';
1.12 raeburn 6390: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6391: }
1.70 raeburn 6392: if ($role eq 'login') {
6393: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6394: $changes->{$role}{'showlogo'}{$img} = 1;
6395: }
6396: }
1.6 raeburn 6397: }
6398: if ($confhash->{$role}{'font'}) {
6399: $changes->{$role}{'font'} = 1;
6400: }
1.48 raeburn 6401: }
1.6 raeburn 6402:
6403: sub display_colorchgs {
6404: my ($dom,$changes,$roles,$confhash) = @_;
6405: my (%choices,$resulttext);
6406: if (!grep(/^login$/,@{$roles})) {
6407: $resulttext = &mt('Changes made:').'<br />';
6408: }
6409: foreach my $role (@{$roles}) {
6410: if ($role eq 'login') {
6411: %choices = &login_choices();
6412: } else {
6413: %choices = &color_font_choices();
6414: }
6415: if (ref($changes->{$role}) eq 'HASH') {
6416: if ($role ne 'login') {
6417: $resulttext .= '<h4>'.&mt($role).'</h4>';
6418: }
6419: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6420: if ($role ne 'login') {
6421: $resulttext .= '<ul>';
6422: }
6423: if (ref($changes->{$role}{$key}) eq 'HASH') {
6424: if ($role ne 'login') {
6425: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6426: }
6427: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6428: if (($role eq 'login') && ($key eq 'showlogo')) {
6429: if ($confhash->{$role}{$key}{$item}) {
6430: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6431: } else {
6432: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6433: }
6434: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6435: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6436: } else {
1.12 raeburn 6437: my $newitem = $confhash->{$role}{$item};
6438: if ($key eq 'images') {
6439: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6440: }
6441: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6442: }
6443: }
6444: if ($role ne 'login') {
6445: $resulttext .= '</ul></li>';
6446: }
6447: } else {
6448: if ($confhash->{$role}{$key} eq '') {
6449: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6450: } else {
6451: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6452: }
6453: }
6454: if ($role ne 'login') {
6455: $resulttext .= '</ul>';
6456: }
6457: }
6458: }
6459: }
1.3 raeburn 6460: return $resulttext;
1.1 raeburn 6461: }
6462:
1.9 raeburn 6463: sub thumb_dimensions {
6464: return ('200','50');
6465: }
6466:
1.16 raeburn 6467: sub check_dimensions {
6468: my ($inputfile) = @_;
6469: my ($fullwidth,$fullheight);
6470: if ($inputfile =~ m|^[/\w.\-]+$|) {
6471: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6472: my $imageinfo = <PIPE>;
6473: if (!close(PIPE)) {
6474: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6475: }
6476: chomp($imageinfo);
6477: my ($fullsize) =
1.21 raeburn 6478: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6479: if ($fullsize) {
6480: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6481: }
6482: }
6483: }
6484: return ($fullwidth,$fullheight);
6485: }
6486:
1.9 raeburn 6487: sub check_configuser {
6488: my ($uhome,$dom,$confname,$servadm) = @_;
6489: my ($configuserok,%currroles);
6490: if ($uhome eq 'no_host') {
6491: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6492: my $configpass = &LONCAPA::Enrollment::create_password();
6493: $configuserok =
6494: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6495: $configpass,'','','','','',undef,$servadm);
6496: } else {
6497: $configuserok = 'ok';
6498: %currroles =
6499: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6500: }
6501: return ($configuserok,%currroles);
6502: }
6503:
6504: sub check_authorstatus {
6505: my ($dom,$confname,%currroles) = @_;
6506: my $author_ok;
1.40 raeburn 6507: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6508: my $start = time;
6509: my $end = 0;
6510: $author_ok =
6511: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6512: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6513: } else {
6514: $author_ok = 'ok';
6515: }
6516: return $author_ok;
6517: }
6518:
6519: sub publishlogo {
1.46 raeburn 6520: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6521: my ($output,$fname,$logourl);
6522: if ($action eq 'upload') {
6523: $fname=$env{'form.'.$formname.'.filename'};
6524: chop($env{'form.'.$formname});
6525: } else {
6526: ($fname) = ($formname =~ /([^\/]+)$/);
6527: }
1.46 raeburn 6528: if ($savefileas ne '') {
6529: $fname = $savefileas;
6530: }
1.9 raeburn 6531: $fname=&Apache::lonnet::clean_filename($fname);
6532: # See if there is anything left
6533: unless ($fname) { return ('error: no uploaded file'); }
6534: $fname="$subdir/$fname";
1.160.6.5 raeburn 6535: my $docroot=$r->dir_config('lonDocRoot');
6536: my $filepath="$docroot/priv";
6537: my $relpath = "$dom/$confname";
1.9 raeburn 6538: my ($fnamepath,$file,$fetchthumb);
6539: $file=$fname;
6540: if ($fname=~m|/|) {
6541: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6542: }
1.160.6.26 raeburn 6543: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6544: my $count;
1.160.6.5 raeburn 6545: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6546: $filepath.="/$parts[$count]";
6547: if ((-e $filepath)!=1) {
6548: mkdir($filepath,02770);
6549: }
6550: }
6551: # Check for bad extension and disallow upload
6552: if ($file=~/\.(\w+)$/ &&
6553: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6554: $output =
1.160.6.25 raeburn 6555: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6556: } elsif ($file=~/\.(\w+)$/ &&
6557: !defined(&Apache::loncommon::fileembstyle($1))) {
6558: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6559: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6560: $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 6561: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6562: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6563: } else {
6564: my $source = $filepath.'/'.$file;
6565: my $logfile;
6566: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6567: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6568: }
6569: print $logfile
6570: "\n================= Publish ".localtime()." ================\n".
6571: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6572: # Save the file
6573: if (!open(FH,'>'.$source)) {
6574: &Apache::lonnet::logthis('Failed to create '.$source);
6575: return (&mt('Failed to create file'));
6576: }
6577: if ($action eq 'upload') {
6578: if (!print FH ($env{'form.'.$formname})) {
6579: &Apache::lonnet::logthis('Failed to write to '.$source);
6580: return (&mt('Failed to write file'));
6581: }
6582: } else {
6583: my $original = &Apache::lonnet::filelocation('',$formname);
6584: if(!copy($original,$source)) {
6585: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6586: return (&mt('Failed to write file'));
6587: }
6588: }
6589: close(FH);
6590: chmod(0660, $source); # Permissions to rw-rw---.
6591:
6592: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6593: my $copyfile=$targetdir.'/'.$file;
6594:
6595: my @parts=split(/\//,$targetdir);
6596: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6597: for (my $count=5;$count<=$#parts;$count++) {
6598: $path.="/$parts[$count]";
6599: if (!-e $path) {
6600: print $logfile "\nCreating directory ".$path;
6601: mkdir($path,02770);
6602: }
6603: }
6604: my $versionresult;
6605: if (-e $copyfile) {
6606: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6607: } else {
6608: $versionresult = 'ok';
6609: }
6610: if ($versionresult eq 'ok') {
6611: if (copy($source,$copyfile)) {
6612: print $logfile "\nCopied original source to ".$copyfile."\n";
6613: $output = 'ok';
6614: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6615: push(@{$modified_urls},[$copyfile,$source]);
6616: my $metaoutput =
6617: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6618: unless ($registered_cleanup) {
6619: my $handlers = $r->get_handlers('PerlCleanupHandler');
6620: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6621: $registered_cleanup=1;
6622: }
1.9 raeburn 6623: } else {
6624: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6625: $output = &mt('Failed to copy file to RES space').", $!";
6626: }
6627: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6628: my $inputfile = $filepath.'/'.$file;
6629: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6630: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6631: if ($fullwidth ne '' && $fullheight ne '') {
6632: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6633: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6634: system("convert -sample $thumbsize $inputfile $outfile");
6635: chmod(0660, $filepath.'/tn-'.$file);
6636: if (-e $outfile) {
6637: my $copyfile=$targetdir.'/tn-'.$file;
6638: if (copy($outfile,$copyfile)) {
6639: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6640: my $thumb_metaoutput =
6641: &write_metadata($dom,$confname,$formname,
6642: $targetdir,'tn-'.$file,$logfile);
6643: push(@{$modified_urls},[$copyfile,$outfile]);
6644: unless ($registered_cleanup) {
6645: my $handlers = $r->get_handlers('PerlCleanupHandler');
6646: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6647: $registered_cleanup=1;
6648: }
1.16 raeburn 6649: } else {
6650: print $logfile "\nUnable to write ".$copyfile.
6651: ':'.$!."\n";
6652: }
6653: }
1.9 raeburn 6654: }
6655: }
6656: }
6657: } else {
6658: $output = $versionresult;
6659: }
6660: }
6661: return ($output,$logourl);
6662: }
6663:
6664: sub logo_versioning {
6665: my ($targetdir,$file,$logfile) = @_;
6666: my $target = $targetdir.'/'.$file;
6667: my ($maxversion,$fn,$extn,$output);
6668: $maxversion = 0;
6669: if ($file =~ /^(.+)\.(\w+)$/) {
6670: $fn=$1;
6671: $extn=$2;
6672: }
6673: opendir(DIR,$targetdir);
6674: while (my $filename=readdir(DIR)) {
6675: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6676: $maxversion=($1>$maxversion)?$1:$maxversion;
6677: }
6678: }
6679: $maxversion++;
6680: print $logfile "\nCreating old version ".$maxversion."\n";
6681: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6682: if (copy($target,$copyfile)) {
6683: print $logfile "Copied old target to ".$copyfile."\n";
6684: $copyfile=$copyfile.'.meta';
6685: if (copy($target.'.meta',$copyfile)) {
6686: print $logfile "Copied old target metadata to ".$copyfile."\n";
6687: $output = 'ok';
6688: } else {
6689: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6690: $output = &mt('Failed to copy old meta').", $!, ";
6691: }
6692: } else {
6693: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6694: $output = &mt('Failed to copy old target').", $!, ";
6695: }
6696: return $output;
6697: }
6698:
6699: sub write_metadata {
6700: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6701: my (%metadatafields,%metadatakeys,$output);
6702: $metadatafields{'title'}=$formname;
6703: $metadatafields{'creationdate'}=time;
6704: $metadatafields{'lastrevisiondate'}=time;
6705: $metadatafields{'copyright'}='public';
6706: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6707: $env{'user.domain'};
6708: $metadatafields{'authorspace'}=$confname.':'.$dom;
6709: $metadatafields{'domain'}=$dom;
6710: {
6711: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6712: my $mfh;
1.155 raeburn 6713: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6714: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6715: unless ($_=~/\./) {
6716: my $unikey=$_;
6717: $unikey=~/^([A-Za-z]+)/;
6718: my $tag=$1;
6719: $tag=~tr/A-Z/a-z/;
6720: print $mfh "\n\<$tag";
6721: foreach (split(/\,/,$metadatakeys{$unikey})) {
6722: my $value=$metadatafields{$unikey.'.'.$_};
6723: $value=~s/\"/\'\'/g;
6724: print $mfh ' '.$_.'="'.$value.'"';
6725: }
6726: print $mfh '>'.
6727: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6728: .'</'.$tag.'>';
6729: }
6730: }
6731: $output = 'ok';
6732: print $logfile "\nWrote metadata";
6733: close($mfh);
6734: } else {
6735: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6736: $output = &mt('Could not write metadata');
6737: }
6738: }
1.155 raeburn 6739: return $output;
6740: }
6741:
6742: sub notifysubscribed {
6743: foreach my $targetsource (@{$modified_urls}){
6744: next unless (ref($targetsource) eq 'ARRAY');
6745: my ($target,$source)=@{$targetsource};
6746: if ($source ne '') {
6747: if (open(my $logfh,'>>'.$source.'.log')) {
6748: print $logfh "\nCleanup phase: Notifications\n";
6749: my @subscribed=&subscribed_hosts($target);
6750: foreach my $subhost (@subscribed) {
6751: print $logfh "\nNotifying host ".$subhost.':';
6752: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6753: print $logfh $reply;
6754: }
6755: my @subscribedmeta=&subscribed_hosts("$target.meta");
6756: foreach my $subhost (@subscribedmeta) {
6757: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6758: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6759: $subhost);
6760: print $logfh $reply;
6761: }
6762: print $logfh "\n============ Done ============\n";
1.160 raeburn 6763: close($logfh);
1.155 raeburn 6764: }
6765: }
6766: }
6767: return OK;
6768: }
6769:
6770: sub subscribed_hosts {
6771: my ($target) = @_;
6772: my @subscribed;
6773: if (open(my $fh,"<$target.subscription")) {
6774: while (my $subline=<$fh>) {
6775: if ($subline =~ /^($match_lonid):/) {
6776: my $host = $1;
6777: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6778: unless (grep(/^\Q$host\E$/,@subscribed)) {
6779: push(@subscribed,$host);
6780: }
6781: }
6782: }
6783: }
6784: }
6785: return @subscribed;
1.9 raeburn 6786: }
6787:
6788: sub check_switchserver {
6789: my ($dom,$confname) = @_;
6790: my ($allowed,$switchserver);
6791: my $home = &Apache::lonnet::homeserver($confname,$dom);
6792: if ($home eq 'no_host') {
6793: $home = &Apache::lonnet::domain($dom,'primary');
6794: }
6795: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6796: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6797: if (!$allowed) {
1.160.6.11 raeburn 6798: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6799: }
6800: return $switchserver;
6801: }
6802:
1.1 raeburn 6803: sub modify_quotas {
1.160.6.30 raeburn 6804: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6805: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6806: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6807: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6808: $validationfieldsref);
1.86 raeburn 6809: if ($action eq 'quotas') {
6810: $context = 'tools';
1.160.6.26 raeburn 6811: } else {
1.86 raeburn 6812: $context = $action;
6813: }
6814: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6815: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6816: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6817: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6818: %titles = &courserequest_titles();
6819: $toolregexp = join('|',@usertools);
6820: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6821: $confname = $dom.'-domainconfig';
6822: my $servadm = $r->dir_config('lonAdmEMail');
6823: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6824: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6825: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6826: } elsif ($context eq 'requestauthor') {
6827: @usertools = ('author');
6828: %titles = &authorrequest_titles();
1.86 raeburn 6829: } else {
1.160.6.4 raeburn 6830: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6831: %titles = &tool_titles();
1.86 raeburn 6832: }
1.160.6.27 raeburn 6833: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6834: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6835: foreach my $key (keys(%env)) {
1.101 raeburn 6836: if ($context eq 'requestcourses') {
6837: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6838: my $item = $1;
6839: my $type = $2;
6840: if ($type =~ /^limit_(.+)/) {
6841: $limithash{$item}{$1} = $env{$key};
6842: } else {
6843: $confhash{$item}{$type} = $env{$key};
6844: }
6845: }
1.160.6.5 raeburn 6846: } elsif ($context eq 'requestauthor') {
6847: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6848: $confhash{$1} = $env{$key};
6849: }
1.101 raeburn 6850: } else {
1.86 raeburn 6851: if ($key =~ /^form\.quota_(.+)$/) {
6852: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6853: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6854: $confhash{'authorquota'}{$1} = $env{$key};
6855: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6856: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6857: }
1.72 raeburn 6858: }
6859: }
1.160.6.5 raeburn 6860: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6861: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6862: @approvalnotify = sort(@approvalnotify);
6863: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6864: my @crstypes = ('official','unofficial','community','textbook');
6865: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6866: foreach my $type (@hasuniquecode) {
6867: if (grep(/^\Q$type\E$/,@crstypes)) {
6868: $confhash{'uniquecode'}{$type} = 1;
6869: }
6870: }
1.160.6.46 raeburn 6871: my (%newbook,%allpos);
1.160.6.30 raeburn 6872: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6873: foreach my $type ('textbooks','templates') {
6874: @{$allpos{$type}} = ();
6875: my $invalid;
6876: if ($type eq 'textbooks') {
6877: $invalid = &mt('Invalid LON-CAPA course for textbook');
6878: } else {
6879: $invalid = &mt('Invalid LON-CAPA course for template');
6880: }
6881: if ($env{'form.'.$type.'_addbook'}) {
6882: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6883: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6884: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6885: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6886: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6887: } else {
6888: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6889: my $position = $env{'form.'.$type.'_addbook_pos'};
6890: $position =~ s/\D+//g;
6891: if ($position ne '') {
6892: $allpos{$type}[$position] = $newbook{$type};
6893: }
1.160.6.30 raeburn 6894: }
1.160.6.46 raeburn 6895: } else {
6896: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 6897: }
6898: }
1.160.6.46 raeburn 6899: }
1.160.6.30 raeburn 6900: }
1.102 raeburn 6901: if (ref($domconfig{$action}) eq 'HASH') {
6902: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6903: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6904: $changes{'notify'}{'approval'} = 1;
6905: }
6906: } else {
1.144 raeburn 6907: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6908: $changes{'notify'}{'approval'} = 1;
6909: }
6910: }
1.160.6.30 raeburn 6911: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6912: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6913: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6914: unless ($confhash{'uniquecode'}{$crstype}) {
6915: $changes{'uniquecode'} = 1;
6916: }
6917: }
6918: unless ($changes{'uniquecode'}) {
6919: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6920: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6921: $changes{'uniquecode'} = 1;
6922: }
6923: }
6924: }
6925: } else {
6926: $changes{'uniquecode'} = 1;
6927: }
6928: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6929: $changes{'uniquecode'} = 1;
6930: }
6931: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6932: foreach my $type ('textbooks','templates') {
6933: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6934: my %deletions;
6935: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6936: if (@todelete) {
6937: map { $deletions{$_} = 1; } @todelete;
6938: }
6939: my %imgdeletions;
6940: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6941: if (@todeleteimages) {
6942: map { $imgdeletions{$_} = 1; } @todeleteimages;
6943: }
6944: my $maxnum = $env{'form.'.$type.'_maxnum'};
6945: for (my $i=0; $i<=$maxnum; $i++) {
6946: my $itemid = $env{'form.'.$type.'_id_'.$i};
6947: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6948: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6949: if ($deletions{$key}) {
6950: if ($domconfig{$action}{$type}{$key}{'image'}) {
6951: #FIXME need to obsolete item in RES space
6952: }
6953: next;
6954: } else {
6955: my $newpos = $env{'form.'.$itemid};
6956: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 6957: foreach my $item ('subject','title','publisher','author') {
6958: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6959: ($type eq 'templates'));
1.160.6.46 raeburn 6960: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6961: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6962: $changes{$type}{$key} = 1;
6963: }
6964: }
6965: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 6966: }
1.160.6.46 raeburn 6967: if ($imgdeletions{$key}) {
6968: $changes{$type}{$key} = 1;
6969: #FIXME need to obsolete item in RES space
6970: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
6971: my ($cdom,$cnum) = split(/_/,$key);
6972: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
6973: $cdom,$cnum,$type,$configuserok,
6974: $switchserver,$author_ok);
6975: if ($imgurl) {
6976: $confhash{$type}{$key}{'image'} = $imgurl;
6977: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 6978: }
1.160.6.46 raeburn 6979: if ($error) {
6980: &Apache::lonnet::logthis($error);
6981: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6982: }
6983: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
6984: $confhash{$type}{$key}{'image'} =
6985: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 6986: }
6987: }
6988: }
6989: }
6990: }
6991: }
1.102 raeburn 6992: } else {
1.144 raeburn 6993: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6994: $changes{'notify'}{'approval'} = 1;
6995: }
1.160.6.30 raeburn 6996: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6997: $changes{'uniquecode'} = 1;
6998: }
6999: }
7000: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7001: foreach my $type ('textbooks','templates') {
7002: if ($newbook{$type}) {
7003: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7004: foreach my $item ('subject','title','publisher','author') {
7005: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7006: ($type eq 'template'));
1.160.6.46 raeburn 7007: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7008: if ($env{'form.'.$type.'_addbook_'.$item}) {
7009: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7010: }
7011: }
7012: if ($type eq 'textbooks') {
7013: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7014: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7015: my ($imageurl,$error) =
7016: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7017: $configuserok,$switchserver,$author_ok);
7018: if ($imageurl) {
7019: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7020: }
7021: if ($error) {
7022: &Apache::lonnet::logthis($error);
7023: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7024: }
7025: }
1.160.6.30 raeburn 7026: }
7027: }
1.160.6.46 raeburn 7028: if (@{$allpos{$type}} > 0) {
7029: my $idx = 0;
7030: foreach my $item (@{$allpos{$type}}) {
7031: if ($item ne '') {
7032: $confhash{$type}{$item}{'order'} = $idx;
7033: if (ref($domconfig{$action}) eq 'HASH') {
7034: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7035: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7036: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7037: $changes{$type}{$item} = 1;
7038: }
1.160.6.30 raeburn 7039: }
7040: }
7041: }
1.160.6.46 raeburn 7042: $idx ++;
1.160.6.30 raeburn 7043: }
7044: }
7045: }
7046: }
1.160.6.39 raeburn 7047: if (ref($validationitemsref) eq 'ARRAY') {
7048: foreach my $item (@{$validationitemsref}) {
7049: if ($item eq 'fields') {
7050: my @changed;
7051: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7052: if (@{$confhash{'validation'}{$item}} > 0) {
7053: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7054: }
7055: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7056: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7057: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7058: $domconfig{'requestcourses'}{'validation'}{$item});
7059: } else {
7060: @changed = @{$confhash{'validation'}{$item}};
7061: }
7062: } else {
7063: @changed = @{$confhash{'validation'}{$item}};
7064: }
7065: if (@changed) {
7066: if ($confhash{'validation'}{$item}) {
7067: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7068: } else {
7069: $changes{'validation'}{$item} = &mt('None');
7070: }
7071: }
7072: } else {
7073: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7074: if ($item eq 'markup') {
7075: if ($env{'form.requestcourses_validation_'.$item}) {
7076: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7077: }
7078: }
7079: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7080: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7081: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7082: }
7083: } else {
7084: if ($confhash{'validation'}{$item} ne '') {
7085: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7086: }
7087: }
7088: }
7089: }
7090: }
7091: if ($env{'form.validationdc'}) {
7092: my $newval = $env{'form.validationdc'};
7093: my %domcoords = &get_active_dcs($dom);
7094: if (exists($domcoords{$newval})) {
7095: $confhash{'validation'}{'dc'} = $newval;
7096: }
7097: }
7098: if (ref($confhash{'validation'}) eq 'HASH') {
7099: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7100: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7101: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7102: if ($confhash{'validation'}{'dc'} eq '') {
7103: $changes{'validation'}{'dc'} = &mt('None');
7104: } else {
7105: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7106: }
7107: }
7108: } elsif ($confhash{'validation'}{'dc'} ne '') {
7109: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7110: }
7111: } elsif ($confhash{'validation'}{'dc'} ne '') {
7112: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7113: }
7114: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7115: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7116: $changes{'validation'}{'dc'} = &mt('None');
7117: }
7118: }
1.102 raeburn 7119: }
7120: } else {
1.86 raeburn 7121: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7122: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7123: }
1.72 raeburn 7124: foreach my $item (@usertools) {
7125: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7126: my $unset;
1.101 raeburn 7127: if ($context eq 'requestcourses') {
1.104 raeburn 7128: $unset = '0';
7129: if ($type eq '_LC_adv') {
7130: $unset = '';
7131: }
1.101 raeburn 7132: if ($confhash{$item}{$type} eq 'autolimit') {
7133: $confhash{$item}{$type} .= '=';
7134: unless ($limithash{$item}{$type} =~ /\D/) {
7135: $confhash{$item}{$type} .= $limithash{$item}{$type};
7136: }
7137: }
1.160.6.5 raeburn 7138: } elsif ($context eq 'requestauthor') {
7139: $unset = '0';
7140: if ($type eq '_LC_adv') {
7141: $unset = '';
7142: }
1.72 raeburn 7143: } else {
1.101 raeburn 7144: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7145: $confhash{$item}{$type} = 1;
7146: } else {
7147: $confhash{$item}{$type} = 0;
7148: }
1.72 raeburn 7149: }
1.86 raeburn 7150: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7151: if ($action eq 'requestauthor') {
7152: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7153: $changes{$type} = 1;
7154: }
7155: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7156: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7157: $changes{$item}{$type} = 1;
7158: }
7159: } else {
7160: if ($context eq 'requestcourses') {
1.104 raeburn 7161: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7162: $changes{$item}{$type} = 1;
7163: }
7164: } else {
7165: if (!$confhash{$item}{$type}) {
7166: $changes{$item}{$type} = 1;
7167: }
7168: }
7169: }
7170: } else {
7171: if ($context eq 'requestcourses') {
1.104 raeburn 7172: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7173: $changes{$item}{$type} = 1;
7174: }
1.160.6.5 raeburn 7175: } elsif ($context eq 'requestauthor') {
7176: if ($confhash{$type} ne $unset) {
7177: $changes{$type} = 1;
7178: }
1.72 raeburn 7179: } else {
7180: if (!$confhash{$item}{$type}) {
7181: $changes{$item}{$type} = 1;
7182: }
7183: }
7184: }
1.1 raeburn 7185: }
7186: }
1.160.6.5 raeburn 7187: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7188: if (ref($domconfig{'quotas'}) eq 'HASH') {
7189: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7190: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7191: if (exists($confhash{'defaultquota'}{$key})) {
7192: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7193: $changes{'defaultquota'}{$key} = 1;
7194: }
7195: } else {
7196: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7197: }
7198: }
1.86 raeburn 7199: } else {
7200: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7201: if (exists($confhash{'defaultquota'}{$key})) {
7202: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7203: $changes{'defaultquota'}{$key} = 1;
7204: }
7205: } else {
7206: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7207: }
1.1 raeburn 7208: }
7209: }
1.160.6.20 raeburn 7210: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7211: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7212: if (exists($confhash{'authorquota'}{$key})) {
7213: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7214: $changes{'authorquota'}{$key} = 1;
7215: }
7216: } else {
7217: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7218: }
7219: }
7220: }
1.1 raeburn 7221: }
1.86 raeburn 7222: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7223: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7224: if (ref($domconfig{'quotas'}) eq 'HASH') {
7225: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7226: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7227: $changes{'defaultquota'}{$key} = 1;
7228: }
7229: } else {
7230: if (!exists($domconfig{'quotas'}{$key})) {
7231: $changes{'defaultquota'}{$key} = 1;
7232: }
1.72 raeburn 7233: }
7234: } else {
1.86 raeburn 7235: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7236: }
1.1 raeburn 7237: }
7238: }
1.160.6.20 raeburn 7239: if (ref($confhash{'authorquota'}) eq 'HASH') {
7240: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7241: if (ref($domconfig{'quotas'}) eq 'HASH') {
7242: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7243: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7244: $changes{'authorquota'}{$key} = 1;
7245: }
7246: } else {
7247: $changes{'authorquota'}{$key} = 1;
7248: }
7249: } else {
7250: $changes{'authorquota'}{$key} = 1;
7251: }
7252: }
7253: }
1.1 raeburn 7254: }
1.72 raeburn 7255:
1.160.6.5 raeburn 7256: if ($context eq 'requestauthor') {
7257: $domdefaults{'requestauthor'} = \%confhash;
7258: } else {
7259: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7260: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7261: $domdefaults{$key} = $confhash{$key};
7262: }
1.160.6.5 raeburn 7263: }
1.72 raeburn 7264: }
1.160.6.5 raeburn 7265:
1.1 raeburn 7266: my %quotahash = (
1.86 raeburn 7267: $action => { %confhash }
1.1 raeburn 7268: );
7269: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7270: $dom);
7271: if ($putresult eq 'ok') {
7272: if (keys(%changes) > 0) {
1.72 raeburn 7273: my $cachetime = 24*60*60;
7274: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7275: if (ref($lastactref) eq 'HASH') {
7276: $lastactref->{'domdefaults'} = 1;
7277: }
1.1 raeburn 7278: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7279: unless (($context eq 'requestcourses') ||
7280: ($context eq 'requestauthor')) {
1.86 raeburn 7281: if (ref($changes{'defaultquota'}) eq 'HASH') {
7282: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7283: foreach my $type (@{$types},'default') {
7284: if (defined($changes{'defaultquota'}{$type})) {
7285: my $typetitle = $usertypes->{$type};
7286: if ($type eq 'default') {
7287: $typetitle = $othertitle;
7288: }
1.160.6.28 raeburn 7289: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7290: }
7291: }
1.86 raeburn 7292: $resulttext .= '</ul></li>';
1.72 raeburn 7293: }
1.160.6.20 raeburn 7294: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7295: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7296: foreach my $type (@{$types},'default') {
7297: if (defined($changes{'authorquota'}{$type})) {
7298: my $typetitle = $usertypes->{$type};
7299: if ($type eq 'default') {
7300: $typetitle = $othertitle;
7301: }
1.160.6.28 raeburn 7302: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7303: }
7304: }
7305: $resulttext .= '</ul></li>';
7306: }
1.72 raeburn 7307: }
1.80 raeburn 7308: my %newenv;
1.72 raeburn 7309: foreach my $item (@usertools) {
1.160.6.5 raeburn 7310: my (%haschgs,%inconf);
7311: if ($context eq 'requestauthor') {
7312: %haschgs = %changes;
7313: %inconf = %confhash;
7314: } else {
7315: if (ref($changes{$item}) eq 'HASH') {
7316: %haschgs = %{$changes{$item}};
7317: }
7318: if (ref($confhash{$item}) eq 'HASH') {
7319: %inconf = %{$confhash{$item}};
7320: }
7321: }
7322: if (keys(%haschgs) > 0) {
1.80 raeburn 7323: my $newacc =
7324: &Apache::lonnet::usertools_access($env{'user.name'},
7325: $env{'user.domain'},
1.86 raeburn 7326: $item,'reload',$context);
1.160.6.5 raeburn 7327: if (($context eq 'requestcourses') ||
7328: ($context eq 'requestauthor')) {
1.108 raeburn 7329: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7330: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7331: }
7332: } else {
7333: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7334: $newenv{'environment.availabletools.'.$item} = $newacc;
7335: }
1.80 raeburn 7336: }
1.160.6.5 raeburn 7337: unless ($context eq 'requestauthor') {
7338: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7339: }
1.72 raeburn 7340: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7341: if ($haschgs{$type}) {
1.72 raeburn 7342: my $typetitle = $usertypes->{$type};
7343: if ($type eq 'default') {
7344: $typetitle = $othertitle;
7345: } elsif ($type eq '_LC_adv') {
7346: $typetitle = 'LON-CAPA Advanced Users';
7347: }
1.160.6.5 raeburn 7348: if ($inconf{$type}) {
1.101 raeburn 7349: if ($context eq 'requestcourses') {
7350: my $cond;
1.160.6.5 raeburn 7351: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7352: if ($1 eq '') {
7353: $cond = &mt('(Automatic processing of any request).');
7354: } else {
7355: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7356: }
7357: } else {
1.160.6.5 raeburn 7358: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7359: }
7360: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7361: } elsif ($context eq 'requestauthor') {
7362: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7363: $titles{$inconf{$type}},$typetitle);
7364:
1.101 raeburn 7365: } else {
7366: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7367: }
1.72 raeburn 7368: } else {
1.104 raeburn 7369: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7370: if ($inconf{$type} eq '0') {
1.104 raeburn 7371: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7372: } else {
7373: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7374: }
7375: } else {
7376: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7377: }
1.72 raeburn 7378: }
7379: }
1.26 raeburn 7380: }
1.160.6.5 raeburn 7381: unless ($context eq 'requestauthor') {
7382: $resulttext .= '</ul></li>';
7383: }
1.26 raeburn 7384: }
1.1 raeburn 7385: }
1.160.6.5 raeburn 7386: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7387: if (ref($changes{'notify'}) eq 'HASH') {
7388: if ($changes{'notify'}{'approval'}) {
7389: if (ref($confhash{'notify'}) eq 'HASH') {
7390: if ($confhash{'notify'}{'approval'}) {
7391: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7392: } else {
1.160.6.5 raeburn 7393: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7394: }
7395: }
7396: }
7397: }
7398: }
1.160.6.30 raeburn 7399: if ($action eq 'requestcourses') {
7400: my @offon = ('off','on');
7401: if ($changes{'uniquecode'}) {
7402: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7403: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7404: $resulttext .= '<li>'.
7405: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7406: '</li>';
7407: } else {
7408: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7409: '</li>';
7410: }
7411: }
1.160.6.46 raeburn 7412: foreach my $type ('textbooks','templates') {
7413: if (ref($changes{$type}) eq 'HASH') {
7414: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7415: foreach my $key (sort(keys(%{$changes{$type}}))) {
7416: my %coursehash = &Apache::lonnet::coursedescription($key);
7417: my $coursetitle = $coursehash{'description'};
7418: my $position = $confhash{$type}{$key}{'order'} + 1;
7419: $resulttext .= '<li>';
1.160.6.47 raeburn 7420: foreach my $item ('subject','title','publisher','author') {
7421: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7422: ($type eq 'templates'));
1.160.6.46 raeburn 7423: my $name = $item.':';
7424: $name =~ s/^(\w)/\U$1/;
7425: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7426: }
7427: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7428: if ($type eq 'textbooks') {
7429: if ($confhash{$type}{$key}{'image'}) {
7430: $resulttext .= ' '.&mt('Image: [_1]',
7431: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7432: ' alt="Textbook cover" />').'<br />';
7433: }
7434: }
7435: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7436: }
1.160.6.46 raeburn 7437: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7438: }
7439: }
1.160.6.39 raeburn 7440: if (ref($changes{'validation'}) eq 'HASH') {
7441: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7442: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7443: foreach my $item (@{$validationitemsref}) {
7444: if (exists($changes{'validation'}{$item})) {
7445: if ($item eq 'markup') {
7446: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7447: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7448: } else {
7449: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7450: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7451: }
7452: }
7453: }
7454: if (exists($changes{'validation'}{'dc'})) {
7455: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7456: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7457: }
7458: }
7459: }
1.160.6.30 raeburn 7460: }
1.1 raeburn 7461: $resulttext .= '</ul>';
1.80 raeburn 7462: if (keys(%newenv)) {
7463: &Apache::lonnet::appenv(\%newenv);
7464: }
1.1 raeburn 7465: } else {
1.86 raeburn 7466: if ($context eq 'requestcourses') {
7467: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7468: } elsif ($context eq 'requestauthor') {
7469: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7470: } else {
1.90 weissno 7471: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7472: }
1.1 raeburn 7473: }
7474: } else {
1.11 albertel 7475: $resulttext = '<span class="LC_error">'.
7476: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7477: }
1.160.6.30 raeburn 7478: if ($errors) {
7479: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7480: '<ul>'.$errors.'</ul></p>';
7481: }
1.3 raeburn 7482: return $resulttext;
1.1 raeburn 7483: }
7484:
1.160.6.30 raeburn 7485: sub process_textbook_image {
1.160.6.46 raeburn 7486: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7487: my $filename = $env{'form.'.$caller.'.filename'};
7488: my ($error,$url);
7489: my ($width,$height) = (50,50);
7490: if ($configuserok eq 'ok') {
7491: if ($switchserver) {
7492: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7493: $switchserver);
7494: } elsif ($author_ok eq 'ok') {
7495: my ($result,$imageurl) =
7496: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7497: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7498: if ($result eq 'ok') {
7499: $url = $imageurl;
7500: } else {
7501: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7502: }
7503: } else {
7504: $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);
7505: }
7506: } else {
7507: $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);
7508: }
7509: return ($url,$error);
7510: }
7511:
1.3 raeburn 7512: sub modify_autoenroll {
1.160.6.24 raeburn 7513: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7514: my ($resulttext,%changes);
7515: my %currautoenroll;
7516: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7517: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7518: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7519: }
7520: }
7521: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7522: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7523: sender => 'Sender for notification messages',
7524: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7525: my @offon = ('off','on');
1.17 raeburn 7526: my $sender_uname = $env{'form.sender_uname'};
7527: my $sender_domain = $env{'form.sender_domain'};
7528: if ($sender_domain eq '') {
7529: $sender_uname = '';
7530: } elsif ($sender_uname eq '') {
7531: $sender_domain = '';
7532: }
1.129 raeburn 7533: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7534: my %autoenrollhash = (
1.129 raeburn 7535: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7536: 'sender_uname' => $sender_uname,
7537: 'sender_domain' => $sender_domain,
7538: 'co-owners' => $coowners,
1.1 raeburn 7539: }
7540: );
1.4 raeburn 7541: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7542: $dom);
1.1 raeburn 7543: if ($putresult eq 'ok') {
7544: if (exists($currautoenroll{'run'})) {
7545: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7546: $changes{'run'} = 1;
7547: }
7548: } elsif ($autorun) {
7549: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7550: $changes{'run'} = 1;
1.1 raeburn 7551: }
7552: }
1.17 raeburn 7553: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7554: $changes{'sender'} = 1;
7555: }
1.17 raeburn 7556: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7557: $changes{'sender'} = 1;
7558: }
1.129 raeburn 7559: if ($currautoenroll{'co-owners'} ne '') {
7560: if ($currautoenroll{'co-owners'} ne $coowners) {
7561: $changes{'coowners'} = 1;
7562: }
7563: } elsif ($coowners) {
7564: $changes{'coowners'} = 1;
7565: }
1.1 raeburn 7566: if (keys(%changes) > 0) {
7567: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7568: if ($changes{'run'}) {
1.1 raeburn 7569: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7570: }
7571: if ($changes{'sender'}) {
1.17 raeburn 7572: if ($sender_uname eq '' || $sender_domain eq '') {
7573: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7574: } else {
7575: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7576: }
1.1 raeburn 7577: }
1.129 raeburn 7578: if ($changes{'coowners'}) {
7579: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7580: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7581: if (ref($lastactref) eq 'HASH') {
7582: $lastactref->{'domainconfig'} = 1;
7583: }
1.129 raeburn 7584: }
1.1 raeburn 7585: $resulttext .= '</ul>';
7586: } else {
7587: $resulttext = &mt('No changes made to auto-enrollment settings');
7588: }
7589: } else {
1.11 albertel 7590: $resulttext = '<span class="LC_error">'.
7591: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7592: }
1.3 raeburn 7593: return $resulttext;
1.1 raeburn 7594: }
7595:
7596: sub modify_autoupdate {
1.3 raeburn 7597: my ($dom,%domconfig) = @_;
1.1 raeburn 7598: my ($resulttext,%currautoupdate,%fields,%changes);
7599: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7600: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7601: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7602: }
7603: }
7604: my @offon = ('off','on');
7605: my %title = &Apache::lonlocal::texthash (
7606: run => 'Auto-update:',
7607: classlists => 'Updates to user information in classlists?'
7608: );
1.44 raeburn 7609: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7610: my %fieldtitles = &Apache::lonlocal::texthash (
7611: id => 'Student/Employee ID',
1.20 raeburn 7612: permanentemail => 'E-mail address',
1.1 raeburn 7613: lastname => 'Last Name',
7614: firstname => 'First Name',
7615: middlename => 'Middle Name',
1.132 raeburn 7616: generation => 'Generation',
1.1 raeburn 7617: );
1.142 raeburn 7618: $othertitle = &mt('All users');
1.1 raeburn 7619: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7620: $othertitle = &mt('Other users');
1.1 raeburn 7621: }
7622: foreach my $key (keys(%env)) {
7623: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7624: my ($usertype,$item) = ($1,$2);
7625: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7626: if ($usertype eq 'default') {
7627: push(@{$fields{$1}},$2);
7628: } elsif (ref($types) eq 'ARRAY') {
7629: if (grep(/^\Q$usertype\E$/,@{$types})) {
7630: push(@{$fields{$1}},$2);
7631: }
7632: }
7633: }
1.1 raeburn 7634: }
7635: }
1.131 raeburn 7636: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7637: @lockablenames = sort(@lockablenames);
7638: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7639: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7640: if (@changed) {
7641: $changes{'lockablenames'} = 1;
7642: }
7643: } else {
7644: if (@lockablenames) {
7645: $changes{'lockablenames'} = 1;
7646: }
7647: }
1.1 raeburn 7648: my %updatehash = (
7649: autoupdate => { run => $env{'form.autoupdate_run'},
7650: classlists => $env{'form.classlists'},
7651: fields => {%fields},
1.131 raeburn 7652: lockablenames => \@lockablenames,
1.1 raeburn 7653: }
7654: );
7655: foreach my $key (keys(%currautoupdate)) {
7656: if (($key eq 'run') || ($key eq 'classlists')) {
7657: if (exists($updatehash{autoupdate}{$key})) {
7658: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7659: $changes{$key} = 1;
7660: }
7661: }
7662: } elsif ($key eq 'fields') {
7663: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7664: foreach my $item (@{$types},'default') {
1.1 raeburn 7665: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7666: my $change = 0;
7667: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7668: if (!exists($fields{$item})) {
7669: $change = 1;
1.132 raeburn 7670: last;
1.1 raeburn 7671: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7672: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7673: $change = 1;
1.132 raeburn 7674: last;
1.1 raeburn 7675: }
7676: }
7677: }
7678: if ($change) {
7679: push(@{$changes{$key}},$item);
7680: }
1.26 raeburn 7681: }
1.1 raeburn 7682: }
7683: }
1.131 raeburn 7684: } elsif ($key eq 'lockablenames') {
7685: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7686: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7687: if (@changed) {
7688: $changes{'lockablenames'} = 1;
7689: }
7690: } else {
7691: if (@lockablenames) {
7692: $changes{'lockablenames'} = 1;
7693: }
7694: }
7695: }
7696: }
7697: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7698: if (@lockablenames) {
7699: $changes{'lockablenames'} = 1;
1.1 raeburn 7700: }
7701: }
1.26 raeburn 7702: foreach my $item (@{$types},'default') {
7703: if (defined($fields{$item})) {
7704: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7705: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7706: my $change = 0;
7707: if (ref($fields{$item}) eq 'ARRAY') {
7708: foreach my $type (@{$fields{$item}}) {
7709: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7710: $change = 1;
7711: last;
7712: }
7713: }
7714: }
7715: if ($change) {
7716: push(@{$changes{'fields'}},$item);
7717: }
7718: } else {
1.26 raeburn 7719: push(@{$changes{'fields'}},$item);
7720: }
7721: } else {
7722: push(@{$changes{'fields'}},$item);
1.1 raeburn 7723: }
7724: }
7725: }
7726: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7727: $dom);
7728: if ($putresult eq 'ok') {
7729: if (keys(%changes) > 0) {
7730: $resulttext = &mt('Changes made:').'<ul>';
7731: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7732: if ($key eq 'lockablenames') {
7733: $resulttext .= '<li>';
7734: if (@lockablenames) {
7735: $usertypes->{'default'} = $othertitle;
7736: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7737: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7738: } else {
7739: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7740: }
7741: $resulttext .= '</li>';
7742: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7743: foreach my $item (@{$changes{$key}}) {
7744: my @newvalues;
7745: foreach my $type (@{$fields{$item}}) {
7746: push(@newvalues,$fieldtitles{$type});
7747: }
1.3 raeburn 7748: my $newvaluestr;
7749: if (@newvalues > 0) {
7750: $newvaluestr = join(', ',@newvalues);
7751: } else {
7752: $newvaluestr = &mt('none');
1.6 raeburn 7753: }
1.1 raeburn 7754: if ($item eq 'default') {
1.26 raeburn 7755: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7756: } else {
1.26 raeburn 7757: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7758: }
7759: }
7760: } else {
7761: my $newvalue;
7762: if ($key eq 'run') {
7763: $newvalue = $offon[$env{'form.autoupdate_run'}];
7764: } else {
7765: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7766: }
1.1 raeburn 7767: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7768: }
7769: }
7770: $resulttext .= '</ul>';
7771: } else {
1.3 raeburn 7772: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7773: }
7774: } else {
1.11 albertel 7775: $resulttext = '<span class="LC_error">'.
7776: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7777: }
1.3 raeburn 7778: return $resulttext;
1.1 raeburn 7779: }
7780:
1.125 raeburn 7781: sub modify_autocreate {
7782: my ($dom,%domconfig) = @_;
7783: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7784: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7785: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7786: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7787: }
7788: }
7789: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7790: req => 'Auto-creation of validated requests for official courses',
7791: xmldc => 'Identity of course creator of courses from XML files',
7792: );
7793: my @types = ('xml','req');
7794: foreach my $item (@types) {
7795: $newvals{$item} = $env{'form.autocreate_'.$item};
7796: $newvals{$item} =~ s/\D//g;
7797: $newvals{$item} = 0 if ($newvals{$item} eq '');
7798: }
7799: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7800: my %domcoords = &get_active_dcs($dom);
7801: unless (exists($domcoords{$newvals{'xmldc'}})) {
7802: $newvals{'xmldc'} = '';
7803: }
7804: %autocreatehash = (
7805: autocreate => { xml => $newvals{'xml'},
7806: req => $newvals{'req'},
7807: }
7808: );
7809: if ($newvals{'xmldc'} ne '') {
7810: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7811: }
7812: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7813: $dom);
7814: if ($putresult eq 'ok') {
7815: my @items = @types;
7816: if ($newvals{'xml'}) {
7817: push(@items,'xmldc');
7818: }
7819: foreach my $item (@items) {
7820: if (exists($currautocreate{$item})) {
7821: if ($currautocreate{$item} ne $newvals{$item}) {
7822: $changes{$item} = 1;
7823: }
7824: } elsif ($newvals{$item}) {
7825: $changes{$item} = 1;
7826: }
7827: }
7828: if (keys(%changes) > 0) {
7829: my @offon = ('off','on');
7830: $resulttext = &mt('Changes made:').'<ul>';
7831: foreach my $item (@types) {
7832: if ($changes{$item}) {
7833: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7834: $resulttext .= '<li>'.
7835: &mt("$title{$item} set to [_1]$newtxt [_2]",
7836: '<b>','</b>').
7837: '</li>';
1.125 raeburn 7838: }
7839: }
7840: if ($changes{'xmldc'}) {
7841: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7842: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7843: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7844: }
7845: $resulttext .= '</ul>';
7846: } else {
7847: $resulttext = &mt('No changes made to auto-creation settings');
7848: }
7849: } else {
7850: $resulttext = '<span class="LC_error">'.
7851: &mt('An error occurred: [_1]',$putresult).'</span>';
7852: }
7853: return $resulttext;
7854: }
7855:
1.23 raeburn 7856: sub modify_directorysrch {
7857: my ($dom,%domconfig) = @_;
7858: my ($resulttext,%changes);
7859: my %currdirsrch;
7860: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7861: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7862: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7863: }
7864: }
7865: my %title = ( available => 'Directory search available',
1.24 raeburn 7866: localonly => 'Other domains can search',
1.23 raeburn 7867: searchby => 'Search types',
7868: searchtypes => 'Search latitude');
7869: my @offon = ('off','on');
1.24 raeburn 7870: my @otherdoms = ('Yes','No');
1.23 raeburn 7871:
1.25 raeburn 7872: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7873: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7874: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7875:
1.44 raeburn 7876: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7877: if (keys(%{$usertypes}) == 0) {
7878: @cansearch = ('default');
7879: } else {
7880: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7881: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7882: if (!grep(/^\Q$type\E$/,@cansearch)) {
7883: push(@{$changes{'cansearch'}},$type);
7884: }
1.23 raeburn 7885: }
1.26 raeburn 7886: foreach my $type (@cansearch) {
7887: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7888: push(@{$changes{'cansearch'}},$type);
7889: }
1.23 raeburn 7890: }
1.26 raeburn 7891: } else {
7892: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7893: }
7894: }
7895:
7896: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7897: foreach my $by (@{$currdirsrch{'searchby'}}) {
7898: if (!grep(/^\Q$by\E$/,@searchby)) {
7899: push(@{$changes{'searchby'}},$by);
7900: }
7901: }
7902: foreach my $by (@searchby) {
7903: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7904: push(@{$changes{'searchby'}},$by);
7905: }
7906: }
7907: } else {
7908: push(@{$changes{'searchby'}},@searchby);
7909: }
1.25 raeburn 7910:
7911: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7912: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7913: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7914: push(@{$changes{'searchtypes'}},$type);
7915: }
7916: }
7917: foreach my $type (@searchtypes) {
7918: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7919: push(@{$changes{'searchtypes'}},$type);
7920: }
7921: }
7922: } else {
7923: if (exists($currdirsrch{'searchtypes'})) {
7924: foreach my $type (@searchtypes) {
7925: if ($type ne $currdirsrch{'searchtypes'}) {
7926: push(@{$changes{'searchtypes'}},$type);
7927: }
7928: }
7929: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7930: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7931: }
7932: } else {
7933: push(@{$changes{'searchtypes'}},@searchtypes);
7934: }
7935: }
7936:
1.23 raeburn 7937: my %dirsrch_hash = (
7938: directorysrch => { available => $env{'form.dirsrch_available'},
7939: cansearch => \@cansearch,
1.24 raeburn 7940: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7941: searchby => \@searchby,
1.25 raeburn 7942: searchtypes => \@searchtypes,
1.23 raeburn 7943: }
7944: );
7945: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7946: $dom);
7947: if ($putresult eq 'ok') {
7948: if (exists($currdirsrch{'available'})) {
7949: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7950: $changes{'available'} = 1;
7951: }
7952: } else {
7953: if ($env{'form.dirsrch_available'} eq '1') {
7954: $changes{'available'} = 1;
7955: }
7956: }
1.24 raeburn 7957: if (exists($currdirsrch{'localonly'})) {
7958: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7959: $changes{'localonly'} = 1;
7960: }
7961: } else {
7962: if ($env{'form.dirsrch_localonly'} eq '1') {
7963: $changes{'localonly'} = 1;
7964: }
7965: }
1.23 raeburn 7966: if (keys(%changes) > 0) {
7967: $resulttext = &mt('Changes made:').'<ul>';
7968: if ($changes{'available'}) {
7969: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7970: }
1.24 raeburn 7971: if ($changes{'localonly'}) {
7972: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7973: }
7974:
1.23 raeburn 7975: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7976: my $chgtext;
1.26 raeburn 7977: if (ref($usertypes) eq 'HASH') {
7978: if (keys(%{$usertypes}) > 0) {
7979: foreach my $type (@{$types}) {
7980: if (grep(/^\Q$type\E$/,@cansearch)) {
7981: $chgtext .= $usertypes->{$type}.'; ';
7982: }
7983: }
7984: if (grep(/^default$/,@cansearch)) {
7985: $chgtext .= $othertitle;
7986: } else {
7987: $chgtext =~ s/\; $//;
7988: }
1.160.6.13 raeburn 7989: $resulttext .=
7990: '<li>'.
7991: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7992: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7993: '</li>';
1.23 raeburn 7994: }
7995: }
7996: }
7997: if (ref($changes{'searchby'}) eq 'ARRAY') {
7998: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7999: my $chgtext;
8000: foreach my $type (@{$titleorder}) {
8001: if (grep(/^\Q$type\E$/,@searchby)) {
8002: if (defined($searchtitles->{$type})) {
8003: $chgtext .= $searchtitles->{$type}.'; ';
8004: }
8005: }
8006: }
8007: $chgtext =~ s/\; $//;
8008: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8009: }
1.25 raeburn 8010: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8011: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8012: my $chgtext;
8013: foreach my $type (@{$srchtypeorder}) {
8014: if (grep(/^\Q$type\E$/,@searchtypes)) {
8015: if (defined($srchtypes_desc->{$type})) {
8016: $chgtext .= $srchtypes_desc->{$type}.'; ';
8017: }
8018: }
8019: }
8020: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8021: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8022: }
8023: $resulttext .= '</ul>';
8024: } else {
8025: $resulttext = &mt('No changes made to institution directory search settings');
8026: }
8027: } else {
8028: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8029: &mt('An error occurred: [_1]',$putresult).'</span>';
8030: }
8031: return $resulttext;
8032: }
8033:
1.28 raeburn 8034: sub modify_contacts {
1.160.6.24 raeburn 8035: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8036: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8037: if (ref($domconfig{'contacts'}) eq 'HASH') {
8038: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8039: $currsetting{$key} = $domconfig{'contacts'}{$key};
8040: }
8041: }
1.134 raeburn 8042: my (%others,%to,%bcc);
1.28 raeburn 8043: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8044: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8045: 'requestsmail','updatesmail','idconflictsmail');
8046: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8047: foreach my $type (@mailings) {
8048: @{$newsetting{$type}} =
8049: &Apache::loncommon::get_env_multiple('form.'.$type);
8050: foreach my $item (@contacts) {
8051: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8052: $contacts_hash{contacts}{$type}{$item} = 1;
8053: } else {
8054: $contacts_hash{contacts}{$type}{$item} = 0;
8055: }
8056: }
8057: $others{$type} = $env{'form.'.$type.'_others'};
8058: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8059: if ($type eq 'helpdeskmail') {
8060: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8061: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8062: }
1.28 raeburn 8063: }
8064: foreach my $item (@contacts) {
8065: $to{$item} = $env{'form.'.$item};
8066: $contacts_hash{'contacts'}{$item} = $to{$item};
8067: }
1.160.6.23 raeburn 8068: foreach my $item (@toggles) {
8069: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8070: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8071: }
8072: }
1.28 raeburn 8073: if (keys(%currsetting) > 0) {
8074: foreach my $item (@contacts) {
8075: if ($to{$item} ne $currsetting{$item}) {
8076: $changes{$item} = 1;
8077: }
8078: }
8079: foreach my $type (@mailings) {
8080: foreach my $item (@contacts) {
8081: if (ref($currsetting{$type}) eq 'HASH') {
8082: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8083: push(@{$changes{$type}},$item);
8084: }
8085: } else {
8086: push(@{$changes{$type}},@{$newsetting{$type}});
8087: }
8088: }
8089: if ($others{$type} ne $currsetting{$type}{'others'}) {
8090: push(@{$changes{$type}},'others');
8091: }
1.134 raeburn 8092: if ($type eq 'helpdeskmail') {
8093: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8094: push(@{$changes{$type}},'bcc');
8095: }
8096: }
1.28 raeburn 8097: }
8098: } else {
8099: my %default;
8100: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8101: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8102: $default{'errormail'} = 'adminemail';
8103: $default{'packagesmail'} = 'adminemail';
8104: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8105: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8106: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8107: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8108: foreach my $item (@contacts) {
8109: if ($to{$item} ne $default{$item}) {
8110: $changes{$item} = 1;
1.160.6.23 raeburn 8111: }
1.28 raeburn 8112: }
8113: foreach my $type (@mailings) {
8114: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8115:
8116: push(@{$changes{$type}},@{$newsetting{$type}});
8117: }
8118: if ($others{$type} ne '') {
8119: push(@{$changes{$type}},'others');
1.134 raeburn 8120: }
8121: if ($type eq 'helpdeskmail') {
8122: if ($bcc{$type} ne '') {
8123: push(@{$changes{$type}},'bcc');
8124: }
8125: }
1.28 raeburn 8126: }
8127: }
1.160.6.23 raeburn 8128: foreach my $item (@toggles) {
8129: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8130: $changes{$item} = 1;
8131: } elsif ((!$env{'form.'.$item}) &&
8132: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8133: $changes{$item} = 1;
8134: }
8135: }
1.28 raeburn 8136: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8137: $dom);
8138: if ($putresult eq 'ok') {
8139: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8140: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8141: if (ref($lastactref) eq 'HASH') {
8142: $lastactref->{'domainconfig'} = 1;
8143: }
1.28 raeburn 8144: my ($titles,$short_titles) = &contact_titles();
8145: $resulttext = &mt('Changes made:').'<ul>';
8146: foreach my $item (@contacts) {
8147: if ($changes{$item}) {
8148: $resulttext .= '<li>'.$titles->{$item}.
8149: &mt(' set to: ').
8150: '<span class="LC_cusr_emph">'.
8151: $to{$item}.'</span></li>';
8152: }
8153: }
8154: foreach my $type (@mailings) {
8155: if (ref($changes{$type}) eq 'ARRAY') {
8156: $resulttext .= '<li>'.$titles->{$type}.': ';
8157: my @text;
8158: foreach my $item (@{$newsetting{$type}}) {
8159: push(@text,$short_titles->{$item});
8160: }
8161: if ($others{$type} ne '') {
8162: push(@text,$others{$type});
8163: }
8164: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8165: join(', ',@text).'</span>';
8166: if ($type eq 'helpdeskmail') {
8167: if ($bcc{$type} ne '') {
8168: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8169: }
8170: }
8171: $resulttext .= '</li>';
1.28 raeburn 8172: }
8173: }
1.160.6.23 raeburn 8174: my @offon = ('off','on');
8175: if ($changes{'reporterrors'}) {
8176: $resulttext .= '<li>'.
8177: &mt('E-mail error reports to [_1] set to "'.
8178: $offon[$env{'form.reporterrors'}].'".',
8179: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8180: &mt('LON-CAPA core group - MSU'),600,500)).
8181: '</li>';
8182: }
8183: if ($changes{'reportupdates'}) {
8184: $resulttext .= '<li>'.
8185: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8186: $offon[$env{'form.reportupdates'}].'".',
8187: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8188: &mt('LON-CAPA core group - MSU'),600,500)).
8189: '</li>';
8190: }
1.28 raeburn 8191: $resulttext .= '</ul>';
8192: } else {
1.34 raeburn 8193: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8194: }
8195: } else {
8196: $resulttext = '<span class="LC_error">'.
8197: &mt('An error occurred: [_1].',$putresult).'</span>';
8198: }
8199: return $resulttext;
8200: }
8201:
8202: sub modify_usercreation {
1.27 raeburn 8203: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8204: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8205: my $warningmsg;
1.27 raeburn 8206: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8207: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8208: if ($key eq 'cancreate') {
8209: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8210: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8211: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8212: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8213: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8214: } else {
8215: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8216: }
1.50 raeburn 8217: }
1.43 raeburn 8218: }
1.160.6.34 raeburn 8219: } elsif ($key eq 'email_rule') {
8220: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8221: } else {
8222: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8223: }
8224: }
1.34 raeburn 8225: }
1.160.6.34 raeburn 8226: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8227: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8228: my @contexts = ('author','course','requestcrs');
8229: foreach my $item(@contexts) {
8230: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8231: }
1.34 raeburn 8232: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8233: foreach my $item (@contexts) {
1.160.6.34 raeburn 8234: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8235: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8236: }
1.27 raeburn 8237: }
1.34 raeburn 8238: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8239: foreach my $item (@contexts) {
1.43 raeburn 8240: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8241: if ($cancreate{$item} ne 'any') {
8242: push(@{$changes{'cancreate'}},$item);
8243: }
8244: } else {
8245: if ($cancreate{$item} ne 'none') {
8246: push(@{$changes{'cancreate'}},$item);
8247: }
1.27 raeburn 8248: }
8249: }
8250: } else {
1.43 raeburn 8251: foreach my $item (@contexts) {
1.34 raeburn 8252: push(@{$changes{'cancreate'}},$item);
8253: }
1.27 raeburn 8254: }
1.34 raeburn 8255:
1.27 raeburn 8256: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8257: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8258: if (!grep(/^\Q$type\E$/,@username_rule)) {
8259: push(@{$changes{'username_rule'}},$type);
8260: }
8261: }
8262: foreach my $type (@username_rule) {
8263: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8264: push(@{$changes{'username_rule'}},$type);
8265: }
8266: }
8267: } else {
8268: push(@{$changes{'username_rule'}},@username_rule);
8269: }
8270:
1.32 raeburn 8271: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8272: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8273: if (!grep(/^\Q$type\E$/,@id_rule)) {
8274: push(@{$changes{'id_rule'}},$type);
8275: }
8276: }
8277: foreach my $type (@id_rule) {
8278: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8279: push(@{$changes{'id_rule'}},$type);
8280: }
8281: }
8282: } else {
8283: push(@{$changes{'id_rule'}},@id_rule);
8284: }
8285:
1.43 raeburn 8286: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8287: my @authtypes = ('int','krb4','krb5','loc');
8288: my %authhash;
1.43 raeburn 8289: foreach my $item (@authen_contexts) {
1.28 raeburn 8290: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8291: foreach my $auth (@authtypes) {
8292: if (grep(/^\Q$auth\E$/,@authallowed)) {
8293: $authhash{$item}{$auth} = 1;
8294: } else {
8295: $authhash{$item}{$auth} = 0;
8296: }
8297: }
8298: }
8299: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8300: foreach my $item (@authen_contexts) {
1.28 raeburn 8301: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8302: foreach my $auth (@authtypes) {
8303: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8304: push(@{$changes{'authtypes'}},$item);
8305: last;
8306: }
8307: }
8308: }
8309: }
8310: } else {
1.43 raeburn 8311: foreach my $item (@authen_contexts) {
1.28 raeburn 8312: push(@{$changes{'authtypes'}},$item);
8313: }
8314: }
8315:
1.160.6.34 raeburn 8316: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8317: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8318: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8319: $save_usercreate{'id_rule'} = \@id_rule;
8320: $save_usercreate{'username_rule'} = \@username_rule,
8321: $save_usercreate{'authtypes'} = \%authhash;
8322:
1.27 raeburn 8323: my %usercreation_hash = (
1.160.6.34 raeburn 8324: usercreation => \%save_usercreate,
8325: );
1.27 raeburn 8326:
8327: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8328: $dom);
1.50 raeburn 8329:
1.160.6.34 raeburn 8330: if ($putresult eq 'ok') {
8331: if (keys(%changes) > 0) {
8332: $resulttext = &mt('Changes made:').'<ul>';
8333: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8334: my %lt = &usercreation_types();
8335: foreach my $type (@{$changes{'cancreate'}}) {
8336: my $chgtext = $lt{$type}.', ';
8337: if ($cancreate{$type} eq 'none') {
8338: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8339: } elsif ($cancreate{$type} eq 'any') {
8340: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8341: } elsif ($cancreate{$type} eq 'official') {
8342: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8343: } elsif ($cancreate{$type} eq 'unofficial') {
8344: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8345: }
8346: $resulttext .= '<li>'.$chgtext.'</li>';
8347: }
8348: }
8349: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8350: my ($rules,$ruleorder) =
8351: &Apache::lonnet::inst_userrules($dom,'username');
8352: my $chgtext = '<ul>';
8353: foreach my $type (@username_rule) {
8354: if (ref($rules->{$type}) eq 'HASH') {
8355: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8356: }
8357: }
8358: $chgtext .= '</ul>';
8359: if (@username_rule > 0) {
8360: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8361: } else {
8362: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8363: }
8364: }
8365: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8366: my ($idrules,$idruleorder) =
8367: &Apache::lonnet::inst_userrules($dom,'id');
8368: my $chgtext = '<ul>';
8369: foreach my $type (@id_rule) {
8370: if (ref($idrules->{$type}) eq 'HASH') {
8371: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8372: }
8373: }
8374: $chgtext .= '</ul>';
8375: if (@id_rule > 0) {
8376: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8377: } else {
8378: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8379: }
8380: }
8381: my %authname = &authtype_names();
8382: my %context_title = &context_names();
8383: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8384: my $chgtext = '<ul>';
8385: foreach my $type (@{$changes{'authtypes'}}) {
8386: my @allowed;
8387: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8388: foreach my $auth (@authtypes) {
8389: if ($authhash{$type}{$auth}) {
8390: push(@allowed,$authname{$auth});
8391: }
8392: }
8393: if (@allowed > 0) {
8394: $chgtext .= join(', ',@allowed).'</li>';
8395: } else {
8396: $chgtext .= &mt('none').'</li>';
8397: }
8398: }
8399: $chgtext .= '</ul>';
8400: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8401: $resulttext .= '</li>';
8402: }
8403: $resulttext .= '</ul>';
8404: } else {
8405: $resulttext = &mt('No changes made to user creation settings');
8406: }
8407: } else {
8408: $resulttext = '<span class="LC_error">'.
8409: &mt('An error occurred: [_1]',$putresult).'</span>';
8410: }
8411: if ($warningmsg ne '') {
8412: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8413: }
8414: return $resulttext;
8415: }
8416:
8417: sub modify_selfcreation {
8418: my ($dom,%domconfig) = @_;
8419: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8420: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8421: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8422: if (ref($types) eq 'ARRAY') {
8423: $usertypes->{'default'} = $othertitle;
8424: push(@{$types},'default');
8425: }
1.160.6.34 raeburn 8426: #
8427: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8428: #
8429: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8430: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8431: if ($key eq 'cancreate') {
8432: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8433: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8434: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8435: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8436: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8437: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8438: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8439: } else {
8440: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8441: }
8442: }
8443: }
8444: } elsif ($key eq 'email_rule') {
8445: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8446: } else {
8447: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8448: }
8449: }
8450: }
8451: #
8452: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8453: #
8454: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8455: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8456: if ($key eq 'selfcreate') {
8457: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8458: } else {
8459: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8460: }
8461: }
8462: }
8463:
8464: my @contexts = ('selfcreate');
8465: @{$cancreate{'selfcreate'}} = ();
8466: %{$cancreate{'emailusername'}} = ();
8467: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8468: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8469: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8470: my %selfcreatetypes = (
8471: sso => 'users authenticated by institutional single sign on',
8472: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8473: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8474: );
1.160.6.34 raeburn 8475: #
8476: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8477: # is permitted.
8478: #
1.160.6.40 raeburn 8479:
8480: my @statuses;
8481: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8482: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8483: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8484: }
8485: }
8486: push(@statuses,'default');
8487:
1.160.6.35 raeburn 8488: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8489: if ($item eq 'email') {
1.160.6.40 raeburn 8490: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8491: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8492: push(@contexts,'selfcreateprocessing');
8493: foreach my $type (@statuses) {
8494: if ($type eq 'default') {
8495: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8496: } else {
8497: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8498: }
8499: }
1.160.6.34 raeburn 8500: }
8501: } else {
8502: if ($env{'form.cancreate_'.$item}) {
8503: push(@{$cancreate{'selfcreate'}},$item);
8504: }
8505: }
8506: }
8507: my (@email_rule,%userinfo,%savecaptcha);
8508: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8509: #
1.160.6.35 raeburn 8510: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8511: # 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 8512: #
1.160.6.40 raeburn 8513:
1.160.6.48 raeburn 8514: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8515: push(@contexts,'emailusername');
1.160.6.35 raeburn 8516: if (ref($types) eq 'ARRAY') {
8517: foreach my $type (@{$types}) {
8518: if (ref($infofields) eq 'ARRAY') {
8519: foreach my $field (@{$infofields}) {
8520: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8521: $cancreate{'emailusername'}{$type}{$field} = $1;
8522: }
8523: }
1.160.6.34 raeburn 8524: }
8525: }
8526: }
8527: #
8528: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8529: # queued requests for self-creation of account using e-mail address as username
8530: #
8531:
8532: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8533: @approvalnotify = sort(@approvalnotify);
8534: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8535: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8536: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8537: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8538: push(@{$changes{'cancreate'}},'notify');
8539: }
8540: } else {
8541: if ($cancreate{'notify'}{'approval'}) {
8542: push(@{$changes{'cancreate'}},'notify');
8543: }
8544: }
8545: } elsif ($cancreate{'notify'}{'approval'}) {
8546: push(@{$changes{'cancreate'}},'notify');
8547: }
8548:
8549: #
8550: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8551: #
8552: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8553: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8554: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8555: if (@{$curr_usercreation{'email_rule'}} > 0) {
8556: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8557: if (!grep(/^\Q$type\E$/,@email_rule)) {
8558: push(@{$changes{'email_rule'}},$type);
8559: }
8560: }
8561: }
8562: if (@email_rule > 0) {
8563: foreach my $type (@email_rule) {
8564: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8565: push(@{$changes{'email_rule'}},$type);
8566: }
8567: }
8568: }
8569: } elsif (@email_rule > 0) {
8570: push(@{$changes{'email_rule'}},@email_rule);
8571: }
8572: }
8573: #
1.160.6.40 raeburn 8574: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8575: # institutional log-in.
8576: #
8577: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8579: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8580: ($domdefaults{'auth_def'} eq 'localauth'))) {
8581: $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.').' '.
8582: &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.');
8583: }
8584: }
8585: my @fields = ('lastname','firstname','middlename','generation',
8586: 'permanentemail','id');
1.160.6.44 raeburn 8587: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8588: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8589: #
8590: # Where usernames may created for institutional log-in and/or institutional single sign on:
8591: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8592: # may self-create accounts
8593: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8594: # which the user may supply, if institutional data is unavailable.
8595: #
8596: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8597: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8598: if (@{$types} > 1) {
1.160.6.34 raeburn 8599: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8600: push(@contexts,'statustocreate');
8601: } else {
8602: undef($cancreate{'statustocreate'});
8603: }
8604: foreach my $type (@{$types}) {
8605: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8606: foreach my $field (@fields) {
8607: if (grep(/^\Q$field\E$/,@modifiable)) {
8608: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8609: } else {
8610: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8611: }
8612: }
8613: }
8614: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8615: foreach my $type (@{$types}) {
8616: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8617: foreach my $field (@fields) {
8618: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8619: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8620: push(@{$changes{'selfcreate'}},$type);
8621: last;
8622: }
8623: }
8624: }
8625: }
8626: } else {
8627: foreach my $type (@{$types}) {
8628: push(@{$changes{'selfcreate'}},$type);
8629: }
8630: }
8631: }
1.160.6.44 raeburn 8632: foreach my $field (@shibfields) {
8633: if ($env{'form.shibenv_'.$field} ne '') {
8634: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8635: }
8636: }
8637: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8638: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8639: foreach my $field (@shibfields) {
8640: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8641: push(@{$changes{'cancreate'}},'shibenv');
8642: }
8643: }
8644: } else {
8645: foreach my $field (@shibfields) {
8646: if ($env{'form.shibenv_'.$field}) {
8647: push(@{$changes{'cancreate'}},'shibenv');
8648: last;
8649: }
8650: }
8651: }
8652: }
1.160.6.34 raeburn 8653: }
8654: foreach my $item (@contexts) {
8655: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8656: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8657: if (ref($cancreate{$item}) eq 'ARRAY') {
8658: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8659: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8660: push(@{$changes{'cancreate'}},$item);
8661: }
8662: }
8663: }
8664: }
8665: if (ref($cancreate{$item}) eq 'ARRAY') {
8666: foreach my $type (@{$cancreate{$item}}) {
8667: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8668: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8669: push(@{$changes{'cancreate'}},$item);
8670: }
8671: }
8672: }
8673: }
8674: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8675: if (ref($cancreate{$item}) eq 'HASH') {
8676: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8677: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8678: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8679: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8680: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8681: push(@{$changes{'cancreate'}},$item);
8682: }
8683: }
8684: }
1.160.6.40 raeburn 8685: } elsif ($item eq 'selfcreateprocessing') {
8686: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8687: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8688: push(@{$changes{'cancreate'}},$item);
8689: }
8690: }
1.160.6.35 raeburn 8691: } else {
8692: if (!$cancreate{$item}{$curr}) {
8693: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8694: push(@{$changes{'cancreate'}},$item);
8695: }
1.160.6.34 raeburn 8696: }
8697: }
8698: }
8699: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8700: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8701: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8702: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8703: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8704: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8705: push(@{$changes{'cancreate'}},$item);
8706: }
8707: }
8708: } else {
8709: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8710: push(@{$changes{'cancreate'}},$item);
8711: }
8712: }
8713: }
1.160.6.40 raeburn 8714: } elsif ($item eq 'selfcreateprocessing') {
8715: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8716: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8717: push(@{$changes{'cancreate'}},$item);
8718: }
8719: }
1.160.6.35 raeburn 8720: } else {
8721: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8722: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8723: push(@{$changes{'cancreate'}},$item);
8724: }
1.160.6.34 raeburn 8725: }
8726: }
8727: }
8728: }
8729: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8730: if (ref($cancreate{$item}) eq 'ARRAY') {
8731: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8732: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8733: push(@{$changes{'cancreate'}},$item);
8734: }
8735: }
8736: } elsif (ref($cancreate{$item}) eq 'HASH') {
8737: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8738: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8739: push(@{$changes{'cancreate'}},$item);
8740: }
8741: }
8742: }
8743: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8744: if (ref($cancreate{$item}) eq 'HASH') {
8745: foreach my $type (keys(%{$cancreate{$item}})) {
8746: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8747: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8748: if ($cancreate{$item}{$type}{$field}) {
8749: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8750: push(@{$changes{'cancreate'}},$item);
8751: }
8752: last;
8753: }
8754: }
8755: }
8756: }
1.160.6.34 raeburn 8757: }
8758: }
8759: }
8760: #
8761: # Populate %save_usercreate hash with updates to self-creation configuration.
8762: #
8763: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8764: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8765: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8766: if (ref($cancreate{'notify'}) eq 'HASH') {
8767: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8768: }
1.160.6.40 raeburn 8769: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8770: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8771: }
1.160.6.34 raeburn 8772: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8773: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8774: }
1.160.6.44 raeburn 8775: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8776: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8777: }
1.160.6.34 raeburn 8778: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8779: $save_usercreate{'emailrule'} = \@email_rule;
8780:
8781: my %userconfig_hash = (
8782: usercreation => \%save_usercreate,
8783: usermodification => \%save_usermodify,
8784: );
8785: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8786: $dom);
8787: #
8788: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8789: #
1.27 raeburn 8790: if ($putresult eq 'ok') {
8791: if (keys(%changes) > 0) {
8792: $resulttext = &mt('Changes made:').'<ul>';
8793: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8794: my %lt = &selfcreation_types();
1.34 raeburn 8795: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8796: my $chgtext;
1.45 raeburn 8797: if ($type eq 'selfcreate') {
1.50 raeburn 8798: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8799: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8800: } else {
1.160.6.34 raeburn 8801: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8802: '<ul>';
1.50 raeburn 8803: foreach my $case (@{$cancreate{$type}}) {
8804: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8805: }
8806: $chgtext .= '</ul>';
1.100 raeburn 8807: if (ref($cancreate{$type}) eq 'ARRAY') {
8808: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8809: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8810: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8811: $chgtext .= '<br />'.
8812: '<span class="LC_warning">'.
8813: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8814: '</span>';
1.100 raeburn 8815: }
8816: }
8817: }
8818: }
1.43 raeburn 8819: }
1.160.6.44 raeburn 8820: } elsif ($type eq 'shibenv') {
8821: if (keys(%{$cancreate{$type}}) == 0) {
8822: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8823: } else {
8824: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8825: '<ul>';
8826: foreach my $field (@shibfields) {
8827: next if ($cancreate{$type}{$field} eq '');
8828: if ($field eq 'inststatus') {
8829: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8830: } else {
8831: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8832: }
8833: }
8834: $chgtext .= '</ul>';
8835: }
1.93 raeburn 8836: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8837: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8838: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8839: if (@{$cancreate{'selfcreate'}} > 0) {
8840: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8841: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8842: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8843: $chgtext .= '<br />'.
8844: '<span class="LC_warning">'.
8845: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8846: '</span>';
8847: }
1.96 raeburn 8848: } elsif (ref($usertypes) eq 'HASH') {
8849: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8850: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8851: } else {
8852: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8853: }
8854: $chgtext .= '<ul>';
8855: foreach my $case (@{$cancreate{$type}}) {
8856: if ($case eq 'default') {
8857: $chgtext .= '<li>'.$othertitle.'</li>';
8858: } else {
8859: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8860: }
8861: }
1.100 raeburn 8862: $chgtext .= '</ul>';
8863: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8864: $chgtext .= '<br /><span class="LC_warning">'.
8865: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8866: '</span>';
1.100 raeburn 8867: }
8868: }
8869: } else {
8870: if (@{$cancreate{$type}} == 0) {
8871: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8872: } else {
8873: $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 8874: }
8875: }
8876: }
1.160.6.40 raeburn 8877: } elsif ($type eq 'selfcreateprocessing') {
8878: my %choices = &Apache::lonlocal::texthash (
8879: automatic => 'Automatic approval',
8880: approval => 'Queued for approval',
8881: );
8882: if (@statuses > 1) {
8883: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8884: '<ul>';
8885: foreach my $type (@statuses) {
8886: if ($type eq 'default') {
8887: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8888: } else {
8889: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8890: }
8891: }
8892: $chgtext .= '</ul>';
8893: } else {
8894: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8895: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8896: }
1.160.6.5 raeburn 8897: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8898: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8899: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8900: } else {
8901: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8902: if ($captchas{$savecaptcha{$type}}) {
8903: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8904: } else {
8905: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8906: }
8907: }
8908: } elsif ($type eq 'recaptchakeys') {
8909: my ($privkey,$pubkey);
1.160.6.34 raeburn 8910: if (ref($savecaptcha{$type}) eq 'HASH') {
8911: $pubkey = $savecaptcha{$type}{'public'};
8912: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8913: }
8914: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8915: if (!$pubkey) {
8916: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8917: } else {
8918: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8919: }
8920: if (!$privkey) {
8921: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8922: } else {
8923: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8924: }
8925: $chgtext .= '</ul>';
1.160.6.34 raeburn 8926: } elsif ($type eq 'emailusername') {
8927: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8928: if (ref($types) eq 'ARRAY') {
8929: foreach my $type (@{$types}) {
8930: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8931: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8932: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8933: '<ul>';
8934: foreach my $field (@{$infofields}) {
8935: if ($cancreate{'emailusername'}{$type}{$field}) {
8936: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8937: }
8938: }
8939: }
8940: $chgtext .= '</ul>';
8941: } else {
8942: $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 8943: }
8944: }
8945: }
8946: }
8947: } elsif ($type eq 'notify') {
8948: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8949: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8950: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8951: if ($cancreate{'notify'}{'approval'}) {
8952: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8953: }
8954: }
1.43 raeburn 8955: }
1.34 raeburn 8956: }
1.160.6.34 raeburn 8957: if ($chgtext) {
8958: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8959: }
8960: }
8961: }
1.43 raeburn 8962: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8963: my ($emailrules,$emailruleorder) =
8964: &Apache::lonnet::inst_userrules($dom,'email');
8965: my $chgtext = '<ul>';
8966: foreach my $type (@email_rule) {
8967: if (ref($emailrules->{$type}) eq 'HASH') {
8968: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8969: }
8970: }
8971: $chgtext .= '</ul>';
8972: if (@email_rule > 0) {
1.160.6.34 raeburn 8973: $resulttext .= '<li>'.
8974: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8975: $chgtext.
8976: '</li>';
1.43 raeburn 8977: } else {
1.160.6.34 raeburn 8978: $resulttext .= '<li>'.
8979: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8980: '</li>';
1.43 raeburn 8981: }
8982: }
1.160.6.34 raeburn 8983: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8984: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8985: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8986: foreach my $type (@{$changes{'selfcreate'}}) {
8987: my $typename = $type;
8988: if (ref($usertypes) eq 'HASH') {
8989: if ($usertypes->{$type} ne '') {
8990: $typename = $usertypes->{$type};
1.28 raeburn 8991: }
8992: }
1.160.6.34 raeburn 8993: my @modifiable;
8994: $resulttext .= '<li>'.
8995: &mt('Self-creation of account by users with status: [_1]',
8996: '<span class="LC_cusr_emph">'.$typename.'</span>').
8997: ' - '.&mt('modifiable fields (if institutional data blank): ');
8998: foreach my $field (@fields) {
8999: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9000: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9001: }
9002: }
9003: if (@modifiable > 0) {
9004: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9005: } else {
1.160.6.34 raeburn 9006: $resulttext .= &mt('none');
1.43 raeburn 9007: }
1.160.6.34 raeburn 9008: $resulttext .= '</li>';
1.28 raeburn 9009: }
1.160.6.34 raeburn 9010: $resulttext .= '</ul></li>';
1.28 raeburn 9011: }
1.27 raeburn 9012: $resulttext .= '</ul>';
9013: } else {
1.160.6.34 raeburn 9014: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9015: }
9016: } else {
9017: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9018: &mt('An error occurred: [_1]',$putresult).'</span>';
9019: }
1.43 raeburn 9020: if ($warningmsg ne '') {
9021: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9022: }
1.23 raeburn 9023: return $resulttext;
9024: }
9025:
1.160.6.5 raeburn 9026: sub process_captcha {
9027: my ($container,$changes,$newsettings,$current) = @_;
9028: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9029: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9030: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9031: $newsettings->{'captcha'} = 'original';
9032: }
9033: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9034: if ($container eq 'cancreate') {
9035: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9036: push(@{$changes->{'cancreate'}},'captcha');
9037: } elsif (!defined($changes->{'cancreate'})) {
9038: $changes->{'cancreate'} = ['captcha'];
9039: }
9040: } else {
9041: $changes->{'captcha'} = 1;
9042: }
9043: }
9044: my ($newpub,$newpriv,$currpub,$currpriv);
9045: if ($newsettings->{'captcha'} eq 'recaptcha') {
9046: $newpub = $env{'form.'.$container.'_recaptchapub'};
9047: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9048: $newpub =~ s/\W//g;
9049: $newpriv =~ s/\W//g;
9050: $newsettings->{'recaptchakeys'} = {
9051: public => $newpub,
9052: private => $newpriv,
9053: };
9054: }
9055: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9056: $currpub = $current->{'recaptchakeys'}{'public'};
9057: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9058: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9059: $newsettings->{'recaptchakeys'} = {
9060: public => '',
9061: private => '',
9062: }
9063: }
1.160.6.5 raeburn 9064: }
9065: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9066: if ($container eq 'cancreate') {
9067: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9068: push(@{$changes->{'cancreate'}},'recaptchakeys');
9069: } elsif (!defined($changes->{'cancreate'})) {
9070: $changes->{'cancreate'} = ['recaptchakeys'];
9071: }
9072: } else {
9073: $changes->{'recaptchakeys'} = 1;
9074: }
9075: }
9076: return;
9077: }
9078:
1.33 raeburn 9079: sub modify_usermodification {
9080: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9081: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9082: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9083: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9084: if ($key eq 'selfcreate') {
9085: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9086: } else {
9087: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9088: }
1.33 raeburn 9089: }
9090: }
1.160.6.34 raeburn 9091: my @contexts = ('author','course');
1.33 raeburn 9092: my %context_title = (
9093: author => 'In author context',
9094: course => 'In course context',
9095: );
9096: my @fields = ('lastname','firstname','middlename','generation',
9097: 'permanentemail','id');
9098: my %roles = (
9099: author => ['ca','aa'],
9100: course => ['st','ep','ta','in','cr'],
9101: );
9102: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9103: foreach my $context (@contexts) {
9104: foreach my $role (@{$roles{$context}}) {
9105: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9106: foreach my $item (@fields) {
9107: if (grep(/^\Q$item\E$/,@modifiable)) {
9108: $modifyhash{$context}{$role}{$item} = 1;
9109: } else {
9110: $modifyhash{$context}{$role}{$item} = 0;
9111: }
9112: }
9113: }
9114: if (ref($curr_usermodification{$context}) eq 'HASH') {
9115: foreach my $role (@{$roles{$context}}) {
9116: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9117: foreach my $field (@fields) {
9118: if ($modifyhash{$context}{$role}{$field} ne
9119: $curr_usermodification{$context}{$role}{$field}) {
9120: push(@{$changes{$context}},$role);
9121: last;
9122: }
9123: }
9124: }
9125: }
9126: } else {
9127: foreach my $context (@contexts) {
9128: foreach my $role (@{$roles{$context}}) {
9129: push(@{$changes{$context}},$role);
9130: }
9131: }
9132: }
9133: }
9134: my %usermodification_hash = (
9135: usermodification => \%modifyhash,
9136: );
9137: my $putresult = &Apache::lonnet::put_dom('configuration',
9138: \%usermodification_hash,$dom);
9139: if ($putresult eq 'ok') {
9140: if (keys(%changes) > 0) {
9141: $resulttext = &mt('Changes made: ').'<ul>';
9142: foreach my $context (@contexts) {
9143: if (ref($changes{$context}) eq 'ARRAY') {
9144: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9145: if (ref($changes{$context}) eq 'ARRAY') {
9146: foreach my $role (@{$changes{$context}}) {
9147: my $rolename;
1.160.6.34 raeburn 9148: if ($role eq 'cr') {
9149: $rolename = &mt('Custom');
1.33 raeburn 9150: } else {
1.160.6.34 raeburn 9151: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9152: }
9153: my @modifiable;
1.160.6.34 raeburn 9154: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9155: foreach my $field (@fields) {
9156: if ($modifyhash{$context}{$role}{$field}) {
9157: push(@modifiable,$fieldtitles{$field});
9158: }
9159: }
9160: if (@modifiable > 0) {
9161: $resulttext .= join(', ',@modifiable);
9162: } else {
9163: $resulttext .= &mt('none');
9164: }
9165: $resulttext .= '</li>';
9166: }
9167: $resulttext .= '</ul></li>';
9168: }
9169: }
9170: }
9171: $resulttext .= '</ul>';
9172: } else {
9173: $resulttext = &mt('No changes made to user modification settings');
9174: }
9175: } else {
9176: $resulttext = '<span class="LC_error">'.
9177: &mt('An error occurred: [_1]',$putresult).'</span>';
9178: }
9179: return $resulttext;
9180: }
9181:
1.43 raeburn 9182: sub modify_defaults {
1.160.6.27 raeburn 9183: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9184: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9185: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9186: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9187: my @authtypes = ('internal','krb4','krb5','localauth');
9188: foreach my $item (@items) {
9189: $newvalues{$item} = $env{'form.'.$item};
9190: if ($item eq 'auth_def') {
9191: if ($newvalues{$item} ne '') {
9192: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9193: push(@errors,$item);
9194: }
9195: }
9196: } elsif ($item eq 'lang_def') {
9197: if ($newvalues{$item} ne '') {
9198: if ($newvalues{$item} =~ /^(\w+)/) {
9199: my $langcode = $1;
1.103 raeburn 9200: if ($langcode ne 'x_chef') {
9201: if (code2language($langcode) eq '') {
9202: push(@errors,$item);
9203: }
1.43 raeburn 9204: }
9205: } else {
9206: push(@errors,$item);
9207: }
9208: }
1.54 raeburn 9209: } elsif ($item eq 'timezone_def') {
9210: if ($newvalues{$item} ne '') {
1.62 raeburn 9211: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9212: push(@errors,$item);
9213: }
9214: }
1.68 raeburn 9215: } elsif ($item eq 'datelocale_def') {
9216: if ($newvalues{$item} ne '') {
9217: my @datelocale_ids = DateTime::Locale->ids();
9218: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9219: push(@errors,$item);
9220: }
9221: }
1.141 raeburn 9222: } elsif ($item eq 'portal_def') {
9223: if ($newvalues{$item} ne '') {
9224: 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])\/?$/) {
9225: push(@errors,$item);
9226: }
9227: }
1.43 raeburn 9228: }
9229: if (grep(/^\Q$item\E$/,@errors)) {
9230: $newvalues{$item} = $domdefaults{$item};
9231: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9232: $changes{$item} = 1;
9233: }
1.72 raeburn 9234: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9235: }
9236: my %defaults_hash = (
1.72 raeburn 9237: defaults => \%newvalues,
9238: );
1.43 raeburn 9239: my $title = &defaults_titles();
1.160.6.40 raeburn 9240:
9241: my $currinststatus;
9242: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9243: $currinststatus = $domconfig{'inststatus'};
9244: } else {
9245: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9246: $currinststatus = {
9247: inststatustypes => $usertypes,
9248: inststatusorder => $types,
9249: inststatusguest => [],
9250: };
9251: }
9252: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9253: my @allpos;
9254: my %guests;
9255: my %alltypes;
9256: my ($currtitles,$currguests,$currorder);
9257: if (ref($currinststatus) eq 'HASH') {
9258: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9259: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9260: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9261: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9262: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9263: }
9264: }
9265: unless (grep(/^\Q$type\E$/,@todelete)) {
9266: my $position = $env{'form.inststatus_pos_'.$type};
9267: $position =~ s/\D+//g;
9268: $allpos[$position] = $type;
9269: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9270: $alltypes{$type} =~ s/`//g;
9271: if ($env{'form.inststatus_guest_'.$type}) {
9272: $guests{$type} = 1;
9273: }
9274: }
9275: }
9276: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9277: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9278: }
9279: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9280: $currtitles =~ s/,$//;
9281: }
9282: }
9283: if ($env{'form.addinststatus'}) {
9284: my $newtype = $env{'form.addinststatus'};
9285: $newtype =~ s/\W//g;
9286: unless (exists($alltypes{$newtype})) {
9287: if ($env{'form.addinststatus_guest'}) {
9288: $guests{$newtype} = 1;
9289: }
9290: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9291: $alltypes{$newtype} =~ s/`//g;
9292: my $position = $env{'form.addinststatus_pos'};
9293: $position =~ s/\D+//g;
9294: if ($position ne '') {
9295: $allpos[$position] = $newtype;
9296: }
9297: }
9298: }
9299: my (@orderedstatus,@orderedguests);
9300: foreach my $type (@allpos) {
9301: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9302: push(@orderedstatus,$type);
9303: if ($guests{$type}) {
9304: push(@orderedguests,$type);
9305: }
9306: }
9307: }
9308: foreach my $type (keys(%alltypes)) {
9309: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9310: delete($alltypes{$type});
9311: }
9312: }
9313: $defaults_hash{'inststatus'} = {
9314: inststatustypes => \%alltypes,
9315: inststatusorder => \@orderedstatus,
9316: inststatusguest => \@orderedguests,
9317: };
9318: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9319: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9320: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9321: }
9322: }
9323: if ($currorder ne join(',',@orderedstatus)) {
9324: $changes{'inststatus'}{'inststatusorder'} = 1;
9325: }
9326: if ($currguests ne join(',',@orderedguests)) {
9327: $changes{'inststatus'}{'inststatusguest'} = 1;
9328: }
9329: my $newtitles;
9330: foreach my $item (@orderedstatus) {
9331: $newtitles .= $alltypes{$item}.',';
9332: }
9333: $newtitles =~ s/,$//;
9334: if ($currtitles ne $newtitles) {
9335: $changes{'inststatus'}{'inststatustypes'} = 1;
9336: }
1.43 raeburn 9337: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9338: $dom);
9339: if ($putresult eq 'ok') {
9340: if (keys(%changes) > 0) {
9341: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9342: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9343: 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";
9344: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9345: if ($item eq 'inststatus') {
9346: if (ref($changes{'inststatus'}) eq 'HASH') {
9347: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9348: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9349: foreach my $type (@orderedstatus) {
9350: $resulttext .= $alltypes{$type}.', ';
9351: }
9352: $resulttext =~ s/, $//;
9353: $resulttext .= '</li>';
9354: }
9355: if ($changes{'inststatus'}{'inststatusguest'}) {
9356: $resulttext .= '<li>';
9357: if (@orderedguests) {
9358: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9359: foreach my $type (@orderedguests) {
9360: $resulttext .= $alltypes{$type}.', ';
9361: }
9362: $resulttext =~ s/, $//;
9363: } else {
9364: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9365: }
9366: $resulttext .= '</li>';
9367: }
9368: }
9369: } else {
9370: my $value = $env{'form.'.$item};
9371: if ($value eq '') {
9372: $value = &mt('none');
9373: } elsif ($item eq 'auth_def') {
9374: my %authnames = &authtype_names();
9375: my %shortauth = (
9376: internal => 'int',
9377: krb4 => 'krb4',
9378: krb5 => 'krb5',
9379: localauth => 'loc',
9380: );
9381: $value = $authnames{$shortauth{$value}};
9382: }
9383: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9384: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9385: }
9386: }
9387: $resulttext .= '</ul>';
9388: $mailmsgtext .= "\n";
9389: my $cachetime = 24*60*60;
1.72 raeburn 9390: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9391: if (ref($lastactref) eq 'HASH') {
9392: $lastactref->{'domdefaults'} = 1;
9393: }
1.68 raeburn 9394: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9395: my $notify = 1;
9396: if (ref($domconfig{'contacts'}) eq 'HASH') {
9397: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9398: $notify = 0;
9399: }
9400: }
9401: if ($notify) {
9402: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9403: "LON-CAPA Domain Settings Change - $dom",
9404: $mailmsgtext);
9405: }
1.54 raeburn 9406: }
1.43 raeburn 9407: } else {
1.54 raeburn 9408: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9409: }
9410: } else {
9411: $resulttext = '<span class="LC_error">'.
9412: &mt('An error occurred: [_1]',$putresult).'</span>';
9413: }
9414: if (@errors > 0) {
9415: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9416: foreach my $item (@errors) {
9417: $resulttext .= ' "'.$title->{$item}.'",';
9418: }
9419: $resulttext =~ s/,$//;
9420: }
9421: return $resulttext;
9422: }
9423:
1.46 raeburn 9424: sub modify_scantron {
1.160.6.24 raeburn 9425: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9426: my ($resulttext,%confhash,%changes,$errors);
9427: my $custom = 'custom.tab';
9428: my $default = 'default.tab';
9429: my $servadm = $r->dir_config('lonAdmEMail');
9430: my ($configuserok,$author_ok,$switchserver) =
9431: &config_check($dom,$confname,$servadm);
9432: if ($env{'form.scantronformat.filename'} ne '') {
9433: my $error;
9434: if ($configuserok eq 'ok') {
9435: if ($switchserver) {
1.130 raeburn 9436: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9437: } else {
9438: if ($author_ok eq 'ok') {
9439: my ($result,$scantronurl) =
9440: &publishlogo($r,'upload','scantronformat',$dom,
9441: $confname,'scantron','','',$custom);
9442: if ($result eq 'ok') {
9443: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9444: $changes{'scantronformat'} = 1;
1.46 raeburn 9445: } else {
9446: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9447: }
9448: } else {
9449: $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);
9450: }
9451: }
9452: } else {
9453: $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);
9454: }
9455: if ($error) {
9456: &Apache::lonnet::logthis($error);
9457: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9458: }
9459: }
1.48 raeburn 9460: if (ref($domconfig{'scantron'}) eq 'HASH') {
9461: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9462: if ($env{'form.scantronformat_del'}) {
9463: $confhash{'scantron'}{'scantronformat'} = '';
9464: $changes{'scantronformat'} = 1;
1.46 raeburn 9465: }
9466: }
9467: }
9468: if (keys(%confhash) > 0) {
9469: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9470: $dom);
9471: if ($putresult eq 'ok') {
9472: if (keys(%changes) > 0) {
1.48 raeburn 9473: if (ref($confhash{'scantron'}) eq 'HASH') {
9474: $resulttext = &mt('Changes made:').'<ul>';
9475: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9476: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9477: } else {
1.130 raeburn 9478: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9479: }
1.48 raeburn 9480: $resulttext .= '</ul>';
9481: } else {
1.130 raeburn 9482: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9483: }
9484: $resulttext .= '</ul>';
9485: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9486: if (ref($lastactref) eq 'HASH') {
9487: $lastactref->{'domainconfig'} = 1;
9488: }
1.46 raeburn 9489: } else {
1.130 raeburn 9490: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9491: }
9492: } else {
9493: $resulttext = '<span class="LC_error">'.
9494: &mt('An error occurred: [_1]',$putresult).'</span>';
9495: }
9496: } else {
1.130 raeburn 9497: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9498: }
9499: if ($errors) {
9500: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9501: $errors.'</ul>';
9502: }
9503: return $resulttext;
9504: }
9505:
1.48 raeburn 9506: sub modify_coursecategories {
1.160.6.43 raeburn 9507: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9508: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9509: $cathash);
1.48 raeburn 9510: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9511: my @catitems = ('unauth','auth');
9512: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9513: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9514: $cathash = $domconfig{'coursecategories'}{'cats'};
9515: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9516: $changes{'togglecats'} = 1;
9517: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9518: }
9519: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9520: $changes{'categorize'} = 1;
9521: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9522: }
1.120 raeburn 9523: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9524: $changes{'togglecatscomm'} = 1;
9525: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9526: }
9527: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9528: $changes{'categorizecomm'} = 1;
9529: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9530: }
1.160.6.42 raeburn 9531: foreach my $item (@catitems) {
9532: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9533: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9534: $changes{$item} = 1;
9535: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9536: }
9537: }
9538: }
1.57 raeburn 9539: } else {
9540: $changes{'togglecats'} = 1;
9541: $changes{'categorize'} = 1;
1.124 raeburn 9542: $changes{'togglecatscomm'} = 1;
9543: $changes{'categorizecomm'} = 1;
1.87 raeburn 9544: $domconfig{'coursecategories'} = {
9545: togglecats => $env{'form.togglecats'},
9546: categorize => $env{'form.categorize'},
1.124 raeburn 9547: togglecatscomm => $env{'form.togglecatscomm'},
9548: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9549: };
1.160.6.42 raeburn 9550: foreach my $item (@catitems) {
9551: if ($env{'form.coursecat_'.$item} ne 'std') {
9552: $changes{$item} = 1;
9553: }
9554: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9555: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9556: }
9557: }
1.57 raeburn 9558: }
9559: if (ref($cathash) eq 'HASH') {
9560: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9561: push (@deletecategory,'instcode::0');
9562: }
1.120 raeburn 9563: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9564: push(@deletecategory,'communities::0');
9565: }
1.48 raeburn 9566: }
1.57 raeburn 9567: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9568: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9569: if (@deletecategory > 0) {
9570: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9571: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9572: foreach my $item (@deletecategory) {
1.57 raeburn 9573: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9574: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9575: $deletions{$item} = 1;
1.57 raeburn 9576: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9577: }
9578: }
9579: }
1.57 raeburn 9580: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9581: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9582: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9583: $reorderings{$item} = 1;
1.57 raeburn 9584: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9585: }
9586: if ($env{'form.addcategory_name_'.$item} ne '') {
9587: my $newcat = $env{'form.addcategory_name_'.$item};
9588: my $newdepth = $depth+1;
9589: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9590: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9591: $adds{$newitem} = 1;
9592: }
9593: if ($env{'form.subcat_'.$item} ne '') {
9594: my $newcat = $env{'form.subcat_'.$item};
9595: my $newdepth = $depth+1;
9596: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9597: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9598: $adds{$newitem} = 1;
9599: }
9600: }
9601: }
9602: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9603: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9604: my $newitem = 'instcode::0';
1.57 raeburn 9605: if ($cathash->{$newitem} eq '') {
9606: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9607: $adds{$newitem} = 1;
9608: }
9609: } else {
9610: my $newitem = 'instcode::0';
1.57 raeburn 9611: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9612: $adds{$newitem} = 1;
9613: }
9614: }
1.120 raeburn 9615: if ($env{'form.communities'} eq '1') {
9616: if (ref($cathash) eq 'HASH') {
9617: my $newitem = 'communities::0';
9618: if ($cathash->{$newitem} eq '') {
9619: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9620: $adds{$newitem} = 1;
9621: }
9622: } else {
9623: my $newitem = 'communities::0';
9624: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9625: $adds{$newitem} = 1;
9626: }
9627: }
1.48 raeburn 9628: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9629: if (($env{'form.addcategory_name'} ne 'instcode') &&
9630: ($env{'form.addcategory_name'} ne 'communities')) {
9631: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9632: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9633: $adds{$newitem} = 1;
9634: }
1.48 raeburn 9635: }
1.57 raeburn 9636: my $putresult;
1.48 raeburn 9637: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9638: if (keys(%deletions) > 0) {
9639: foreach my $key (keys(%deletions)) {
9640: if ($predelallitems{$key} ne '') {
9641: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9642: }
9643: }
9644: }
9645: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9646: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9647: if (ref($chkcats[0]) eq 'ARRAY') {
9648: my $depth = 0;
9649: my $chg = 0;
9650: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9651: my $name = $chkcats[0][$i];
9652: my $item;
9653: if ($name eq '') {
9654: $chg ++;
9655: } else {
9656: $item = &escape($name).'::0';
9657: if ($chg) {
1.57 raeburn 9658: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9659: }
9660: $depth ++;
1.57 raeburn 9661: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9662: $depth --;
9663: }
9664: }
9665: }
1.57 raeburn 9666: }
9667: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9668: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9669: if ($putresult eq 'ok') {
1.57 raeburn 9670: my %title = (
1.120 raeburn 9671: togglecats => 'Show/Hide a course in catalog',
9672: categorize => 'Assign a category to a course',
9673: togglecatscomm => 'Show/Hide a community in catalog',
9674: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9675: );
9676: my %level = (
1.120 raeburn 9677: dom => 'set in Domain ("Modify Course/Community")',
9678: crs => 'set in Course ("Course Configuration")',
9679: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9680: none => 'No catalog',
9681: std => 'Standard catalog',
9682: domonly => 'Domain-only catalog',
9683: codesrch => 'Code search form',
1.57 raeburn 9684: );
1.48 raeburn 9685: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9686: if ($changes{'togglecats'}) {
9687: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9688: }
9689: if ($changes{'categorize'}) {
9690: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9691: }
1.120 raeburn 9692: if ($changes{'togglecatscomm'}) {
9693: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9694: }
9695: if ($changes{'categorizecomm'}) {
9696: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9697: }
1.160.6.42 raeburn 9698: if ($changes{'unauth'}) {
9699: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9700: }
9701: if ($changes{'auth'}) {
9702: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9703: }
1.57 raeburn 9704: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9705: my $cathash;
9706: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9707: $cathash = $domconfig{'coursecategories'}{'cats'};
9708: } else {
9709: $cathash = {};
9710: }
9711: my (@cats,@trails,%allitems);
9712: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9713: if (keys(%deletions) > 0) {
9714: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9715: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9716: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9717: }
9718: $resulttext .= '</ul></li>';
9719: }
9720: if (keys(%reorderings) > 0) {
9721: my %sort_by_trail;
9722: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9723: foreach my $key (keys(%reorderings)) {
9724: if ($allitems{$key} ne '') {
9725: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9726: }
1.48 raeburn 9727: }
1.57 raeburn 9728: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9729: $resulttext .= '<li>'.$trails[$trail].'</li>';
9730: }
9731: $resulttext .= '</ul></li>';
1.48 raeburn 9732: }
1.57 raeburn 9733: if (keys(%adds) > 0) {
9734: my %sort_by_trail;
9735: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9736: foreach my $key (keys(%adds)) {
9737: if ($allitems{$key} ne '') {
9738: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9739: }
9740: }
9741: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9742: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9743: }
1.57 raeburn 9744: $resulttext .= '</ul></li>';
1.48 raeburn 9745: }
9746: }
9747: $resulttext .= '</ul>';
1.160.6.43 raeburn 9748: if ($changes{'unauth'} || $changes{'auth'}) {
9749: &Apache::loncommon::devalidate_domconfig_cache($dom);
9750: if (ref($lastactref) eq 'HASH') {
9751: $lastactref->{'domainconfig'} = 1;
9752: }
9753: }
1.48 raeburn 9754: } else {
9755: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9756: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9757: }
9758: } else {
1.120 raeburn 9759: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9760: }
9761: return $resulttext;
9762: }
9763:
1.69 raeburn 9764: sub modify_serverstatuses {
9765: my ($dom,%domconfig) = @_;
9766: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9767: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9768: %currserverstatus = %{$domconfig{'serverstatuses'}};
9769: }
9770: my @pages = &serverstatus_pages();
9771: foreach my $type (@pages) {
9772: $newserverstatus{$type}{'namedusers'} = '';
9773: $newserverstatus{$type}{'machines'} = '';
9774: if (defined($env{'form.'.$type.'_namedusers'})) {
9775: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9776: my @okusers;
9777: foreach my $user (@users) {
9778: my ($uname,$udom) = split(/:/,$user);
9779: if (($udom =~ /^$match_domain$/) &&
9780: (&Apache::lonnet::domain($udom)) &&
9781: ($uname =~ /^$match_username$/)) {
9782: if (!grep(/^\Q$user\E/,@okusers)) {
9783: push(@okusers,$user);
9784: }
9785: }
9786: }
9787: if (@okusers > 0) {
9788: @okusers = sort(@okusers);
9789: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9790: }
9791: }
9792: if (defined($env{'form.'.$type.'_machines'})) {
9793: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9794: my @okmachines;
9795: foreach my $ip (@machines) {
9796: my @parts = split(/\./,$ip);
9797: next if (@parts < 4);
9798: my $badip = 0;
9799: for (my $i=0; $i<4; $i++) {
9800: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9801: $badip = 1;
9802: last;
9803: }
9804: }
9805: if (!$badip) {
9806: push(@okmachines,$ip);
9807: }
9808: }
9809: @okmachines = sort(@okmachines);
9810: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9811: }
9812: }
9813: my %serverstatushash = (
9814: serverstatuses => \%newserverstatus,
9815: );
9816: foreach my $type (@pages) {
1.83 raeburn 9817: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9818: my (@current,@new);
1.83 raeburn 9819: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9820: if ($currserverstatus{$type}{$setting} ne '') {
9821: @current = split(/,/,$currserverstatus{$type}{$setting});
9822: }
9823: }
9824: if ($newserverstatus{$type}{$setting} ne '') {
9825: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9826: }
9827: if (@current > 0) {
9828: if (@new > 0) {
9829: foreach my $item (@current) {
9830: if (!grep(/^\Q$item\E$/,@new)) {
9831: $changes{$type}{$setting} = 1;
1.82 raeburn 9832: last;
9833: }
9834: }
1.84 raeburn 9835: foreach my $item (@new) {
9836: if (!grep(/^\Q$item\E$/,@current)) {
9837: $changes{$type}{$setting} = 1;
9838: last;
1.82 raeburn 9839: }
9840: }
9841: } else {
1.83 raeburn 9842: $changes{$type}{$setting} = 1;
1.69 raeburn 9843: }
1.83 raeburn 9844: } elsif (@new > 0) {
9845: $changes{$type}{$setting} = 1;
1.69 raeburn 9846: }
9847: }
9848: }
9849: if (keys(%changes) > 0) {
1.81 raeburn 9850: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9851: my $putresult = &Apache::lonnet::put_dom('configuration',
9852: \%serverstatushash,$dom);
9853: if ($putresult eq 'ok') {
9854: $resulttext .= &mt('Changes made:').'<ul>';
9855: foreach my $type (@pages) {
1.84 raeburn 9856: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9857: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9858: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9859: if ($newserverstatus{$type}{'namedusers'} eq '') {
9860: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9861: } else {
9862: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9863: }
1.84 raeburn 9864: }
9865: if ($changes{$type}{'machines'}) {
1.69 raeburn 9866: if ($newserverstatus{$type}{'machines'} eq '') {
9867: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9868: } else {
9869: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9870: }
9871:
9872: }
9873: $resulttext .= '</ul></li>';
9874: }
9875: }
9876: $resulttext .= '</ul>';
9877: } else {
9878: $resulttext = '<span class="LC_error">'.
9879: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9880:
9881: }
9882: } else {
9883: $resulttext = &mt('No changes made to access to server status pages');
9884: }
9885: return $resulttext;
9886: }
9887:
1.118 jms 9888: sub modify_helpsettings {
1.122 jms 9889: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9890: my ($resulttext,$errors,%changes,%helphash);
9891: my %defaultchecked = ('submitbugs' => 'on');
9892: my @offon = ('off','on');
1.118 jms 9893: my @toggles = ('submitbugs');
9894: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9895: foreach my $item (@toggles) {
1.160.6.5 raeburn 9896: if ($defaultchecked{$item} eq 'on') {
9897: if ($domconfig{'helpsettings'}{$item} eq '') {
9898: if ($env{'form.'.$item} eq '0') {
9899: $changes{$item} = 1;
9900: }
9901: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9902: $changes{$item} = 1;
9903: }
9904: } elsif ($defaultchecked{$item} eq 'off') {
9905: if ($domconfig{'helpsettings'}{$item} eq '') {
9906: if ($env{'form.'.$item} eq '1') {
9907: $changes{$item} = 1;
9908: }
9909: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9910: $changes{$item} = 1;
9911: }
1.160.6.26 raeburn 9912: }
1.160.6.5 raeburn 9913: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9914: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9915: }
9916: }
1.118 jms 9917: }
1.123 jms 9918: my $putresult;
9919: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9920: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9921: if ($putresult eq 'ok') {
9922: $resulttext = &mt('Changes made:').'<ul>';
9923: foreach my $item (sort(keys(%changes))) {
9924: if ($item eq 'submitbugs') {
9925: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9926: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9927: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9928: }
9929: }
9930: $resulttext .= '</ul>';
9931: } else {
9932: $resulttext = &mt('No changes made to help settings');
9933: $errors .= '<li><span class="LC_error">'.
9934: &mt('An error occurred storing the settings: [_1]',
9935: $putresult).'</span></li>';
9936: }
1.118 jms 9937: }
9938: if ($errors) {
1.160.6.5 raeburn 9939: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9940: $errors.'</ul>';
9941: }
9942: return $resulttext;
9943: }
9944:
1.121 raeburn 9945: sub modify_coursedefaults {
1.160.6.27 raeburn 9946: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9947: my ($resulttext,$errors,%changes,%defaultshash);
9948: my %defaultchecked = ('canuse_pdfforms' => 'off');
9949: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9950: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9951: 'uploadquota_community','uploadquota_textbook');
9952: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9953: my %staticdefaults = (
9954: anonsurvey_threshold => 10,
9955: uploadquota => 500,
9956: );
1.121 raeburn 9957:
9958: $defaultshash{'coursedefaults'} = {};
9959:
9960: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9961: if ($domconfig{'coursedefaults'} eq '') {
9962: $domconfig{'coursedefaults'} = {};
9963: }
9964: }
9965:
9966: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9967: foreach my $item (@toggles) {
9968: if ($defaultchecked{$item} eq 'on') {
9969: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9970: ($env{'form.'.$item} eq '0')) {
9971: $changes{$item} = 1;
1.160.6.16 raeburn 9972: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9973: $changes{$item} = 1;
9974: }
9975: } elsif ($defaultchecked{$item} eq 'off') {
9976: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9977: ($env{'form.'.$item} eq '1')) {
9978: $changes{$item} = 1;
9979: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9980: $changes{$item} = 1;
9981: }
9982: }
9983: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9984: }
1.160.6.21 raeburn 9985: foreach my $item (@numbers) {
9986: my ($currdef,$newdef);
1.160.6.26 raeburn 9987: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 9988: if ($item eq 'anonsurvey_threshold') {
9989: $currdef = $domconfig{'coursedefaults'}{$item};
9990: $newdef =~ s/\D//g;
9991: if ($newdef eq '' || $newdef < 1) {
9992: $newdef = 1;
9993: }
9994: $defaultshash{'coursedefaults'}{$item} = $newdef;
9995: } else {
9996: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9997: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9998: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9999: }
10000: $newdef =~ s/[^\w.\-]//g;
10001: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10002: }
10003: if ($currdef ne $newdef) {
10004: my $staticdef;
10005: if ($item eq 'anonsurvey_threshold') {
10006: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10007: $changes{$item} = 1;
10008: }
10009: } else {
10010: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10011: $changes{'uploadquota'} = 1;
10012: }
10013: }
1.139 raeburn 10014: }
10015: }
1.160.6.37 raeburn 10016:
1.160.6.16 raeburn 10017: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 10018: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10019: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 10020: $unofficialcreds =~ s/[^\d.]+//g;
10021: my $textbookcreds = $env{'form.textbook_credits'};
10022: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10023: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10024: ($env{'form.coursecredits'} eq '1')) {
10025: $changes{'coursecredits'} = 1;
10026: } else {
10027: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 10028: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10029: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 10030: $changes{'coursecredits'} = 1;
10031: }
10032: }
10033: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10034: official => $officialcreds,
10035: unofficial => $unofficialcreds,
1.160.6.30 raeburn 10036: textbook => $textbookcreds,
1.160.6.16 raeburn 10037: }
1.121 raeburn 10038: }
10039: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10040: $dom);
10041: if ($putresult eq 'ok') {
10042: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 10044: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
10045: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 10046: if ($changes{'canuse_pdfforms'}) {
10047: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10048: }
10049: if ($changes{'coursecredits'}) {
10050: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10051: $domdefaults{'officialcredits'} =
10052: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10053: $domdefaults{'unofficialcredits'} =
10054: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 10055: $domdefaults{'textbookcredits'} =
10056: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 10057: }
10058: }
1.160.6.21 raeburn 10059: if ($changes{'uploadquota'}) {
10060: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10061: foreach my $type (@types) {
10062: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10063: }
10064: }
10065: }
1.121 raeburn 10066: my $cachetime = 24*60*60;
10067: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10068: if (ref($lastactref) eq 'HASH') {
10069: $lastactref->{'domdefaults'} = 1;
10070: }
1.121 raeburn 10071: }
10072: $resulttext = &mt('Changes made:').'<ul>';
10073: foreach my $item (sort(keys(%changes))) {
10074: if ($item eq 'canuse_pdfforms') {
10075: if ($env{'form.'.$item} eq '1') {
10076: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10077: } else {
10078: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10079: }
1.139 raeburn 10080: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10081: $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 10082: } elsif ($item eq 'uploadquota') {
10083: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10084: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10085: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10086: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10087: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10088:
1.160.6.21 raeburn 10089: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10090: '</ul>'.
10091: '</li>';
10092: } else {
10093: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10094: }
1.160.6.16 raeburn 10095: } elsif ($item eq 'coursecredits') {
10096: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10097: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10098: ($domdefaults{'unofficialcredits'} eq '') &&
10099: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10100: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10101: } else {
10102: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10103: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10104: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10105: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10106: '</ul>'.
10107: '</li>';
10108: }
10109: } else {
10110: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10111: }
1.140 raeburn 10112: }
1.121 raeburn 10113: }
10114: $resulttext .= '</ul>';
10115: } else {
10116: $resulttext = &mt('No changes made to course defaults');
10117: }
10118: } else {
10119: $resulttext = '<span class="LC_error">'.
10120: &mt('An error occurred: [_1]',$putresult).'</span>';
10121: }
10122: return $resulttext;
10123: }
10124:
1.160.6.37 raeburn 10125: sub modify_selfenrollment {
10126: my ($dom,$lastactref,%domconfig) = @_;
10127: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10128: my @types = ('official','unofficial','community','textbook');
10129: my %titles = &tool_titles();
10130: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10131: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10132: $ordered{'default'} = ['types','registered','approval','limit'];
10133:
10134: my (%roles,%shown,%toplevel);
10135: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10136:
10137: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10138: if ($domconfig{'selfenrollment'} eq '') {
10139: $domconfig{'selfenrollment'} = {};
10140: }
10141: }
10142: %toplevel = (
10143: admin => 'Configuration Rights',
10144: default => 'Default settings',
10145: validation => 'Validation of self-enrollment requests',
10146: );
10147: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10148:
10149: if (ref($ordered{'admin'}) eq 'ARRAY') {
10150: foreach my $item (@{$ordered{'admin'}}) {
10151: foreach my $type (@types) {
10152: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10153: $selfenrollhash{'admin'}{$type}{$item} = 1;
10154: } else {
10155: $selfenrollhash{'admin'}{$type}{$item} = 0;
10156: }
10157: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10158: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10159: if ($selfenrollhash{'admin'}{$type}{$item} ne
10160: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10161: push(@{$changes{'admin'}{$type}},$item);
10162: }
10163: } else {
10164: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10165: push(@{$changes{'admin'}{$type}},$item);
10166: }
10167: }
10168: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10169: push(@{$changes{'admin'}{$type}},$item);
10170: }
10171: }
10172: }
10173: }
10174:
10175: foreach my $item (@{$ordered{'default'}}) {
10176: foreach my $type (@types) {
10177: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10178: if ($item eq 'types') {
10179: unless (($value eq 'all') || ($value eq 'dom')) {
10180: $value = '';
10181: }
10182: } elsif ($item eq 'registered') {
10183: unless ($value eq '1') {
10184: $value = 0;
10185: }
10186: } elsif ($item eq 'approval') {
10187: unless ($value =~ /^[012]$/) {
10188: $value = 0;
10189: }
10190: } else {
10191: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10192: $value = 'none';
10193: }
10194: }
10195: $selfenrollhash{'default'}{$type}{$item} = $value;
10196: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10197: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10198: if ($selfenrollhash{'default'}{$type}{$item} ne
10199: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10200: push(@{$changes{'default'}{$type}},$item);
10201: }
10202: } else {
10203: push(@{$changes{'default'}{$type}},$item);
10204: }
10205: } else {
10206: push(@{$changes{'default'}{$type}},$item);
10207: }
10208: if ($item eq 'limit') {
10209: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10210: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10211: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10212: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10213: }
10214: } else {
10215: $selfenrollhash{'default'}{$type}{'cap'} = '';
10216: }
10217: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10218: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10219: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10220: push(@{$changes{'default'}{$type}},'cap');
10221: }
10222: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10223: push(@{$changes{'default'}{$type}},'cap');
10224: }
10225: }
10226: }
10227: }
10228:
10229: foreach my $item (@{$itemsref}) {
10230: if ($item eq 'fields') {
10231: my @changed;
10232: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10233: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10234: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10235: }
10236: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10237: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10238: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10239: $domconfig{'selfenrollment'}{'validation'}{$item});
10240: } else {
10241: @changed = @{$selfenrollhash{'validation'}{$item}};
10242: }
10243: } else {
10244: @changed = @{$selfenrollhash{'validation'}{$item}};
10245: }
10246: if (@changed) {
10247: if ($selfenrollhash{'validation'}{$item}) {
10248: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10249: } else {
10250: $changes{'validation'}{$item} = &mt('None');
10251: }
10252: }
10253: } else {
10254: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10255: if ($item eq 'markup') {
10256: if ($env{'form.selfenroll_validation_'.$item}) {
10257: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10258: }
10259: }
10260: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10261: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10262: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10263: }
10264: }
10265: }
10266: }
10267:
10268: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10269: $dom);
10270: if ($putresult eq 'ok') {
10271: if (keys(%changes) > 0) {
10272: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10273: $resulttext = &mt('Changes made:').'<ul>';
10274: foreach my $key ('admin','default','validation') {
10275: if (ref($changes{$key}) eq 'HASH') {
10276: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10277: if ($key eq 'validation') {
10278: foreach my $item (@{$itemsref}) {
10279: if (exists($changes{$key}{$item})) {
10280: if ($item eq 'markup') {
10281: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10282: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10283: } else {
10284: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10285: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10286: }
10287: }
10288: }
10289: } else {
10290: foreach my $type (@types) {
10291: if ($type eq 'community') {
10292: $roles{'1'} = &mt('Community personnel');
10293: } else {
10294: $roles{'1'} = &mt('Course personnel');
10295: }
10296: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10297: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10298: if ($key eq 'admin') {
10299: my @mgrdc = ();
10300: if (ref($ordered{$key}) eq 'ARRAY') {
10301: foreach my $item (@{$ordered{'admin'}}) {
10302: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10303: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10304: push(@mgrdc,$item);
10305: }
10306: }
10307: }
10308: if (@mgrdc) {
10309: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10310: } else {
10311: delete($domdefaults{$type.'selfenrolladmdc'});
10312: }
10313: }
10314: } else {
10315: if (ref($ordered{$key}) eq 'ARRAY') {
10316: foreach my $item (@{$ordered{$key}}) {
10317: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10318: $domdefaults{$type.'selfenroll'.$item} =
10319: $selfenrollhash{$key}{$type}{$item};
10320: }
10321: }
10322: }
10323: }
10324: }
10325: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10326: foreach my $item (@{$ordered{$key}}) {
10327: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10328: $resulttext .= '<li>';
10329: if ($key eq 'admin') {
10330: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10331: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10332: } else {
10333: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10334: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10335: }
10336: $resulttext .= '</li>';
10337: }
10338: }
10339: $resulttext .= '</ul></li>';
10340: }
10341: }
10342: $resulttext .= '</ul></li>';
10343: }
10344: }
10345: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10346: my $cachetime = 24*60*60;
10347: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10348: if (ref($lastactref) eq 'HASH') {
10349: $lastactref->{'domdefaults'} = 1;
10350: }
10351: }
10352: }
10353: $resulttext .= '</ul>';
10354: } else {
10355: $resulttext = &mt('No changes made to self-enrollment settings');
10356: }
10357: } else {
10358: $resulttext = '<span class="LC_error">'.
10359: &mt('An error occurred: [_1]',$putresult).'</span>';
10360: }
10361: return $resulttext;
10362: }
10363:
1.137 raeburn 10364: sub modify_usersessions {
1.160.6.27 raeburn 10365: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10366: my @hostingtypes = ('version','excludedomain','includedomain');
10367: my @offloadtypes = ('primary','default');
10368: my %types = (
10369: remote => \@hostingtypes,
10370: hosted => \@hostingtypes,
10371: spares => \@offloadtypes,
10372: );
10373: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10374: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10375: my (%by_ip,%by_location,@intdoms);
10376: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10377: my @locations = sort(keys(%by_location));
1.137 raeburn 10378: my (%defaultshash,%changes);
10379: foreach my $prefix (@prefixes) {
10380: $defaultshash{'usersessions'}{$prefix} = {};
10381: }
1.160.6.27 raeburn 10382: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10383: my $resulttext;
1.138 raeburn 10384: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10385: foreach my $prefix (@prefixes) {
1.145 raeburn 10386: next if ($prefix eq 'spares');
10387: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10388: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10389: if ($type eq 'version') {
10390: my $value = $env{'form.'.$prefix.'_'.$type};
10391: my $okvalue;
10392: if ($value ne '') {
10393: if (grep(/^\Q$value\E$/,@lcversions)) {
10394: $okvalue = $value;
10395: }
10396: }
10397: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10398: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10399: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10400: if ($inuse == 0) {
10401: $changes{$prefix}{$type} = 1;
10402: } else {
10403: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10404: $changes{$prefix}{$type} = 1;
10405: }
10406: if ($okvalue ne '') {
10407: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10408: }
10409: }
10410: } else {
10411: if (($inuse == 1) && ($okvalue ne '')) {
10412: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10413: $changes{$prefix}{$type} = 1;
10414: }
10415: }
10416: } else {
10417: if (($inuse == 1) && ($okvalue ne '')) {
10418: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10419: $changes{$prefix}{$type} = 1;
10420: }
10421: }
10422: } else {
10423: if (($inuse == 1) && ($okvalue ne '')) {
10424: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10425: $changes{$prefix}{$type} = 1;
10426: }
10427: }
10428: } else {
10429: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10430: my @okvals;
10431: foreach my $val (@vals) {
1.138 raeburn 10432: if ($val =~ /:/) {
10433: my @items = split(/:/,$val);
10434: foreach my $item (@items) {
10435: if (ref($by_location{$item}) eq 'ARRAY') {
10436: push(@okvals,$item);
10437: }
10438: }
10439: } else {
10440: if (ref($by_location{$val}) eq 'ARRAY') {
10441: push(@okvals,$val);
10442: }
1.137 raeburn 10443: }
10444: }
10445: @okvals = sort(@okvals);
10446: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10447: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10448: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10449: if ($inuse == 0) {
10450: $changes{$prefix}{$type} = 1;
10451: } else {
10452: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10453: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10454: if (@changed > 0) {
10455: $changes{$prefix}{$type} = 1;
10456: }
10457: }
10458: } else {
10459: if ($inuse == 1) {
10460: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10461: $changes{$prefix}{$type} = 1;
10462: }
10463: }
10464: } else {
10465: if ($inuse == 1) {
10466: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10467: $changes{$prefix}{$type} = 1;
10468: }
10469: }
10470: } else {
10471: if ($inuse == 1) {
10472: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10473: $changes{$prefix}{$type} = 1;
10474: }
10475: }
10476: }
10477: }
10478: }
1.145 raeburn 10479:
10480: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10481: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10482: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10483: my $savespares;
10484:
10485: foreach my $lonhost (sort(keys(%servers))) {
10486: my $serverhomeID =
10487: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10488: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10489: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10490: my %spareschg;
10491: foreach my $type (@{$types{'spares'}}) {
10492: my @okspares;
10493: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10494: foreach my $server (@checked) {
1.152 raeburn 10495: if (&Apache::lonnet::hostname($server) ne '') {
10496: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10497: unless (grep(/^\Q$server\E$/,@okspares)) {
10498: push(@okspares,$server);
10499: }
1.145 raeburn 10500: }
10501: }
10502: }
10503: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10504: my $newspare;
1.152 raeburn 10505: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10506: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10507: $newspare = $new;
10508: }
10509: }
1.152 raeburn 10510: my @spares;
10511: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10512: @spares = sort(@okspares,$newspare);
10513: } else {
10514: @spares = sort(@okspares);
10515: }
10516: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10517: if (ref($spareid{$lonhost}) eq 'HASH') {
10518: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10519: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10520: if (@diffs > 0) {
10521: $spareschg{$type} = 1;
10522: }
10523: }
10524: }
10525: }
10526: if (keys(%spareschg) > 0) {
10527: $changes{'spares'}{$lonhost} = \%spareschg;
10528: }
10529: }
10530:
10531: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10532: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10533: if (ref($changes{'spares'}) eq 'HASH') {
10534: if (keys(%{$changes{'spares'}}) > 0) {
10535: $savespares = 1;
10536: }
10537: }
10538: } else {
10539: $savespares = 1;
10540: }
10541: }
10542:
1.147 raeburn 10543: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10544: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10545: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10546: $dom);
10547: if ($putresult eq 'ok') {
10548: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10549: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10550: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10551: }
10552: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10553: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10554: }
10555: }
10556: my $cachetime = 24*60*60;
10557: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10558: if (ref($lastactref) eq 'HASH') {
10559: $lastactref->{'domdefaults'} = 1;
10560: }
1.147 raeburn 10561: if (keys(%changes) > 0) {
10562: my %lt = &usersession_titles();
10563: $resulttext = &mt('Changes made:').'<ul>';
10564: foreach my $prefix (@prefixes) {
10565: if (ref($changes{$prefix}) eq 'HASH') {
10566: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10567: if ($prefix eq 'spares') {
10568: if (ref($changes{$prefix}) eq 'HASH') {
10569: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10570: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10571: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10572: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10573: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10574: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10575: foreach my $type (@{$types{$prefix}}) {
10576: if ($changes{$prefix}{$lonhost}{$type}) {
10577: my $offloadto = &mt('None');
10578: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10579: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10580: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10581: }
1.145 raeburn 10582: }
1.147 raeburn 10583: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10584: }
1.137 raeburn 10585: }
10586: }
1.147 raeburn 10587: $resulttext .= '</li>';
1.137 raeburn 10588: }
10589: }
1.147 raeburn 10590: } else {
10591: foreach my $type (@{$types{$prefix}}) {
10592: if (defined($changes{$prefix}{$type})) {
10593: my $newvalue;
10594: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10595: if (ref($defaultshash{'usersessions'}{$prefix})) {
10596: if ($type eq 'version') {
10597: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10598: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10599: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10600: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10601: }
1.145 raeburn 10602: }
10603: }
10604: }
1.147 raeburn 10605: if ($newvalue eq '') {
10606: if ($type eq 'version') {
10607: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10608: } else {
10609: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10610: }
1.145 raeburn 10611: } else {
1.147 raeburn 10612: if ($type eq 'version') {
10613: $newvalue .= ' '.&mt('(or later)');
10614: }
10615: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10616: }
1.137 raeburn 10617: }
10618: }
10619: }
1.147 raeburn 10620: $resulttext .= '</ul>';
1.137 raeburn 10621: }
10622: }
1.147 raeburn 10623: $resulttext .= '</ul>';
10624: } else {
10625: $resulttext = $nochgmsg;
1.137 raeburn 10626: }
10627: } else {
10628: $resulttext = '<span class="LC_error">'.
10629: &mt('An error occurred: [_1]',$putresult).'</span>';
10630: }
10631: } else {
1.147 raeburn 10632: $resulttext = $nochgmsg;
1.137 raeburn 10633: }
10634: return $resulttext;
10635: }
10636:
1.150 raeburn 10637: sub modify_loadbalancing {
10638: my ($dom,%domconfig) = @_;
10639: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10640: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10641: my ($othertitle,$usertypes,$types) =
10642: &Apache::loncommon::sorted_inst_types($dom);
10643: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10644: my @sparestypes = ('primary','default');
10645: my %typetitles = &sparestype_titles();
10646: my $resulttext;
1.160.6.7 raeburn 10647: my (%currbalancer,%currtargets,%currrules,%existing);
10648: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10649: %existing = %{$domconfig{'loadbalancing'}};
10650: }
10651: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10652: \%currtargets,\%currrules);
10653: my ($saveloadbalancing,%defaultshash,%changes);
10654: my ($alltypes,$othertypes,$titles) =
10655: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10656: my %ruletitles = &offloadtype_text();
10657: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10658: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10659: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10660: if ($balancer eq '') {
10661: next;
10662: }
10663: if (!exists($servers{$balancer})) {
10664: if (exists($currbalancer{$balancer})) {
10665: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10666: }
1.160.6.7 raeburn 10667: next;
10668: }
10669: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10670: push(@{$changes{'delete'}},$balancer);
10671: next;
10672: }
10673: if (!exists($currbalancer{$balancer})) {
10674: push(@{$changes{'add'}},$balancer);
10675: }
10676: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10677: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10678: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10679: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10680: $saveloadbalancing = 1;
10681: }
10682: foreach my $sparetype (@sparestypes) {
10683: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10684: my @offloadto;
10685: foreach my $target (@targets) {
10686: if (($servers{$target}) && ($target ne $balancer)) {
10687: if ($sparetype eq 'default') {
10688: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10689: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10690: }
10691: }
1.160.6.7 raeburn 10692: unless(grep(/^\Q$target\E$/,@offloadto)) {
10693: push(@offloadto,$target);
10694: }
1.150 raeburn 10695: }
1.160.6.7 raeburn 10696: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10697: }
10698: }
1.160.6.7 raeburn 10699: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10700: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10701: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10702: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10703: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10704: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10705: }
1.160.6.7 raeburn 10706: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10707: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10708: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10709: }
10710: }
10711: }
10712: } else {
1.160.6.7 raeburn 10713: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10714: foreach my $sparetype (@sparestypes) {
10715: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10716: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10717: $changes{'curr'}{$balancer}{'targets'} = 1;
10718: }
1.150 raeburn 10719: }
10720: }
1.160.6.7 raeburn 10721: }
1.150 raeburn 10722: }
10723: my $ishomedom;
1.160.6.7 raeburn 10724: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10725: $ishomedom = 1;
1.150 raeburn 10726: }
10727: if (ref($alltypes) eq 'ARRAY') {
10728: foreach my $type (@{$alltypes}) {
10729: my $rule;
1.160.6.7 raeburn 10730: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10731: (!$ishomedom)) {
1.160.6.7 raeburn 10732: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10733: }
10734: if ($rule eq 'specific') {
10735: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10736: }
1.160.6.7 raeburn 10737: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10738: if (ref($currrules{$balancer}) eq 'HASH') {
10739: if ($rule ne $currrules{$balancer}{$type}) {
10740: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10741: }
10742: } elsif ($rule ne '') {
1.160.6.7 raeburn 10743: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10744: }
10745: }
10746: }
1.160.6.7 raeburn 10747: }
10748: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10749: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10750: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10751: $defaultshash{'loadbalancing'} = {};
10752: }
10753: my $putresult = &Apache::lonnet::put_dom('configuration',
10754: \%defaultshash,$dom);
10755: if ($putresult eq 'ok') {
10756: if (keys(%changes) > 0) {
10757: if (ref($changes{'delete'}) eq 'ARRAY') {
10758: foreach my $balancer (sort(@{$changes{'delete'}})) {
10759: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10760: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10761: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10762: }
1.160.6.7 raeburn 10763: }
10764: if (ref($changes{'add'}) eq 'ARRAY') {
10765: foreach my $balancer (sort(@{$changes{'add'}})) {
10766: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10767: }
10768: }
10769: if (ref($changes{'curr'}) eq 'HASH') {
10770: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10771: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10772: if ($changes{'curr'}{$balancer}{'targets'}) {
10773: my %offloadstr;
10774: foreach my $sparetype (@sparestypes) {
10775: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10776: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10777: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10778: }
10779: }
1.150 raeburn 10780: }
1.160.6.7 raeburn 10781: if (keys(%offloadstr) == 0) {
10782: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10783: } else {
1.160.6.7 raeburn 10784: my $showoffload;
10785: foreach my $sparetype (@sparestypes) {
10786: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10787: if (defined($offloadstr{$sparetype})) {
10788: $showoffload .= $offloadstr{$sparetype};
10789: } else {
10790: $showoffload .= &mt('None');
10791: }
10792: $showoffload .= (' 'x3);
10793: }
10794: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10795: }
10796: }
10797: }
1.160.6.7 raeburn 10798: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10799: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10800: foreach my $type (@{$alltypes}) {
10801: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10802: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10803: my $balancetext;
10804: if ($rule eq '') {
10805: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10806: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10807: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10808: $balancetext = $ruletitles{$rule};
10809: } else {
10810: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10811: }
1.160.6.26 raeburn 10812: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10813: }
10814: }
10815: }
10816: }
1.160.6.29 raeburn 10817: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10818: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10819: }
1.160.6.7 raeburn 10820: }
10821: if ($resulttext ne '') {
10822: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10823: } else {
10824: $resulttext = $nochgmsg;
10825: }
10826: } else {
1.160.6.7 raeburn 10827: $resulttext = $nochgmsg;
1.150 raeburn 10828: }
10829: } else {
1.160.6.7 raeburn 10830: $resulttext = '<span class="LC_error">'.
10831: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10832: }
10833: } else {
1.160.6.7 raeburn 10834: $resulttext = $nochgmsg;
1.150 raeburn 10835: }
10836: return $resulttext;
10837: }
10838:
1.48 raeburn 10839: sub recurse_check {
10840: my ($chkcats,$categories,$depth,$name) = @_;
10841: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10842: my $chg = 0;
10843: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10844: my $category = $chkcats->[$depth]{$name}[$j];
10845: my $item;
10846: if ($category eq '') {
10847: $chg ++;
10848: } else {
10849: my $deeper = $depth + 1;
10850: $item = &escape($category).':'.&escape($name).':'.$depth;
10851: if ($chg) {
10852: $categories->{$item} -= $chg;
10853: }
10854: &recurse_check($chkcats,$categories,$deeper,$category);
10855: $deeper --;
10856: }
10857: }
10858: }
10859: return;
10860: }
10861:
10862: sub recurse_cat_deletes {
10863: my ($item,$coursecategories,$deletions) = @_;
10864: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10865: my $subdepth = $depth + 1;
10866: if (ref($coursecategories) eq 'HASH') {
10867: foreach my $subitem (keys(%{$coursecategories})) {
10868: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10869: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10870: delete($coursecategories->{$subitem});
10871: $deletions->{$subitem} = 1;
10872: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10873: }
1.48 raeburn 10874: }
10875: }
10876: return;
10877: }
10878:
1.125 raeburn 10879: sub get_active_dcs {
10880: my ($dom) = @_;
1.160.6.16 raeburn 10881: my $now = time;
10882: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10883: my %domcoords;
10884: my $numdcs = 0;
10885: foreach my $server (keys(%dompersonnel)) {
10886: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10887: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10888: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10889: }
10890: }
10891: return %domcoords;
10892: }
10893:
10894: sub active_dc_picker {
1.160.6.16 raeburn 10895: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10896: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10897: my @domcoord = keys(%domcoords);
10898: if (keys(%currhash)) {
10899: foreach my $dc (keys(%currhash)) {
10900: unless (exists($domcoords{$dc})) {
10901: push(@domcoord,$dc);
10902: }
10903: }
10904: }
10905: @domcoord = sort(@domcoord);
10906: my $numdcs = scalar(@domcoord);
10907: my $rows = 0;
10908: my $table;
1.125 raeburn 10909: if ($numdcs > 1) {
1.160.6.16 raeburn 10910: $table = '<table>';
10911: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10912: my $rem = $i%($numinrow);
10913: if ($rem == 0) {
10914: if ($i > 0) {
1.160.6.16 raeburn 10915: $table .= '</tr>';
1.125 raeburn 10916: }
1.160.6.16 raeburn 10917: $table .= '<tr>';
10918: $rows ++;
1.125 raeburn 10919: }
1.160.6.16 raeburn 10920: my $check = '';
10921: if ($inputtype eq 'radio') {
10922: if (keys(%currhash) == 0) {
10923: if (!$i) {
10924: $check = ' checked="checked"';
10925: }
10926: } elsif (exists($currhash{$domcoord[$i]})) {
10927: $check = ' checked="checked"';
10928: }
10929: } else {
10930: if (exists($currhash{$domcoord[$i]})) {
10931: $check = ' checked="checked"';
1.125 raeburn 10932: }
10933: }
1.160.6.16 raeburn 10934: if ($i == @domcoord - 1) {
1.125 raeburn 10935: my $colsleft = $numinrow - $rem;
10936: if ($colsleft > 1) {
1.160.6.16 raeburn 10937: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10938: } else {
1.160.6.16 raeburn 10939: $table .= '<td class="LC_left_item">';
1.125 raeburn 10940: }
10941: } else {
1.160.6.16 raeburn 10942: $table .= '<td class="LC_left_item">';
10943: }
10944: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10945: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10946: $table .= '<span class="LC_nobreak"><label>'.
10947: '<input type="'.$inputtype.'" name="'.$name.'"'.
10948: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10949: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10950: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10951: }
1.160.6.33 raeburn 10952: $table .= '</label></span></td>';
1.125 raeburn 10953: }
1.160.6.16 raeburn 10954: $table .= '</tr></table>';
10955: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10956: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10957: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10958: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 10959: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10960: if ($user ne $dcname.':'.$dcdom) {
10961: $table .= ' ('.$dcname.':'.$dcdom.')';
10962: }
1.160.6.16 raeburn 10963: } else {
10964: my $check;
10965: if (exists($currhash{$domcoord[0]})) {
10966: $check = ' checked="checked"';
10967: }
1.160.6.31 raeburn 10968: $table .= '<span class="LC_nobreak"><label>'.
10969: '<input type="checkbox" name="'.$name.'" '.
10970: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10971: if ($user ne $dcname.':'.$dcdom) {
10972: $table .= ' ('.$dcname.':'.$dcdom.')';
10973: }
10974: $table .= '</label></span>';
1.160.6.16 raeburn 10975: $rows ++;
10976: }
1.125 raeburn 10977: }
1.160.6.16 raeburn 10978: return ($numdcs,$table,$rows);
1.125 raeburn 10979: }
10980:
1.137 raeburn 10981: sub usersession_titles {
10982: return &Apache::lonlocal::texthash(
10983: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10984: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10985: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10986: version => 'LON-CAPA version requirement',
1.138 raeburn 10987: excludedomain => 'Allow all, but exclude specific domains',
10988: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10989: primary => 'Primary (checked first)',
1.154 raeburn 10990: default => 'Default',
1.137 raeburn 10991: );
10992: }
10993:
1.152 raeburn 10994: sub id_for_thisdom {
10995: my (%servers) = @_;
10996: my %altids;
10997: foreach my $server (keys(%servers)) {
10998: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10999: if ($serverhome ne $server) {
11000: $altids{$serverhome} = $server;
11001: }
11002: }
11003: return %altids;
11004: }
11005:
1.150 raeburn 11006: sub count_servers {
11007: my ($currbalancer,%servers) = @_;
11008: my (@spares,$numspares);
11009: foreach my $lonhost (sort(keys(%servers))) {
11010: next if ($currbalancer eq $lonhost);
11011: push(@spares,$lonhost);
11012: }
11013: if ($currbalancer) {
11014: $numspares = scalar(@spares);
11015: } else {
11016: $numspares = scalar(@spares) - 1;
11017: }
11018: return ($numspares,@spares);
11019: }
11020:
11021: sub lonbalance_targets_js {
1.160.6.7 raeburn 11022: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11023: my $select = &mt('Select');
11024: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11025: if (ref($servers) eq 'HASH') {
11026: $alltargets = join("','",sort(keys(%{$servers})));
11027: my @homedoms;
11028: foreach my $server (sort(keys(%{$servers}))) {
11029: if (&Apache::lonnet::host_domain($server) eq $dom) {
11030: push(@homedoms,'1');
11031: } else {
11032: push(@homedoms,'0');
11033: }
11034: }
11035: $allishome = join("','",@homedoms);
11036: }
11037: if (ref($types) eq 'ARRAY') {
11038: if (@{$types} > 0) {
11039: @alltypes = @{$types};
11040: }
11041: }
11042: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11043: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11044: my (%currbalancer,%currtargets,%currrules,%existing);
11045: if (ref($settings) eq 'HASH') {
11046: %existing = %{$settings};
11047: }
11048: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11049: \%currtargets,\%currrules);
11050: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11051: return <<"END";
11052:
11053: <script type="text/javascript">
11054: // <![CDATA[
11055:
1.160.6.7 raeburn 11056: currBalancers = new Array('$balancers');
11057:
11058: function toggleTargets(balnum) {
11059: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11060: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11061: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11062: var prevbalancer = prevhostitem.value;
11063: var baltotal = document.getElementById('loadbalancing_total').value;
11064: prevhostitem.value = balancer;
11065: if (prevbalancer != '') {
11066: var prevIdx = currBalancers.indexOf(prevbalancer);
11067: if (prevIdx != -1) {
11068: currBalancers.splice(prevIdx,1);
11069: }
11070: }
1.150 raeburn 11071: if (balancer == '') {
1.160.6.7 raeburn 11072: hideSpares(balnum);
1.150 raeburn 11073: } else {
1.160.6.7 raeburn 11074: var currIdx = currBalancers.indexOf(balancer);
11075: if (currIdx == -1) {
11076: currBalancers.push(balancer);
11077: }
1.150 raeburn 11078: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11079: var ishomedom = homedoms[lonhostitem.selectedIndex];
11080: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11081: }
1.160.6.7 raeburn 11082: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11083: return;
11084: }
11085:
1.160.6.7 raeburn 11086: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11087: var alltargets = new Array('$alltargets');
11088: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11089: var offloadtypes = new Array('primary','default');
11090:
1.160.6.7 raeburn 11091: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11092: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11093:
1.151 raeburn 11094: for (var i=0; i<offloadtypes.length; i++) {
11095: var count = 0;
11096: for (var j=0; j<alltargets.length; j++) {
11097: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11098: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11099: item.value = alltargets[j];
11100: item.style.textAlign='left';
11101: item.style.textFace='normal';
11102: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11103: if (currBalancers.indexOf(alltargets[j]) == -1) {
11104: item.disabled = '';
11105: } else {
11106: item.disabled = 'disabled';
11107: item.checked = false;
11108: }
1.151 raeburn 11109: count ++;
11110: }
1.150 raeburn 11111: }
11112: }
1.151 raeburn 11113: for (var k=0; k<insttypes.length; k++) {
11114: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11115: if (ishomedom == 1) {
1.160.6.7 raeburn 11116: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11117: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11118: } else {
1.160.6.7 raeburn 11119: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11120: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11121: }
11122: } else {
1.160.6.7 raeburn 11123: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11124: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11125: }
1.151 raeburn 11126: if ((insttypes[k] != '_LC_external') &&
11127: ((insttypes[k] != '_LC_internetdom') ||
11128: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11129: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11130: item.options.length = 0;
11131: item.options[0] = new Option("","",true,true);
11132: var idx = 0;
1.151 raeburn 11133: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11134: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11135: idx ++;
11136: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11137: }
11138: }
11139: }
11140: }
11141: return;
11142: }
11143:
1.160.6.7 raeburn 11144: function hideSpares(balnum) {
1.150 raeburn 11145: var alltargets = new Array('$alltargets');
11146: var insttypes = new Array('$allinsttypes');
11147: var offloadtypes = new Array('primary','default');
11148:
1.160.6.7 raeburn 11149: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11150: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11151:
11152: var total = alltargets.length - 1;
11153: for (var i=0; i<offloadtypes; i++) {
11154: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11155: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11156: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11157: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11158: }
1.150 raeburn 11159: }
11160: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11161: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11162: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11163: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11164: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11165: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11166: }
11167: }
11168: return;
11169: }
11170:
1.160.6.7 raeburn 11171: function checkOffloads(item,balnum,type) {
1.150 raeburn 11172: var alltargets = new Array('$alltargets');
11173: var offloadtypes = new Array('primary','default');
11174: if (item.checked) {
11175: var total = alltargets.length - 1;
11176: var other;
11177: if (type == offloadtypes[0]) {
1.151 raeburn 11178: other = offloadtypes[1];
1.150 raeburn 11179: } else {
1.151 raeburn 11180: other = offloadtypes[0];
1.150 raeburn 11181: }
11182: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11183: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11184: if (server == item.value) {
1.160.6.7 raeburn 11185: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11186: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11187: }
11188: }
11189: }
11190: }
11191: return;
11192: }
11193:
1.160.6.7 raeburn 11194: function singleServerToggle(balnum,type) {
11195: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11196: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11197: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11198: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11199:
11200: } else {
1.160.6.7 raeburn 11201: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11203: }
11204: return;
11205: }
11206:
1.160.6.7 raeburn 11207: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11208: if (type == '_LC_external') {
1.160.6.26 raeburn 11209: return;
1.150 raeburn 11210: }
1.160.6.7 raeburn 11211: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11212: for (var i=0; i<typesRules.length; i++) {
11213: if (formname.elements[typesRules[i]].checked) {
11214: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11215: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11216: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11217: } else {
1.160.6.7 raeburn 11218: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11219: }
11220: }
11221: }
11222: return;
11223: }
11224:
11225: function balancerDeleteChange(balnum) {
11226: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11227: var baltotal = document.getElementById('loadbalancing_total').value;
11228: var addtarget;
11229: var removetarget;
11230: var action = 'delete';
11231: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11232: var lonhost = hostitem.value;
11233: var currIdx = currBalancers.indexOf(lonhost);
11234: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11235: if (currIdx != -1) {
11236: currBalancers.splice(currIdx,1);
11237: }
11238: addtarget = lonhost;
11239: } else {
11240: if (currIdx == -1) {
11241: currBalancers.push(lonhost);
11242: }
11243: removetarget = lonhost;
11244: action = 'undelete';
11245: }
11246: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11247: }
11248: return;
11249: }
11250:
11251: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11252: if (baltotal > 1) {
11253: var offloadtypes = new Array('primary','default');
11254: var alltargets = new Array('$alltargets');
11255: var insttypes = new Array('$allinsttypes');
11256: for (var i=0; i<baltotal; i++) {
11257: if (i != balnum) {
11258: for (var j=0; j<offloadtypes.length; j++) {
11259: var total = alltargets.length - 1;
11260: for (var k=0; k<total; k++) {
11261: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11262: var server = serveritem.value;
11263: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11264: if (server == addtarget) {
11265: serveritem.disabled = '';
11266: }
11267: }
11268: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11269: if (server == removetarget) {
11270: serveritem.disabled = 'disabled';
11271: serveritem.checked = false;
11272: }
11273: }
11274: }
11275: }
11276: for (var j=0; j<insttypes.length; j++) {
11277: if (insttypes[j] != '_LC_external') {
11278: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11279: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11280: var currSel = singleserver.selectedIndex;
11281: var currVal = singleserver.options[currSel].value;
11282: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11283: var numoptions = singleserver.options.length;
11284: var needsnew = 1;
11285: for (var k=0; k<numoptions; k++) {
11286: if (singleserver.options[k] == addtarget) {
11287: needsnew = 0;
11288: break;
11289: }
11290: }
11291: if (needsnew == 1) {
11292: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11293: }
11294: }
11295: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11296: singleserver.options.length = 0;
11297: if ((currVal) && (currVal != removetarget)) {
11298: singleserver.options[0] = new Option("","",false,false);
11299: } else {
11300: singleserver.options[0] = new Option("","",true,true);
11301: }
11302: var idx = 0;
11303: for (var m=0; m<alltargets.length; m++) {
11304: if (currBalancers.indexOf(alltargets[m]) == -1) {
11305: idx ++;
11306: if (currVal == alltargets[m]) {
11307: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11308: } else {
11309: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11310: }
11311: }
11312: }
11313: }
11314: }
11315: }
11316: }
1.150 raeburn 11317: }
11318: }
11319: }
11320: return;
11321: }
11322:
1.152 raeburn 11323: // ]]>
11324: </script>
11325:
11326: END
11327: }
11328:
11329: sub new_spares_js {
11330: my @sparestypes = ('primary','default');
11331: my $types = join("','",@sparestypes);
11332: my $select = &mt('Select');
11333: return <<"END";
11334:
11335: <script type="text/javascript">
11336: // <![CDATA[
11337:
11338: function updateNewSpares(formname,lonhost) {
11339: var types = new Array('$types');
11340: var include = new Array();
11341: var exclude = new Array();
11342: for (var i=0; i<types.length; i++) {
11343: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11344: for (var j=0; j<spareboxes.length; j++) {
11345: if (formname.elements[spareboxes[j]].checked) {
11346: exclude.push(formname.elements[spareboxes[j]].value);
11347: } else {
11348: include.push(formname.elements[spareboxes[j]].value);
11349: }
11350: }
11351: }
11352: for (var i=0; i<types.length; i++) {
11353: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11354: var selIdx = newSpare.selectedIndex;
11355: var currnew = newSpare.options[selIdx].value;
11356: var okSpares = new Array();
11357: for (var j=0; j<newSpare.options.length; j++) {
11358: var possible = newSpare.options[j].value;
11359: if (possible != '') {
11360: if (exclude.indexOf(possible) == -1) {
11361: okSpares.push(possible);
11362: } else {
11363: if (currnew == possible) {
11364: selIdx = 0;
11365: }
11366: }
11367: }
11368: }
11369: for (var k=0; k<include.length; k++) {
11370: if (okSpares.indexOf(include[k]) == -1) {
11371: okSpares.push(include[k]);
11372: }
11373: }
11374: okSpares.sort();
11375: newSpare.options.length = 0;
11376: if (selIdx == 0) {
11377: newSpare.options[0] = new Option("$select","",true,true);
11378: } else {
11379: newSpare.options[0] = new Option("$select","",false,false);
11380: }
11381: for (var m=0; m<okSpares.length; m++) {
11382: var idx = m+1;
11383: var selThis = 0;
11384: if (selIdx != 0) {
11385: if (okSpares[m] == currnew) {
11386: selThis = 1;
11387: }
11388: }
11389: if (selThis == 1) {
11390: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11391: } else {
11392: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11393: }
11394: }
11395: }
11396: return;
11397: }
11398:
11399: function checkNewSpares(lonhost,type) {
11400: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11401: var chosen = newSpare.options[newSpare.selectedIndex].value;
11402: if (chosen != '') {
11403: var othertype;
11404: var othernewSpare;
11405: if (type == 'primary') {
11406: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11407: }
11408: if (type == 'default') {
11409: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11410: }
11411: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11412: othernewSpare.selectedIndex = 0;
11413: }
11414: }
11415: return;
11416: }
11417:
11418: // ]]>
11419: </script>
11420:
11421: END
11422:
11423: }
11424:
11425: sub common_domprefs_js {
11426: return <<"END";
11427:
11428: <script type="text/javascript">
11429: // <![CDATA[
11430:
1.150 raeburn 11431: function getIndicesByName(formname,item) {
1.152 raeburn 11432: var group = new Array();
1.150 raeburn 11433: for (var i=0;i<formname.elements.length;i++) {
11434: if (formname.elements[i].name == item) {
1.152 raeburn 11435: group.push(formname.elements[i].id);
1.150 raeburn 11436: }
11437: }
1.152 raeburn 11438: return group;
1.150 raeburn 11439: }
11440:
11441: // ]]>
11442: </script>
11443:
11444: END
1.152 raeburn 11445:
1.150 raeburn 11446: }
11447:
1.160.6.5 raeburn 11448: sub recaptcha_js {
11449: my %lt = &captcha_phrases();
11450: return <<"END";
11451:
11452: <script type="text/javascript">
11453: // <![CDATA[
11454:
11455: function updateCaptcha(caller,context) {
11456: var privitem;
11457: var pubitem;
11458: var privtext;
11459: var pubtext;
11460: if (document.getElementById(context+'_recaptchapub')) {
11461: pubitem = document.getElementById(context+'_recaptchapub');
11462: } else {
11463: return;
11464: }
11465: if (document.getElementById(context+'_recaptchapriv')) {
11466: privitem = document.getElementById(context+'_recaptchapriv');
11467: } else {
11468: return;
11469: }
11470: if (document.getElementById(context+'_recaptchapubtxt')) {
11471: pubtext = document.getElementById(context+'_recaptchapubtxt');
11472: } else {
11473: return;
11474: }
11475: if (document.getElementById(context+'_recaptchaprivtxt')) {
11476: privtext = document.getElementById(context+'_recaptchaprivtxt');
11477: } else {
11478: return;
11479: }
11480: if (caller.checked) {
11481: if (caller.value == 'recaptcha') {
11482: pubitem.type = 'text';
11483: privitem.type = 'text';
11484: pubitem.size = '40';
11485: privitem.size = '40';
11486: pubtext.innerHTML = "$lt{'pub'}";
11487: privtext.innerHTML = "$lt{'priv'}";
11488: } else {
11489: pubitem.type = 'hidden';
11490: privitem.type = 'hidden';
11491: pubtext.innerHTML = '';
11492: privtext.innerHTML = '';
11493: }
11494: }
11495: return;
11496: }
11497:
11498: // ]]>
11499: </script>
11500:
11501: END
11502:
11503: }
11504:
1.160.6.40 raeburn 11505: sub toggle_display_js {
1.160.6.16 raeburn 11506: return <<"END";
11507:
11508: <script type="text/javascript">
11509: // <![CDATA[
11510:
1.160.6.40 raeburn 11511: function toggleDisplay(domForm,caller) {
11512: if (document.getElementById(caller)) {
11513: var divitem = document.getElementById(caller);
11514: var optionsElement = domForm.coursecredits;
11515: if (caller == 'emailoptions') {
11516: optionsElement = domForm.cancreate_email;
11517: }
11518: if (optionsElement.length) {
1.160.6.16 raeburn 11519: var currval;
1.160.6.40 raeburn 11520: for (var i=0; i<optionsElement.length; i++) {
11521: if (optionsElement[i].checked) {
11522: currval = optionsElement[i].value;
1.160.6.16 raeburn 11523: }
11524: }
11525: if (currval == 1) {
1.160.6.40 raeburn 11526: divitem.style.display = 'block';
1.160.6.16 raeburn 11527: } else {
1.160.6.40 raeburn 11528: divitem.style.display = 'none';
1.160.6.16 raeburn 11529: }
11530: }
11531: }
11532: return;
11533: }
11534:
11535: // ]]>
11536: </script>
11537:
11538: END
11539:
11540: }
11541:
1.160.6.5 raeburn 11542: sub captcha_phrases {
11543: return &Apache::lonlocal::texthash (
11544: priv => 'Private key',
11545: pub => 'Public key',
11546: original => 'original (CAPTCHA)',
11547: recaptcha => 'successor (ReCAPTCHA)',
11548: notused => 'unused',
11549: );
11550: }
11551:
1.160.6.24 raeburn 11552: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11553: my ($dom,$cachekeys) = @_;
11554: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11555: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11556: my %thismachine;
11557: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11558: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11559: if (keys(%servers) > 1) {
11560: foreach my $server (keys(%servers)) {
11561: next if ($thismachine{$server});
1.160.6.27 raeburn 11562: my @cached;
11563: foreach my $name (@posscached) {
11564: if ($cachekeys->{$name}) {
11565: push(@cached,&escape($name).':'.&escape($dom));
11566: }
11567: }
11568: if (@cached) {
11569: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11570: }
1.160.6.24 raeburn 11571: }
11572: }
11573: return;
11574: }
11575:
1.3 raeburn 11576: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>