Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.50
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.50! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.49 2014/05/23 09:00:22 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.50! raeburn 744: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
! 745: $rowtotal ++;
! 746: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 747: </table>
748: </td>
749: </tr>
750: <tr>
751: <td>
752: <table class="LC_nested">
753: <tr class="LC_info_row">
754: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
755: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 756: &textbookcourses_javascript($settings).
757: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
758: </table>
759: </td>
760: </tr>
761: <tr>
762: <td>
763: <table class="LC_nested">
764: <tr class="LC_info_row">
765: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
766: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
767: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 768: </table>
769: </td>
770: </tr>
771: <tr>
772: <td>
773: <table class="LC_nested">
774: <tr class="LC_info_row">
1.160.6.46 raeburn 775: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
776: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 777: </tr>'.
778: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 779: } elsif ($action eq 'requestauthor') {
780: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50! raeburn 781: $rowtotal ++;
1.122 jms 782: } elsif ($action eq 'rolecolors') {
1.30 raeburn 783: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 784: </table>
785: </td>
786: </tr>
787: <tr>
788: <td>
789: <table class="LC_nested">
790: <tr class="LC_info_row">
1.69 raeburn 791: <td class="LC_left_item"'.$colspan.' valign="top">'.
792: &mt($item->{'header'}->[2]->{'col1'}).'</td>
793: <td class="LC_right_item" valign="top">'.
794: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 795: </tr>'.
1.30 raeburn 796: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 797: </table>
798: </td>
799: </tr>
800: <tr>
801: <td>
802: <table class="LC_nested">
803: <tr class="LC_info_row">
1.59 bisitz 804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
805: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 806: </tr>'.
1.30 raeburn 807: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
808: $rowtotal += 2;
1.6 raeburn 809: }
1.3 raeburn 810: } else {
1.30 raeburn 811: $output .= '
1.3 raeburn 812: <tr>
813: <td>
814: <table class="LC_nested">
1.30 raeburn 815: <tr class="LC_info_row">';
1.24 raeburn 816: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 817: $output .= '
1.59 bisitz 818: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 819: } elsif ($action eq 'serverstatuses') {
820: $output .= '
821: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
822: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
823:
1.6 raeburn 824: } else {
1.30 raeburn 825: $output .= '
1.69 raeburn 826: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
827: }
1.72 raeburn 828: if (defined($item->{'header'}->[0]->{'col3'})) {
829: $output .= '<td class="LC_left_item" valign="top">'.
830: &mt($item->{'header'}->[0]->{'col2'});
831: if ($action eq 'serverstatuses') {
832: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
833: }
1.69 raeburn 834: } else {
835: $output .= '<td class="LC_right_item" valign="top">'.
836: &mt($item->{'header'}->[0]->{'col2'});
837: }
838: $output .= '</td>';
839: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 840: if (defined($item->{'header'}->[0]->{'col4'})) {
841: $output .= '<td class="LC_left_item" valign="top">'.
842: &mt($item->{'header'}->[0]->{'col3'});
843: } else {
844: $output .= '<td class="LC_right_item" valign="top">'.
845: &mt($item->{'header'}->[0]->{'col3'});
846: }
1.69 raeburn 847: if ($action eq 'serverstatuses') {
848: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
849: }
850: $output .= '</td>';
1.6 raeburn 851: }
1.150 raeburn 852: if ($item->{'header'}->[0]->{'col4'}) {
853: $output .= '<td class="LC_right_item" valign="top">'.
854: &mt($item->{'header'}->[0]->{'col4'});
855: }
1.69 raeburn 856: $output .= '</tr>';
1.48 raeburn 857: $rowtotal ++;
1.160.6.5 raeburn 858: if ($action eq 'quotas') {
1.86 raeburn 859: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 860: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 861: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 862: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 863: } elsif ($action eq 'scantron') {
864: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 865: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 866: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.160.6.49 raeburn 867: } elsif ($action eq 'coursedefaults') {
868: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 869: }
1.3 raeburn 870: }
1.30 raeburn 871: $output .= '
1.3 raeburn 872: </table>
873: </td>
874: </tr>
1.30 raeburn 875: </table><br />';
876: return ($output,$rowtotal);
1.1 raeburn 877: }
878:
1.3 raeburn 879: sub print_login {
1.160.6.5 raeburn 880: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 881: my ($css_class,$datatable);
1.6 raeburn 882: my %choices = &login_choices();
1.110 raeburn 883:
1.160.6.5 raeburn 884: if ($caller eq 'service') {
1.149 raeburn 885: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 886: my $choice = $choices{'disallowlogin'};
887: $css_class = ' class="LC_odd_row"';
1.128 raeburn 888: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 889: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 890: '<th>'.$choices{'server'}.'</th>'.
891: '<th>'.$choices{'serverpath'}.'</th>'.
892: '<th>'.$choices{'custompath'}.'</th>'.
893: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 894: my %disallowed;
895: if (ref($settings) eq 'HASH') {
896: if (ref($settings->{'loginvia'}) eq 'HASH') {
897: %disallowed = %{$settings->{'loginvia'}};
898: }
899: }
900: foreach my $lonhost (sort(keys(%servers))) {
901: my $direct = 'selected="selected"';
1.128 raeburn 902: if (ref($disallowed{$lonhost}) eq 'HASH') {
903: if ($disallowed{$lonhost}{'server'} ne '') {
904: $direct = '';
905: }
1.110 raeburn 906: }
1.115 raeburn 907: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 908: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 909: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
910: '</option>';
1.160.6.13 raeburn 911: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 912: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 913: my $selected = '';
1.128 raeburn 914: if (ref($disallowed{$lonhost}) eq 'HASH') {
915: if ($hostid eq $disallowed{$lonhost}{'server'}) {
916: $selected = 'selected="selected"';
917: }
1.110 raeburn 918: }
919: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
920: $servers{$hostid}.'</option>';
921: }
1.128 raeburn 922: $datatable .= '</select></td>'.
923: '<td><select name="'.$lonhost.'_serverpath">';
924: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
925: my $pathname = $path;
926: if ($path eq 'custom') {
927: $pathname = &mt('Custom Path').' ->';
928: }
929: my $selected = '';
930: if (ref($disallowed{$lonhost}) eq 'HASH') {
931: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
932: $selected = 'selected="selected"';
933: }
934: } elsif ($path eq '') {
935: $selected = 'selected="selected"';
936: }
937: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
938: }
939: $datatable .= '</select></td>';
940: my ($custom,$exempt);
941: if (ref($disallowed{$lonhost}) eq 'HASH') {
942: $custom = $disallowed{$lonhost}{'custompath'};
943: $exempt = $disallowed{$lonhost}{'exempt'};
944: }
945: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
946: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
947: '</tr>';
1.110 raeburn 948: }
949: $datatable .= '</table></td></tr>';
950: return $datatable;
1.160.6.5 raeburn 951: } elsif ($caller eq 'page') {
952: my %defaultchecked = (
953: 'coursecatalog' => 'on',
1.160.6.14 raeburn 954: 'helpdesk' => 'on',
1.160.6.5 raeburn 955: 'adminmail' => 'off',
956: 'newuser' => 'off',
957: );
1.160.6.14 raeburn 958: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 959: my (%checkedon,%checkedoff);
1.42 raeburn 960: foreach my $item (@toggles) {
1.160.6.5 raeburn 961: if ($defaultchecked{$item} eq 'on') {
962: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 963: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 964: } elsif ($defaultchecked{$item} eq 'off') {
965: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 966: $checkedon{$item} = ' ';
967: }
1.1 raeburn 968: }
1.160.6.5 raeburn 969: my @images = ('img','logo','domlogo','login');
970: my @logintext = ('textcol','bgcol');
971: my @bgs = ('pgbg','mainbg','sidebg');
972: my @links = ('link','alink','vlink');
973: my %designhash = &Apache::loncommon::get_domainconf($dom);
974: my %defaultdesign = %Apache::loncommon::defaultdesign;
975: my (%is_custom,%designs);
976: my %defaults = (
977: font => $defaultdesign{'login.font'},
978: );
1.6 raeburn 979: foreach my $item (@images) {
1.160.6.5 raeburn 980: $defaults{$item} = $defaultdesign{'login.'.$item};
981: $defaults{'showlogo'}{$item} = 1;
982: }
983: foreach my $item (@bgs) {
984: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 985: }
1.41 raeburn 986: foreach my $item (@logintext) {
1.160.6.5 raeburn 987: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 988: }
1.160.6.5 raeburn 989: foreach my $item (@links) {
990: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 991: }
1.160.6.5 raeburn 992: if (ref($settings) eq 'HASH') {
993: foreach my $item (@toggles) {
994: if ($settings->{$item} eq '1') {
995: $checkedon{$item} = ' checked="checked" ';
996: $checkedoff{$item} = ' ';
997: } elsif ($settings->{$item} eq '0') {
998: $checkedoff{$item} = ' checked="checked" ';
999: $checkedon{$item} = ' ';
1000: }
1.6 raeburn 1001: }
1.160.6.5 raeburn 1002: foreach my $item (@images) {
1003: if (defined($settings->{$item})) {
1004: $designs{$item} = $settings->{$item};
1005: $is_custom{$item} = 1;
1006: }
1007: if (defined($settings->{'showlogo'}{$item})) {
1008: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1009: }
1010: }
1011: foreach my $item (@logintext) {
1012: if ($settings->{$item} ne '') {
1013: $designs{'logintext'}{$item} = $settings->{$item};
1014: $is_custom{$item} = 1;
1015: }
1016: }
1017: if ($settings->{'font'} ne '') {
1018: $designs{'font'} = $settings->{'font'};
1019: $is_custom{'font'} = 1;
1020: }
1021: foreach my $item (@bgs) {
1022: if ($settings->{$item} ne '') {
1023: $designs{'bgs'}{$item} = $settings->{$item};
1024: $is_custom{$item} = 1;
1025: }
1026: }
1027: foreach my $item (@links) {
1028: if ($settings->{$item} ne '') {
1029: $designs{'links'}{$item} = $settings->{$item};
1030: $is_custom{$item} = 1;
1031: }
1032: }
1033: } else {
1034: if ($designhash{$dom.'.login.font'} ne '') {
1035: $designs{'font'} = $designhash{$dom.'.login.font'};
1036: $is_custom{'font'} = 1;
1037: }
1038: foreach my $item (@images) {
1039: if ($designhash{$dom.'.login.'.$item} ne '') {
1040: $designs{$item} = $designhash{$dom.'.login.'.$item};
1041: $is_custom{$item} = 1;
1042: }
1043: }
1044: foreach my $item (@bgs) {
1045: if ($designhash{$dom.'.login.'.$item} ne '') {
1046: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1047: $is_custom{$item} = 1;
1048: }
1049: }
1050: foreach my $item (@links) {
1051: if ($designhash{$dom.'.login.'.$item} ne '') {
1052: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1053: $is_custom{$item} = 1;
1054: }
1.6 raeburn 1055: }
1056: }
1.160.6.5 raeburn 1057: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1058: logo => 'Institution Logo',
1059: domlogo => 'Domain Logo',
1060: login => 'Login box');
1061: my $itemcount = 1;
1062: foreach my $item (@toggles) {
1063: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1064: $datatable .=
1065: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1066: '</td><td>'.
1067: '<span class="LC_nobreak"><label><input type="radio" name="'.
1068: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1069: '</label> <label><input type="radio" name="'.$item.'"'.
1070: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1071: '</tr>';
1072: $itemcount ++;
1.6 raeburn 1073: }
1.160.6.5 raeburn 1074: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1075: $datatable .= '</tr></table></td></tr>';
1076: } elsif ($caller eq 'help') {
1077: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1078: my $switchserver = &check_switchserver($dom,$confname);
1079: my $itemcount = 1;
1080: $defaulturl = '/adm/loginproblems.html';
1081: $defaulttype = 'default';
1082: %lt = &Apache::lonlocal::texthash (
1083: del => 'Delete?',
1084: rep => 'Replace:',
1085: upl => 'Upload:',
1086: default => 'Default',
1087: custom => 'Custom',
1088: );
1089: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1090: my @currlangs;
1091: if (ref($settings) eq 'HASH') {
1092: if (ref($settings->{'helpurl'}) eq 'HASH') {
1093: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1094: next if ($settings->{'helpurl'}{$key} eq '');
1095: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1096: $type{$key} = 'custom';
1097: unless ($key eq 'nolang') {
1098: push(@currlangs,$key);
1099: }
1100: }
1101: } elsif ($settings->{'helpurl'} ne '') {
1102: $type{'nolang'} = 'custom';
1103: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1104: }
1105: }
1.160.6.5 raeburn 1106: foreach my $lang ('nolang',sort(@currlangs)) {
1107: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1108: $datatable .= '<tr'.$css_class.'>';
1109: if ($url{$lang} eq '') {
1110: $url{$lang} = $defaulturl;
1111: }
1112: if ($type{$lang} eq '') {
1113: $type{$lang} = $defaulttype;
1114: }
1115: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1116: if ($lang eq 'nolang') {
1117: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1118: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1119: } else {
1120: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1121: $langchoices{$lang},
1122: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1123: }
1124: $datatable .= '</span></td>'."\n".
1125: '<td class="LC_left_item">';
1126: if ($type{$lang} eq 'custom') {
1127: $datatable .= '<span class="LC_nobreak"><label>'.
1128: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1129: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1130: } else {
1131: $datatable .= $lt{'upl'};
1132: }
1133: $datatable .='<br />';
1134: if ($switchserver) {
1135: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1136: } else {
1137: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1138: }
1.160.6.5 raeburn 1139: $datatable .= '</td></tr>';
1140: $itemcount ++;
1.6 raeburn 1141: }
1.160.6.5 raeburn 1142: my @addlangs;
1143: foreach my $lang (sort(keys(%langchoices))) {
1144: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1145: push(@addlangs,$lang);
1146: }
1147: if (@addlangs > 0) {
1148: my %toadd;
1149: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1150: $toadd{''} = &mt('Select');
1151: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1152: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1153: &mt('Add log-in help page for a specific language:').' '.
1154: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1155: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1156: if ($switchserver) {
1157: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1158: } else {
1159: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1160: }
1.160.6.5 raeburn 1161: $datatable .= '</td></tr>';
1162: $itemcount ++;
1.6 raeburn 1163: }
1.160.6.5 raeburn 1164: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1165: }
1.6 raeburn 1166: return $datatable;
1167: }
1168:
1169: sub login_choices {
1170: my %choices =
1171: &Apache::lonlocal::texthash (
1.116 bisitz 1172: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1173: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1174: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1175: disallowlogin => "Login page requests redirected",
1176: hostid => "Server",
1.128 raeburn 1177: server => "Redirect to:",
1178: serverpath => "Path",
1179: custompath => "Custom",
1180: exempt => "Exempt IP(s)",
1.110 raeburn 1181: directlogin => "No redirect",
1182: newuser => "Link to create a user account",
1183: img => "Header",
1184: logo => "Main Logo",
1185: domlogo => "Domain Logo",
1186: login => "Log-in Header",
1187: textcol => "Text color",
1188: bgcol => "Box color",
1189: bgs => "Background colors",
1190: links => "Link colors",
1191: font => "Font color",
1192: pgbg => "Header",
1193: mainbg => "Page",
1194: sidebg => "Login box",
1195: link => "Link",
1196: alink => "Active link",
1197: vlink => "Visited link",
1.6 raeburn 1198: );
1199: return %choices;
1200: }
1201:
1202: sub print_rolecolors {
1.30 raeburn 1203: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1204: my %choices = &color_font_choices();
1205: my @bgs = ('pgbg','tabbg','sidebg');
1206: my @links = ('link','alink','vlink');
1207: my @images = ('img');
1208: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1209: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1210: my %defaultdesign = %Apache::loncommon::defaultdesign;
1211: my (%is_custom,%designs);
1.160.6.22 raeburn 1212: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1213: if (ref($settings) eq 'HASH') {
1214: if (ref($settings->{$role}) eq 'HASH') {
1215: if ($settings->{$role}->{'img'} ne '') {
1216: $designs{'img'} = $settings->{$role}->{'img'};
1217: $is_custom{'img'} = 1;
1218: }
1219: if ($settings->{$role}->{'font'} ne '') {
1220: $designs{'font'} = $settings->{$role}->{'font'};
1221: $is_custom{'font'} = 1;
1222: }
1.97 tempelho 1223: if ($settings->{$role}->{'fontmenu'} ne '') {
1224: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1225: $is_custom{'fontmenu'} = 1;
1226: }
1.6 raeburn 1227: foreach my $item (@bgs) {
1228: if ($settings->{$role}->{$item} ne '') {
1229: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1230: $is_custom{$item} = 1;
1231: }
1232: }
1233: foreach my $item (@links) {
1234: if ($settings->{$role}->{$item} ne '') {
1235: $designs{'links'}{$item} = $settings->{$role}->{$item};
1236: $is_custom{$item} = 1;
1237: }
1238: }
1239: }
1240: } else {
1241: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1242: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1243: $is_custom{'img'} = 1;
1244: }
1.97 tempelho 1245: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1246: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1247: $is_custom{'fontmenu'} = 1;
1248: }
1.6 raeburn 1249: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1250: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1251: $is_custom{'font'} = 1;
1252: }
1253: foreach my $item (@bgs) {
1254: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1255: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1256: $is_custom{$item} = 1;
1257:
1258: }
1259: }
1260: foreach my $item (@links) {
1261: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1262: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1263: $is_custom{$item} = 1;
1264: }
1265: }
1266: }
1267: my $itemcount = 1;
1.30 raeburn 1268: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1269: $datatable .= '</tr></table></td></tr>';
1270: return $datatable;
1271: }
1272:
1.160.6.22 raeburn 1273: sub role_defaults {
1274: my ($role,$bgs,$links,$images,$logintext) = @_;
1275: my %defaults;
1276: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1277: return %defaults;
1278: }
1279: my %defaultdesign = %Apache::loncommon::defaultdesign;
1280: if ($role eq 'login') {
1281: %defaults = (
1282: font => $defaultdesign{$role.'.font'},
1283: );
1284: if (ref($logintext) eq 'ARRAY') {
1285: foreach my $item (@{$logintext}) {
1286: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1287: }
1288: }
1289: foreach my $item (@{$images}) {
1290: $defaults{'showlogo'}{$item} = 1;
1291: }
1292: } else {
1293: %defaults = (
1294: img => $defaultdesign{$role.'.img'},
1295: font => $defaultdesign{$role.'.font'},
1296: fontmenu => $defaultdesign{$role.'.fontmenu'},
1297: );
1298: }
1299: foreach my $item (@{$bgs}) {
1300: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1301: }
1302: foreach my $item (@{$links}) {
1303: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1304: }
1305: foreach my $item (@{$images}) {
1306: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1307: }
1308: return %defaults;
1309: }
1310:
1.6 raeburn 1311: sub display_color_options {
1.9 raeburn 1312: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1313: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1314: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1315: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1316: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1317: '<td>'.$choices->{'font'}.'</td>';
1318: if (!$is_custom->{'font'}) {
1.30 raeburn 1319: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1320: } else {
1321: $datatable .= '<td> </td>';
1322: }
1.160.6.9 raeburn 1323: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1324:
1.8 raeburn 1325: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1326: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1327: ' value="'.$current_color.'" /> '.
1328: ' </td></tr>';
1.107 raeburn 1329: unless ($role eq 'login') {
1330: $datatable .= '<tr'.$css_class.'>'.
1331: '<td>'.$choices->{'fontmenu'}.'</td>';
1332: if (!$is_custom->{'fontmenu'}) {
1333: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1334: } else {
1335: $datatable .= '<td> </td>';
1336: }
1.160.6.22 raeburn 1337: $current_color = $designs->{'fontmenu'} ?
1338: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1339: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1340: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1341: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1342: ' value="'.$current_color.'" /> '.
1343: ' </td></tr>';
1.97 tempelho 1344: }
1.9 raeburn 1345: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1346: foreach my $img (@{$images}) {
1.18 albertel 1347: $itemcount ++;
1.6 raeburn 1348: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1349: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1350: '<td>'.$choices->{$img};
1.41 raeburn 1351: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1352: if ($role eq 'login') {
1353: if ($img eq 'login') {
1354: $login_hdr_pick =
1.135 bisitz 1355: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1356: $logincolors =
1357: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1358: $designs,$defaults);
1.70 raeburn 1359: } elsif ($img ne 'domlogo') {
1360: $datatable.= &logo_display_options($img,$defaults,$designs);
1361: }
1362: }
1363: $datatable .= '</td>';
1.6 raeburn 1364: if ($designs->{$img} ne '') {
1365: $imgfile = $designs->{$img};
1.18 albertel 1366: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1367: } else {
1368: $imgfile = $defaults->{$img};
1369: }
1370: if ($imgfile) {
1.9 raeburn 1371: my ($showfile,$fullsize);
1372: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1373: my $urldir = $1;
1374: my $filename = $2;
1375: my @info = &Apache::lonnet::stat_file($designs->{$img});
1376: if (@info) {
1377: my $thumbfile = 'tn-'.$filename;
1378: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1379: if (@thumb) {
1380: $showfile = $urldir.'/'.$thumbfile;
1381: } else {
1382: $showfile = $imgfile;
1383: }
1384: } else {
1385: $showfile = '';
1386: }
1387: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1388: $showfile = $imgfile;
1.6 raeburn 1389: my $imgdir = $1;
1390: my $filename = $2;
1.159 raeburn 1391: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1392: $showfile = "/$imgdir/tn-".$filename;
1393: } else {
1.159 raeburn 1394: my $input = $londocroot.$imgfile;
1395: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1396: if (!-e $output) {
1.9 raeburn 1397: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1398: my ($fullwidth,$fullheight) = &check_dimensions($input);
1399: if ($fullwidth ne '' && $fullheight ne '') {
1400: if ($fullwidth > $width && $fullheight > $height) {
1401: my $size = $width.'x'.$height;
1402: system("convert -sample $size $input $output");
1.159 raeburn 1403: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1404: }
1405: }
1.6 raeburn 1406: }
1407: }
1.16 raeburn 1408: }
1.6 raeburn 1409: if ($showfile) {
1.40 raeburn 1410: if ($showfile =~ m{^/(adm|res)/}) {
1411: if ($showfile =~ m{^/res/}) {
1412: my $local_showfile =
1413: &Apache::lonnet::filelocation('',$showfile);
1414: &Apache::lonnet::repcopy($local_showfile);
1415: }
1416: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1417: }
1418: if ($imgfile) {
1419: if ($imgfile =~ m{^/(adm|res)/}) {
1420: if ($imgfile =~ m{^/res/}) {
1421: my $local_imgfile =
1422: &Apache::lonnet::filelocation('',$imgfile);
1423: &Apache::lonnet::repcopy($local_imgfile);
1424: }
1425: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1426: } else {
1427: $fullsize = $imgfile;
1428: }
1429: }
1.41 raeburn 1430: $datatable .= '<td>';
1431: if ($img eq 'login') {
1.135 bisitz 1432: $datatable .= $login_hdr_pick;
1433: }
1.41 raeburn 1434: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1435: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1436: } else {
1.160.6.22 raeburn 1437: $datatable .= '<td> </td><td class="LC_left_item">'.
1438: &mt('Upload:').'<br />';
1.6 raeburn 1439: }
1440: } else {
1.160.6.22 raeburn 1441: $datatable .= '<td> </td><td class="LC_left_item">'.
1442: &mt('Upload:').'<br />';
1.6 raeburn 1443: }
1.9 raeburn 1444: if ($switchserver) {
1445: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1446: } else {
1.135 bisitz 1447: if ($img ne 'login') { # suppress file selection for Log-in header
1448: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1449: }
1.9 raeburn 1450: }
1451: $datatable .= '</td></tr>';
1.6 raeburn 1452: }
1453: $itemcount ++;
1454: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1455: $datatable .= '<tr'.$css_class.'>'.
1456: '<td>'.$choices->{'bgs'}.'</td>';
1457: my $bgs_def;
1458: foreach my $item (@{$bgs}) {
1459: if (!$is_custom->{$item}) {
1.70 raeburn 1460: $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 1461: }
1462: }
1463: if ($bgs_def) {
1.8 raeburn 1464: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1465: } else {
1466: $datatable .= '<td> </td>';
1467: }
1468: $datatable .= '<td class="LC_right_item">'.
1469: '<table border="0"><tr>';
1.160.6.13 raeburn 1470:
1.6 raeburn 1471: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1472: $datatable .= '<td align="center">'.$choices->{$item};
1473: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1474: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1475: $datatable .= ' ';
1.6 raeburn 1476: }
1.160.6.9 raeburn 1477: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1478: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1479: }
1480: $datatable .= '</tr></table></td></tr>';
1481: $itemcount ++;
1482: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1483: $datatable .= '<tr'.$css_class.'>'.
1484: '<td>'.$choices->{'links'}.'</td>';
1485: my $links_def;
1486: foreach my $item (@{$links}) {
1487: if (!$is_custom->{$item}) {
1.30 raeburn 1488: $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 1489: }
1490: }
1491: if ($links_def) {
1.8 raeburn 1492: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1493: } else {
1494: $datatable .= '<td> </td>';
1495: }
1496: $datatable .= '<td class="LC_right_item">'.
1497: '<table border="0"><tr>';
1498: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1499: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1500: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1501: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1502: $datatable.=' ';
1.6 raeburn 1503: }
1.160.6.9 raeburn 1504: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1505: '" /></td>';
1506: }
1.30 raeburn 1507: $$rowtotal += $itemcount;
1.3 raeburn 1508: return $datatable;
1509: }
1510:
1.70 raeburn 1511: sub logo_display_options {
1512: my ($img,$defaults,$designs) = @_;
1513: my $checkedon;
1514: if (ref($defaults) eq 'HASH') {
1515: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1516: if ($defaults->{'showlogo'}{$img}) {
1517: $checkedon = 'checked="checked" ';
1518: }
1519: }
1520: }
1521: if (ref($designs) eq 'HASH') {
1522: if (ref($designs->{'showlogo'}) eq 'HASH') {
1523: if (defined($designs->{'showlogo'}{$img})) {
1524: if ($designs->{'showlogo'}{$img} == 0) {
1525: $checkedon = '';
1526: } elsif ($designs->{'showlogo'}{$img} == 1) {
1527: $checkedon = 'checked="checked" ';
1528: }
1529: }
1530: }
1531: }
1532: return '<br /><label> <input type="checkbox" name="'.
1533: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1534: &mt('show').'</label>'."\n";
1535: }
1536:
1.41 raeburn 1537: sub login_header_options {
1.135 bisitz 1538: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1539: my $output = '';
1.41 raeburn 1540: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1541: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1542: if (!$is_custom->{'textcol'}) {
1543: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1544: ' ';
1545: }
1546: if (!$is_custom->{'bgcol'}) {
1547: $output .= $choices->{'bgcol'}.': '.
1548: '<span id="css_'.$role.'_font" style="background-color: '.
1549: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1550: }
1551: $output .= '<br />';
1552: }
1553: $output .='<br />';
1554: return $output;
1555: }
1556:
1557: sub login_text_colors {
1.160.6.22 raeburn 1558: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1559: my $color_menu = '<table border="0"><tr>';
1560: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1561: $color_menu .= '<td align="center">'.$choices->{$item};
1562: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1563: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1564: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1565: }
1566: $color_menu .= '</tr></table><br />';
1567: return $color_menu;
1568: }
1569:
1570: sub image_changes {
1571: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1572: my $output;
1.135 bisitz 1573: if ($img eq 'login') {
1574: # suppress image for Log-in header
1575: } elsif (!$is_custom) {
1.70 raeburn 1576: if ($img ne 'domlogo') {
1.41 raeburn 1577: $output .= &mt('Default image:').'<br />';
1578: } else {
1579: $output .= &mt('Default in use:').'<br />';
1580: }
1581: }
1.135 bisitz 1582: if ($img eq 'login') { # suppress image for Log-in header
1583: $output .= '<td>'.$logincolors;
1.41 raeburn 1584: } else {
1.135 bisitz 1585: if ($img_import) {
1586: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1587: }
1588: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1589: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1590: if ($is_custom) {
1591: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1592: '<input type="checkbox" name="'.
1593: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1594: '</label> '.&mt('Replace:').'</span><br />';
1595: } else {
1.160.6.22 raeburn 1596: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1597: }
1.41 raeburn 1598: }
1599: return $output;
1600: }
1601:
1.3 raeburn 1602: sub print_quotas {
1.86 raeburn 1603: my ($dom,$settings,$rowtotal,$action) = @_;
1604: my $context;
1605: if ($action eq 'quotas') {
1606: $context = 'tools';
1607: } else {
1608: $context = $action;
1609: }
1.160.6.20 raeburn 1610: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1611: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1612: my $typecount = 0;
1.101 raeburn 1613: my ($css_class,%titles);
1.86 raeburn 1614: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1615: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1616: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1617: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1618: %titles = &courserequest_titles();
1.160.6.5 raeburn 1619: } elsif ($context eq 'requestauthor') {
1620: @usertools = ('author');
1621: @options = ('norequest','approval','automatic');
1622: %titles = &authorrequest_titles();
1.86 raeburn 1623: } else {
1.160.6.4 raeburn 1624: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1625: %titles = &tool_titles();
1.86 raeburn 1626: }
1.26 raeburn 1627: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1628: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1629: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1630: unless (($context eq 'requestcourses') ||
1631: ($context eq 'requestauthor')) {
1.86 raeburn 1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1634: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1635: } else {
1636: $currdefquota = $settings->{$type};
1637: }
1.160.6.20 raeburn 1638: if (ref($settings->{authorquota}) eq 'HASH') {
1639: $currauthorquota = $settings->{authorquota}->{$type};
1640: }
1.78 raeburn 1641: }
1.72 raeburn 1642: }
1.3 raeburn 1643: if (defined($usertypes->{$type})) {
1644: $typecount ++;
1645: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1646: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1647: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1648: '<td class="LC_left_item">';
1.101 raeburn 1649: if ($context eq 'requestcourses') {
1650: $datatable .= '<table><tr>';
1651: }
1652: my %cell;
1.72 raeburn 1653: foreach my $item (@usertools) {
1.101 raeburn 1654: if ($context eq 'requestcourses') {
1655: my ($curroption,$currlimit);
1656: if (ref($settings) eq 'HASH') {
1657: if (ref($settings->{$item}) eq 'HASH') {
1658: $curroption = $settings->{$item}->{$type};
1659: if ($curroption =~ /^autolimit=(\d*)$/) {
1660: $currlimit = $1;
1661: }
1662: }
1663: }
1664: if (!$curroption) {
1665: $curroption = 'norequest';
1666: }
1667: $datatable .= '<th>'.$titles{$item}.'</th>';
1668: foreach my $option (@options) {
1669: my $val = $option;
1670: if ($option eq 'norequest') {
1671: $val = 0;
1672: }
1673: if ($option eq 'validate') {
1674: my $canvalidate = 0;
1675: if (ref($validations{$item}) eq 'HASH') {
1676: if ($validations{$item}{$type}) {
1677: $canvalidate = 1;
1678: }
1679: }
1680: next if (!$canvalidate);
1681: }
1682: my $checked = '';
1683: if ($option eq $curroption) {
1684: $checked = ' checked="checked"';
1685: } elsif ($option eq 'autolimit') {
1686: if ($curroption =~ /^autolimit/) {
1687: $checked = ' checked="checked"';
1688: }
1689: }
1690: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1691: '<input type="radio" name="crsreq_'.$item.
1692: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1693: $titles{$option}.'</label>';
1.101 raeburn 1694: if ($option eq 'autolimit') {
1.127 raeburn 1695: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1696: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1697: 'value="'.$currlimit.'" />';
1.101 raeburn 1698: }
1.127 raeburn 1699: $cell{$item} .= '</span> ';
1.103 raeburn 1700: if ($option eq 'autolimit') {
1.127 raeburn 1701: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1702: }
1.101 raeburn 1703: }
1.160.6.5 raeburn 1704: } elsif ($context eq 'requestauthor') {
1705: my $curroption;
1706: if (ref($settings) eq 'HASH') {
1707: $curroption = $settings->{$type};
1708: }
1709: if (!$curroption) {
1710: $curroption = 'norequest';
1711: }
1712: foreach my $option (@options) {
1713: my $val = $option;
1714: if ($option eq 'norequest') {
1715: $val = 0;
1716: }
1717: my $checked = '';
1718: if ($option eq $curroption) {
1719: $checked = ' checked="checked"';
1720: }
1721: $datatable .= '<span class="LC_nobreak"><label>'.
1722: '<input type="radio" name="authorreq_'.$type.
1723: '" value="'.$val.'"'.$checked.' />'.
1724: $titles{$option}.'</label></span> ';
1725: }
1.101 raeburn 1726: } else {
1727: my $checked = 'checked="checked" ';
1728: if (ref($settings) eq 'HASH') {
1729: if (ref($settings->{$item}) eq 'HASH') {
1730: if ($settings->{$item}->{$type} == 0) {
1731: $checked = '';
1732: } elsif ($settings->{$item}->{$type} == 1) {
1733: $checked = 'checked="checked" ';
1734: }
1.78 raeburn 1735: }
1.72 raeburn 1736: }
1.101 raeburn 1737: $datatable .= '<span class="LC_nobreak"><label>'.
1738: '<input type="checkbox" name="'.$context.'_'.$item.
1739: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1740: '</label></span> ';
1.72 raeburn 1741: }
1.101 raeburn 1742: }
1743: if ($context eq 'requestcourses') {
1744: $datatable .= '</tr><tr>';
1745: foreach my $item (@usertools) {
1.106 raeburn 1746: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1747: }
1748: $datatable .= '</tr></table>';
1.72 raeburn 1749: }
1.86 raeburn 1750: $datatable .= '</td>';
1.160.6.5 raeburn 1751: unless (($context eq 'requestcourses') ||
1752: ($context eq 'requestauthor')) {
1.86 raeburn 1753: $datatable .=
1.160.6.20 raeburn 1754: '<td class="LC_right_item">'.
1755: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1756: '<input type="text" name="quota_'.$type.
1.72 raeburn 1757: '" value="'.$currdefquota.
1.160.6.20 raeburn 1758: '" size="5" /></span>'.(' ' x 2).
1759: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1760: '<input type="text" name="authorquota_'.$type.
1761: '" value="'.$currauthorquota.
1762: '" size="5" /></span></td>';
1.86 raeburn 1763: }
1764: $datatable .= '</tr>';
1.3 raeburn 1765: }
1766: }
1767: }
1.160.6.5 raeburn 1768: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1769: $defaultquota = '20';
1.160.6.20 raeburn 1770: $authorquota = '500';
1.86 raeburn 1771: if (ref($settings) eq 'HASH') {
1772: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1773: $defaultquota = $settings->{'defaultquota'}->{'default'};
1774: } elsif (defined($settings->{'default'})) {
1775: $defaultquota = $settings->{'default'};
1776: }
1.160.6.20 raeburn 1777: if (ref($settings->{'authorquota'}) eq 'HASH') {
1778: $authorquota = $settings->{'authorquota'}->{'default'};
1779: }
1.3 raeburn 1780: }
1781: }
1782: $typecount ++;
1783: $css_class = $typecount%2?' class="LC_odd_row"':'';
1784: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1785: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1786: '<td class="LC_left_item">';
1.101 raeburn 1787: if ($context eq 'requestcourses') {
1788: $datatable .= '<table><tr>';
1789: }
1790: my %defcell;
1.72 raeburn 1791: foreach my $item (@usertools) {
1.101 raeburn 1792: if ($context eq 'requestcourses') {
1793: my ($curroption,$currlimit);
1794: if (ref($settings) eq 'HASH') {
1795: if (ref($settings->{$item}) eq 'HASH') {
1796: $curroption = $settings->{$item}->{'default'};
1797: if ($curroption =~ /^autolimit=(\d*)$/) {
1798: $currlimit = $1;
1799: }
1800: }
1801: }
1802: if (!$curroption) {
1803: $curroption = 'norequest';
1804: }
1805: $datatable .= '<th>'.$titles{$item}.'</th>';
1806: foreach my $option (@options) {
1807: my $val = $option;
1808: if ($option eq 'norequest') {
1809: $val = 0;
1810: }
1811: if ($option eq 'validate') {
1812: my $canvalidate = 0;
1813: if (ref($validations{$item}) eq 'HASH') {
1814: if ($validations{$item}{'default'}) {
1815: $canvalidate = 1;
1816: }
1817: }
1818: next if (!$canvalidate);
1819: }
1820: my $checked = '';
1821: if ($option eq $curroption) {
1822: $checked = ' checked="checked"';
1823: } elsif ($option eq 'autolimit') {
1824: if ($curroption =~ /^autolimit/) {
1825: $checked = ' checked="checked"';
1826: }
1827: }
1828: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1829: '<input type="radio" name="crsreq_'.$item.
1830: '_default" value="'.$val.'"'.$checked.' />'.
1831: $titles{$option}.'</label>';
1832: if ($option eq 'autolimit') {
1.127 raeburn 1833: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1834: $item.'_limit_default" size="1" '.
1835: 'value="'.$currlimit.'" />';
1836: }
1.127 raeburn 1837: $defcell{$item} .= '</span> ';
1.104 raeburn 1838: if ($option eq 'autolimit') {
1.127 raeburn 1839: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1840: }
1.101 raeburn 1841: }
1.160.6.5 raeburn 1842: } elsif ($context eq 'requestauthor') {
1843: my $curroption;
1844: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1845: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1846: }
1847: if (!$curroption) {
1848: $curroption = 'norequest';
1849: }
1850: foreach my $option (@options) {
1851: my $val = $option;
1852: if ($option eq 'norequest') {
1853: $val = 0;
1854: }
1855: my $checked = '';
1856: if ($option eq $curroption) {
1857: $checked = ' checked="checked"';
1858: }
1859: $datatable .= '<span class="LC_nobreak"><label>'.
1860: '<input type="radio" name="authorreq_default"'.
1861: ' value="'.$val.'"'.$checked.' />'.
1862: $titles{$option}.'</label></span> ';
1863: }
1.101 raeburn 1864: } else {
1865: my $checked = 'checked="checked" ';
1866: if (ref($settings) eq 'HASH') {
1867: if (ref($settings->{$item}) eq 'HASH') {
1868: if ($settings->{$item}->{'default'} == 0) {
1869: $checked = '';
1870: } elsif ($settings->{$item}->{'default'} == 1) {
1871: $checked = 'checked="checked" ';
1872: }
1.78 raeburn 1873: }
1.72 raeburn 1874: }
1.101 raeburn 1875: $datatable .= '<span class="LC_nobreak"><label>'.
1876: '<input type="checkbox" name="'.$context.'_'.$item.
1877: '" value="default" '.$checked.'/>'.$titles{$item}.
1878: '</label></span> ';
1879: }
1880: }
1881: if ($context eq 'requestcourses') {
1882: $datatable .= '</tr><tr>';
1883: foreach my $item (@usertools) {
1.106 raeburn 1884: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1885: }
1.101 raeburn 1886: $datatable .= '</tr></table>';
1.72 raeburn 1887: }
1.86 raeburn 1888: $datatable .= '</td>';
1.160.6.5 raeburn 1889: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1890: $datatable .= '<td class="LC_right_item">'.
1891: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1892: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1893: $defaultquota.'" size="5" /></span>'.(' ' x2).
1894: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1895: '<input type="text" name="authorquota" value="'.
1896: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1897: }
1898: $datatable .= '</tr>';
1.72 raeburn 1899: $typecount ++;
1900: $css_class = $typecount%2?' class="LC_odd_row"':'';
1901: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1902: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1903: if ($context eq 'requestcourses') {
1.109 raeburn 1904: $datatable .= &mt('(overrides affiliation, if set)').
1905: '</td>'.
1906: '<td class="LC_left_item">'.
1907: '<table><tr>';
1.101 raeburn 1908: } else {
1.109 raeburn 1909: $datatable .= &mt('(overrides affiliation, if checked)').
1910: '</td>'.
1911: '<td class="LC_left_item" colspan="2">'.
1912: '<br />';
1.101 raeburn 1913: }
1914: my %advcell;
1.72 raeburn 1915: foreach my $item (@usertools) {
1.101 raeburn 1916: if ($context eq 'requestcourses') {
1917: my ($curroption,$currlimit);
1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{$item}) eq 'HASH') {
1920: $curroption = $settings->{$item}->{'_LC_adv'};
1921: if ($curroption =~ /^autolimit=(\d*)$/) {
1922: $currlimit = $1;
1923: }
1924: }
1925: }
1926: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1927: my $checked = '';
1928: if ($curroption eq '') {
1929: $checked = ' checked="checked"';
1930: }
1931: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1932: '<input type="radio" name="crsreq_'.$item.
1933: '__LC_adv" value=""'.$checked.' />'.
1934: &mt('No override set').'</label></span> ';
1.101 raeburn 1935: foreach my $option (@options) {
1936: my $val = $option;
1937: if ($option eq 'norequest') {
1938: $val = 0;
1939: }
1940: if ($option eq 'validate') {
1941: my $canvalidate = 0;
1942: if (ref($validations{$item}) eq 'HASH') {
1943: if ($validations{$item}{'_LC_adv'}) {
1944: $canvalidate = 1;
1945: }
1946: }
1947: next if (!$canvalidate);
1948: }
1949: my $checked = '';
1.104 raeburn 1950: if ($val eq $curroption) {
1.101 raeburn 1951: $checked = ' checked="checked"';
1952: } elsif ($option eq 'autolimit') {
1953: if ($curroption =~ /^autolimit/) {
1954: $checked = ' checked="checked"';
1955: }
1956: }
1957: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1958: '<input type="radio" name="crsreq_'.$item.
1959: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1960: $titles{$option}.'</label>';
1961: if ($option eq 'autolimit') {
1.127 raeburn 1962: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1963: $item.'_limit__LC_adv" size="1" '.
1964: 'value="'.$currlimit.'" />';
1965: }
1.127 raeburn 1966: $advcell{$item} .= '</span> ';
1.104 raeburn 1967: if ($option eq 'autolimit') {
1.127 raeburn 1968: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1969: }
1.101 raeburn 1970: }
1.160.6.5 raeburn 1971: } elsif ($context eq 'requestauthor') {
1972: my $curroption;
1973: if (ref($settings) eq 'HASH') {
1974: $curroption = $settings->{'_LC_adv'};
1975: }
1976: my $checked = '';
1977: if ($curroption eq '') {
1978: $checked = ' checked="checked"';
1979: }
1980: $datatable .= '<span class="LC_nobreak"><label>'.
1981: '<input type="radio" name="authorreq__LC_adv"'.
1982: ' value=""'.$checked.' />'.
1983: &mt('No override set').'</label></span> ';
1984: foreach my $option (@options) {
1985: my $val = $option;
1986: if ($option eq 'norequest') {
1987: $val = 0;
1988: }
1989: my $checked = '';
1990: if ($val eq $curroption) {
1991: $checked = ' checked="checked"';
1992: }
1993: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1994: '<input type="radio" name="authorreq__LC_adv"'.
1995: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1996: $titles{$option}.'</label></span> ';
1997: }
1.101 raeburn 1998: } else {
1999: my $checked = 'checked="checked" ';
2000: if (ref($settings) eq 'HASH') {
2001: if (ref($settings->{$item}) eq 'HASH') {
2002: if ($settings->{$item}->{'_LC_adv'} == 0) {
2003: $checked = '';
2004: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2005: $checked = 'checked="checked" ';
2006: }
1.79 raeburn 2007: }
1.72 raeburn 2008: }
1.101 raeburn 2009: $datatable .= '<span class="LC_nobreak"><label>'.
2010: '<input type="checkbox" name="'.$context.'_'.$item.
2011: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2012: '</label></span> ';
2013: }
2014: }
2015: if ($context eq 'requestcourses') {
2016: $datatable .= '</tr><tr>';
2017: foreach my $item (@usertools) {
1.106 raeburn 2018: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2019: }
1.101 raeburn 2020: $datatable .= '</tr></table>';
1.72 raeburn 2021: }
1.98 raeburn 2022: $datatable .= '</td></tr>';
1.30 raeburn 2023: $$rowtotal += $typecount;
1.3 raeburn 2024: return $datatable;
2025: }
2026:
1.160.6.5 raeburn 2027: sub print_requestmail {
2028: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2029: my ($now,$datatable,%currapp);
1.102 raeburn 2030: $now = time;
2031: if (ref($settings) eq 'HASH') {
2032: if (ref($settings->{'notify'}) eq 'HASH') {
2033: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2034: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2035: }
2036: }
2037: }
1.160.6.16 raeburn 2038: my $numinrow = 2;
1.160.6.34 raeburn 2039: my $css_class;
2040: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2041: my $text;
2042: if ($action eq 'requestcourses') {
2043: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2044: } elsif ($action eq 'requestauthor') {
2045: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2046: } else {
1.160.6.34 raeburn 2047: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2048: }
1.160.6.34 raeburn 2049: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2050: ' <td>'.$text.'</td>'.
1.102 raeburn 2051: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2052: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2053: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2054: if ($numdc > 0) {
2055: $datatable .= $table;
1.102 raeburn 2056: } else {
2057: $datatable .= &mt('There are no active Domain Coordinators');
2058: }
2059: $datatable .='</td></tr>';
2060: return $datatable;
2061: }
2062:
1.160.6.30 raeburn 2063: sub print_studentcode {
2064: my ($settings,$rowtotal) = @_;
2065: my $rownum = 0;
2066: my ($output,%current);
2067: my @crstypes = ('official','unofficial','community','textbook');
2068: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2069: foreach my $type (@crstypes) {
2070: $current{$type} = $settings->{'uniquecode'}{$type};
2071: }
2072: }
2073: $output .= '<tr>'.
2074: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2075: '<td class="LC_left_item">';
2076: foreach my $type (@crstypes) {
2077: my $check = ' ';
2078: if ($current{$type}) {
2079: $check = ' checked="checked" ';
2080: }
2081: $output .= '<span class="LC_nobreak"><label>'.
2082: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2083: &mt($type).'</label></span>'.(' 'x2).' ';
2084: }
2085: $output .= '</td></tr>';
2086: $$rowtotal ++;
2087: return $output;
2088: }
2089:
2090: sub print_textbookcourses {
1.160.6.46 raeburn 2091: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2092: my $rownum = 0;
2093: my $css_class;
2094: my $itemcount = 1;
2095: my $maxnum = 0;
2096: my $bookshash;
2097: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2098: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2099: }
2100: my %ordered;
2101: if (ref($bookshash) eq 'HASH') {
2102: foreach my $item (keys(%{$bookshash})) {
2103: if (ref($bookshash->{$item}) eq 'HASH') {
2104: my $num = $bookshash->{$item}{'order'};
2105: $ordered{$num} = $item;
2106: }
2107: }
2108: }
2109: my $confname = $dom.'-domainconfig';
2110: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2111: my $maxnum = scalar(keys(%ordered));
2112: my $datatable;
1.160.6.30 raeburn 2113: if (keys(%ordered)) {
2114: my @items = sort { $a <=> $b } keys(%ordered);
2115: for (my $i=0; $i<@items; $i++) {
2116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2117: my $key = $ordered{$items[$i]};
2118: my %coursehash=&Apache::lonnet::coursedescription($key);
2119: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2120: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2121: if (ref($bookshash->{$key}) eq 'HASH') {
2122: $subject = $bookshash->{$key}->{'subject'};
2123: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2124: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2125: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2126: $author = $bookshash->{$key}->{'author'};
2127: $image = $bookshash->{$key}->{'image'};
2128: if ($image ne '') {
2129: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2130: my $imagethumb = "$path/tn-".$imagefile;
2131: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2132: }
1.160.6.30 raeburn 2133: }
2134: }
1.160.6.46 raeburn 2135: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2136: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2137: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2138: for (my $k=0; $k<=$maxnum; $k++) {
2139: my $vpos = $k+1;
2140: my $selstr;
2141: if ($k == $i) {
2142: $selstr = ' selected="selected" ';
2143: }
2144: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2145: }
2146: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2147: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2148: &mt('Delete?').'</label></span></td>'.
2149: '<td colspan="2">'.
1.160.6.46 raeburn 2150: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2151: (' 'x2).
1.160.6.46 raeburn 2152: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2153: if ($type eq 'textbooks') {
2154: $datatable .= (' 'x2).
1.160.6.47 raeburn 2155: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2156: (' 'x2).
1.160.6.46 raeburn 2157: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2158: (' 'x2).
2159: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2160: if ($image) {
2161: $datatable .= '<span class="LC_nobreak">'.
2162: $imgsrc.
2163: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2164: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2165: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2166: }
2167: if ($switchserver) {
2168: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2169: } else {
2170: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2171: }
1.160.6.30 raeburn 2172: }
1.160.6.46 raeburn 2173: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2174: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2175: $coursetitle.'</span></td></tr>'."\n";
2176: $itemcount ++;
2177: }
2178: }
2179: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2180: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2181: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2182: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2183: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2184: for (my $k=0; $k<$maxnum+1; $k++) {
2185: my $vpos = $k+1;
2186: my $selstr;
2187: if ($k == $maxnum) {
2188: $selstr = ' selected="selected" ';
2189: }
2190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2191: }
2192: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2193: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2194: '<td colspan="2">'.
1.160.6.46 raeburn 2195: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2196: (' 'x2).
1.160.6.46 raeburn 2197: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2198: (' 'x2);
2199: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2200: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2201: (' 'x2).
2202: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2203: (' 'x2).
2204: '<span class="LC_nobreak">'.&mt('Image:').' ';
2205: if ($switchserver) {
2206: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2207: } else {
2208: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2209: }
1.160.6.30 raeburn 2210: }
2211: $datatable .= '</span>'."\n".
2212: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2213: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2214: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2215: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2216: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2217: '</span></td>'."\n".
2218: '</tr>'."\n";
2219: $itemcount ++;
2220: return $datatable;
2221: }
2222:
2223: sub textbookcourses_javascript {
1.160.6.46 raeburn 2224: my ($settings) = @_;
2225: return unless(ref($settings) eq 'HASH');
2226: my (%ordered,%total,%jstext);
2227: foreach my $type ('textbooks','templates') {
2228: $total{$type} = 0;
2229: if (ref($settings->{$type}) eq 'HASH') {
2230: foreach my $item (keys(%{$settings->{$type}})) {
2231: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2232: my $num = $settings->{$type}->{$item}{'order'};
2233: $ordered{$type}{$num} = $item;
2234: }
2235: }
2236: $total{$type} = scalar(keys(%{$settings->{$type}}));
2237: }
2238: my @jsarray = ();
2239: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2240: push(@jsarray,$ordered{$type}{$item});
2241: }
2242: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2243: }
2244: return <<"ENDSCRIPT";
2245: <script type="text/javascript">
2246: // <![CDATA[
1.160.6.46 raeburn 2247: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2248: var changedVal;
1.160.6.46 raeburn 2249: $jstext{'textbooks'};
2250: $jstext{'templates'};
2251: var newpos;
2252: var maxh;
2253: if (caller == 'textbooks') {
2254: newpos = 'textbooks_addbook_pos';
2255: maxh = 1 + $total{'textbooks'};
2256: } else {
2257: newpos = 'templates_addbook_pos';
2258: maxh = 1 + $total{'templates'};
2259: }
1.160.6.30 raeburn 2260: var current = new Array;
2261: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2262: if (item == newpos) {
2263: changedVal = newitemVal;
2264: } else {
2265: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2266: current[newitemVal] = newpos;
2267: }
1.160.6.46 raeburn 2268: if (caller == 'textbooks') {
2269: for (var i=0; i<textbooks.length; i++) {
2270: var elementName = 'textbooks_'+textbooks[i];
2271: if (elementName != item) {
2272: if (form.elements[elementName]) {
2273: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2274: current[currVal] = elementName;
2275: }
2276: }
2277: }
2278: }
2279: if (caller == 'templates') {
2280: for (var i=0; i<templates.length; i++) {
2281: var elementName = 'templates_'+templates[i];
2282: if (elementName != item) {
2283: if (form.elements[elementName]) {
2284: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2285: current[currVal] = elementName;
2286: }
1.160.6.30 raeburn 2287: }
2288: }
2289: }
2290: var oldVal;
2291: for (var j=0; j<maxh; j++) {
2292: if (current[j] == undefined) {
2293: oldVal = j;
2294: }
2295: }
2296: if (oldVal < changedVal) {
2297: for (var k=oldVal+1; k<=changedVal ; k++) {
2298: var elementName = current[k];
2299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2300: }
2301: } else {
2302: for (var k=changedVal; k<oldVal; k++) {
2303: var elementName = current[k];
2304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2305: }
2306: }
2307: return;
2308: }
2309:
2310: // ]]>
2311: </script>
2312:
2313: ENDSCRIPT
2314: }
2315:
1.3 raeburn 2316: sub print_autoenroll {
1.30 raeburn 2317: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2318: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2319: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2320: if (ref($settings) eq 'HASH') {
2321: if (exists($settings->{'run'})) {
2322: if ($settings->{'run'} eq '0') {
2323: $runoff = ' checked="checked" ';
2324: $runon = ' ';
2325: } else {
2326: $runon = ' checked="checked" ';
2327: $runoff = ' ';
2328: }
2329: } else {
2330: if ($autorun) {
2331: $runon = ' checked="checked" ';
2332: $runoff = ' ';
2333: } else {
2334: $runoff = ' checked="checked" ';
2335: $runon = ' ';
2336: }
2337: }
1.129 raeburn 2338: if (exists($settings->{'co-owners'})) {
2339: if ($settings->{'co-owners'} eq '0') {
2340: $coownersoff = ' checked="checked" ';
2341: $coownerson = ' ';
2342: } else {
2343: $coownerson = ' checked="checked" ';
2344: $coownersoff = ' ';
2345: }
2346: } else {
2347: $coownersoff = ' checked="checked" ';
2348: $coownerson = ' ';
2349: }
1.3 raeburn 2350: if (exists($settings->{'sender_domain'})) {
2351: $defdom = $settings->{'sender_domain'};
2352: }
1.14 raeburn 2353: } else {
2354: if ($autorun) {
2355: $runon = ' checked="checked" ';
2356: $runoff = ' ';
2357: } else {
2358: $runoff = ' checked="checked" ';
2359: $runon = ' ';
2360: }
1.3 raeburn 2361: }
2362: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2363: my $notif_sender;
2364: if (ref($settings) eq 'HASH') {
2365: $notif_sender = $settings->{'sender_uname'};
2366: }
1.3 raeburn 2367: my $datatable='<tr class="LC_odd_row">'.
2368: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2369: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2370: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2371: $runon.' value="1" />'.&mt('Yes').'</label> '.
2372: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2373: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2374: '</tr><tr>'.
2375: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2376: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2377: &mt('username').': '.
2378: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2379: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2380: ': '.$domform.'</span></td></tr>'.
2381: '<tr class="LC_odd_row">'.
2382: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2383: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2384: '<input type="radio" name="autoassign_coowners"'.
2385: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2386: '<label><input type="radio" name="autoassign_coowners"'.
2387: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2388: '</tr>';
2389: $$rowtotal += 3;
1.3 raeburn 2390: return $datatable;
2391: }
2392:
2393: sub print_autoupdate {
1.30 raeburn 2394: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2395: my $datatable;
2396: if ($position eq 'top') {
2397: my $updateon = ' ';
2398: my $updateoff = ' checked="checked" ';
2399: my $classlistson = ' ';
2400: my $classlistsoff = ' checked="checked" ';
2401: if (ref($settings) eq 'HASH') {
2402: if ($settings->{'run'} eq '1') {
2403: $updateon = $updateoff;
2404: $updateoff = ' ';
2405: }
2406: if ($settings->{'classlists'} eq '1') {
2407: $classlistson = $classlistsoff;
2408: $classlistsoff = ' ';
2409: }
2410: }
2411: my %title = (
2412: run => 'Auto-update active?',
2413: classlists => 'Update information in classlists?',
2414: );
2415: $datatable = '<tr class="LC_odd_row">'.
2416: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2417: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2418: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2419: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2420: '<label><input type="radio" name="autoupdate_run"'.
2421: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2422: '</tr><tr>'.
2423: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2424: '<td class="LC_right_item"><span class="LC_nobreak">'.
2425: '<label><input type="radio" name="classlists"'.
2426: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2427: '<label><input type="radio" name="classlists"'.
2428: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2429: '</tr>';
1.30 raeburn 2430: $$rowtotal += 2;
1.131 raeburn 2431: } elsif ($position eq 'middle') {
2432: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2433: my $numinrow = 3;
2434: my $locknamesettings;
2435: $datatable .= &insttypes_row($settings,$types,$usertypes,
2436: $dom,$numinrow,$othertitle,
2437: 'lockablenames');
2438: $$rowtotal ++;
1.3 raeburn 2439: } else {
1.44 raeburn 2440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2441: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2442: 'permanentemail','id');
1.33 raeburn 2443: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2444: my $numrows = 0;
1.26 raeburn 2445: if (ref($types) eq 'ARRAY') {
2446: if (@{$types} > 0) {
2447: $datatable =
2448: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2449: \@fields,$types,\$numrows);
1.30 raeburn 2450: $$rowtotal += @{$types};
1.26 raeburn 2451: }
1.3 raeburn 2452: }
2453: $datatable .=
2454: &usertype_update_row($settings,{'default' => $othertitle},
2455: \%fieldtitles,\@fields,['default'],
2456: \$numrows);
1.30 raeburn 2457: $$rowtotal ++;
1.3 raeburn 2458: }
2459: return $datatable;
2460: }
2461:
1.125 raeburn 2462: sub print_autocreate {
2463: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2464: my (%createon,%createoff,%currhash);
1.125 raeburn 2465: my @types = ('xml','req');
2466: if (ref($settings) eq 'HASH') {
2467: foreach my $item (@types) {
2468: $createoff{$item} = ' checked="checked" ';
2469: $createon{$item} = ' ';
2470: if (exists($settings->{$item})) {
2471: if ($settings->{$item}) {
2472: $createon{$item} = ' checked="checked" ';
2473: $createoff{$item} = ' ';
2474: }
2475: }
2476: }
1.160.6.16 raeburn 2477: if ($settings->{'xmldc'} ne '') {
2478: $currhash{$settings->{'xmldc'}} = 1;
2479: }
1.125 raeburn 2480: } else {
2481: foreach my $item (@types) {
2482: $createoff{$item} = ' checked="checked" ';
2483: $createon{$item} = ' ';
2484: }
2485: }
2486: $$rowtotal += 2;
1.160.6.16 raeburn 2487: my $numinrow = 2;
1.125 raeburn 2488: my $datatable='<tr class="LC_odd_row">'.
2489: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2490: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2491: '<input type="radio" name="autocreate_xml"'.
2492: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2493: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2494: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2495: '</td></tr><tr>'.
2496: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2497: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2498: '<input type="radio" name="autocreate_req"'.
2499: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2500: '<label><input type="radio" name="autocreate_req"'.
2501: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2502: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2503: 'autocreate_xmldc',%currhash);
1.160.6.50! raeburn 2504: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2505: if ($numdc > 1) {
1.160.6.50! raeburn 2506: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
! 2507: '</td><td class="LC_left_item">';
1.125 raeburn 2508: } else {
1.160.6.50! raeburn 2509: $datatable .= &mt('Course creation processed as:').
! 2510: '</td><td class="LC_right_item">';
1.125 raeburn 2511: }
1.160.6.50! raeburn 2512: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2513: $$rowtotal += $rows;
1.125 raeburn 2514: return $datatable;
2515: }
2516:
1.23 raeburn 2517: sub print_directorysrch {
1.30 raeburn 2518: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2519: my $srchon = ' ';
2520: my $srchoff = ' checked="checked" ';
1.25 raeburn 2521: my ($exacton,$containson,$beginson);
1.24 raeburn 2522: my $localon = ' ';
2523: my $localoff = ' checked="checked" ';
1.23 raeburn 2524: if (ref($settings) eq 'HASH') {
2525: if ($settings->{'available'} eq '1') {
2526: $srchon = $srchoff;
2527: $srchoff = ' ';
2528: }
1.24 raeburn 2529: if ($settings->{'localonly'} eq '1') {
2530: $localon = $localoff;
2531: $localoff = ' ';
2532: }
1.25 raeburn 2533: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2534: foreach my $type (@{$settings->{'searchtypes'}}) {
2535: if ($type eq 'exact') {
2536: $exacton = ' checked="checked" ';
2537: } elsif ($type eq 'contains') {
2538: $containson = ' checked="checked" ';
2539: } elsif ($type eq 'begins') {
2540: $beginson = ' checked="checked" ';
2541: }
2542: }
2543: } else {
2544: if ($settings->{'searchtypes'} eq 'exact') {
2545: $exacton = ' checked="checked" ';
2546: } elsif ($settings->{'searchtypes'} eq 'contains') {
2547: $containson = ' checked="checked" ';
2548: } elsif ($settings->{'searchtypes'} eq 'specify') {
2549: $exacton = ' checked="checked" ';
2550: $containson = ' checked="checked" ';
2551: }
1.23 raeburn 2552: }
2553: }
2554: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2555: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2556:
2557: my $numinrow = 4;
1.26 raeburn 2558: my $cansrchrow = 0;
1.23 raeburn 2559: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2560: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2561: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2562: '<input type="radio" name="dirsrch_available"'.
2563: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2564: '<label><input type="radio" name="dirsrch_available"'.
2565: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2566: '</tr><tr>'.
1.30 raeburn 2567: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2569: '<input type="radio" name="dirsrch_localonly"'.
2570: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2571: '<label><input type="radio" name="dirsrch_localonly"'.
2572: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2573: '</tr>';
1.30 raeburn 2574: $$rowtotal += 2;
1.26 raeburn 2575: if (ref($usertypes) eq 'HASH') {
2576: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2577: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2578: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2579: $cansrchrow = 1;
2580: }
2581: }
2582: if ($cansrchrow) {
1.30 raeburn 2583: $$rowtotal ++;
1.26 raeburn 2584: $datatable .= '<tr>';
2585: } else {
2586: $datatable .= '<tr class="LC_odd_row">';
2587: }
1.30 raeburn 2588: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2589: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2590: foreach my $title (@{$titleorder}) {
2591: if (defined($searchtitles->{$title})) {
2592: my $check = ' ';
1.93 raeburn 2593: if (ref($settings) eq 'HASH') {
1.39 raeburn 2594: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2595: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2596: $check = ' checked="checked" ';
2597: }
1.25 raeburn 2598: }
2599: }
2600: $datatable .= '<td class="LC_left_item">'.
2601: '<span class="LC_nobreak"><label>'.
2602: '<input type="checkbox" name="searchby" '.
2603: 'value="'.$title.'"'.$check.'/>'.
2604: $searchtitles->{$title}.'</label></span></td>';
2605: }
2606: }
1.26 raeburn 2607: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2608: $$rowtotal ++;
1.26 raeburn 2609: if ($cansrchrow) {
2610: $datatable .= '<tr class="LC_odd_row">';
2611: } else {
2612: $datatable .= '<tr>';
2613: }
1.30 raeburn 2614: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2615: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2616: '<span class="LC_nobreak"><label>'.
2617: '<input type="checkbox" name="searchtypes" '.
2618: $exacton.' value="exact" />'.&mt('Exact match').
2619: '</label> '.
2620: '<label><input type="checkbox" name="searchtypes" '.
2621: $beginson.' value="begins" />'.&mt('Begins with').
2622: '</label> '.
2623: '<label><input type="checkbox" name="searchtypes" '.
2624: $containson.' value="contains" />'.&mt('Contains').
2625: '</label></span></td></tr>';
1.30 raeburn 2626: $$rowtotal ++;
1.25 raeburn 2627: return $datatable;
2628: }
2629:
1.28 raeburn 2630: sub print_contacts {
1.30 raeburn 2631: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2632: my $datatable;
2633: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2634: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2635: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2636: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2637: foreach my $type (@mailings) {
2638: $otheremails{$type} = '';
2639: }
1.134 raeburn 2640: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2641: if (ref($settings) eq 'HASH') {
2642: foreach my $item (@contacts) {
2643: if (exists($settings->{$item})) {
2644: $to{$item} = $settings->{$item};
2645: }
2646: }
2647: foreach my $type (@mailings) {
2648: if (exists($settings->{$type})) {
2649: if (ref($settings->{$type}) eq 'HASH') {
2650: foreach my $item (@contacts) {
2651: if ($settings->{$type}{$item}) {
2652: $checked{$type}{$item} = ' checked="checked" ';
2653: }
2654: }
2655: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2656: if ($type eq 'helpdeskmail') {
2657: $bccemails{$type} = $settings->{$type}{'bcc'};
2658: }
1.28 raeburn 2659: }
1.89 raeburn 2660: } elsif ($type eq 'lonstatusmail') {
2661: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2662: }
2663: }
2664: } else {
2665: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2666: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2667: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2668: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2669: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2670: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2671: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2672: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2673: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2674: }
2675: my ($titles,$short_titles) = &contact_titles();
2676: my $rownum = 0;
2677: my $css_class;
2678: foreach my $item (@contacts) {
1.69 raeburn 2679: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2680: $datatable .= '<tr'.$css_class.'>'.
2681: '<td><span class="LC_nobreak">'.$titles->{$item}.
2682: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2683: '<input type="text" name="'.$item.'" value="'.
2684: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2685: $rownum ++;
1.28 raeburn 2686: }
2687: foreach my $type (@mailings) {
1.69 raeburn 2688: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2689: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2690: '<td><span class="LC_nobreak">'.
2691: $titles->{$type}.': </span></td>'.
1.28 raeburn 2692: '<td class="LC_left_item">'.
2693: '<span class="LC_nobreak">';
2694: foreach my $item (@contacts) {
2695: $datatable .= '<label>'.
2696: '<input type="checkbox" name="'.$type.'"'.
2697: $checked{$type}{$item}.
2698: ' value="'.$item.'" />'.$short_titles->{$item}.
2699: '</label> ';
2700: }
2701: $datatable .= '</span><br />'.&mt('Others').': '.
2702: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2703: 'value="'.$otheremails{$type}.'" />';
2704: if ($type eq 'helpdeskmail') {
1.136 raeburn 2705: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2706: '<input type="text" name="'.$type.'_bcc" '.
2707: 'value="'.$bccemails{$type}.'" />';
2708: }
2709: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2710: $rownum ++;
1.28 raeburn 2711: }
1.160.6.23 raeburn 2712: my %choices;
2713: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2714: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2715: &mt('LON-CAPA core group - MSU'),600,500));
2716: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2717: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2718: &mt('LON-CAPA core group - MSU'),600,500));
2719: my @toggles = ('reporterrors','reportupdates');
2720: my %defaultchecked = ('reporterrors' => 'on',
2721: 'reportupdates' => 'on');
2722: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2723: \%choices,$rownum);
2724: $datatable .= $reports;
1.30 raeburn 2725: $$rowtotal += $rownum;
1.28 raeburn 2726: return $datatable;
2727: }
2728:
1.118 jms 2729: sub print_helpsettings {
1.160.6.5 raeburn 2730: my ($dom,$confname,$settings,$rowtotal) = @_;
2731: my ($datatable,$itemcount);
2732: $itemcount = 1;
2733: my (%choices,%defaultchecked,@toggles);
2734: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2735: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2736: &mt('LON-CAPA bug tracker'),600,500));
2737: %defaultchecked = ('submitbugs' => 'on');
2738: @toggles = ('submitbugs',);
1.122 jms 2739:
1.160.6.5 raeburn 2740: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2741: \%choices,$itemcount);
2742: return $datatable;
1.121 raeburn 2743: }
2744:
2745: sub radiobutton_prefs {
1.160.6.16 raeburn 2746: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2747: $additional) = @_;
1.121 raeburn 2748: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2749: (ref($choices) eq 'HASH'));
2750:
2751: my (%checkedon,%checkedoff,$datatable,$css_class);
2752:
2753: foreach my $item (@{$toggles}) {
2754: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2755: $checkedon{$item} = ' checked="checked" ';
2756: $checkedoff{$item} = ' ';
1.121 raeburn 2757: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2758: $checkedoff{$item} = ' checked="checked" ';
2759: $checkedon{$item} = ' ';
2760: }
2761: }
2762: if (ref($settings) eq 'HASH') {
1.121 raeburn 2763: foreach my $item (@{$toggles}) {
1.118 jms 2764: if ($settings->{$item} eq '1') {
2765: $checkedon{$item} = ' checked="checked" ';
2766: $checkedoff{$item} = ' ';
2767: } elsif ($settings->{$item} eq '0') {
2768: $checkedoff{$item} = ' checked="checked" ';
2769: $checkedon{$item} = ' ';
2770: }
2771: }
1.121 raeburn 2772: }
1.160.6.16 raeburn 2773: if ($onclick) {
2774: $onclick = ' onclick="'.$onclick.'"';
2775: }
1.121 raeburn 2776: foreach my $item (@{$toggles}) {
1.118 jms 2777: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2778: $datatable .=
1.160.6.16 raeburn 2779: '<tr'.$css_class.'><td valign="top">'.
2780: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2781: '</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak">'.
2783: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2784: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2785: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2786: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2787: '</span>'.$additional.
2788: '</td>'.
1.118 jms 2789: '</tr>';
2790: $itemcount ++;
1.121 raeburn 2791: }
2792: return ($datatable,$itemcount);
2793: }
2794:
2795: sub print_coursedefaults {
1.139 raeburn 2796: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2797: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2798: my $itemcount = 1;
1.160.6.16 raeburn 2799: my %choices = &Apache::lonlocal::texthash (
2800: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2801: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2802: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2803: coursecredits => 'Credits can be specified for courses',
2804: );
1.160.6.21 raeburn 2805: my %staticdefaults = (
2806: anonsurvey_threshold => 10,
2807: uploadquota => 500,
2808: );
1.139 raeburn 2809: if ($position eq 'top') {
2810: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2811: @toggles = ('canuse_pdfforms');
1.139 raeburn 2812: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2813: \%choices,$itemcount);
1.139 raeburn 2814: } else {
2815: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2816: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2817: %curruploadquota);
1.160.6.16 raeburn 2818: my $currusecredits = 0;
1.160.6.30 raeburn 2819: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2820: if (ref($settings) eq 'HASH') {
2821: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2822: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2823: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2824: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2825: }
2826: }
1.160.6.16 raeburn 2827: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2828: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2829: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2830: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2831: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2832: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2833: $currusecredits = 1;
2834: }
2835: }
1.139 raeburn 2836: }
2837: if (!$currdefresponder) {
1.160.6.21 raeburn 2838: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2839: } elsif ($currdefresponder < 1) {
2840: $currdefresponder = 1;
2841: }
1.160.6.21 raeburn 2842: foreach my $type (@types) {
2843: if ($curruploadquota{$type} eq '') {
2844: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2845: }
2846: }
1.139 raeburn 2847: $datatable .=
1.160.6.16 raeburn 2848: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2849: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2850: '</span></td>'.
2851: '<td class="LC_right_item"><span class="LC_nobreak">'.
2852: '<input type="text" name="anonsurvey_threshold"'.
2853: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2854: '</td></tr>'."\n";
2855: $itemcount ++;
2856: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2857: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2858: $choices{'uploadquota'}.
2859: '</span></td>'.
2860: '<td align="right" class="LC_right_item">'.
2861: '<table><tr>';
1.160.6.21 raeburn 2862: foreach my $type (@types) {
2863: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2864: '<input type="text" name="uploadquota_'.$type.'"'.
2865: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2866: }
2867: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2868: $itemcount ++;
1.160.6.40 raeburn 2869: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2870: my $display = 'none';
2871: if ($currusecredits) {
2872: $display = 'block';
2873: }
2874: my $additional = '<div id="credits" style="display: '.$display.'">'.
2875: '<span class="LC_nobreak">'.
2876: &mt('Default credits for official courses [_1]',
2877: '<input type="text" name="official_credits" value="'.
2878: $def_official_credits.'" size="3" />').
2879: '</span><br />'.
2880: '<span class="LC_nobreak">'.
2881: &mt('Default credits for unofficial courses [_1]',
2882: '<input type="text" name="unofficial_credits" value="'.
2883: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2884: '</span><br />'.
2885: '<span class="LC_nobreak">'.
2886: &mt('Default credits for textbook courses [_1]',
2887: '<input type="text" name="textbook_credits" value="'.
2888: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2889: '</span></div>'."\n";
2890: %defaultchecked = ('coursecredits' => 'off');
2891: @toggles = ('coursecredits');
2892: my $current = {
2893: 'coursecredits' => $currusecredits,
2894: };
2895: (my $table,$itemcount) =
2896: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2897: \%choices,$itemcount,$onclick,$additional);
2898: $datatable .= $table;
1.160.6.37 raeburn 2899: $itemcount ++;
2900: }
2901: $$rowtotal += $itemcount;
2902: return $datatable;
2903: }
2904:
2905: sub print_selfenrollment {
2906: my ($position,$dom,$settings,$rowtotal) = @_;
2907: my ($css_class,$datatable);
2908: my $itemcount = 1;
2909: my @types = ('official','unofficial','community','textbook');
2910: if (($position eq 'top') || ($position eq 'middle')) {
2911: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2912: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2913: my @rows;
2914: my $key;
2915: if ($position eq 'top') {
2916: $key = 'admin';
2917: if (ref($rowsref) eq 'ARRAY') {
2918: @rows = @{$rowsref};
2919: }
2920: } elsif ($position eq 'middle') {
2921: $key = 'default';
2922: @rows = ('types','registered','approval','limit');
2923: }
2924: foreach my $row (@rows) {
2925: if (defined($titlesref->{$row})) {
2926: $itemcount ++;
2927: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2928: $datatable .= '<tr'.$css_class.'>'.
2929: '<td>'.$titlesref->{$row}.'</td>'.
2930: '<td class="LC_left_item">'.
2931: '<table><tr>';
2932: my (%current,%currentcap);
2933: if (ref($settings) eq 'HASH') {
2934: if (ref($settings->{$key}) eq 'HASH') {
2935: foreach my $type (@types) {
2936: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2937: $current{$type} = $settings->{$key}->{$type}->{$row};
2938: }
2939: if (($row eq 'limit') && ($key eq 'default')) {
2940: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2941: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2942: }
2943: }
2944: }
2945: }
2946: }
2947: my %roles = (
2948: '0' => &Apache::lonnet::plaintext('dc'),
2949: );
2950:
2951: foreach my $type (@types) {
2952: unless (($row eq 'registered') && ($key eq 'default')) {
2953: $datatable .= '<th>'.&mt($type).'</th>';
2954: }
2955: }
2956: unless (($row eq 'registered') && ($key eq 'default')) {
2957: $datatable .= '</tr><tr>';
2958: }
2959: foreach my $type (@types) {
2960: if ($type eq 'community') {
2961: $roles{'1'} = &mt('Community personnel');
2962: } else {
2963: $roles{'1'} = &mt('Course personnel');
2964: }
2965: $datatable .= '<td style="vertical-align: top">';
2966: if ($position eq 'top') {
2967: my %checked;
2968: if ($current{$type} eq '0') {
2969: $checked{'0'} = ' checked="checked"';
2970: } else {
2971: $checked{'1'} = ' checked="checked"';
2972: }
2973: foreach my $role ('1','0') {
2974: $datatable .= '<span class="LC_nobreak"><label>'.
2975: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2976: 'value="'.$role.'"'.$checked{$role}.' />'.
2977: $roles{$role}.'</label></span> ';
2978: }
2979: } else {
2980: if ($row eq 'types') {
2981: my %checked;
2982: if ($current{$type} =~ /^(all|dom)$/) {
2983: $checked{$1} = ' checked="checked"';
2984: } else {
2985: $checked{''} = ' checked="checked"';
2986: }
2987: foreach my $val ('','dom','all') {
2988: $datatable .= '<span class="LC_nobreak"><label>'.
2989: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2990: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2991: }
2992: } elsif ($row eq 'registered') {
2993: my %checked;
2994: if ($current{$type} eq '1') {
2995: $checked{'1'} = ' checked="checked"';
2996: } else {
2997: $checked{'0'} = ' checked="checked"';
2998: }
2999: foreach my $val ('0','1') {
3000: $datatable .= '<span class="LC_nobreak"><label>'.
3001: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3002: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3003: }
3004: } elsif ($row eq 'approval') {
3005: my %checked;
3006: if ($current{$type} =~ /^([12])$/) {
3007: $checked{$1} = ' checked="checked"';
3008: } else {
3009: $checked{'0'} = ' checked="checked"';
3010: }
3011: for my $val (0..2) {
3012: $datatable .= '<span class="LC_nobreak"><label>'.
3013: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3014: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3015: }
3016: } elsif ($row eq 'limit') {
3017: my %checked;
3018: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3019: $checked{$1} = ' checked="checked"';
3020: } else {
3021: $checked{'none'} = ' checked="checked"';
3022: }
3023: my $cap;
3024: if ($currentcap{$type} =~ /^\d+$/) {
3025: $cap = $currentcap{$type};
3026: }
3027: foreach my $val ('none','allstudents','selfenrolled') {
3028: $datatable .= '<span class="LC_nobreak"><label>'.
3029: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3030: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3031: }
3032: $datatable .= '<br />'.
3033: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3034: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3035: '</span>';
3036: }
3037: }
3038: $datatable .= '</td>';
3039: }
3040: $datatable .= '</tr>';
3041: }
3042: $datatable .= '</table></td></tr>';
3043: }
3044: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3045: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3046: }
3047: $$rowtotal += $itemcount;
3048: return $datatable;
3049: }
3050:
3051: sub print_validation_rows {
3052: my ($caller,$dom,$settings,$rowtotal) = @_;
3053: my ($itemsref,$namesref,$fieldsref);
3054: if ($caller eq 'selfenroll') {
3055: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3056: } elsif ($caller eq 'requestcourses') {
3057: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3058: }
3059: my %currvalidation;
3060: if (ref($settings) eq 'HASH') {
3061: if (ref($settings->{'validation'}) eq 'HASH') {
3062: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3063: }
1.160.6.39 raeburn 3064: }
3065: my $datatable;
3066: my $itemcount = 0;
3067: foreach my $item (@{$itemsref}) {
3068: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3069: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3070: $namesref->{$item}.
3071: '</span></td>'.
3072: '<td class="LC_left_item">';
3073: if (($item eq 'url') || ($item eq 'button')) {
3074: $datatable .= '<span class="LC_nobreak">'.
3075: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3076: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3077: } elsif ($item eq 'fields') {
3078: my @currfields;
3079: if (ref($currvalidation{$item}) eq 'ARRAY') {
3080: @currfields = @{$currvalidation{$item}};
3081: }
3082: foreach my $field (@{$fieldsref}) {
3083: my $check = '';
3084: if (grep(/^\Q$field\E$/,@currfields)) {
3085: $check = ' checked="checked"';
3086: }
3087: $datatable .= '<span class="LC_nobreak"><label>'.
3088: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3089: ' value="'.$field.'"'.$check.' />'.$field.
3090: '</label></span> ';
3091: }
3092: } elsif ($item eq 'markup') {
3093: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3094: $currvalidation{$item}.
1.160.6.37 raeburn 3095: '</textarea>';
1.160.6.39 raeburn 3096: }
3097: $datatable .= '</td></tr>'."\n";
3098: if (ref($rowtotal)) {
1.160.6.37 raeburn 3099: $itemcount ++;
3100: }
1.139 raeburn 3101: }
1.160.6.39 raeburn 3102: if ($caller eq 'requestcourses') {
3103: my %currhash;
3104: if (ref($settings->{'validation'}) eq 'HASH') {
3105: if ($settings->{'validation'}{'dc'} ne '') {
3106: $currhash{$settings->{'validation'}{'dc'}} = 1;
3107: }
3108: }
3109: my $numinrow = 2;
3110: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3111: 'validationdc',%currhash);
1.160.6.50! raeburn 3112: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
! 3113: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3114: if ($numdc > 1) {
1.160.6.50! raeburn 3115: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3116: } else {
1.160.6.50! raeburn 3117: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3118: }
1.160.6.50! raeburn 3119: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3120: $itemcount ++;
3121: }
3122: if (ref($rowtotal)) {
3123: $$rowtotal += $itemcount;
3124: }
1.121 raeburn 3125: return $datatable;
1.118 jms 3126: }
3127:
1.137 raeburn 3128: sub print_usersessions {
3129: my ($position,$dom,$settings,$rowtotal) = @_;
3130: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3131: my (%by_ip,%by_location,@intdoms);
3132: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3133:
3134: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3135: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3136: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3137: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3138: my $itemcount = 1;
3139: if ($position eq 'top') {
1.152 raeburn 3140: if (keys(%serverhomes) > 1) {
1.145 raeburn 3141: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3142: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3143: } else {
1.140 raeburn 3144: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3145: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3146: }
1.137 raeburn 3147: } else {
1.145 raeburn 3148: if (keys(%by_location) == 0) {
3149: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3150: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3151: } else {
3152: my %lt = &usersession_titles();
3153: my $numinrow = 5;
3154: my $prefix;
3155: my @types;
3156: if ($position eq 'bottom') {
3157: $prefix = 'remote';
3158: @types = ('version','excludedomain','includedomain');
3159: } else {
3160: $prefix = 'hosted';
3161: @types = ('excludedomain','includedomain');
3162: }
3163: my (%current,%checkedon,%checkedoff);
3164: my @lcversions = &Apache::lonnet::all_loncaparevs();
3165: my @locations = sort(keys(%by_location));
3166: foreach my $type (@types) {
3167: $checkedon{$type} = '';
3168: $checkedoff{$type} = ' checked="checked"';
3169: }
3170: if (ref($settings) eq 'HASH') {
3171: if (ref($settings->{$prefix}) eq 'HASH') {
3172: foreach my $key (keys(%{$settings->{$prefix}})) {
3173: $current{$key} = $settings->{$prefix}{$key};
3174: if ($key eq 'version') {
3175: if ($current{$key} ne '') {
3176: $checkedon{$key} = ' checked="checked"';
3177: $checkedoff{$key} = '';
3178: }
3179: } elsif (ref($current{$key}) eq 'ARRAY') {
3180: $checkedon{$key} = ' checked="checked"';
3181: $checkedoff{$key} = '';
3182: }
1.137 raeburn 3183: }
3184: }
3185: }
1.145 raeburn 3186: foreach my $type (@types) {
3187: next if ($type ne 'version' && !@locations);
3188: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3189: $datatable .= '<tr'.$css_class.'>
3190: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3191: <span class="LC_nobreak">
3192: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3193: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3194: if ($type eq 'version') {
3195: my $selector = '<select name="'.$prefix.'_version">';
3196: foreach my $version (@lcversions) {
3197: my $selected = '';
3198: if ($current{'version'} eq $version) {
3199: $selected = ' selected="selected"';
3200: }
3201: $selector .= ' <option value="'.$version.'"'.
3202: $selected.'>'.$version.'</option>';
3203: }
3204: $selector .= '</select> ';
3205: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3206: } else {
3207: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3208: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3209: ' />'.(' 'x2).
3210: '<input type="button" value="'.&mt('uncheck all').'" '.
3211: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3212: "\n".
3213: '</div><div><table>';
3214: my $rem;
3215: for (my $i=0; $i<@locations; $i++) {
3216: my ($showloc,$value,$checkedtype);
3217: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3218: my $ip = $by_location{$locations[$i]}->[0];
3219: if (ref($by_ip{$ip}) eq 'ARRAY') {
3220: $value = join(':',@{$by_ip{$ip}});
3221: $showloc = join(', ',@{$by_ip{$ip}});
3222: if (ref($current{$type}) eq 'ARRAY') {
3223: foreach my $loc (@{$by_ip{$ip}}) {
3224: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3225: $checkedtype = ' checked="checked"';
3226: last;
3227: }
3228: }
1.138 raeburn 3229: }
3230: }
3231: }
1.145 raeburn 3232: $rem = $i%($numinrow);
3233: if ($rem == 0) {
3234: if ($i > 0) {
3235: $datatable .= '</tr>';
3236: }
3237: $datatable .= '<tr>';
3238: }
3239: $datatable .= '<td class="LC_left_item">'.
3240: '<span class="LC_nobreak"><label>'.
3241: '<input type="checkbox" name="'.$prefix.'_'.$type.
3242: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3243: '</label></span></td>';
1.137 raeburn 3244: }
1.145 raeburn 3245: $rem = @locations%($numinrow);
3246: my $colsleft = $numinrow - $rem;
3247: if ($colsleft > 1 ) {
3248: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3249: ' </td>';
3250: } elsif ($colsleft == 1) {
3251: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3252: }
1.145 raeburn 3253: $datatable .= '</tr></table>';
1.137 raeburn 3254: }
1.145 raeburn 3255: $datatable .= '</td></tr>';
3256: $itemcount ++;
1.137 raeburn 3257: }
3258: }
3259: }
3260: $$rowtotal += $itemcount;
3261: return $datatable;
3262: }
3263:
1.138 raeburn 3264: sub build_location_hashes {
3265: my ($intdoms,$by_ip,$by_location) = @_;
3266: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3267: (ref($by_location) eq 'HASH'));
3268: my %iphost = &Apache::lonnet::get_iphost();
3269: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3270: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3271: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3272: foreach my $id (@{$iphost{$primary_ip}}) {
3273: my $intdom = &Apache::lonnet::internet_dom($id);
3274: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3275: push(@{$intdoms},$intdom);
3276: }
3277: }
3278: }
3279: foreach my $ip (keys(%iphost)) {
3280: if (ref($iphost{$ip}) eq 'ARRAY') {
3281: foreach my $id (@{$iphost{$ip}}) {
3282: my $location = &Apache::lonnet::internet_dom($id);
3283: if ($location) {
3284: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3285: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3286: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3287: push(@{$by_ip->{$ip}},$location);
3288: }
3289: } else {
3290: $by_ip->{$ip} = [$location];
3291: }
3292: }
3293: }
3294: }
3295: }
3296: foreach my $ip (sort(keys(%{$by_ip}))) {
3297: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3298: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3299: my $first = $by_ip->{$ip}->[0];
3300: if (ref($by_location->{$first}) eq 'ARRAY') {
3301: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3302: push(@{$by_location->{$first}},$ip);
3303: }
3304: } else {
3305: $by_location->{$first} = [$ip];
3306: }
3307: }
3308: }
3309: return;
3310: }
3311:
1.145 raeburn 3312: sub current_offloads_to {
3313: my ($dom,$settings,$servers) = @_;
3314: my (%spareid,%otherdomconfigs);
1.152 raeburn 3315: if (ref($servers) eq 'HASH') {
1.145 raeburn 3316: foreach my $lonhost (sort(keys(%{$servers}))) {
3317: my $gotspares;
1.152 raeburn 3318: if (ref($settings) eq 'HASH') {
3319: if (ref($settings->{'spares'}) eq 'HASH') {
3320: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3321: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3322: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3323: $gotspares = 1;
3324: }
1.145 raeburn 3325: }
3326: }
3327: unless ($gotspares) {
3328: my $gotspares;
3329: my $serverhomeID =
3330: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3331: my $serverhomedom =
3332: &Apache::lonnet::host_domain($serverhomeID);
3333: if ($serverhomedom ne $dom) {
3334: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3335: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3336: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3337: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3338: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3339: $gotspares = 1;
3340: }
3341: }
3342: } else {
3343: $otherdomconfigs{$serverhomedom} =
3344: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3345: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3346: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3347: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3348: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3349: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3350: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3351: $gotspares = 1;
3352: }
3353: }
3354: }
3355: }
3356: }
3357: }
3358: }
3359: unless ($gotspares) {
3360: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3361: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3362: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3363: } else {
3364: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3365: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3366: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3367: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3368: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3369: } else {
1.150 raeburn 3370: my %what = (
3371: spareid => 1,
3372: );
3373: my ($result,$returnhash) =
3374: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3375: if ($result eq 'ok') {
3376: if (ref($returnhash) eq 'HASH') {
3377: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3378: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3379: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3380: }
3381: }
1.145 raeburn 3382: }
3383: }
3384: }
3385: }
3386: }
3387: }
3388: return %spareid;
3389: }
3390:
3391: sub spares_row {
1.152 raeburn 3392: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3393: my $css_class;
3394: my $numinrow = 4;
3395: my $itemcount = 1;
3396: my $datatable;
1.152 raeburn 3397: my %typetitles = &sparestype_titles();
3398: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3399: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3400: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3401: my ($othercontrol,$serverdom);
3402: if ($serverhome ne $server) {
3403: $serverdom = &Apache::lonnet::host_domain($serverhome);
3404: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3405: } else {
3406: $serverdom = &Apache::lonnet::host_domain($server);
3407: if ($serverdom ne $dom) {
3408: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3409: }
3410: }
3411: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3412: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3413: $datatable .= '<tr'.$css_class.'>
3414: <td rowspan="2">
1.160.6.13 raeburn 3415: <span class="LC_nobreak">'.
3416: &mt('[_1] when busy, offloads to:'
3417: ,'<b>'.$server.'</b>').
3418: "\n";
1.145 raeburn 3419: my (%current,%canselect);
1.152 raeburn 3420: my @choices =
3421: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3422: foreach my $type ('primary','default') {
3423: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3424: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3425: my @spares = @{$spareid->{$server}{$type}};
3426: if (@spares > 0) {
1.152 raeburn 3427: if ($othercontrol) {
3428: $current{$type} = join(', ',@spares);
3429: } else {
3430: $current{$type} .= '<table>';
3431: my $numspares = scalar(@spares);
3432: for (my $i=0; $i<@spares; $i++) {
3433: my $rem = $i%($numinrow);
3434: if ($rem == 0) {
3435: if ($i > 0) {
3436: $current{$type} .= '</tr>';
3437: }
3438: $current{$type} .= '<tr>';
1.145 raeburn 3439: }
1.152 raeburn 3440: $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'".');" /> '.
3441: $spareid->{$server}{$type}[$i].
3442: '</label></td>'."\n";
3443: }
3444: my $rem = @spares%($numinrow);
3445: my $colsleft = $numinrow - $rem;
3446: if ($colsleft > 1 ) {
3447: $current{$type} .= '<td colspan="'.$colsleft.
3448: '" class="LC_left_item">'.
3449: ' </td>';
3450: } elsif ($colsleft == 1) {
3451: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3452: }
1.152 raeburn 3453: $current{$type} .= '</tr></table>';
1.150 raeburn 3454: }
1.145 raeburn 3455: }
3456: }
3457: if ($current{$type} eq '') {
3458: $current{$type} = &mt('None specified');
3459: }
1.152 raeburn 3460: if ($othercontrol) {
3461: if ($type eq 'primary') {
3462: $canselect{$type} = $othercontrol;
3463: }
3464: } else {
3465: $canselect{$type} =
3466: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3467: '<select name="newspare_'.$type.'_'.$server.'" '.
3468: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3469: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3470: if (@choices > 0) {
3471: foreach my $lonhost (@choices) {
3472: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3473: }
3474: }
3475: $canselect{$type} .= '</select>'."\n";
3476: }
3477: } else {
3478: $current{$type} = &mt('Could not be determined');
3479: if ($type eq 'primary') {
3480: $canselect{$type} = $othercontrol;
3481: }
1.145 raeburn 3482: }
1.152 raeburn 3483: if ($type eq 'default') {
3484: $datatable .= '<tr'.$css_class.'>';
3485: }
3486: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3487: '<td>'.$current{$type}.'</td>'."\n".
3488: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3489: }
3490: $itemcount ++;
3491: }
3492: }
3493: $$rowtotal += $itemcount;
3494: return $datatable;
3495: }
3496:
1.152 raeburn 3497: sub possible_newspares {
3498: my ($server,$currspares,$serverhomes,$altids) = @_;
3499: my $serverhostname = &Apache::lonnet::hostname($server);
3500: my %excluded;
3501: if ($serverhostname ne '') {
3502: %excluded = (
3503: $serverhostname => 1,
3504: );
3505: }
3506: if (ref($currspares) eq 'HASH') {
3507: foreach my $type (keys(%{$currspares})) {
3508: if (ref($currspares->{$type}) eq 'ARRAY') {
3509: if (@{$currspares->{$type}} > 0) {
3510: foreach my $curr (@{$currspares->{$type}}) {
3511: my $hostname = &Apache::lonnet::hostname($curr);
3512: $excluded{$hostname} = 1;
3513: }
3514: }
3515: }
3516: }
3517: }
3518: my @choices;
3519: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3520: if (keys(%{$serverhomes}) > 1) {
3521: foreach my $name (sort(keys(%{$serverhomes}))) {
3522: unless ($excluded{$name}) {
3523: if (exists($altids->{$serverhomes->{$name}})) {
3524: push(@choices,$altids->{$serverhomes->{$name}});
3525: } else {
3526: push(@choices,$serverhomes->{$name});
1.145 raeburn 3527: }
3528: }
3529: }
3530: }
3531: }
1.152 raeburn 3532: return sort(@choices);
1.145 raeburn 3533: }
3534:
1.150 raeburn 3535: sub print_loadbalancing {
3536: my ($dom,$settings,$rowtotal) = @_;
3537: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3538: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3539: my $numinrow = 1;
3540: my $datatable;
3541: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3542: my (%currbalancer,%currtargets,%currrules,%existing);
3543: if (ref($settings) eq 'HASH') {
3544: %existing = %{$settings};
3545: }
3546: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3547: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3548: \%currtargets,\%currrules);
1.150 raeburn 3549: } else {
3550: return;
3551: }
3552: my ($othertitle,$usertypes,$types) =
3553: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3554: my $rownum = 8;
1.150 raeburn 3555: if (ref($types) eq 'ARRAY') {
3556: $rownum += scalar(@{$types});
3557: }
1.160.6.7 raeburn 3558: my @css_class = ('LC_odd_row','LC_even_row');
3559: my $balnum = 0;
3560: my $islast;
3561: my (@toshow,$disabledtext);
3562: if (keys(%currbalancer) > 0) {
3563: @toshow = sort(keys(%currbalancer));
3564: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3565: push(@toshow,'');
3566: }
3567: } else {
3568: @toshow = ('');
3569: $disabledtext = &mt('No existing load balancer');
3570: }
3571: foreach my $lonhost (@toshow) {
3572: if ($balnum == scalar(@toshow)-1) {
3573: $islast = 1;
3574: } else {
3575: $islast = 0;
3576: }
3577: my $cssidx = $balnum%2;
3578: my $targets_div_style = 'display: none';
3579: my $disabled_div_style = 'display: block';
3580: my $homedom_div_style = 'display: none';
3581: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3582: '<td rowspan="'.$rownum.'" valign="top">'.
3583: '<p>';
3584: if ($lonhost eq '') {
3585: $datatable .= '<span class="LC_nobreak">';
3586: if (keys(%currbalancer) > 0) {
3587: $datatable .= &mt('Add balancer:');
3588: } else {
3589: $datatable .= &mt('Enable balancer:');
3590: }
3591: $datatable .= ' '.
3592: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3593: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3594: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3595: '<option value="" selected="selected">'.&mt('None').
3596: '</option>'."\n";
3597: foreach my $server (sort(keys(%servers))) {
3598: next if ($currbalancer{$server});
3599: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3600: }
3601: $datatable .=
3602: '</select>'."\n".
3603: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3604: } else {
3605: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3606: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3607: &mt('Stop balancing').'</label>'.
3608: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3609: $targets_div_style = 'display: block';
3610: $disabled_div_style = 'display: none';
3611: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3612: $homedom_div_style = 'display: block';
3613: }
3614: }
3615: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3616: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3617: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3618: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3619: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3620: my @sparestypes = ('primary','default');
3621: my %typetitles = &sparestype_titles();
3622: foreach my $sparetype (@sparestypes) {
3623: my $targettable;
3624: for (my $i=0; $i<$numspares; $i++) {
3625: my $checked;
3626: if (ref($currtargets{$lonhost}) eq 'HASH') {
3627: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3628: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3629: $checked = ' checked="checked"';
3630: }
3631: }
3632: }
3633: my ($chkboxval,$disabled);
3634: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3635: $chkboxval = $spares[$i];
3636: }
3637: if (exists($currbalancer{$spares[$i]})) {
3638: $disabled = ' disabled="disabled"';
3639: }
3640: $targettable .=
3641: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3642: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3643: '</span></label></td>';
3644: my $rem = $i%($numinrow);
3645: if ($rem == 0) {
3646: if (($i > 0) && ($i < $numspares-1)) {
3647: $targettable .= '</tr>';
3648: }
3649: if ($i < $numspares-1) {
3650: $targettable .= '<tr>';
1.150 raeburn 3651: }
3652: }
3653: }
1.160.6.7 raeburn 3654: if ($targettable ne '') {
3655: my $rem = $numspares%($numinrow);
3656: my $colsleft = $numinrow - $rem;
3657: if ($colsleft > 1 ) {
3658: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3659: ' </td>';
3660: } elsif ($colsleft == 1) {
3661: $targettable .= '<td class="LC_left_item"> </td>';
3662: }
3663: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3664: '<table><tr>'.$targettable.'</tr></table><br />';
3665: }
3666: }
3667: $datatable .= '</div></td></tr>'.
3668: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3669: $othertitle,$usertypes,$types,\%servers,
3670: \%currbalancer,$lonhost,
3671: $targets_div_style,$homedom_div_style,
3672: $css_class[$cssidx],$balnum,$islast);
3673: $$rowtotal += $rownum;
3674: $balnum ++;
3675: }
3676: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3677: return $datatable;
3678: }
3679:
3680: sub get_loadbalancers_config {
3681: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3682: return unless ((ref($servers) eq 'HASH') &&
3683: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3684: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3685: if (keys(%{$existing}) > 0) {
3686: my $oldlonhost;
3687: foreach my $key (sort(keys(%{$existing}))) {
3688: if ($key eq 'lonhost') {
3689: $oldlonhost = $existing->{'lonhost'};
3690: $currbalancer->{$oldlonhost} = 1;
3691: } elsif ($key eq 'targets') {
3692: if ($oldlonhost) {
3693: $currtargets->{$oldlonhost} = $existing->{'targets'};
3694: }
3695: } elsif ($key eq 'rules') {
3696: if ($oldlonhost) {
3697: $currrules->{$oldlonhost} = $existing->{'rules'};
3698: }
3699: } elsif (ref($existing->{$key}) eq 'HASH') {
3700: $currbalancer->{$key} = 1;
3701: $currtargets->{$key} = $existing->{$key}{'targets'};
3702: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3703: }
3704: }
1.160.6.7 raeburn 3705: } else {
3706: my ($balancerref,$targetsref) =
3707: &Apache::lonnet::get_lonbalancer_config($servers);
3708: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3709: foreach my $server (sort(keys(%{$balancerref}))) {
3710: $currbalancer->{$server} = 1;
3711: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3712: }
3713: }
3714: }
1.160.6.7 raeburn 3715: return;
1.150 raeburn 3716: }
3717:
3718: sub loadbalancing_rules {
3719: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3720: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3721: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3722: my $output;
1.160.6.7 raeburn 3723: my $num = 0;
3724: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3725: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3726: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3727: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3728: $num ++;
1.150 raeburn 3729: my $current;
3730: if (ref($currrules) eq 'HASH') {
3731: $current = $currrules->{$type};
3732: }
1.160.6.26 raeburn 3733: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3734: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3735: $current = '';
3736: }
3737: }
3738: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3739: $servers,$currbalancer,$lonhost,$dom,
3740: $targets_div_style,$homedom_div_style,
3741: $css_class,$balnum,$num,$islast);
1.150 raeburn 3742: }
3743: }
3744: return $output;
3745: }
3746:
3747: sub loadbalancing_titles {
3748: my ($dom,$intdom,$usertypes,$types) = @_;
3749: my %othertypes = (
3750: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3751: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3752: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3753: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3754: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3755: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3756: );
1.160.6.26 raeburn 3757: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3758: if (ref($types) eq 'ARRAY') {
3759: unshift(@alltypes,@{$types},'default');
3760: }
3761: my %titles;
3762: foreach my $type (@alltypes) {
3763: if ($type =~ /^_LC_/) {
3764: $titles{$type} = $othertypes{$type};
3765: } elsif ($type eq 'default') {
3766: $titles{$type} = &mt('All users from [_1]',$dom);
3767: if (ref($types) eq 'ARRAY') {
3768: if (@{$types} > 0) {
3769: $titles{$type} = &mt('Other users from [_1]',$dom);
3770: }
3771: }
3772: } elsif (ref($usertypes) eq 'HASH') {
3773: $titles{$type} = $usertypes->{$type};
3774: }
3775: }
3776: return (\@alltypes,\%othertypes,\%titles);
3777: }
3778:
3779: sub loadbalance_rule_row {
1.160.6.7 raeburn 3780: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3781: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3782: my @rulenames;
1.150 raeburn 3783: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3784: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3785: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3786: } else {
1.160.6.26 raeburn 3787: @rulenames = ('default','homeserver');
3788: if ($type eq '_LC_external') {
3789: push(@rulenames,'externalbalancer');
3790: } else {
3791: push(@rulenames,'specific');
3792: }
3793: push(@rulenames,'none');
1.150 raeburn 3794: }
3795: my $style = $targets_div_style;
1.160.6.26 raeburn 3796: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3797: $style = $homedom_div_style;
3798: }
1.160.6.7 raeburn 3799: my $space;
3800: if ($islast && $num == 1) {
3801: $space = '<div display="inline-block"> </div>';
3802: }
3803: my $output =
3804: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3805: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3806: '<td valaign="top">'.$space.
3807: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3808: for (my $i=0; $i<@rulenames; $i++) {
3809: my $rule = $rulenames[$i];
3810: my ($checked,$extra);
3811: if ($rulenames[$i] eq 'default') {
3812: $rule = '';
3813: }
3814: if ($rulenames[$i] eq 'specific') {
3815: if (ref($servers) eq 'HASH') {
3816: my $default;
3817: if (($current ne '') && (exists($servers->{$current}))) {
3818: $checked = ' checked="checked"';
3819: }
3820: unless ($checked) {
3821: $default = ' selected="selected"';
3822: }
1.160.6.7 raeburn 3823: $extra =
3824: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3825: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3826: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3827: '<option value=""'.$default.'></option>'."\n";
3828: foreach my $server (sort(keys(%{$servers}))) {
3829: if (ref($currbalancer) eq 'HASH') {
3830: next if (exists($currbalancer->{$server}));
3831: }
1.150 raeburn 3832: my $selected;
1.160.6.7 raeburn 3833: if ($server eq $current) {
1.150 raeburn 3834: $selected = ' selected="selected"';
3835: }
1.160.6.7 raeburn 3836: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3837: }
3838: $extra .= '</select>';
3839: }
3840: } elsif ($rule eq $current) {
3841: $checked = ' checked="checked"';
3842: }
3843: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3844: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3845: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3846: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3847: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3848: '</label>'.$extra.'</span><br />'."\n";
3849: }
3850: $output .= '</div></td></tr>'."\n";
3851: return $output;
3852: }
3853:
3854: sub offloadtype_text {
3855: my %ruletitles = &Apache::lonlocal::texthash (
3856: 'default' => 'Offloads to default destinations',
3857: 'homeserver' => "Offloads to user's home server",
3858: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3859: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3860: 'none' => 'No offload',
1.160.6.26 raeburn 3861: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3862: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3863: );
3864: return %ruletitles;
3865: }
3866:
3867: sub sparestype_titles {
3868: my %typestitles = &Apache::lonlocal::texthash (
3869: 'primary' => 'primary',
3870: 'default' => 'default',
3871: );
3872: return %typestitles;
3873: }
3874:
1.28 raeburn 3875: sub contact_titles {
3876: my %titles = &Apache::lonlocal::texthash (
3877: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3878: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3879: 'errormail' => 'Error reports to be e-mailed to',
3880: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3881: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3882: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3883: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3884: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3885: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3886: );
3887: my %short_titles = &Apache::lonlocal::texthash (
3888: adminemail => 'Admin E-mail address',
3889: supportemail => 'Support E-mail',
3890: );
3891: return (\%titles,\%short_titles);
3892: }
3893:
1.72 raeburn 3894: sub tool_titles {
3895: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3896: aboutme => 'Personal web page',
1.86 raeburn 3897: blog => 'Blog',
1.160.6.4 raeburn 3898: webdav => 'WebDAV',
1.86 raeburn 3899: portfolio => 'Portfolio',
1.88 bisitz 3900: official => 'Official courses (with institutional codes)',
3901: unofficial => 'Unofficial courses',
1.98 raeburn 3902: community => 'Communities',
1.160.6.30 raeburn 3903: textbook => 'Textbook courses',
1.86 raeburn 3904: );
1.72 raeburn 3905: return %titles;
3906: }
3907:
1.101 raeburn 3908: sub courserequest_titles {
3909: my %titles = &Apache::lonlocal::texthash (
3910: official => 'Official',
3911: unofficial => 'Unofficial',
3912: community => 'Communities',
1.160.6.30 raeburn 3913: textbook => 'Textbook',
1.101 raeburn 3914: norequest => 'Not allowed',
1.104 raeburn 3915: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3916: validate => 'With validation',
3917: autolimit => 'Numerical limit',
1.103 raeburn 3918: unlimited => '(blank for unlimited)',
1.101 raeburn 3919: );
3920: return %titles;
3921: }
3922:
1.160.6.5 raeburn 3923: sub authorrequest_titles {
3924: my %titles = &Apache::lonlocal::texthash (
3925: norequest => 'Not allowed',
3926: approval => 'Approval by Dom. Coord.',
3927: automatic => 'Automatic approval',
3928: );
3929: return %titles;
3930: }
3931:
1.101 raeburn 3932: sub courserequest_conditions {
3933: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3934: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3935: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3936: );
3937: return %conditions;
3938: }
3939:
3940:
1.27 raeburn 3941: sub print_usercreation {
1.30 raeburn 3942: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3943: my $numinrow = 4;
1.28 raeburn 3944: my $datatable;
3945: if ($position eq 'top') {
1.30 raeburn 3946: $$rowtotal ++;
1.34 raeburn 3947: my $rowcount = 0;
1.32 raeburn 3948: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3949: if (ref($rules) eq 'HASH') {
3950: if (keys(%{$rules}) > 0) {
1.32 raeburn 3951: $datatable .= &user_formats_row('username',$settings,$rules,
3952: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3953: $$rowtotal ++;
1.32 raeburn 3954: $rowcount ++;
3955: }
3956: }
3957: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3958: if (ref($idrules) eq 'HASH') {
3959: if (keys(%{$idrules}) > 0) {
3960: $datatable .= &user_formats_row('id',$settings,$idrules,
3961: $idruleorder,$numinrow,$rowcount);
3962: $$rowtotal ++;
3963: $rowcount ++;
1.28 raeburn 3964: }
3965: }
1.39 raeburn 3966: if ($rowcount == 0) {
3967: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3968: $$rowtotal ++;
3969: $rowcount ++;
3970: }
1.34 raeburn 3971: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3972: my @creators = ('author','course','requestcrs');
1.37 raeburn 3973: my ($rules,$ruleorder) =
3974: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3975: my %lt = &usercreation_types();
3976: my %checked;
3977: if (ref($settings) eq 'HASH') {
3978: if (ref($settings->{'cancreate'}) eq 'HASH') {
3979: foreach my $item (@creators) {
3980: $checked{$item} = $settings->{'cancreate'}{$item};
3981: }
3982: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3983: foreach my $item (@creators) {
3984: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3985: $checked{$item} = 'none';
3986: }
3987: }
3988: }
3989: }
3990: my $rownum = 0;
3991: foreach my $item (@creators) {
3992: $rownum ++;
1.160.6.34 raeburn 3993: if ($checked{$item} eq '') {
3994: $checked{$item} = 'any';
1.34 raeburn 3995: }
3996: my $css_class;
3997: if ($rownum%2) {
3998: $css_class = '';
3999: } else {
4000: $css_class = ' class="LC_odd_row" ';
4001: }
4002: $datatable .= '<tr'.$css_class.'>'.
4003: '<td><span class="LC_nobreak">'.$lt{$item}.
4004: '</span></td><td align="right">';
1.160.6.34 raeburn 4005: my @options = ('any');
4006: if (ref($rules) eq 'HASH') {
4007: if (keys(%{$rules}) > 0) {
4008: push(@options,('official','unofficial'));
1.37 raeburn 4009: }
4010: }
1.160.6.34 raeburn 4011: push(@options,'none');
1.37 raeburn 4012: foreach my $option (@options) {
1.50 raeburn 4013: my $type = 'radio';
1.34 raeburn 4014: my $check = ' ';
1.160.6.34 raeburn 4015: if ($checked{$item} eq $option) {
4016: $check = ' checked="checked" ';
1.34 raeburn 4017: }
4018: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4019: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4020: $item.'" value="'.$option.'"'.$check.'/> '.
4021: $lt{$option}.'</label> </span>';
4022: }
4023: $datatable .= '</td></tr>';
4024: }
1.28 raeburn 4025: } else {
4026: my @contexts = ('author','course','domain');
4027: my @authtypes = ('int','krb4','krb5','loc');
4028: my %checked;
4029: if (ref($settings) eq 'HASH') {
4030: if (ref($settings->{'authtypes'}) eq 'HASH') {
4031: foreach my $item (@contexts) {
4032: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4033: foreach my $auth (@authtypes) {
4034: if ($settings->{'authtypes'}{$item}{$auth}) {
4035: $checked{$item}{$auth} = ' checked="checked" ';
4036: }
4037: }
4038: }
4039: }
1.27 raeburn 4040: }
1.35 raeburn 4041: } else {
4042: foreach my $item (@contexts) {
1.36 raeburn 4043: foreach my $auth (@authtypes) {
1.35 raeburn 4044: $checked{$item}{$auth} = ' checked="checked" ';
4045: }
4046: }
1.27 raeburn 4047: }
1.28 raeburn 4048: my %title = &context_names();
4049: my %authname = &authtype_names();
4050: my $rownum = 0;
4051: my $css_class;
4052: foreach my $item (@contexts) {
4053: if ($rownum%2) {
4054: $css_class = '';
4055: } else {
4056: $css_class = ' class="LC_odd_row" ';
4057: }
1.30 raeburn 4058: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4059: '<td>'.$title{$item}.
4060: '</td><td class="LC_left_item">'.
4061: '<span class="LC_nobreak">';
4062: foreach my $auth (@authtypes) {
4063: $datatable .= '<label>'.
4064: '<input type="checkbox" name="'.$item.'_auth" '.
4065: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4066: $authname{$auth}.'</label> ';
4067: }
4068: $datatable .= '</span></td></tr>';
4069: $rownum ++;
1.27 raeburn 4070: }
1.30 raeburn 4071: $$rowtotal += $rownum;
1.27 raeburn 4072: }
4073: return $datatable;
4074: }
4075:
1.160.6.34 raeburn 4076: sub print_selfcreation {
4077: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4078: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4079: if (ref($settings) eq 'HASH') {
4080: if (ref($settings->{'cancreate'}) eq 'HASH') {
4081: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4082: if (ref($createsettings) eq 'HASH') {
4083: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4084: @selfcreate = @{$createsettings->{'selfcreate'}};
4085: } elsif ($createsettings->{'selfcreate'} ne '') {
4086: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4087: @selfcreate = ('email','login','sso');
4088: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4089: @selfcreate = ($createsettings->{'selfcreate'});
4090: }
4091: }
4092: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4093: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4094: }
4095: }
4096: }
4097: }
4098: my %radiohash;
4099: my $numinrow = 4;
4100: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4101: if ($position eq 'top') {
4102: my %choices = &Apache::lonlocal::texthash (
4103: cancreate_login => 'Institutional Login',
4104: cancreate_sso => 'Institutional Single Sign On',
4105: );
4106: my @toggles = sort(keys(%choices));
4107: my %defaultchecked = (
4108: 'cancreate_login' => 'off',
4109: 'cancreate_sso' => 'off',
4110: );
1.160.6.35 raeburn 4111: my ($onclick,$itemcount);
1.160.6.34 raeburn 4112: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4113: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4114: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4115:
1.160.6.34 raeburn 4116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4117:
4118: if (ref($usertypes) eq 'HASH') {
4119: if (keys(%{$usertypes}) > 0) {
4120: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4121: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4122: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4123: $$rowtotal ++;
4124: }
4125: }
1.160.6.44 raeburn 4126: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4127: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4128: $fieldtitles{'inststatus'} = &mt('Institutional status');
4129: my $rem;
4130: my $numperrow = 2;
4131: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4132: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4133: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4134: '<td class="LC_left_item">'."\n".
4135: '<table><tr><td>'."\n";
4136: for (my $i=0; $i<@fields; $i++) {
4137: $rem = $i%($numperrow);
4138: if ($rem == 0) {
4139: if ($i > 0) {
4140: $datatable .= '</tr>';
4141: }
4142: $datatable .= '<tr>';
4143: }
4144: my $currval;
4145: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4146: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4147: }
4148: $datatable .= '<td class="LC_left_item">'.
4149: '<span class="LC_nobreak">'.
4150: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4151: 'value="'.$currval.'" size="10" /> '.
4152: $fieldtitles{$fields[$i]}.'</span></td>';
4153: }
4154: my $colsleft = $numperrow - $rem;
4155: if ($colsleft > 1 ) {
4156: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4157: ' </td>';
4158: } elsif ($colsleft == 1) {
4159: $datatable .= '<td class="LC_left_item"> </td>';
4160: }
4161: $datatable .= '</tr></table></td></tr>';
4162: $$rowtotal ++;
1.160.6.34 raeburn 4163: } elsif ($position eq 'middle') {
4164: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4165: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4166: $usertypes->{'default'} = $othertitle;
4167: if (ref($types) eq 'ARRAY') {
4168: push(@{$types},'default');
4169: $usertypes->{'default'} = $othertitle;
4170: foreach my $status (@{$types}) {
4171: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4172: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4173: $$rowtotal ++;
1.160.6.34 raeburn 4174: }
4175: }
4176: } else {
1.160.6.40 raeburn 4177: my %choices = &Apache::lonlocal::texthash (
4178: cancreate_email => 'E-mail address as username',
4179: );
4180: my @toggles = sort(keys(%choices));
4181: my %defaultchecked = (
4182: 'cancreate_email' => 'off',
4183: );
4184: my $itemcount = 0;
4185: my $display = 'none';
4186: if (grep(/^\Qemail\E$/,@selfcreate)) {
4187: $display = 'block';
4188: }
4189: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4190: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4191: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4192: my $usertypes = {};
4193: my $order = [];
4194: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4195: $usertypes = $domdefaults{'inststatustypes'};
4196: $order = $domdefaults{'inststatusguest'};
4197: }
4198: if (ref($order) eq 'ARRAY') {
4199: push(@{$order},'default');
4200: if (@{$order} > 1) {
4201: $usertypes->{'default'} = &mt('Other users');
4202: $additional .= '<table><tr>';
4203: foreach my $status (@{$order}) {
4204: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4205: }
4206: $additional .= '</tr><tr>';
4207: foreach my $status (@{$order}) {
4208: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4209: }
1.160.6.40 raeburn 4210: $additional .= '</tr></table>';
1.160.6.34 raeburn 4211: } else {
1.160.6.40 raeburn 4212: $usertypes->{'default'} = &mt('All users');
4213: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4214: }
4215: }
1.160.6.40 raeburn 4216: $additional .= '</div>'."\n";
4217:
4218: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4219: \%choices,$$rowtotal,$onclick,$additional);
4220: $$rowtotal ++;
1.160.6.40 raeburn 4221: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4222: $$rowtotal ++;
1.160.6.35 raeburn 4223: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4224: $numinrow = 1;
1.160.6.40 raeburn 4225: if (ref($order) eq 'ARRAY') {
4226: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4227: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4228: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4229: $$rowtotal ++;
4230: }
4231: }
1.160.6.34 raeburn 4232: my ($emailrules,$emailruleorder) =
4233: &Apache::lonnet::inst_userrules($dom,'email');
4234: if (ref($emailrules) eq 'HASH') {
4235: if (keys(%{$emailrules}) > 0) {
4236: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4237: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4238: $$rowtotal ++;
4239: }
4240: }
1.160.6.35 raeburn 4241: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4242: }
4243: return $datatable;
4244: }
4245:
1.160.6.40 raeburn 4246: sub email_as_username {
4247: my ($rowtotal,$processing,$type) = @_;
4248: my %choices =
4249: &Apache::lonlocal::texthash (
4250: automatic => 'Automatic approval',
4251: approval => 'Queued for approval',
4252: );
4253: my $output;
4254: foreach my $option ('automatic','approval') {
4255: my $checked;
4256: if (ref($processing) eq 'HASH') {
4257: if ($type eq '') {
4258: if (!exists($processing->{'default'})) {
4259: if ($option eq 'automatic') {
4260: $checked = ' checked="checked"';
4261: }
4262: } else {
4263: if ($processing->{'default'} eq $option) {
4264: $checked = ' checked="checked"';
4265: }
4266: }
4267: } else {
4268: if (!exists($processing->{$type})) {
4269: if ($option eq 'automatic') {
4270: $checked = ' checked="checked"';
4271: }
4272: } else {
4273: if ($processing->{$type} eq $option) {
4274: $checked = ' checked="checked"';
4275: }
4276: }
4277: }
4278: } elsif ($option eq 'automatic') {
4279: $checked = ' checked="checked"';
4280: }
4281: my $name = 'cancreate_emailprocess';
4282: if (($type ne '') && ($type ne 'default')) {
4283: $name .= '_'.$type;
4284: }
4285: $output .= '<span class="LC_nobreak"><label>'.
4286: '<input type="radio" name="'.$name.'"'.
4287: $checked.' value="'.$option.'" />'.
4288: $choices{$option}.'</label></span>';
4289: if ($type eq '') {
4290: $output .= ' ';
4291: } else {
4292: $output .= '<br />';
4293: }
4294: }
4295: $$rowtotal ++;
4296: return $output;
4297: }
4298:
1.160.6.5 raeburn 4299: sub captcha_choice {
4300: my ($context,$settings,$itemcount) = @_;
4301: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4302: my %lt = &captcha_phrases();
4303: $keyentry = 'hidden';
4304: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4305: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4306: } elsif ($context eq 'login') {
4307: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4308: }
4309: if (ref($settings) eq 'HASH') {
4310: if ($settings->{'captcha'}) {
4311: $checked{$settings->{'captcha'}} = ' checked="checked"';
4312: } else {
4313: $checked{'original'} = ' checked="checked"';
4314: }
4315: if ($settings->{'captcha'} eq 'recaptcha') {
4316: $pubtext = $lt{'pub'};
4317: $privtext = $lt{'priv'};
4318: $keyentry = 'text';
4319: }
4320: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4321: $currpub = $settings->{'recaptchakeys'}{'public'};
4322: $currpriv = $settings->{'recaptchakeys'}{'private'};
4323: }
4324: } else {
4325: $checked{'original'} = ' checked="checked"';
4326: }
4327: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4328: my $output = '<tr'.$css_class.'>'.
4329: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4330: '<table><tr><td>'."\n";
4331: foreach my $option ('original','recaptcha','notused') {
4332: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4333: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4334: $lt{$option}.'</label></span>';
4335: unless ($option eq 'notused') {
4336: $output .= (' 'x2)."\n";
4337: }
4338: }
4339: #
4340: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4341: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4342: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4343: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4344: #
4345: $output .= '</td></tr>'."\n".
4346: '<tr><td>'."\n".
4347: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4348: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4349: $currpub.'" size="40" /></span><br />'."\n".
4350: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4351: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4352: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4353: '</td></tr>';
4354: return $output;
4355: }
4356:
1.32 raeburn 4357: sub user_formats_row {
4358: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4359: my $output;
4360: my %text = (
4361: 'username' => 'new usernames',
4362: 'id' => 'IDs',
1.45 raeburn 4363: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4364: );
4365: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4366: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4367: '<td><span class="LC_nobreak">';
4368: if ($type eq 'email') {
4369: $output .= &mt("Formats disallowed for $text{$type}: ");
4370: } else {
4371: $output .= &mt("Format rules to check for $text{$type}: ");
4372: }
4373: $output .= '</span></td>'.
4374: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4375: my $rem;
4376: if (ref($ruleorder) eq 'ARRAY') {
4377: for (my $i=0; $i<@{$ruleorder}; $i++) {
4378: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4379: my $rem = $i%($numinrow);
4380: if ($rem == 0) {
4381: if ($i > 0) {
4382: $output .= '</tr>';
4383: }
4384: $output .= '<tr>';
4385: }
4386: my $check = ' ';
1.39 raeburn 4387: if (ref($settings) eq 'HASH') {
4388: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4389: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4390: $check = ' checked="checked" ';
4391: }
1.27 raeburn 4392: }
4393: }
4394: $output .= '<td class="LC_left_item">'.
4395: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4396: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4397: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4398: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4399: }
4400: }
4401: $rem = @{$ruleorder}%($numinrow);
4402: }
4403: my $colsleft = $numinrow - $rem;
4404: if ($colsleft > 1 ) {
4405: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4406: ' </td>';
4407: } elsif ($colsleft == 1) {
4408: $output .= '<td class="LC_left_item"> </td>';
4409: }
4410: $output .= '</tr></table></td></tr>';
4411: return $output;
4412: }
4413:
1.34 raeburn 4414: sub usercreation_types {
4415: my %lt = &Apache::lonlocal::texthash (
4416: author => 'When adding a co-author',
4417: course => 'When adding a user to a course',
1.100 raeburn 4418: requestcrs => 'When requesting a course',
1.34 raeburn 4419: any => 'Any',
4420: official => 'Institutional only ',
4421: unofficial => 'Non-institutional only',
4422: none => 'None',
4423: );
4424: return %lt;
1.48 raeburn 4425: }
1.34 raeburn 4426:
1.160.6.34 raeburn 4427: sub selfcreation_types {
4428: my %lt = &Apache::lonlocal::texthash (
4429: selfcreate => 'User creates own account',
4430: any => 'Any',
4431: official => 'Institutional only ',
4432: unofficial => 'Non-institutional only',
4433: email => 'E-mail address',
4434: login => 'Institutional Login',
4435: sso => 'SSO',
4436: );
4437: }
4438:
1.28 raeburn 4439: sub authtype_names {
4440: my %lt = &Apache::lonlocal::texthash(
4441: int => 'Internal',
4442: krb4 => 'Kerberos 4',
4443: krb5 => 'Kerberos 5',
4444: loc => 'Local',
4445: );
4446: return %lt;
4447: }
4448:
4449: sub context_names {
4450: my %context_title = &Apache::lonlocal::texthash(
4451: author => 'Creating users when an Author',
4452: course => 'Creating users when in a course',
4453: domain => 'Creating users when a Domain Coordinator',
4454: );
4455: return %context_title;
4456: }
4457:
1.33 raeburn 4458: sub print_usermodification {
4459: my ($position,$dom,$settings,$rowtotal) = @_;
4460: my $numinrow = 4;
4461: my ($context,$datatable,$rowcount);
4462: if ($position eq 'top') {
4463: $rowcount = 0;
4464: $context = 'author';
4465: foreach my $role ('ca','aa') {
4466: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4467: $numinrow,$rowcount);
4468: $$rowtotal ++;
4469: $rowcount ++;
4470: }
1.160.6.37 raeburn 4471: } elsif ($position eq 'bottom') {
1.33 raeburn 4472: $context = 'course';
4473: $rowcount = 0;
4474: foreach my $role ('st','ep','ta','in','cr') {
4475: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4476: $numinrow,$rowcount);
4477: $$rowtotal ++;
4478: $rowcount ++;
4479: }
4480: }
4481: return $datatable;
4482: }
4483:
1.43 raeburn 4484: sub print_defaults {
1.160.6.40 raeburn 4485: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4486: my $rownum = 0;
4487: my ($datatable,$css_class);
1.160.6.40 raeburn 4488: if ($position eq 'top') {
4489: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4490: 'datelocale_def','portal_def');
4491: my %defaults;
4492: if (ref($settings) eq 'HASH') {
4493: %defaults = %{$settings};
1.43 raeburn 4494: } else {
1.160.6.40 raeburn 4495: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4496: foreach my $item (@items) {
4497: $defaults{$item} = $domdefaults{$item};
4498: }
1.43 raeburn 4499: }
1.160.6.40 raeburn 4500: my $titles = &defaults_titles($dom);
4501: foreach my $item (@items) {
4502: if ($rownum%2) {
4503: $css_class = '';
4504: } else {
4505: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4506: }
1.160.6.40 raeburn 4507: $datatable .= '<tr'.$css_class.'>'.
4508: '<td><span class="LC_nobreak">'.$titles->{$item}.
4509: '</span></td><td class="LC_right_item" colspan="3">';
4510: if ($item eq 'auth_def') {
4511: my @authtypes = ('internal','krb4','krb5','localauth');
4512: my %shortauth = (
4513: internal => 'int',
4514: krb4 => 'krb4',
4515: krb5 => 'krb5',
4516: localauth => 'loc'
4517: );
4518: my %authnames = &authtype_names();
4519: foreach my $auth (@authtypes) {
4520: my $checked = ' ';
4521: if ($defaults{$item} eq $auth) {
4522: $checked = ' checked="checked" ';
4523: }
4524: $datatable .= '<label><input type="radio" name="'.$item.
4525: '" value="'.$auth.'"'.$checked.'/>'.
4526: $authnames{$shortauth{$auth}}.'</label> ';
4527: }
4528: } elsif ($item eq 'timezone_def') {
4529: my $includeempty = 1;
4530: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4531: } elsif ($item eq 'datelocale_def') {
4532: my $includeempty = 1;
4533: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4534: } elsif ($item eq 'lang_def') {
4535: my %langchoices = &get_languages_hash();
4536: $langchoices{''} = 'No language preference';
4537: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4538: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4539: \%langchoices);
4540: } else {
4541: my $size;
4542: if ($item eq 'portal_def') {
4543: $size = ' size="25"';
4544: }
4545: $datatable .= '<input type="text" name="'.$item.'" value="'.
4546: $defaults{$item}.'"'.$size.' />';
4547: }
4548: $datatable .= '</td></tr>';
4549: $rownum ++;
4550: }
4551: } else {
4552: my (%defaults);
4553: if (ref($settings) eq 'HASH') {
4554: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4555: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4556: my $maxnum = @{$settings->{'inststatusorder'}};
4557: for (my $i=0; $i<$maxnum; $i++) {
4558: $css_class = $rownum%2?' class="LC_odd_row"':'';
4559: my $item = $settings->{'inststatusorder'}->[$i];
4560: my $title = $settings->{'inststatustypes'}->{$item};
4561: my $guestok;
4562: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4563: $guestok = 1;
4564: }
4565: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4566: $datatable .= '<tr'.$css_class.'>'.
4567: '<td><span class="LC_nobreak">'.
4568: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4569: for (my $k=0; $k<=$maxnum; $k++) {
4570: my $vpos = $k+1;
4571: my $selstr;
4572: if ($k == $i) {
4573: $selstr = ' selected="selected" ';
4574: }
4575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4576: }
4577: my ($checkedon,$checkedoff);
4578: $checkedoff = ' checked="checked"';
4579: if ($guestok) {
4580: $checkedon = $checkedoff;
4581: $checkedoff = '';
4582: }
4583: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4584: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4585: &mt('delete').'</span></td>'.
4586: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4587: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4588: '</span></td>'.
4589: '<td class="LC_right_item"><span class="LC_nobreak">'.
4590: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4591: &mt('Yes').'</label>'.(' 'x2).
4592: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4593: &mt('No').'</label></span></td></tr>';
4594: }
4595: $css_class = $rownum%2?' class="LC_odd_row"':'';
4596: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4597: $datatable .= '<tr '.$css_class.'>'.
4598: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4599: for (my $k=0; $k<=$maxnum; $k++) {
4600: my $vpos = $k+1;
4601: my $selstr;
4602: if ($k == $maxnum) {
4603: $selstr = ' selected="selected" ';
4604: }
4605: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4606: }
4607: $datatable .= '</select> '.&mt('Internal ID:').
4608: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4609: ' '.&mt('(new)').
4610: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4611: &mt('Name displayed:').
4612: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4613: '<td class="LC_right_item"><span class="LC_nobreak">'.
4614: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4615: &mt('Yes').'</label>'.(' 'x2).
4616: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4617: &mt('No').'</label></span></td></tr>';
4618: '</tr>'."\n";
4619: $rownum ++;
1.141 raeburn 4620: }
1.43 raeburn 4621: }
4622: }
4623: $$rowtotal += $rownum;
4624: return $datatable;
4625: }
4626:
1.160.6.5 raeburn 4627: sub get_languages_hash {
4628: my %langchoices;
4629: foreach my $id (&Apache::loncommon::languageids()) {
4630: my $code = &Apache::loncommon::supportedlanguagecode($id);
4631: if ($code ne '') {
4632: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4633: }
4634: }
4635: return %langchoices;
4636: }
4637:
1.43 raeburn 4638: sub defaults_titles {
1.141 raeburn 4639: my ($dom) = @_;
1.43 raeburn 4640: my %titles = &Apache::lonlocal::texthash (
4641: 'auth_def' => 'Default authentication type',
4642: 'auth_arg_def' => 'Default authentication argument',
4643: 'lang_def' => 'Default language',
1.54 raeburn 4644: 'timezone_def' => 'Default timezone',
1.68 raeburn 4645: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4646: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4647: );
1.141 raeburn 4648: if ($dom) {
4649: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4650: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4651: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4652: $protocol = 'http' if ($protocol ne 'https');
4653: if ($uint_dom) {
4654: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4655: $uint_dom);
4656: }
4657: }
1.43 raeburn 4658: return (\%titles);
4659: }
4660:
1.46 raeburn 4661: sub print_scantronformat {
4662: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4663: my $itemcount = 1;
1.60 raeburn 4664: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4665: %confhash);
1.46 raeburn 4666: my $switchserver = &check_switchserver($dom,$confname);
4667: my %lt = &Apache::lonlocal::texthash (
1.95 www 4668: default => 'Default bubblesheet format file error',
4669: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4670: );
4671: my %scantronfiles = (
4672: default => 'default.tab',
4673: custom => 'custom.tab',
4674: );
4675: foreach my $key (keys(%scantronfiles)) {
4676: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4677: .$scantronfiles{$key};
4678: }
4679: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4680: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4681: if (!$switchserver) {
4682: my $servadm = $r->dir_config('lonAdmEMail');
4683: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4684: if ($configuserok eq 'ok') {
4685: if ($author_ok eq 'ok') {
4686: my %legacyfile = (
4687: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4688: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4689: );
4690: my %md5chk;
4691: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4692: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4693: chomp($md5chk{$type});
1.46 raeburn 4694: }
4695: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4696: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4697: ($scantronurls{$type},my $error) =
1.46 raeburn 4698: &legacy_scantronformat($r,$dom,$confname,
4699: $type,$legacyfile{$type},
4700: $scantronurls{$type},
4701: $scantronfiles{$type});
1.60 raeburn 4702: if ($error ne '') {
4703: $error{$type} = $error;
4704: }
4705: }
4706: if (keys(%error) == 0) {
4707: $is_custom = 1;
4708: $confhash{'scantron'}{'scantronformat'} =
4709: $scantronurls{'custom'};
4710: my $putresult =
4711: &Apache::lonnet::put_dom('configuration',
4712: \%confhash,$dom);
4713: if ($putresult ne 'ok') {
4714: $error{'custom'} =
4715: '<span class="LC_error">'.
4716: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4717: }
1.46 raeburn 4718: }
4719: } else {
1.60 raeburn 4720: ($scantronurls{'default'},my $error) =
1.46 raeburn 4721: &legacy_scantronformat($r,$dom,$confname,
4722: 'default',$legacyfile{'default'},
4723: $scantronurls{'default'},
4724: $scantronfiles{'default'});
1.60 raeburn 4725: if ($error eq '') {
4726: $confhash{'scantron'}{'scantronformat'} = '';
4727: my $putresult =
4728: &Apache::lonnet::put_dom('configuration',
4729: \%confhash,$dom);
4730: if ($putresult ne 'ok') {
4731: $error{'default'} =
4732: '<span class="LC_error">'.
4733: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4734: }
4735: } else {
4736: $error{'default'} = $error;
4737: }
1.46 raeburn 4738: }
4739: }
4740: }
4741: } else {
1.95 www 4742: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4743: }
4744: }
4745: if (ref($settings) eq 'HASH') {
4746: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4747: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4748: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4749: $scantronurl = '';
4750: } else {
4751: $scantronurl = $settings->{'scantronformat'};
4752: }
4753: $is_custom = 1;
4754: } else {
4755: $scantronurl = $scantronurls{'default'};
4756: }
4757: } else {
1.60 raeburn 4758: if ($is_custom) {
4759: $scantronurl = $scantronurls{'custom'};
4760: } else {
4761: $scantronurl = $scantronurls{'default'};
4762: }
1.46 raeburn 4763: }
4764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4765: $datatable .= '<tr'.$css_class.'>';
4766: if (!$is_custom) {
1.65 raeburn 4767: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4768: '<span class="LC_nobreak">';
1.46 raeburn 4769: if ($scantronurl) {
1.160.6.21 raeburn 4770: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4771: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4772: } else {
4773: $datatable = &mt('File unavailable for display');
4774: }
1.65 raeburn 4775: $datatable .= '</span></td>';
1.60 raeburn 4776: if (keys(%error) == 0) {
4777: $datatable .= '<td valign="bottom">';
4778: if (!$switchserver) {
4779: $datatable .= &mt('Upload:').'<br />';
4780: }
4781: } else {
4782: my $errorstr;
4783: foreach my $key (sort(keys(%error))) {
4784: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4785: }
4786: $datatable .= '<td>'.$errorstr;
4787: }
1.46 raeburn 4788: } else {
4789: if (keys(%error) > 0) {
4790: my $errorstr;
4791: foreach my $key (sort(keys(%error))) {
4792: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4793: }
1.60 raeburn 4794: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4795: } elsif ($scantronurl) {
1.160.6.26 raeburn 4796: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4797: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4798: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4799: $link.
4800: '<label><input type="checkbox" name="scantronformat_del"'.
4801: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4802: '<td><span class="LC_nobreak"> '.
4803: &mt('Replace:').'</span><br />';
1.46 raeburn 4804: }
4805: }
4806: if (keys(%error) == 0) {
4807: if ($switchserver) {
4808: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4809: } else {
1.65 raeburn 4810: $datatable .='<span class="LC_nobreak"> '.
4811: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4812: }
4813: }
4814: $datatable .= '</td></tr>';
4815: $$rowtotal ++;
4816: return $datatable;
4817: }
4818:
4819: sub legacy_scantronformat {
4820: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4821: my ($url,$error);
4822: my @statinfo = &Apache::lonnet::stat_file($newurl);
4823: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4824: (my $result,$url) =
4825: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4826: '','',$newfile);
4827: if ($result ne 'ok') {
1.130 raeburn 4828: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4829: }
4830: }
4831: return ($url,$error);
4832: }
1.43 raeburn 4833:
1.49 raeburn 4834: sub print_coursecategories {
1.57 raeburn 4835: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4836: my $datatable;
4837: if ($position eq 'top') {
1.160.6.42 raeburn 4838: my (%checked);
4839: my @catitems = ('unauth','auth');
4840: my @cattypes = ('std','domonly','codesrch','none');
4841: $checked{'unauth'} = 'std';
4842: $checked{'auth'} = 'std';
4843: if (ref($settings) eq 'HASH') {
4844: foreach my $type (@cattypes) {
4845: if ($type eq $settings->{'unauth'}) {
4846: $checked{'unauth'} = $type;
4847: }
4848: if ($type eq $settings->{'auth'}) {
4849: $checked{'auth'} = $type;
4850: }
4851: }
4852: }
4853: my %lt = &Apache::lonlocal::texthash (
4854: unauth => 'Catalog type for unauthenticated users',
4855: auth => 'Catalog type for authenticated users',
4856: none => 'No catalog',
4857: std => 'Standard catalog',
4858: domonly => 'Domain-only catalog',
4859: codesrch => "Code search form",
4860: );
4861: my $itemcount = 0;
4862: foreach my $item (@catitems) {
4863: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4864: $datatable .= '<tr '.$css_class.'>'.
4865: '<td>'.$lt{$item}.'</td>'.
4866: '<td class="LC_right_item"><span class="LC_nobreak">';
4867: foreach my $type (@cattypes) {
4868: my $ischecked;
4869: if ($checked{$item} eq $type) {
4870: $ischecked=' checked="checked"';
4871: }
4872: $datatable .= '<label>'.
4873: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4874: ' />'.$lt{$type}.'</label> ';
4875: }
4876: $datatable .= '</td></tr>';
4877: $itemcount ++;
4878: }
4879: $$rowtotal += $itemcount;
4880: } elsif ($position eq 'middle') {
1.57 raeburn 4881: my $toggle_cats_crs = ' ';
4882: my $toggle_cats_dom = ' checked="checked" ';
4883: my $can_cat_crs = ' ';
4884: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4885: my $toggle_catscomm_comm = ' ';
4886: my $toggle_catscomm_dom = ' checked="checked" ';
4887: my $can_catcomm_comm = ' ';
4888: my $can_catcomm_dom = ' checked="checked" ';
4889:
1.57 raeburn 4890: if (ref($settings) eq 'HASH') {
4891: if ($settings->{'togglecats'} eq 'crs') {
4892: $toggle_cats_crs = $toggle_cats_dom;
4893: $toggle_cats_dom = ' ';
4894: }
4895: if ($settings->{'categorize'} eq 'crs') {
4896: $can_cat_crs = $can_cat_dom;
4897: $can_cat_dom = ' ';
4898: }
1.120 raeburn 4899: if ($settings->{'togglecatscomm'} eq 'comm') {
4900: $toggle_catscomm_comm = $toggle_catscomm_dom;
4901: $toggle_catscomm_dom = ' ';
4902: }
4903: if ($settings->{'categorizecomm'} eq 'comm') {
4904: $can_catcomm_comm = $can_catcomm_dom;
4905: $can_catcomm_dom = ' ';
4906: }
1.57 raeburn 4907: }
4908: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4909: togglecats => 'Show/Hide a course in catalog',
4910: togglecatscomm => 'Show/Hide a community in catalog',
4911: categorize => 'Assign a category to a course',
4912: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4913: );
4914: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4915: dom => 'Set in Domain',
4916: crs => 'Set in Course',
4917: comm => 'Set in Community',
1.57 raeburn 4918: );
4919: $datatable = '<tr class="LC_odd_row">'.
4920: '<td>'.$title{'togglecats'}.'</td>'.
4921: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4922: '<input type="radio" name="togglecats"'.
4923: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4924: '<label><input type="radio" name="togglecats"'.
4925: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4926: '</tr><tr>'.
4927: '<td>'.$title{'categorize'}.'</td>'.
4928: '<td class="LC_right_item"><span class="LC_nobreak">'.
4929: '<label><input type="radio" name="categorize"'.
4930: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4931: '<label><input type="radio" name="categorize"'.
4932: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4933: '</tr><tr class="LC_odd_row">'.
4934: '<td>'.$title{'togglecatscomm'}.'</td>'.
4935: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4936: '<input type="radio" name="togglecatscomm"'.
4937: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4938: '<label><input type="radio" name="togglecatscomm"'.
4939: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4940: '</tr><tr>'.
4941: '<td>'.$title{'categorizecomm'}.'</td>'.
4942: '<td class="LC_right_item"><span class="LC_nobreak">'.
4943: '<label><input type="radio" name="categorizecomm"'.
4944: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4945: '<label><input type="radio" name="categorizecomm"'.
4946: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4947: '</tr>';
1.120 raeburn 4948: $$rowtotal += 4;
1.57 raeburn 4949: } else {
4950: my $css_class;
4951: my $itemcount = 1;
4952: my $cathash;
4953: if (ref($settings) eq 'HASH') {
4954: $cathash = $settings->{'cats'};
4955: }
4956: if (ref($cathash) eq 'HASH') {
4957: my (@cats,@trails,%allitems,%idx,@jsarray);
4958: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4959: \%allitems,\%idx,\@jsarray);
4960: my $maxdepth = scalar(@cats);
4961: my $colattrib = '';
4962: if ($maxdepth > 2) {
4963: $colattrib = ' colspan="2" ';
4964: }
4965: my @path;
4966: if (@cats > 0) {
4967: if (ref($cats[0]) eq 'ARRAY') {
4968: my $numtop = @{$cats[0]};
4969: my $maxnum = $numtop;
1.120 raeburn 4970: my %default_names = (
4971: instcode => &mt('Official courses'),
4972: communities => &mt('Communities'),
4973: );
4974:
4975: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4976: ($cathash->{'instcode::0'} eq '') ||
4977: (!grep(/^communities$/,@{$cats[0]})) ||
4978: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4979: $maxnum ++;
4980: }
4981: my $lastidx;
4982: for (my $i=0; $i<$numtop; $i++) {
4983: my $parent = $cats[0][$i];
4984: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4985: my $item = &escape($parent).'::0';
4986: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4987: $lastidx = $idx{$item};
4988: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4989: .'<select name="'.$item.'"'.$chgstr.'>';
4990: for (my $k=0; $k<=$maxnum; $k++) {
4991: my $vpos = $k+1;
4992: my $selstr;
4993: if ($k == $i) {
4994: $selstr = ' selected="selected" ';
4995: }
4996: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4997: }
1.160.6.29 raeburn 4998: $datatable .= '</select></span></td><td>';
1.120 raeburn 4999: if ($parent eq 'instcode' || $parent eq 'communities') {
5000: $datatable .= '<span class="LC_nobreak">'
5001: .$default_names{$parent}.'</span>';
5002: if ($parent eq 'instcode') {
5003: $datatable .= '<br /><span class="LC_nobreak">('
5004: .&mt('with institutional codes')
5005: .')</span></td><td'.$colattrib.'>';
5006: } else {
5007: $datatable .= '<table><tr><td>';
5008: }
5009: $datatable .= '<span class="LC_nobreak">'
5010: .'<label><input type="radio" name="'
5011: .$parent.'" value="1" checked="checked" />'
5012: .&mt('Display').'</label>';
5013: if ($parent eq 'instcode') {
5014: $datatable .= ' ';
5015: } else {
5016: $datatable .= '</span></td></tr><tr><td>'
5017: .'<span class="LC_nobreak">';
5018: }
5019: $datatable .= '<label><input type="radio" name="'
5020: .$parent.'" value="0" />'
5021: .&mt('Do not display').'</label></span>';
5022: if ($parent eq 'communities') {
5023: $datatable .= '</td></tr></table>';
5024: }
5025: $datatable .= '</td>';
1.57 raeburn 5026: } else {
5027: $datatable .= $parent
1.160.6.29 raeburn 5028: .' <span class="LC_nobreak"><label>'
5029: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5030: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5031: }
5032: my $depth = 1;
5033: push(@path,$parent);
5034: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5035: pop(@path);
5036: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5037: $itemcount ++;
5038: }
1.48 raeburn 5039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5040: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5041: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5042: for (my $k=0; $k<=$maxnum; $k++) {
5043: my $vpos = $k+1;
5044: my $selstr;
1.57 raeburn 5045: if ($k == $numtop) {
1.48 raeburn 5046: $selstr = ' selected="selected" ';
5047: }
5048: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5049: }
1.59 bisitz 5050: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5051: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5052: .'</tr>'."\n";
1.48 raeburn 5053: $itemcount ++;
1.120 raeburn 5054: foreach my $default ('instcode','communities') {
5055: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5056: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5057: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5058: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5059: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5060: for (my $k=0; $k<=$maxnum; $k++) {
5061: my $vpos = $k+1;
5062: my $selstr;
5063: if ($k == $maxnum) {
5064: $selstr = ' selected="selected" ';
5065: }
5066: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5067: }
1.120 raeburn 5068: $datatable .= '</select></span></td>'.
5069: '<td><span class="LC_nobreak">'.
5070: $default_names{$default}.'</span>';
5071: if ($default eq 'instcode') {
5072: $datatable .= '<br /><span class="LC_nobreak">('
5073: .&mt('with institutional codes').')</span>';
5074: }
5075: $datatable .= '</td>'
5076: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5077: .&mt('Display').'</label> '
5078: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5079: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5080: }
5081: }
5082: }
1.57 raeburn 5083: } else {
5084: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5085: }
5086: } else {
1.160.6.42 raeburn 5087: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5088: .&initialize_categories($itemcount);
1.48 raeburn 5089: }
1.57 raeburn 5090: $$rowtotal += $itemcount;
1.48 raeburn 5091: }
5092: return $datatable;
5093: }
5094:
1.69 raeburn 5095: sub print_serverstatuses {
5096: my ($dom,$settings,$rowtotal) = @_;
5097: my $datatable;
5098: my @pages = &serverstatus_pages();
5099: my (%namedaccess,%machineaccess);
5100: foreach my $type (@pages) {
5101: $namedaccess{$type} = '';
5102: $machineaccess{$type}= '';
5103: }
5104: if (ref($settings) eq 'HASH') {
5105: foreach my $type (@pages) {
5106: if (exists($settings->{$type})) {
5107: if (ref($settings->{$type}) eq 'HASH') {
5108: foreach my $key (keys(%{$settings->{$type}})) {
5109: if ($key eq 'namedusers') {
5110: $namedaccess{$type} = $settings->{$type}->{$key};
5111: } elsif ($key eq 'machines') {
5112: $machineaccess{$type} = $settings->{$type}->{$key};
5113: }
5114: }
5115: }
5116: }
5117: }
5118: }
1.81 raeburn 5119: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5120: my $rownum = 0;
5121: my $css_class;
5122: foreach my $type (@pages) {
5123: $rownum ++;
5124: $css_class = $rownum%2?' class="LC_odd_row"':'';
5125: $datatable .= '<tr'.$css_class.'>'.
5126: '<td><span class="LC_nobreak">'.
5127: $titles->{$type}.'</span></td>'.
5128: '<td class="LC_left_item">'.
5129: '<input type="text" name="'.$type.'_namedusers" '.
5130: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5131: '<td class="LC_right_item">'.
5132: '<span class="LC_nobreak">'.
5133: '<input type="text" name="'.$type.'_machines" '.
5134: 'value="'.$machineaccess{$type}.'" size="10" />'.
5135: '</td></tr>'."\n";
5136: }
5137: $$rowtotal += $rownum;
5138: return $datatable;
5139: }
5140:
5141: sub serverstatus_pages {
5142: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5143: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5144: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5145: 'uniquecodes','diskusage');
1.69 raeburn 5146: }
5147:
1.160.6.40 raeburn 5148: sub defaults_javascript {
5149: my ($settings) = @_;
5150: my ($output,$jstext);
5151: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5152: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5153: if ($maxnum eq '') {
5154: $maxnum = 0;
5155: }
5156: $maxnum ++;
5157: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5158: return <<"ENDSCRIPT";
5159: <script type="text/javascript">
5160: // <![CDATA[
5161: function reorderTypes(form,caller) {
5162: var changedVal;
5163: $jstext
5164: var newpos = 'addinststatus_pos';
5165: var current = new Array;
5166: var maxh = $maxnum;
5167: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5168: var oldVal;
5169: if (caller == newpos) {
5170: changedVal = newitemVal;
5171: } else {
5172: var curritem = 'inststatus_pos_'+caller;
5173: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5174: current[newitemVal] = newpos;
5175: }
5176: for (var i=0; i<inststatuses.length; i++) {
5177: if (inststatuses[i] != caller) {
5178: var elementName = 'inststatus_pos_'+inststatuses[i];
5179: if (form.elements[elementName]) {
5180: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5181: current[currVal] = elementName;
5182: }
5183: }
5184: }
5185: for (var j=0; j<maxh; j++) {
5186: if (current[j] == undefined) {
5187: oldVal = j;
5188: }
5189: }
5190: if (oldVal < changedVal) {
5191: for (var k=oldVal+1; k<=changedVal ; k++) {
5192: var elementName = current[k];
5193: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5194: }
5195: } else {
5196: for (var k=changedVal; k<oldVal; k++) {
5197: var elementName = current[k];
5198: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5199: }
5200: }
5201: return;
5202: }
5203:
5204: // ]]>
5205: </script>
5206:
5207: ENDSCRIPT
5208: }
5209: }
5210:
1.49 raeburn 5211: sub coursecategories_javascript {
5212: my ($settings) = @_;
1.57 raeburn 5213: my ($output,$jstext,$cathash);
1.49 raeburn 5214: if (ref($settings) eq 'HASH') {
1.57 raeburn 5215: $cathash = $settings->{'cats'};
5216: }
5217: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5218: my (@cats,@jsarray,%idx);
1.57 raeburn 5219: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5220: if (@jsarray > 0) {
5221: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5222: for (my $i=0; $i<@jsarray; $i++) {
5223: if (ref($jsarray[$i]) eq 'ARRAY') {
5224: my $catstr = join('","',@{$jsarray[$i]});
5225: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5226: }
5227: }
5228: }
5229: } else {
5230: $jstext = ' var categories = Array(1);'."\n".
5231: ' categories[0] = Array("instcode_pos");'."\n";
5232: }
1.160.6.42 raeburn 5233: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5234: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5235: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5236: $output = <<"ENDSCRIPT";
5237: <script type="text/javascript">
1.109 raeburn 5238: // <![CDATA[
1.49 raeburn 5239: function reorderCats(form,parent,item,idx) {
5240: var changedVal;
5241: $jstext
5242: var newpos = 'addcategory_pos';
5243: if (parent == '') {
5244: var has_instcode = 0;
5245: var maxtop = categories[idx].length;
5246: for (var j=0; j<maxtop; j++) {
5247: if (categories[idx][j] == 'instcode::0') {
5248: has_instcode == 1;
5249: }
5250: }
5251: if (has_instcode == 0) {
5252: categories[idx][maxtop] = 'instcode_pos';
5253: }
5254: } else {
5255: newpos += '_'+parent;
5256: }
5257: var maxh = 1 + categories[idx].length;
5258: var current = new Array;
5259: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5260: if (item == newpos) {
5261: changedVal = newitemVal;
5262: } else {
5263: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5264: current[newitemVal] = newpos;
5265: }
5266: for (var i=0; i<categories[idx].length; i++) {
5267: var elementName = categories[idx][i];
5268: if (elementName != item) {
5269: if (form.elements[elementName]) {
5270: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5271: current[currVal] = elementName;
5272: }
5273: }
5274: }
5275: var oldVal;
5276: for (var j=0; j<maxh; j++) {
5277: if (current[j] == undefined) {
5278: oldVal = j;
5279: }
5280: }
5281: if (oldVal < changedVal) {
5282: for (var k=oldVal+1; k<=changedVal ; k++) {
5283: var elementName = current[k];
5284: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5285: }
5286: } else {
5287: for (var k=changedVal; k<oldVal; k++) {
5288: var elementName = current[k];
5289: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5290: }
5291: }
5292: return;
5293: }
1.120 raeburn 5294:
5295: function categoryCheck(form) {
5296: if (form.elements['addcategory_name'].value == 'instcode') {
5297: alert('$instcode_reserved\\n$choose_again');
5298: return false;
5299: }
5300: if (form.elements['addcategory_name'].value == 'communities') {
5301: alert('$communities_reserved\\n$choose_again');
5302: return false;
5303: }
5304: return true;
5305: }
5306:
1.109 raeburn 5307: // ]]>
1.49 raeburn 5308: </script>
5309:
5310: ENDSCRIPT
5311: return $output;
5312: }
5313:
1.48 raeburn 5314: sub initialize_categories {
5315: my ($itemcount) = @_;
1.120 raeburn 5316: my ($datatable,$css_class,$chgstr);
5317: my %default_names = (
5318: instcode => 'Official courses (with institutional codes)',
5319: communities => 'Communities',
5320: );
5321: my $select0 = ' selected="selected"';
5322: my $select1 = '';
5323: foreach my $default ('instcode','communities') {
5324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5325: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5326: if ($default eq 'communities') {
5327: $select1 = $select0;
5328: $select0 = '';
5329: }
5330: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5331: .'<select name="'.$default.'_pos">'
5332: .'<option value="0"'.$select0.'>1</option>'
5333: .'<option value="1"'.$select1.'>2</option>'
5334: .'<option value="2">3</option></select> '
5335: .$default_names{$default}
5336: .'</span></td><td><span class="LC_nobreak">'
5337: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5338: .&mt('Display').'</label> <label>'
5339: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5340: .'</label></span></td></tr>';
1.120 raeburn 5341: $itemcount ++;
5342: }
1.48 raeburn 5343: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5344: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5345: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5346: .'<select name="addcategory_pos"'.$chgstr.'>'
5347: .'<option value="0">1</option>'
5348: .'<option value="1">2</option>'
5349: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5350: .&mt('Add category').'</td><td>'.&mt('Name:')
5351: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5352: return $datatable;
5353: }
5354:
5355: sub build_category_rows {
1.49 raeburn 5356: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5357: my ($text,$name,$item,$chgstr);
1.48 raeburn 5358: if (ref($cats) eq 'ARRAY') {
5359: my $maxdepth = scalar(@{$cats});
5360: if (ref($cats->[$depth]) eq 'HASH') {
5361: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5362: my $numchildren = @{$cats->[$depth]{$parent}};
5363: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5364: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5365: my ($idxnum,$parent_name,$parent_item);
5366: my $higher = $depth - 1;
5367: if ($higher == 0) {
5368: $parent_name = &escape($parent).'::'.$higher;
5369: } else {
5370: if (ref($path) eq 'ARRAY') {
5371: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5372: }
5373: }
5374: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5375: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5376: if ($j < $numchildren) {
1.48 raeburn 5377: $name = $cats->[$depth]{$parent}[$j];
5378: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5379: $idxnum = $idx->{$item};
5380: } else {
5381: $name = $parent_name;
5382: $item = $parent_item;
1.48 raeburn 5383: }
1.49 raeburn 5384: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5385: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5386: for (my $i=0; $i<=$numchildren; $i++) {
5387: my $vpos = $i+1;
5388: my $selstr;
5389: if ($j == $i) {
5390: $selstr = ' selected="selected" ';
5391: }
5392: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5393: }
5394: $text .= '</select> ';
5395: if ($j < $numchildren) {
5396: my $deeper = $depth+1;
5397: $text .= $name.' '
5398: .'<label><input type="checkbox" name="deletecategory" value="'
5399: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5400: if(ref($path) eq 'ARRAY') {
5401: push(@{$path},$name);
1.49 raeburn 5402: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5403: pop(@{$path});
5404: }
5405: } else {
1.59 bisitz 5406: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5407: if ($j == $numchildren) {
5408: $text .= $name;
5409: } else {
5410: $text .= $item;
5411: }
5412: $text .= '" value="" />';
5413: }
5414: $text .= '</td></tr>';
5415: }
5416: $text .= '</table></td>';
5417: } else {
5418: my $higher = $depth-1;
5419: if ($higher == 0) {
5420: $name = &escape($parent).'::'.$higher;
5421: } else {
5422: if (ref($path) eq 'ARRAY') {
5423: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5424: }
5425: }
5426: my $colspan;
5427: if ($parent ne 'instcode') {
5428: $colspan = $maxdepth - $depth - 1;
5429: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5430: }
5431: }
5432: }
5433: }
5434: return $text;
5435: }
5436:
1.33 raeburn 5437: sub modifiable_userdata_row {
1.160.6.35 raeburn 5438: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5439: my ($role,$rolename,$statustype);
5440: $role = $item;
1.160.6.34 raeburn 5441: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5442: if ($item =~ /^emailusername_(.+)$/) {
5443: $statustype = $1;
5444: $role = 'emailusername';
5445: if (ref($usertypes) eq 'HASH') {
5446: if ($usertypes->{$statustype}) {
5447: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5448: } else {
5449: $rolename = &mt('Data provided by user');
5450: }
5451: }
1.160.6.34 raeburn 5452: }
5453: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5454: if (ref($usertypes) eq 'HASH') {
5455: $rolename = $usertypes->{$role};
5456: } else {
5457: $rolename = $role;
5458: }
1.33 raeburn 5459: } else {
1.63 raeburn 5460: if ($role eq 'cr') {
5461: $rolename = &mt('Custom role');
5462: } else {
5463: $rolename = &Apache::lonnet::plaintext($role);
5464: }
1.33 raeburn 5465: }
1.160.6.34 raeburn 5466: my (@fields,%fieldtitles);
5467: if (ref($fieldsref) eq 'ARRAY') {
5468: @fields = @{$fieldsref};
5469: } else {
5470: @fields = ('lastname','firstname','middlename','generation',
5471: 'permanentemail','id');
5472: }
5473: if ((ref($titlesref) eq 'HASH')) {
5474: %fieldtitles = %{$titlesref};
5475: } else {
5476: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5477: }
1.33 raeburn 5478: my $output;
5479: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5480: $output = '<tr '.$css_class.'>'.
5481: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5482: '<td class="LC_left_item" colspan="2"><table>';
5483: my $rem;
5484: my %checks;
5485: if (ref($settings) eq 'HASH') {
5486: if (ref($settings->{$context}) eq 'HASH') {
5487: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5488: my $hashref = $settings->{$context}->{$role};
5489: if ($role eq 'emailusername') {
5490: if ($statustype) {
5491: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5492: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5493: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5494: foreach my $field (@fields) {
5495: if ($hashref->{$field}) {
5496: $checks{$field} = $hashref->{$field};
5497: }
5498: }
5499: }
5500: }
5501: }
5502: } else {
5503: if (ref($hashref) eq 'HASH') {
5504: foreach my $field (@fields) {
5505: if ($hashref->{$field}) {
5506: $checks{$field} = ' checked="checked" ';
5507: }
5508: }
1.33 raeburn 5509: }
5510: }
5511: }
5512: }
5513: }
1.160.6.39 raeburn 5514:
1.33 raeburn 5515: for (my $i=0; $i<@fields; $i++) {
5516: my $rem = $i%($numinrow);
5517: if ($rem == 0) {
5518: if ($i > 0) {
5519: $output .= '</tr>';
5520: }
5521: $output .= '<tr>';
5522: }
5523: my $check = ' ';
1.160.6.35 raeburn 5524: unless ($role eq 'emailusername') {
5525: if (exists($checks{$fields[$i]})) {
5526: $check = $checks{$fields[$i]}
5527: } else {
5528: if ($role eq 'st') {
5529: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5530: $check = ' checked="checked" ';
1.160.6.35 raeburn 5531: }
1.33 raeburn 5532: }
5533: }
5534: }
5535: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5536: '<span class="LC_nobreak">';
5537: if ($role eq 'emailusername') {
5538: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5539: $checks{$fields[$i]} = 'omit';
5540: }
5541: foreach my $option ('required','optional','omit') {
5542: my $checked='';
5543: if ($checks{$fields[$i]} eq $option) {
5544: $checked='checked="checked" ';
5545: }
5546: $output .= '<label>'.
5547: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5548: &mt($option).'</label>'.(' ' x2);
5549: }
5550: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5551: } else {
5552: $output .= '<label>'.
5553: '<input type="checkbox" name="canmodify_'.$role.'" '.
5554: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5555: '</label>';
5556: }
5557: $output .= '</span></td>';
1.33 raeburn 5558: $rem = @fields%($numinrow);
5559: }
5560: my $colsleft = $numinrow - $rem;
5561: if ($colsleft > 1 ) {
5562: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5563: ' </td>';
5564: } elsif ($colsleft == 1) {
5565: $output .= '<td class="LC_left_item"> </td>';
5566: }
5567: $output .= '</tr></table></td></tr>';
5568: return $output;
5569: }
1.28 raeburn 5570:
1.93 raeburn 5571: sub insttypes_row {
1.160.6.34 raeburn 5572: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5573: my %lt = &Apache::lonlocal::texthash (
5574: cansearch => 'Users allowed to search',
5575: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5576: lockablenames => 'User preference to lock name',
1.93 raeburn 5577: );
5578: my $showdom;
5579: if ($context eq 'cansearch') {
5580: $showdom = ' ('.$dom.')';
5581: }
1.160.6.5 raeburn 5582: my $class = 'LC_left_item';
5583: if ($context eq 'statustocreate') {
5584: $class = 'LC_right_item';
5585: }
1.160.6.34 raeburn 5586: my $css_class = ' class="LC_odd_row"';
5587: if ($rownum ne '') {
5588: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5589: }
5590: my $output = '<tr'.$css_class.'>'.
5591: '<td>'.$lt{$context}.$showdom.
5592: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5593: my $rem;
5594: if (ref($types) eq 'ARRAY') {
5595: for (my $i=0; $i<@{$types}; $i++) {
5596: if (defined($usertypes->{$types->[$i]})) {
5597: my $rem = $i%($numinrow);
5598: if ($rem == 0) {
5599: if ($i > 0) {
5600: $output .= '</tr>';
5601: }
5602: $output .= '<tr>';
1.23 raeburn 5603: }
1.26 raeburn 5604: my $check = ' ';
1.99 raeburn 5605: if (ref($settings) eq 'HASH') {
5606: if (ref($settings->{$context}) eq 'ARRAY') {
5607: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5608: $check = ' checked="checked" ';
5609: }
5610: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5611: $check = ' checked="checked" ';
5612: }
1.23 raeburn 5613: }
1.26 raeburn 5614: $output .= '<td class="LC_left_item">'.
5615: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5616: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5617: 'value="'.$types->[$i].'"'.$check.'/>'.
5618: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5619: }
5620: }
1.26 raeburn 5621: $rem = @{$types}%($numinrow);
1.23 raeburn 5622: }
5623: my $colsleft = $numinrow - $rem;
1.131 raeburn 5624: if (($rem == 0) && (@{$types} > 0)) {
5625: $output .= '<tr>';
5626: }
1.23 raeburn 5627: if ($colsleft > 1) {
1.25 raeburn 5628: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5629: } else {
1.25 raeburn 5630: $output .= '<td class="LC_left_item">';
1.23 raeburn 5631: }
5632: my $defcheck = ' ';
1.99 raeburn 5633: if (ref($settings) eq 'HASH') {
5634: if (ref($settings->{$context}) eq 'ARRAY') {
5635: if (grep(/^default$/,@{$settings->{$context}})) {
5636: $defcheck = ' checked="checked" ';
5637: }
5638: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5639: $defcheck = ' checked="checked" ';
5640: }
1.23 raeburn 5641: }
1.25 raeburn 5642: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5643: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5644: 'value="default"'.$defcheck.'/>'.
5645: $othertitle.'</label></span></td>'.
5646: '</tr></table></td></tr>';
5647: return $output;
1.23 raeburn 5648: }
5649:
5650: sub sorted_searchtitles {
5651: my %searchtitles = &Apache::lonlocal::texthash(
5652: 'uname' => 'username',
5653: 'lastname' => 'last name',
5654: 'lastfirst' => 'last name, first name',
5655: );
5656: my @titleorder = ('uname','lastname','lastfirst');
5657: return (\%searchtitles,\@titleorder);
5658: }
5659:
1.25 raeburn 5660: sub sorted_searchtypes {
5661: my %srchtypes_desc = (
5662: exact => 'is exact match',
5663: contains => 'contains ..',
5664: begins => 'begins with ..',
5665: );
5666: my @srchtypeorder = ('exact','begins','contains');
5667: return (\%srchtypes_desc,\@srchtypeorder);
5668: }
5669:
1.3 raeburn 5670: sub usertype_update_row {
5671: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5672: my $datatable;
5673: my $numinrow = 4;
5674: foreach my $type (@{$types}) {
5675: if (defined($usertypes->{$type})) {
5676: $$rownums ++;
5677: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5678: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5679: '</td><td class="LC_left_item"><table>';
5680: for (my $i=0; $i<@{$fields}; $i++) {
5681: my $rem = $i%($numinrow);
5682: if ($rem == 0) {
5683: if ($i > 0) {
5684: $datatable .= '</tr>';
5685: }
5686: $datatable .= '<tr>';
5687: }
5688: my $check = ' ';
1.39 raeburn 5689: if (ref($settings) eq 'HASH') {
5690: if (ref($settings->{'fields'}) eq 'HASH') {
5691: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5692: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5693: $check = ' checked="checked" ';
5694: }
1.3 raeburn 5695: }
5696: }
5697: }
5698:
5699: if ($i == @{$fields}-1) {
5700: my $colsleft = $numinrow - $rem;
5701: if ($colsleft > 1) {
5702: $datatable .= '<td colspan="'.$colsleft.'">';
5703: } else {
5704: $datatable .= '<td>';
5705: }
5706: } else {
5707: $datatable .= '<td>';
5708: }
1.8 raeburn 5709: $datatable .= '<span class="LC_nobreak"><label>'.
5710: '<input type="checkbox" name="updateable_'.$type.
5711: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5712: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5713: }
5714: $datatable .= '</tr></table></td></tr>';
5715: }
5716: }
5717: return $datatable;
1.1 raeburn 5718: }
5719:
5720: sub modify_login {
1.160.6.24 raeburn 5721: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5722: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5723: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5724: %title = ( coursecatalog => 'Display course catalog',
5725: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5726: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5727: newuser => 'Link for visitors to create a user account',
5728: loginheader => 'Log-in box header');
5729: @offon = ('off','on');
1.112 raeburn 5730: if (ref($domconfig{login}) eq 'HASH') {
5731: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5732: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5733: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5734: }
5735: }
5736: }
1.9 raeburn 5737: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5738: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5739: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5740: foreach my $item (@toggles) {
5741: $loginhash{login}{$item} = $env{'form.'.$item};
5742: }
1.41 raeburn 5743: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5744: if (ref($colchanges{'login'}) eq 'HASH') {
5745: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5746: \%loginhash);
5747: }
1.110 raeburn 5748:
1.149 raeburn 5749: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5750: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5751: if (keys(%servers) > 1) {
5752: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5753: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5754: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5755: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5757: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5758: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5759: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5760: $changes{'loginvia'}{$lonhost} = 1;
5761: } else {
5762: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5763: $changes{'loginvia'}{$lonhost} = 1;
5764: }
5765: } else {
5766: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5767: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5768: $changes{'loginvia'}{$lonhost} = 1;
5769: }
5770: }
5771: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5772: foreach my $item (@loginvia_attribs) {
5773: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5774: }
5775: } else {
5776: foreach my $item (@loginvia_attribs) {
5777: my $new = $env{'form.'.$lonhost.'_'.$item};
5778: if (($item eq 'serverpath') && ($new eq 'custom')) {
5779: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5780: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5781: $new = '/';
5782: }
5783: }
5784: if (($item eq 'custompath') &&
5785: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5786: $new = '';
5787: }
5788: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5789: $changes{'loginvia'}{$lonhost} = 1;
5790: }
5791: if ($item eq 'exempt') {
5792: $new =~ s/^\s+//;
5793: $new =~ s/\s+$//;
5794: my @poss_ips = split(/\s*[,:]\s*/,$new);
5795: my @okips;
5796: foreach my $ip (@poss_ips) {
5797: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5798: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5799: push(@okips,$ip);
5800: }
5801: }
5802: }
5803: if (@okips > 0) {
5804: $new = join(',',@okips);
5805: } else {
5806: $new = '';
5807: }
5808: }
5809: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5810: }
5811: }
1.112 raeburn 5812: } else {
1.128 raeburn 5813: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5814: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5815: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5816: foreach my $item (@loginvia_attribs) {
5817: my $new = $env{'form.'.$lonhost.'_'.$item};
5818: if (($item eq 'serverpath') && ($new eq 'custom')) {
5819: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5820: $new = '/';
5821: }
5822: }
5823: if (($item eq 'custompath') &&
5824: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5825: $new = '';
5826: }
5827: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5828: }
1.110 raeburn 5829: }
5830: }
5831: }
5832: }
1.119 raeburn 5833:
1.160.6.5 raeburn 5834: my $servadm = $r->dir_config('lonAdmEMail');
5835: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5836: if (ref($domconfig{'login'}) eq 'HASH') {
5837: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5838: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5839: if ($lang eq 'nolang') {
5840: push(@currlangs,$lang);
5841: } elsif (defined($langchoices{$lang})) {
5842: push(@currlangs,$lang);
5843: } else {
5844: next;
5845: }
5846: }
5847: }
5848: }
5849: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5850: if (@currlangs > 0) {
5851: foreach my $lang (@currlangs) {
5852: if (grep(/^\Q$lang\E$/,@delurls)) {
5853: $changes{'helpurl'}{$lang} = 1;
5854: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5855: $changes{'helpurl'}{$lang} = 1;
5856: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5857: push(@newlangs,$lang);
5858: } else {
5859: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5860: }
5861: }
5862: }
5863: unless (grep(/^nolang$/,@currlangs)) {
5864: if ($env{'form.loginhelpurl_nolang.filename'}) {
5865: $changes{'helpurl'}{'nolang'} = 1;
5866: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5867: push(@newlangs,'nolang');
5868: }
5869: }
5870: if ($env{'form.loginhelpurl_add_lang'}) {
5871: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5872: ($env{'form.loginhelpurl_add_file.filename'})) {
5873: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5874: $addedfile = $env{'form.loginhelpurl_add_lang'};
5875: }
5876: }
5877: if ((@newlangs > 0) || ($addedfile)) {
5878: my $error;
5879: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5880: if ($configuserok eq 'ok') {
5881: if ($switchserver) {
5882: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5883: } elsif ($author_ok eq 'ok') {
5884: my @allnew = @newlangs;
5885: if ($addedfile ne '') {
5886: push(@allnew,$addedfile);
5887: }
5888: foreach my $lang (@allnew) {
5889: my $formelem = 'loginhelpurl_'.$lang;
5890: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5891: $formelem = 'loginhelpurl_add_file';
5892: }
5893: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5894: "help/$lang",'','',$newfile{$lang});
5895: if ($result eq 'ok') {
5896: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5897: $changes{'helpurl'}{$lang} = 1;
5898: } else {
5899: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5900: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5901: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5902: (!grep(/^\Q$lang\E$/,@delurls))) {
5903:
5904: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5905: }
5906: }
5907: }
5908: } else {
5909: $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);
5910: }
5911: } else {
5912: $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);
5913: }
5914: if ($error) {
5915: &Apache::lonnet::logthis($error);
5916: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5917: }
5918: }
5919: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5920:
5921: my $defaulthelpfile = '/adm/loginproblems.html';
5922: my $defaulttext = &mt('Default in use');
5923:
1.1 raeburn 5924: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5925: $dom);
5926: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5927: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5928: my %defaultchecked = (
5929: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5930: 'helpdesk' => 'on',
1.42 raeburn 5931: 'adminmail' => 'off',
1.43 raeburn 5932: 'newuser' => 'off',
1.42 raeburn 5933: );
1.55 raeburn 5934: if (ref($domconfig{'login'}) eq 'HASH') {
5935: foreach my $item (@toggles) {
5936: if ($defaultchecked{$item} eq 'on') {
5937: if (($domconfig{'login'}{$item} eq '0') &&
5938: ($env{'form.'.$item} eq '1')) {
5939: $changes{$item} = 1;
5940: } elsif (($domconfig{'login'}{$item} eq '' ||
5941: $domconfig{'login'}{$item} eq '1') &&
5942: ($env{'form.'.$item} eq '0')) {
5943: $changes{$item} = 1;
5944: }
5945: } elsif ($defaultchecked{$item} eq 'off') {
5946: if (($domconfig{'login'}{$item} eq '1') &&
5947: ($env{'form.'.$item} eq '0')) {
5948: $changes{$item} = 1;
5949: } elsif (($domconfig{'login'}{$item} eq '' ||
5950: $domconfig{'login'}{$item} eq '0') &&
5951: ($env{'form.'.$item} eq '1')) {
5952: $changes{$item} = 1;
5953: }
1.42 raeburn 5954: }
5955: }
1.41 raeburn 5956: }
1.6 raeburn 5957: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5958: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5959: if (ref($lastactref) eq 'HASH') {
5960: $lastactref->{'domainconfig'} = 1;
5961: }
1.1 raeburn 5962: $resulttext = &mt('Changes made:').'<ul>';
5963: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5964: if ($item eq 'loginvia') {
1.112 raeburn 5965: if (ref($changes{$item}) eq 'HASH') {
5966: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5967: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5968: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5969: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5970: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5971: $protocol = 'http' if ($protocol ne 'https');
5972: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5973:
5974: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5975: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5976: } else {
5977: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5978: }
5979: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5980: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5981: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5982: }
5983: $resulttext .= '</li>';
5984: } else {
5985: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5986: }
1.112 raeburn 5987: } else {
1.128 raeburn 5988: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5989: }
5990: }
1.128 raeburn 5991: $resulttext .= '</ul></li>';
1.112 raeburn 5992: }
1.160.6.5 raeburn 5993: } elsif ($item eq 'helpurl') {
5994: if (ref($changes{$item}) eq 'HASH') {
5995: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5996: if (grep(/^\Q$lang\E$/,@delurls)) {
5997: my ($chg,$link);
5998: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5999: if ($lang eq 'nolang') {
6000: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6001: } else {
6002: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6003: }
6004: $resulttext .= '<li>'.$chg.'</li>';
6005: } else {
6006: my $chg;
6007: if ($lang eq 'nolang') {
6008: $chg = &mt('custom log-in help file for no preferred language');
6009: } else {
6010: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6011: }
6012: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6013: $loginhash{'login'}{'helpurl'}{$lang}.
6014: '?inhibitmenu=yes',$chg,600,500).
6015: '</li>';
6016: }
6017: }
6018: }
6019: } elsif ($item eq 'captcha') {
6020: if (ref($loginhash{'login'}) eq 'HASH') {
6021: my $chgtxt;
6022: if ($loginhash{'login'}{$item} eq 'notused') {
6023: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6024: } else {
6025: my %captchas = &captcha_phrases();
6026: if ($captchas{$loginhash{'login'}{$item}}) {
6027: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6028: } else {
6029: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6030: }
6031: }
6032: $resulttext .= '<li>'.$chgtxt.'</li>';
6033: }
6034: } elsif ($item eq 'recaptchakeys') {
6035: if (ref($loginhash{'login'}) eq 'HASH') {
6036: my ($privkey,$pubkey);
6037: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6038: $pubkey = $loginhash{'login'}{$item}{'public'};
6039: $privkey = $loginhash{'login'}{$item}{'private'};
6040: }
6041: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6042: if (!$pubkey) {
6043: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6044: } else {
6045: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6046: }
6047: if (!$privkey) {
6048: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6049: } else {
6050: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6051: }
6052: $chgtxt .= '</ul>';
6053: $resulttext .= '<li>'.$chgtxt.'</li>';
6054: }
1.41 raeburn 6055: } else {
6056: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6057: }
1.1 raeburn 6058: }
1.6 raeburn 6059: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6060: } else {
6061: $resulttext = &mt('No changes made to log-in page settings');
6062: }
6063: } else {
1.11 albertel 6064: $resulttext = '<span class="LC_error">'.
6065: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6066: }
1.6 raeburn 6067: if ($errors) {
1.9 raeburn 6068: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6069: $errors.'</ul>';
6070: }
6071: return $resulttext;
6072: }
6073:
6074: sub color_font_choices {
6075: my %choices =
6076: &Apache::lonlocal::texthash (
6077: img => "Header",
6078: bgs => "Background colors",
6079: links => "Link colors",
1.55 raeburn 6080: images => "Images",
1.6 raeburn 6081: font => "Font color",
1.160.6.22 raeburn 6082: fontmenu => "Font menu",
1.76 raeburn 6083: pgbg => "Page",
1.6 raeburn 6084: tabbg => "Header",
6085: sidebg => "Border",
6086: link => "Link",
6087: alink => "Active link",
6088: vlink => "Visited link",
6089: );
6090: return %choices;
6091: }
6092:
6093: sub modify_rolecolors {
1.160.6.24 raeburn 6094: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6095: my ($resulttext,%rolehash);
6096: $rolehash{'rolecolors'} = {};
1.55 raeburn 6097: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6098: if ($domconfig{'rolecolors'} eq '') {
6099: $domconfig{'rolecolors'} = {};
6100: }
6101: }
1.9 raeburn 6102: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6103: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6104: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6105: $dom);
6106: if ($putresult eq 'ok') {
6107: if (keys(%changes) > 0) {
1.41 raeburn 6108: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6109: if (ref($lastactref) eq 'HASH') {
6110: $lastactref->{'domainconfig'} = 1;
6111: }
1.6 raeburn 6112: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6113: $rolehash{'rolecolors'});
6114: } else {
6115: $resulttext = &mt('No changes made to default color schemes');
6116: }
6117: } else {
1.11 albertel 6118: $resulttext = '<span class="LC_error">'.
6119: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6120: }
6121: if ($errors) {
6122: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6123: $errors.'</ul>';
6124: }
6125: return $resulttext;
6126: }
6127:
6128: sub modify_colors {
1.9 raeburn 6129: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6130: my (%changes,%choices);
1.51 raeburn 6131: my @bgs;
1.6 raeburn 6132: my @links = ('link','alink','vlink');
1.41 raeburn 6133: my @logintext;
1.6 raeburn 6134: my @images;
6135: my $servadm = $r->dir_config('lonAdmEMail');
6136: my $errors;
1.160.6.22 raeburn 6137: my %defaults;
1.6 raeburn 6138: foreach my $role (@{$roles}) {
6139: if ($role eq 'login') {
1.12 raeburn 6140: %choices = &login_choices();
1.41 raeburn 6141: @logintext = ('textcol','bgcol');
1.12 raeburn 6142: } else {
6143: %choices = &color_font_choices();
6144: }
6145: if ($role eq 'login') {
1.41 raeburn 6146: @images = ('img','logo','domlogo','login');
1.51 raeburn 6147: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6148: } else {
6149: @images = ('img');
1.160.6.22 raeburn 6150: @bgs = ('pgbg','tabbg','sidebg');
6151: }
6152: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6153: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6154: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6155: }
6156: if ($role eq 'login') {
6157: foreach my $item (@logintext) {
1.160.6.39 raeburn 6158: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6159: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6160: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6161: }
6162: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6163: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6164: }
6165: }
6166: } else {
1.160.6.39 raeburn 6167: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6168: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6169: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6170: }
6171: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6172: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6173: }
1.6 raeburn 6174: }
1.160.6.22 raeburn 6175: foreach my $item (@bgs) {
1.160.6.39 raeburn 6176: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6177: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6178: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6179: }
6180: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6181: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6182: }
6183: }
6184: foreach my $item (@links) {
1.160.6.39 raeburn 6185: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6186: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6187: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6188: }
6189: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6190: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6191: }
1.6 raeburn 6192: }
1.46 raeburn 6193: my ($configuserok,$author_ok,$switchserver) =
6194: &config_check($dom,$confname,$servadm);
1.9 raeburn 6195: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6196: if (ref($domconfig->{$role}) ne 'HASH') {
6197: $domconfig->{$role} = {};
6198: }
1.8 raeburn 6199: foreach my $img (@images) {
1.70 raeburn 6200: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6201: if (defined($env{'form.login_showlogo_'.$img})) {
6202: $confhash->{$role}{'showlogo'}{$img} = 1;
6203: } else {
6204: $confhash->{$role}{'showlogo'}{$img} = 0;
6205: }
6206: }
1.18 albertel 6207: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6208: && !defined($domconfig->{$role}{$img})
6209: && !$env{'form.'.$role.'_del_'.$img}
6210: && $env{'form.'.$role.'_import_'.$img}) {
6211: # import the old configured image from the .tab setting
6212: # if they haven't provided a new one
6213: $domconfig->{$role}{$img} =
6214: $env{'form.'.$role.'_import_'.$img};
6215: }
1.6 raeburn 6216: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6217: my $error;
1.6 raeburn 6218: if ($configuserok eq 'ok') {
1.9 raeburn 6219: if ($switchserver) {
1.12 raeburn 6220: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6221: } else {
6222: if ($author_ok eq 'ok') {
6223: my ($result,$logourl) =
6224: &publishlogo($r,'upload',$role.'_'.$img,
6225: $dom,$confname,$img,$width,$height);
6226: if ($result eq 'ok') {
6227: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6228: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6229: } else {
1.12 raeburn 6230: $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 6231: }
6232: } else {
1.46 raeburn 6233: $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 6234: }
6235: }
6236: } else {
1.46 raeburn 6237: $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 6238: }
6239: if ($error) {
1.8 raeburn 6240: &Apache::lonnet::logthis($error);
1.11 albertel 6241: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6242: }
6243: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6244: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6245: my $error;
6246: if ($configuserok eq 'ok') {
6247: # is confname an author?
6248: if ($switchserver eq '') {
6249: if ($author_ok eq 'ok') {
6250: my ($result,$logourl) =
6251: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6252: $dom,$confname,$img,$width,$height);
6253: if ($result eq 'ok') {
6254: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6255: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6256: }
6257: }
6258: }
6259: }
1.6 raeburn 6260: }
6261: }
6262: }
6263: if (ref($domconfig) eq 'HASH') {
6264: if (ref($domconfig->{$role}) eq 'HASH') {
6265: foreach my $img (@images) {
6266: if ($domconfig->{$role}{$img} ne '') {
6267: if ($env{'form.'.$role.'_del_'.$img}) {
6268: $confhash->{$role}{$img} = '';
1.12 raeburn 6269: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6270: } else {
1.9 raeburn 6271: if ($confhash->{$role}{$img} eq '') {
6272: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6273: }
1.6 raeburn 6274: }
6275: } else {
6276: if ($env{'form.'.$role.'_del_'.$img}) {
6277: $confhash->{$role}{$img} = '';
1.12 raeburn 6278: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6279: }
6280: }
1.70 raeburn 6281: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6282: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6283: if ($confhash->{$role}{'showlogo'}{$img} ne
6284: $domconfig->{$role}{'showlogo'}{$img}) {
6285: $changes{$role}{'showlogo'}{$img} = 1;
6286: }
6287: } else {
6288: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6289: $changes{$role}{'showlogo'}{$img} = 1;
6290: }
6291: }
6292: }
6293: }
1.6 raeburn 6294: if ($domconfig->{$role}{'font'} ne '') {
6295: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6296: $changes{$role}{'font'} = 1;
6297: }
6298: } else {
6299: if ($confhash->{$role}{'font'}) {
6300: $changes{$role}{'font'} = 1;
6301: }
6302: }
1.107 raeburn 6303: if ($role ne 'login') {
6304: if ($domconfig->{$role}{'fontmenu'} ne '') {
6305: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6306: $changes{$role}{'fontmenu'} = 1;
6307: }
6308: } else {
6309: if ($confhash->{$role}{'fontmenu'}) {
6310: $changes{$role}{'fontmenu'} = 1;
6311: }
1.97 tempelho 6312: }
6313: }
1.6 raeburn 6314: foreach my $item (@bgs) {
6315: if ($domconfig->{$role}{$item} ne '') {
6316: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6317: $changes{$role}{'bgs'}{$item} = 1;
6318: }
6319: } else {
6320: if ($confhash->{$role}{$item}) {
6321: $changes{$role}{'bgs'}{$item} = 1;
6322: }
6323: }
6324: }
6325: foreach my $item (@links) {
6326: if ($domconfig->{$role}{$item} ne '') {
6327: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6328: $changes{$role}{'links'}{$item} = 1;
6329: }
6330: } else {
6331: if ($confhash->{$role}{$item}) {
6332: $changes{$role}{'links'}{$item} = 1;
6333: }
6334: }
6335: }
1.41 raeburn 6336: foreach my $item (@logintext) {
6337: if ($domconfig->{$role}{$item} ne '') {
6338: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6339: $changes{$role}{'logintext'}{$item} = 1;
6340: }
6341: } else {
6342: if ($confhash->{$role}{$item}) {
6343: $changes{$role}{'logintext'}{$item} = 1;
6344: }
6345: }
6346: }
1.6 raeburn 6347: } else {
6348: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6349: \@logintext,$confhash,\%changes);
1.6 raeburn 6350: }
6351: } else {
6352: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6353: \@logintext,$confhash,\%changes);
1.6 raeburn 6354: }
6355: }
6356: return ($errors,%changes);
6357: }
6358:
1.46 raeburn 6359: sub config_check {
6360: my ($dom,$confname,$servadm) = @_;
6361: my ($configuserok,$author_ok,$switchserver,%currroles);
6362: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6363: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6364: $confname,$servadm);
6365: if ($configuserok eq 'ok') {
6366: $switchserver = &check_switchserver($dom,$confname);
6367: if ($switchserver eq '') {
6368: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6369: }
6370: }
6371: return ($configuserok,$author_ok,$switchserver);
6372: }
6373:
1.6 raeburn 6374: sub default_change_checker {
1.41 raeburn 6375: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6376: foreach my $item (@{$links}) {
6377: if ($confhash->{$role}{$item}) {
6378: $changes->{$role}{'links'}{$item} = 1;
6379: }
6380: }
6381: foreach my $item (@{$bgs}) {
6382: if ($confhash->{$role}{$item}) {
6383: $changes->{$role}{'bgs'}{$item} = 1;
6384: }
6385: }
1.41 raeburn 6386: foreach my $item (@{$logintext}) {
6387: if ($confhash->{$role}{$item}) {
6388: $changes->{$role}{'logintext'}{$item} = 1;
6389: }
6390: }
1.6 raeburn 6391: foreach my $img (@{$images}) {
6392: if ($env{'form.'.$role.'_del_'.$img}) {
6393: $confhash->{$role}{$img} = '';
1.12 raeburn 6394: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6395: }
1.70 raeburn 6396: if ($role eq 'login') {
6397: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6398: $changes->{$role}{'showlogo'}{$img} = 1;
6399: }
6400: }
1.6 raeburn 6401: }
6402: if ($confhash->{$role}{'font'}) {
6403: $changes->{$role}{'font'} = 1;
6404: }
1.48 raeburn 6405: }
1.6 raeburn 6406:
6407: sub display_colorchgs {
6408: my ($dom,$changes,$roles,$confhash) = @_;
6409: my (%choices,$resulttext);
6410: if (!grep(/^login$/,@{$roles})) {
6411: $resulttext = &mt('Changes made:').'<br />';
6412: }
6413: foreach my $role (@{$roles}) {
6414: if ($role eq 'login') {
6415: %choices = &login_choices();
6416: } else {
6417: %choices = &color_font_choices();
6418: }
6419: if (ref($changes->{$role}) eq 'HASH') {
6420: if ($role ne 'login') {
6421: $resulttext .= '<h4>'.&mt($role).'</h4>';
6422: }
6423: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6424: if ($role ne 'login') {
6425: $resulttext .= '<ul>';
6426: }
6427: if (ref($changes->{$role}{$key}) eq 'HASH') {
6428: if ($role ne 'login') {
6429: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6430: }
6431: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6432: if (($role eq 'login') && ($key eq 'showlogo')) {
6433: if ($confhash->{$role}{$key}{$item}) {
6434: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6435: } else {
6436: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6437: }
6438: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6439: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6440: } else {
1.12 raeburn 6441: my $newitem = $confhash->{$role}{$item};
6442: if ($key eq 'images') {
6443: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6444: }
6445: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6446: }
6447: }
6448: if ($role ne 'login') {
6449: $resulttext .= '</ul></li>';
6450: }
6451: } else {
6452: if ($confhash->{$role}{$key} eq '') {
6453: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6454: } else {
6455: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6456: }
6457: }
6458: if ($role ne 'login') {
6459: $resulttext .= '</ul>';
6460: }
6461: }
6462: }
6463: }
1.3 raeburn 6464: return $resulttext;
1.1 raeburn 6465: }
6466:
1.9 raeburn 6467: sub thumb_dimensions {
6468: return ('200','50');
6469: }
6470:
1.16 raeburn 6471: sub check_dimensions {
6472: my ($inputfile) = @_;
6473: my ($fullwidth,$fullheight);
6474: if ($inputfile =~ m|^[/\w.\-]+$|) {
6475: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6476: my $imageinfo = <PIPE>;
6477: if (!close(PIPE)) {
6478: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6479: }
6480: chomp($imageinfo);
6481: my ($fullsize) =
1.21 raeburn 6482: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6483: if ($fullsize) {
6484: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6485: }
6486: }
6487: }
6488: return ($fullwidth,$fullheight);
6489: }
6490:
1.9 raeburn 6491: sub check_configuser {
6492: my ($uhome,$dom,$confname,$servadm) = @_;
6493: my ($configuserok,%currroles);
6494: if ($uhome eq 'no_host') {
6495: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6496: my $configpass = &LONCAPA::Enrollment::create_password();
6497: $configuserok =
6498: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6499: $configpass,'','','','','',undef,$servadm);
6500: } else {
6501: $configuserok = 'ok';
6502: %currroles =
6503: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6504: }
6505: return ($configuserok,%currroles);
6506: }
6507:
6508: sub check_authorstatus {
6509: my ($dom,$confname,%currroles) = @_;
6510: my $author_ok;
1.40 raeburn 6511: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6512: my $start = time;
6513: my $end = 0;
6514: $author_ok =
6515: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6516: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6517: } else {
6518: $author_ok = 'ok';
6519: }
6520: return $author_ok;
6521: }
6522:
6523: sub publishlogo {
1.46 raeburn 6524: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6525: my ($output,$fname,$logourl);
6526: if ($action eq 'upload') {
6527: $fname=$env{'form.'.$formname.'.filename'};
6528: chop($env{'form.'.$formname});
6529: } else {
6530: ($fname) = ($formname =~ /([^\/]+)$/);
6531: }
1.46 raeburn 6532: if ($savefileas ne '') {
6533: $fname = $savefileas;
6534: }
1.9 raeburn 6535: $fname=&Apache::lonnet::clean_filename($fname);
6536: # See if there is anything left
6537: unless ($fname) { return ('error: no uploaded file'); }
6538: $fname="$subdir/$fname";
1.160.6.5 raeburn 6539: my $docroot=$r->dir_config('lonDocRoot');
6540: my $filepath="$docroot/priv";
6541: my $relpath = "$dom/$confname";
1.9 raeburn 6542: my ($fnamepath,$file,$fetchthumb);
6543: $file=$fname;
6544: if ($fname=~m|/|) {
6545: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6546: }
1.160.6.26 raeburn 6547: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6548: my $count;
1.160.6.5 raeburn 6549: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6550: $filepath.="/$parts[$count]";
6551: if ((-e $filepath)!=1) {
6552: mkdir($filepath,02770);
6553: }
6554: }
6555: # Check for bad extension and disallow upload
6556: if ($file=~/\.(\w+)$/ &&
6557: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6558: $output =
1.160.6.25 raeburn 6559: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6560: } elsif ($file=~/\.(\w+)$/ &&
6561: !defined(&Apache::loncommon::fileembstyle($1))) {
6562: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6563: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6564: $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 6565: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6566: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6567: } else {
6568: my $source = $filepath.'/'.$file;
6569: my $logfile;
6570: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6571: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6572: }
6573: print $logfile
6574: "\n================= Publish ".localtime()." ================\n".
6575: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6576: # Save the file
6577: if (!open(FH,'>'.$source)) {
6578: &Apache::lonnet::logthis('Failed to create '.$source);
6579: return (&mt('Failed to create file'));
6580: }
6581: if ($action eq 'upload') {
6582: if (!print FH ($env{'form.'.$formname})) {
6583: &Apache::lonnet::logthis('Failed to write to '.$source);
6584: return (&mt('Failed to write file'));
6585: }
6586: } else {
6587: my $original = &Apache::lonnet::filelocation('',$formname);
6588: if(!copy($original,$source)) {
6589: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6590: return (&mt('Failed to write file'));
6591: }
6592: }
6593: close(FH);
6594: chmod(0660, $source); # Permissions to rw-rw---.
6595:
6596: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6597: my $copyfile=$targetdir.'/'.$file;
6598:
6599: my @parts=split(/\//,$targetdir);
6600: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6601: for (my $count=5;$count<=$#parts;$count++) {
6602: $path.="/$parts[$count]";
6603: if (!-e $path) {
6604: print $logfile "\nCreating directory ".$path;
6605: mkdir($path,02770);
6606: }
6607: }
6608: my $versionresult;
6609: if (-e $copyfile) {
6610: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6611: } else {
6612: $versionresult = 'ok';
6613: }
6614: if ($versionresult eq 'ok') {
6615: if (copy($source,$copyfile)) {
6616: print $logfile "\nCopied original source to ".$copyfile."\n";
6617: $output = 'ok';
6618: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6619: push(@{$modified_urls},[$copyfile,$source]);
6620: my $metaoutput =
6621: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6622: unless ($registered_cleanup) {
6623: my $handlers = $r->get_handlers('PerlCleanupHandler');
6624: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6625: $registered_cleanup=1;
6626: }
1.9 raeburn 6627: } else {
6628: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6629: $output = &mt('Failed to copy file to RES space').", $!";
6630: }
6631: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6632: my $inputfile = $filepath.'/'.$file;
6633: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6634: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6635: if ($fullwidth ne '' && $fullheight ne '') {
6636: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6637: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6638: system("convert -sample $thumbsize $inputfile $outfile");
6639: chmod(0660, $filepath.'/tn-'.$file);
6640: if (-e $outfile) {
6641: my $copyfile=$targetdir.'/tn-'.$file;
6642: if (copy($outfile,$copyfile)) {
6643: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6644: my $thumb_metaoutput =
6645: &write_metadata($dom,$confname,$formname,
6646: $targetdir,'tn-'.$file,$logfile);
6647: push(@{$modified_urls},[$copyfile,$outfile]);
6648: unless ($registered_cleanup) {
6649: my $handlers = $r->get_handlers('PerlCleanupHandler');
6650: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6651: $registered_cleanup=1;
6652: }
1.16 raeburn 6653: } else {
6654: print $logfile "\nUnable to write ".$copyfile.
6655: ':'.$!."\n";
6656: }
6657: }
1.9 raeburn 6658: }
6659: }
6660: }
6661: } else {
6662: $output = $versionresult;
6663: }
6664: }
6665: return ($output,$logourl);
6666: }
6667:
6668: sub logo_versioning {
6669: my ($targetdir,$file,$logfile) = @_;
6670: my $target = $targetdir.'/'.$file;
6671: my ($maxversion,$fn,$extn,$output);
6672: $maxversion = 0;
6673: if ($file =~ /^(.+)\.(\w+)$/) {
6674: $fn=$1;
6675: $extn=$2;
6676: }
6677: opendir(DIR,$targetdir);
6678: while (my $filename=readdir(DIR)) {
6679: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6680: $maxversion=($1>$maxversion)?$1:$maxversion;
6681: }
6682: }
6683: $maxversion++;
6684: print $logfile "\nCreating old version ".$maxversion."\n";
6685: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6686: if (copy($target,$copyfile)) {
6687: print $logfile "Copied old target to ".$copyfile."\n";
6688: $copyfile=$copyfile.'.meta';
6689: if (copy($target.'.meta',$copyfile)) {
6690: print $logfile "Copied old target metadata to ".$copyfile."\n";
6691: $output = 'ok';
6692: } else {
6693: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6694: $output = &mt('Failed to copy old meta').", $!, ";
6695: }
6696: } else {
6697: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6698: $output = &mt('Failed to copy old target').", $!, ";
6699: }
6700: return $output;
6701: }
6702:
6703: sub write_metadata {
6704: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6705: my (%metadatafields,%metadatakeys,$output);
6706: $metadatafields{'title'}=$formname;
6707: $metadatafields{'creationdate'}=time;
6708: $metadatafields{'lastrevisiondate'}=time;
6709: $metadatafields{'copyright'}='public';
6710: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6711: $env{'user.domain'};
6712: $metadatafields{'authorspace'}=$confname.':'.$dom;
6713: $metadatafields{'domain'}=$dom;
6714: {
6715: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6716: my $mfh;
1.155 raeburn 6717: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6718: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6719: unless ($_=~/\./) {
6720: my $unikey=$_;
6721: $unikey=~/^([A-Za-z]+)/;
6722: my $tag=$1;
6723: $tag=~tr/A-Z/a-z/;
6724: print $mfh "\n\<$tag";
6725: foreach (split(/\,/,$metadatakeys{$unikey})) {
6726: my $value=$metadatafields{$unikey.'.'.$_};
6727: $value=~s/\"/\'\'/g;
6728: print $mfh ' '.$_.'="'.$value.'"';
6729: }
6730: print $mfh '>'.
6731: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6732: .'</'.$tag.'>';
6733: }
6734: }
6735: $output = 'ok';
6736: print $logfile "\nWrote metadata";
6737: close($mfh);
6738: } else {
6739: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6740: $output = &mt('Could not write metadata');
6741: }
6742: }
1.155 raeburn 6743: return $output;
6744: }
6745:
6746: sub notifysubscribed {
6747: foreach my $targetsource (@{$modified_urls}){
6748: next unless (ref($targetsource) eq 'ARRAY');
6749: my ($target,$source)=@{$targetsource};
6750: if ($source ne '') {
6751: if (open(my $logfh,'>>'.$source.'.log')) {
6752: print $logfh "\nCleanup phase: Notifications\n";
6753: my @subscribed=&subscribed_hosts($target);
6754: foreach my $subhost (@subscribed) {
6755: print $logfh "\nNotifying host ".$subhost.':';
6756: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6757: print $logfh $reply;
6758: }
6759: my @subscribedmeta=&subscribed_hosts("$target.meta");
6760: foreach my $subhost (@subscribedmeta) {
6761: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6762: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6763: $subhost);
6764: print $logfh $reply;
6765: }
6766: print $logfh "\n============ Done ============\n";
1.160 raeburn 6767: close($logfh);
1.155 raeburn 6768: }
6769: }
6770: }
6771: return OK;
6772: }
6773:
6774: sub subscribed_hosts {
6775: my ($target) = @_;
6776: my @subscribed;
6777: if (open(my $fh,"<$target.subscription")) {
6778: while (my $subline=<$fh>) {
6779: if ($subline =~ /^($match_lonid):/) {
6780: my $host = $1;
6781: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6782: unless (grep(/^\Q$host\E$/,@subscribed)) {
6783: push(@subscribed,$host);
6784: }
6785: }
6786: }
6787: }
6788: }
6789: return @subscribed;
1.9 raeburn 6790: }
6791:
6792: sub check_switchserver {
6793: my ($dom,$confname) = @_;
6794: my ($allowed,$switchserver);
6795: my $home = &Apache::lonnet::homeserver($confname,$dom);
6796: if ($home eq 'no_host') {
6797: $home = &Apache::lonnet::domain($dom,'primary');
6798: }
6799: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6800: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6801: if (!$allowed) {
1.160.6.11 raeburn 6802: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6803: }
6804: return $switchserver;
6805: }
6806:
1.1 raeburn 6807: sub modify_quotas {
1.160.6.30 raeburn 6808: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6809: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6810: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6811: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6812: $validationfieldsref);
1.86 raeburn 6813: if ($action eq 'quotas') {
6814: $context = 'tools';
1.160.6.26 raeburn 6815: } else {
1.86 raeburn 6816: $context = $action;
6817: }
6818: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6819: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6820: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6821: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6822: %titles = &courserequest_titles();
6823: $toolregexp = join('|',@usertools);
6824: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6825: $confname = $dom.'-domainconfig';
6826: my $servadm = $r->dir_config('lonAdmEMail');
6827: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6828: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6829: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6830: } elsif ($context eq 'requestauthor') {
6831: @usertools = ('author');
6832: %titles = &authorrequest_titles();
1.86 raeburn 6833: } else {
1.160.6.4 raeburn 6834: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6835: %titles = &tool_titles();
1.86 raeburn 6836: }
1.160.6.27 raeburn 6837: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6838: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6839: foreach my $key (keys(%env)) {
1.101 raeburn 6840: if ($context eq 'requestcourses') {
6841: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6842: my $item = $1;
6843: my $type = $2;
6844: if ($type =~ /^limit_(.+)/) {
6845: $limithash{$item}{$1} = $env{$key};
6846: } else {
6847: $confhash{$item}{$type} = $env{$key};
6848: }
6849: }
1.160.6.5 raeburn 6850: } elsif ($context eq 'requestauthor') {
6851: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6852: $confhash{$1} = $env{$key};
6853: }
1.101 raeburn 6854: } else {
1.86 raeburn 6855: if ($key =~ /^form\.quota_(.+)$/) {
6856: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6857: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6858: $confhash{'authorquota'}{$1} = $env{$key};
6859: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6860: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6861: }
1.72 raeburn 6862: }
6863: }
1.160.6.5 raeburn 6864: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6865: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6866: @approvalnotify = sort(@approvalnotify);
6867: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6868: my @crstypes = ('official','unofficial','community','textbook');
6869: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6870: foreach my $type (@hasuniquecode) {
6871: if (grep(/^\Q$type\E$/,@crstypes)) {
6872: $confhash{'uniquecode'}{$type} = 1;
6873: }
6874: }
1.160.6.46 raeburn 6875: my (%newbook,%allpos);
1.160.6.30 raeburn 6876: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6877: foreach my $type ('textbooks','templates') {
6878: @{$allpos{$type}} = ();
6879: my $invalid;
6880: if ($type eq 'textbooks') {
6881: $invalid = &mt('Invalid LON-CAPA course for textbook');
6882: } else {
6883: $invalid = &mt('Invalid LON-CAPA course for template');
6884: }
6885: if ($env{'form.'.$type.'_addbook'}) {
6886: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6887: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6888: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6889: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6890: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6891: } else {
6892: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6893: my $position = $env{'form.'.$type.'_addbook_pos'};
6894: $position =~ s/\D+//g;
6895: if ($position ne '') {
6896: $allpos{$type}[$position] = $newbook{$type};
6897: }
1.160.6.30 raeburn 6898: }
1.160.6.46 raeburn 6899: } else {
6900: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 6901: }
6902: }
1.160.6.46 raeburn 6903: }
1.160.6.30 raeburn 6904: }
1.102 raeburn 6905: if (ref($domconfig{$action}) eq 'HASH') {
6906: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6907: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6908: $changes{'notify'}{'approval'} = 1;
6909: }
6910: } else {
1.144 raeburn 6911: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6912: $changes{'notify'}{'approval'} = 1;
6913: }
6914: }
1.160.6.30 raeburn 6915: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6916: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6917: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6918: unless ($confhash{'uniquecode'}{$crstype}) {
6919: $changes{'uniquecode'} = 1;
6920: }
6921: }
6922: unless ($changes{'uniquecode'}) {
6923: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6924: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6925: $changes{'uniquecode'} = 1;
6926: }
6927: }
6928: }
6929: } else {
6930: $changes{'uniquecode'} = 1;
6931: }
6932: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6933: $changes{'uniquecode'} = 1;
6934: }
6935: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6936: foreach my $type ('textbooks','templates') {
6937: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6938: my %deletions;
6939: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6940: if (@todelete) {
6941: map { $deletions{$_} = 1; } @todelete;
6942: }
6943: my %imgdeletions;
6944: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6945: if (@todeleteimages) {
6946: map { $imgdeletions{$_} = 1; } @todeleteimages;
6947: }
6948: my $maxnum = $env{'form.'.$type.'_maxnum'};
6949: for (my $i=0; $i<=$maxnum; $i++) {
6950: my $itemid = $env{'form.'.$type.'_id_'.$i};
6951: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6952: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6953: if ($deletions{$key}) {
6954: if ($domconfig{$action}{$type}{$key}{'image'}) {
6955: #FIXME need to obsolete item in RES space
6956: }
6957: next;
6958: } else {
6959: my $newpos = $env{'form.'.$itemid};
6960: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 6961: foreach my $item ('subject','title','publisher','author') {
6962: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6963: ($type eq 'templates'));
1.160.6.46 raeburn 6964: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6965: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6966: $changes{$type}{$key} = 1;
6967: }
6968: }
6969: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 6970: }
1.160.6.46 raeburn 6971: if ($imgdeletions{$key}) {
6972: $changes{$type}{$key} = 1;
6973: #FIXME need to obsolete item in RES space
6974: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
6975: my ($cdom,$cnum) = split(/_/,$key);
6976: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
6977: $cdom,$cnum,$type,$configuserok,
6978: $switchserver,$author_ok);
6979: if ($imgurl) {
6980: $confhash{$type}{$key}{'image'} = $imgurl;
6981: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 6982: }
1.160.6.46 raeburn 6983: if ($error) {
6984: &Apache::lonnet::logthis($error);
6985: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6986: }
6987: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
6988: $confhash{$type}{$key}{'image'} =
6989: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 6990: }
6991: }
6992: }
6993: }
6994: }
6995: }
1.102 raeburn 6996: } else {
1.144 raeburn 6997: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6998: $changes{'notify'}{'approval'} = 1;
6999: }
1.160.6.30 raeburn 7000: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7001: $changes{'uniquecode'} = 1;
7002: }
7003: }
7004: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7005: foreach my $type ('textbooks','templates') {
7006: if ($newbook{$type}) {
7007: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7008: foreach my $item ('subject','title','publisher','author') {
7009: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7010: ($type eq 'template'));
1.160.6.46 raeburn 7011: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7012: if ($env{'form.'.$type.'_addbook_'.$item}) {
7013: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7014: }
7015: }
7016: if ($type eq 'textbooks') {
7017: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7018: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7019: my ($imageurl,$error) =
7020: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7021: $configuserok,$switchserver,$author_ok);
7022: if ($imageurl) {
7023: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7024: }
7025: if ($error) {
7026: &Apache::lonnet::logthis($error);
7027: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7028: }
7029: }
1.160.6.30 raeburn 7030: }
7031: }
1.160.6.46 raeburn 7032: if (@{$allpos{$type}} > 0) {
7033: my $idx = 0;
7034: foreach my $item (@{$allpos{$type}}) {
7035: if ($item ne '') {
7036: $confhash{$type}{$item}{'order'} = $idx;
7037: if (ref($domconfig{$action}) eq 'HASH') {
7038: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7039: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7040: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7041: $changes{$type}{$item} = 1;
7042: }
1.160.6.30 raeburn 7043: }
7044: }
7045: }
1.160.6.46 raeburn 7046: $idx ++;
1.160.6.30 raeburn 7047: }
7048: }
7049: }
7050: }
1.160.6.39 raeburn 7051: if (ref($validationitemsref) eq 'ARRAY') {
7052: foreach my $item (@{$validationitemsref}) {
7053: if ($item eq 'fields') {
7054: my @changed;
7055: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7056: if (@{$confhash{'validation'}{$item}} > 0) {
7057: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7058: }
7059: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7060: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7061: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7062: $domconfig{'requestcourses'}{'validation'}{$item});
7063: } else {
7064: @changed = @{$confhash{'validation'}{$item}};
7065: }
7066: } else {
7067: @changed = @{$confhash{'validation'}{$item}};
7068: }
7069: if (@changed) {
7070: if ($confhash{'validation'}{$item}) {
7071: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7072: } else {
7073: $changes{'validation'}{$item} = &mt('None');
7074: }
7075: }
7076: } else {
7077: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7078: if ($item eq 'markup') {
7079: if ($env{'form.requestcourses_validation_'.$item}) {
7080: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7081: }
7082: }
7083: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7084: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7085: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7086: }
7087: } else {
7088: if ($confhash{'validation'}{$item} ne '') {
7089: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7090: }
7091: }
7092: }
7093: }
7094: }
7095: if ($env{'form.validationdc'}) {
7096: my $newval = $env{'form.validationdc'};
7097: my %domcoords = &get_active_dcs($dom);
7098: if (exists($domcoords{$newval})) {
7099: $confhash{'validation'}{'dc'} = $newval;
7100: }
7101: }
7102: if (ref($confhash{'validation'}) eq 'HASH') {
7103: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7104: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7105: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7106: if ($confhash{'validation'}{'dc'} eq '') {
7107: $changes{'validation'}{'dc'} = &mt('None');
7108: } else {
7109: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7110: }
7111: }
7112: } elsif ($confhash{'validation'}{'dc'} ne '') {
7113: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7114: }
7115: } elsif ($confhash{'validation'}{'dc'} ne '') {
7116: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7117: }
7118: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7119: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7120: $changes{'validation'}{'dc'} = &mt('None');
7121: }
7122: }
1.102 raeburn 7123: }
7124: } else {
1.86 raeburn 7125: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7126: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7127: }
1.72 raeburn 7128: foreach my $item (@usertools) {
7129: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7130: my $unset;
1.101 raeburn 7131: if ($context eq 'requestcourses') {
1.104 raeburn 7132: $unset = '0';
7133: if ($type eq '_LC_adv') {
7134: $unset = '';
7135: }
1.101 raeburn 7136: if ($confhash{$item}{$type} eq 'autolimit') {
7137: $confhash{$item}{$type} .= '=';
7138: unless ($limithash{$item}{$type} =~ /\D/) {
7139: $confhash{$item}{$type} .= $limithash{$item}{$type};
7140: }
7141: }
1.160.6.5 raeburn 7142: } elsif ($context eq 'requestauthor') {
7143: $unset = '0';
7144: if ($type eq '_LC_adv') {
7145: $unset = '';
7146: }
1.72 raeburn 7147: } else {
1.101 raeburn 7148: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7149: $confhash{$item}{$type} = 1;
7150: } else {
7151: $confhash{$item}{$type} = 0;
7152: }
1.72 raeburn 7153: }
1.86 raeburn 7154: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7155: if ($action eq 'requestauthor') {
7156: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7157: $changes{$type} = 1;
7158: }
7159: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7160: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7161: $changes{$item}{$type} = 1;
7162: }
7163: } else {
7164: if ($context eq 'requestcourses') {
1.104 raeburn 7165: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7166: $changes{$item}{$type} = 1;
7167: }
7168: } else {
7169: if (!$confhash{$item}{$type}) {
7170: $changes{$item}{$type} = 1;
7171: }
7172: }
7173: }
7174: } else {
7175: if ($context eq 'requestcourses') {
1.104 raeburn 7176: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7177: $changes{$item}{$type} = 1;
7178: }
1.160.6.5 raeburn 7179: } elsif ($context eq 'requestauthor') {
7180: if ($confhash{$type} ne $unset) {
7181: $changes{$type} = 1;
7182: }
1.72 raeburn 7183: } else {
7184: if (!$confhash{$item}{$type}) {
7185: $changes{$item}{$type} = 1;
7186: }
7187: }
7188: }
1.1 raeburn 7189: }
7190: }
1.160.6.5 raeburn 7191: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7192: if (ref($domconfig{'quotas'}) eq 'HASH') {
7193: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7194: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7195: if (exists($confhash{'defaultquota'}{$key})) {
7196: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7197: $changes{'defaultquota'}{$key} = 1;
7198: }
7199: } else {
7200: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7201: }
7202: }
1.86 raeburn 7203: } else {
7204: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7205: if (exists($confhash{'defaultquota'}{$key})) {
7206: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7207: $changes{'defaultquota'}{$key} = 1;
7208: }
7209: } else {
7210: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7211: }
1.1 raeburn 7212: }
7213: }
1.160.6.20 raeburn 7214: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7215: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7216: if (exists($confhash{'authorquota'}{$key})) {
7217: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7218: $changes{'authorquota'}{$key} = 1;
7219: }
7220: } else {
7221: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7222: }
7223: }
7224: }
1.1 raeburn 7225: }
1.86 raeburn 7226: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7227: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7228: if (ref($domconfig{'quotas'}) eq 'HASH') {
7229: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7230: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7231: $changes{'defaultquota'}{$key} = 1;
7232: }
7233: } else {
7234: if (!exists($domconfig{'quotas'}{$key})) {
7235: $changes{'defaultquota'}{$key} = 1;
7236: }
1.72 raeburn 7237: }
7238: } else {
1.86 raeburn 7239: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7240: }
1.1 raeburn 7241: }
7242: }
1.160.6.20 raeburn 7243: if (ref($confhash{'authorquota'}) eq 'HASH') {
7244: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7245: if (ref($domconfig{'quotas'}) eq 'HASH') {
7246: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7247: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7248: $changes{'authorquota'}{$key} = 1;
7249: }
7250: } else {
7251: $changes{'authorquota'}{$key} = 1;
7252: }
7253: } else {
7254: $changes{'authorquota'}{$key} = 1;
7255: }
7256: }
7257: }
1.1 raeburn 7258: }
1.72 raeburn 7259:
1.160.6.5 raeburn 7260: if ($context eq 'requestauthor') {
7261: $domdefaults{'requestauthor'} = \%confhash;
7262: } else {
7263: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7264: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7265: $domdefaults{$key} = $confhash{$key};
7266: }
1.160.6.5 raeburn 7267: }
1.72 raeburn 7268: }
1.160.6.5 raeburn 7269:
1.1 raeburn 7270: my %quotahash = (
1.86 raeburn 7271: $action => { %confhash }
1.1 raeburn 7272: );
7273: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7274: $dom);
7275: if ($putresult eq 'ok') {
7276: if (keys(%changes) > 0) {
1.72 raeburn 7277: my $cachetime = 24*60*60;
7278: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7279: if (ref($lastactref) eq 'HASH') {
7280: $lastactref->{'domdefaults'} = 1;
7281: }
1.1 raeburn 7282: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7283: unless (($context eq 'requestcourses') ||
7284: ($context eq 'requestauthor')) {
1.86 raeburn 7285: if (ref($changes{'defaultquota'}) eq 'HASH') {
7286: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7287: foreach my $type (@{$types},'default') {
7288: if (defined($changes{'defaultquota'}{$type})) {
7289: my $typetitle = $usertypes->{$type};
7290: if ($type eq 'default') {
7291: $typetitle = $othertitle;
7292: }
1.160.6.28 raeburn 7293: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7294: }
7295: }
1.86 raeburn 7296: $resulttext .= '</ul></li>';
1.72 raeburn 7297: }
1.160.6.20 raeburn 7298: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7299: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7300: foreach my $type (@{$types},'default') {
7301: if (defined($changes{'authorquota'}{$type})) {
7302: my $typetitle = $usertypes->{$type};
7303: if ($type eq 'default') {
7304: $typetitle = $othertitle;
7305: }
1.160.6.28 raeburn 7306: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7307: }
7308: }
7309: $resulttext .= '</ul></li>';
7310: }
1.72 raeburn 7311: }
1.80 raeburn 7312: my %newenv;
1.72 raeburn 7313: foreach my $item (@usertools) {
1.160.6.5 raeburn 7314: my (%haschgs,%inconf);
7315: if ($context eq 'requestauthor') {
7316: %haschgs = %changes;
7317: %inconf = %confhash;
7318: } else {
7319: if (ref($changes{$item}) eq 'HASH') {
7320: %haschgs = %{$changes{$item}};
7321: }
7322: if (ref($confhash{$item}) eq 'HASH') {
7323: %inconf = %{$confhash{$item}};
7324: }
7325: }
7326: if (keys(%haschgs) > 0) {
1.80 raeburn 7327: my $newacc =
7328: &Apache::lonnet::usertools_access($env{'user.name'},
7329: $env{'user.domain'},
1.86 raeburn 7330: $item,'reload',$context);
1.160.6.5 raeburn 7331: if (($context eq 'requestcourses') ||
7332: ($context eq 'requestauthor')) {
1.108 raeburn 7333: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7334: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7335: }
7336: } else {
7337: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7338: $newenv{'environment.availabletools.'.$item} = $newacc;
7339: }
1.80 raeburn 7340: }
1.160.6.5 raeburn 7341: unless ($context eq 'requestauthor') {
7342: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7343: }
1.72 raeburn 7344: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7345: if ($haschgs{$type}) {
1.72 raeburn 7346: my $typetitle = $usertypes->{$type};
7347: if ($type eq 'default') {
7348: $typetitle = $othertitle;
7349: } elsif ($type eq '_LC_adv') {
7350: $typetitle = 'LON-CAPA Advanced Users';
7351: }
1.160.6.5 raeburn 7352: if ($inconf{$type}) {
1.101 raeburn 7353: if ($context eq 'requestcourses') {
7354: my $cond;
1.160.6.5 raeburn 7355: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7356: if ($1 eq '') {
7357: $cond = &mt('(Automatic processing of any request).');
7358: } else {
7359: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7360: }
7361: } else {
1.160.6.5 raeburn 7362: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7363: }
7364: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7365: } elsif ($context eq 'requestauthor') {
7366: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7367: $titles{$inconf{$type}},$typetitle);
7368:
1.101 raeburn 7369: } else {
7370: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7371: }
1.72 raeburn 7372: } else {
1.104 raeburn 7373: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7374: if ($inconf{$type} eq '0') {
1.104 raeburn 7375: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7376: } else {
7377: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7378: }
7379: } else {
7380: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7381: }
1.72 raeburn 7382: }
7383: }
1.26 raeburn 7384: }
1.160.6.5 raeburn 7385: unless ($context eq 'requestauthor') {
7386: $resulttext .= '</ul></li>';
7387: }
1.26 raeburn 7388: }
1.1 raeburn 7389: }
1.160.6.5 raeburn 7390: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7391: if (ref($changes{'notify'}) eq 'HASH') {
7392: if ($changes{'notify'}{'approval'}) {
7393: if (ref($confhash{'notify'}) eq 'HASH') {
7394: if ($confhash{'notify'}{'approval'}) {
7395: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7396: } else {
1.160.6.5 raeburn 7397: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7398: }
7399: }
7400: }
7401: }
7402: }
1.160.6.30 raeburn 7403: if ($action eq 'requestcourses') {
7404: my @offon = ('off','on');
7405: if ($changes{'uniquecode'}) {
7406: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7407: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7408: $resulttext .= '<li>'.
7409: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7410: '</li>';
7411: } else {
7412: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7413: '</li>';
7414: }
7415: }
1.160.6.46 raeburn 7416: foreach my $type ('textbooks','templates') {
7417: if (ref($changes{$type}) eq 'HASH') {
7418: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7419: foreach my $key (sort(keys(%{$changes{$type}}))) {
7420: my %coursehash = &Apache::lonnet::coursedescription($key);
7421: my $coursetitle = $coursehash{'description'};
7422: my $position = $confhash{$type}{$key}{'order'} + 1;
7423: $resulttext .= '<li>';
1.160.6.47 raeburn 7424: foreach my $item ('subject','title','publisher','author') {
7425: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7426: ($type eq 'templates'));
1.160.6.46 raeburn 7427: my $name = $item.':';
7428: $name =~ s/^(\w)/\U$1/;
7429: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7430: }
7431: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7432: if ($type eq 'textbooks') {
7433: if ($confhash{$type}{$key}{'image'}) {
7434: $resulttext .= ' '.&mt('Image: [_1]',
7435: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7436: ' alt="Textbook cover" />').'<br />';
7437: }
7438: }
7439: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7440: }
1.160.6.46 raeburn 7441: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7442: }
7443: }
1.160.6.39 raeburn 7444: if (ref($changes{'validation'}) eq 'HASH') {
7445: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7446: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7447: foreach my $item (@{$validationitemsref}) {
7448: if (exists($changes{'validation'}{$item})) {
7449: if ($item eq 'markup') {
7450: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7451: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7452: } else {
7453: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7454: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7455: }
7456: }
7457: }
7458: if (exists($changes{'validation'}{'dc'})) {
7459: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7460: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7461: }
7462: }
7463: }
1.160.6.30 raeburn 7464: }
1.1 raeburn 7465: $resulttext .= '</ul>';
1.80 raeburn 7466: if (keys(%newenv)) {
7467: &Apache::lonnet::appenv(\%newenv);
7468: }
1.1 raeburn 7469: } else {
1.86 raeburn 7470: if ($context eq 'requestcourses') {
7471: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7472: } elsif ($context eq 'requestauthor') {
7473: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7474: } else {
1.90 weissno 7475: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7476: }
1.1 raeburn 7477: }
7478: } else {
1.11 albertel 7479: $resulttext = '<span class="LC_error">'.
7480: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7481: }
1.160.6.30 raeburn 7482: if ($errors) {
7483: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7484: '<ul>'.$errors.'</ul></p>';
7485: }
1.3 raeburn 7486: return $resulttext;
1.1 raeburn 7487: }
7488:
1.160.6.30 raeburn 7489: sub process_textbook_image {
1.160.6.46 raeburn 7490: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7491: my $filename = $env{'form.'.$caller.'.filename'};
7492: my ($error,$url);
7493: my ($width,$height) = (50,50);
7494: if ($configuserok eq 'ok') {
7495: if ($switchserver) {
7496: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7497: $switchserver);
7498: } elsif ($author_ok eq 'ok') {
7499: my ($result,$imageurl) =
7500: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7501: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7502: if ($result eq 'ok') {
7503: $url = $imageurl;
7504: } else {
7505: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7506: }
7507: } else {
7508: $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);
7509: }
7510: } else {
7511: $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);
7512: }
7513: return ($url,$error);
7514: }
7515:
1.3 raeburn 7516: sub modify_autoenroll {
1.160.6.24 raeburn 7517: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7518: my ($resulttext,%changes);
7519: my %currautoenroll;
7520: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7521: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7522: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7523: }
7524: }
7525: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7526: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7527: sender => 'Sender for notification messages',
7528: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7529: my @offon = ('off','on');
1.17 raeburn 7530: my $sender_uname = $env{'form.sender_uname'};
7531: my $sender_domain = $env{'form.sender_domain'};
7532: if ($sender_domain eq '') {
7533: $sender_uname = '';
7534: } elsif ($sender_uname eq '') {
7535: $sender_domain = '';
7536: }
1.129 raeburn 7537: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7538: my %autoenrollhash = (
1.129 raeburn 7539: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7540: 'sender_uname' => $sender_uname,
7541: 'sender_domain' => $sender_domain,
7542: 'co-owners' => $coowners,
1.1 raeburn 7543: }
7544: );
1.4 raeburn 7545: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7546: $dom);
1.1 raeburn 7547: if ($putresult eq 'ok') {
7548: if (exists($currautoenroll{'run'})) {
7549: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7550: $changes{'run'} = 1;
7551: }
7552: } elsif ($autorun) {
7553: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7554: $changes{'run'} = 1;
1.1 raeburn 7555: }
7556: }
1.17 raeburn 7557: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7558: $changes{'sender'} = 1;
7559: }
1.17 raeburn 7560: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7561: $changes{'sender'} = 1;
7562: }
1.129 raeburn 7563: if ($currautoenroll{'co-owners'} ne '') {
7564: if ($currautoenroll{'co-owners'} ne $coowners) {
7565: $changes{'coowners'} = 1;
7566: }
7567: } elsif ($coowners) {
7568: $changes{'coowners'} = 1;
7569: }
1.1 raeburn 7570: if (keys(%changes) > 0) {
7571: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7572: if ($changes{'run'}) {
1.1 raeburn 7573: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7574: }
7575: if ($changes{'sender'}) {
1.17 raeburn 7576: if ($sender_uname eq '' || $sender_domain eq '') {
7577: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7578: } else {
7579: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7580: }
1.1 raeburn 7581: }
1.129 raeburn 7582: if ($changes{'coowners'}) {
7583: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7584: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7585: if (ref($lastactref) eq 'HASH') {
7586: $lastactref->{'domainconfig'} = 1;
7587: }
1.129 raeburn 7588: }
1.1 raeburn 7589: $resulttext .= '</ul>';
7590: } else {
7591: $resulttext = &mt('No changes made to auto-enrollment settings');
7592: }
7593: } else {
1.11 albertel 7594: $resulttext = '<span class="LC_error">'.
7595: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7596: }
1.3 raeburn 7597: return $resulttext;
1.1 raeburn 7598: }
7599:
7600: sub modify_autoupdate {
1.3 raeburn 7601: my ($dom,%domconfig) = @_;
1.1 raeburn 7602: my ($resulttext,%currautoupdate,%fields,%changes);
7603: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7604: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7605: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7606: }
7607: }
7608: my @offon = ('off','on');
7609: my %title = &Apache::lonlocal::texthash (
7610: run => 'Auto-update:',
7611: classlists => 'Updates to user information in classlists?'
7612: );
1.44 raeburn 7613: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7614: my %fieldtitles = &Apache::lonlocal::texthash (
7615: id => 'Student/Employee ID',
1.20 raeburn 7616: permanentemail => 'E-mail address',
1.1 raeburn 7617: lastname => 'Last Name',
7618: firstname => 'First Name',
7619: middlename => 'Middle Name',
1.132 raeburn 7620: generation => 'Generation',
1.1 raeburn 7621: );
1.142 raeburn 7622: $othertitle = &mt('All users');
1.1 raeburn 7623: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7624: $othertitle = &mt('Other users');
1.1 raeburn 7625: }
7626: foreach my $key (keys(%env)) {
7627: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7628: my ($usertype,$item) = ($1,$2);
7629: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7630: if ($usertype eq 'default') {
7631: push(@{$fields{$1}},$2);
7632: } elsif (ref($types) eq 'ARRAY') {
7633: if (grep(/^\Q$usertype\E$/,@{$types})) {
7634: push(@{$fields{$1}},$2);
7635: }
7636: }
7637: }
1.1 raeburn 7638: }
7639: }
1.131 raeburn 7640: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7641: @lockablenames = sort(@lockablenames);
7642: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7643: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7644: if (@changed) {
7645: $changes{'lockablenames'} = 1;
7646: }
7647: } else {
7648: if (@lockablenames) {
7649: $changes{'lockablenames'} = 1;
7650: }
7651: }
1.1 raeburn 7652: my %updatehash = (
7653: autoupdate => { run => $env{'form.autoupdate_run'},
7654: classlists => $env{'form.classlists'},
7655: fields => {%fields},
1.131 raeburn 7656: lockablenames => \@lockablenames,
1.1 raeburn 7657: }
7658: );
7659: foreach my $key (keys(%currautoupdate)) {
7660: if (($key eq 'run') || ($key eq 'classlists')) {
7661: if (exists($updatehash{autoupdate}{$key})) {
7662: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7663: $changes{$key} = 1;
7664: }
7665: }
7666: } elsif ($key eq 'fields') {
7667: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7668: foreach my $item (@{$types},'default') {
1.1 raeburn 7669: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7670: my $change = 0;
7671: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7672: if (!exists($fields{$item})) {
7673: $change = 1;
1.132 raeburn 7674: last;
1.1 raeburn 7675: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7676: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7677: $change = 1;
1.132 raeburn 7678: last;
1.1 raeburn 7679: }
7680: }
7681: }
7682: if ($change) {
7683: push(@{$changes{$key}},$item);
7684: }
1.26 raeburn 7685: }
1.1 raeburn 7686: }
7687: }
1.131 raeburn 7688: } elsif ($key eq 'lockablenames') {
7689: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7690: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7691: if (@changed) {
7692: $changes{'lockablenames'} = 1;
7693: }
7694: } else {
7695: if (@lockablenames) {
7696: $changes{'lockablenames'} = 1;
7697: }
7698: }
7699: }
7700: }
7701: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7702: if (@lockablenames) {
7703: $changes{'lockablenames'} = 1;
1.1 raeburn 7704: }
7705: }
1.26 raeburn 7706: foreach my $item (@{$types},'default') {
7707: if (defined($fields{$item})) {
7708: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7709: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7710: my $change = 0;
7711: if (ref($fields{$item}) eq 'ARRAY') {
7712: foreach my $type (@{$fields{$item}}) {
7713: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7714: $change = 1;
7715: last;
7716: }
7717: }
7718: }
7719: if ($change) {
7720: push(@{$changes{'fields'}},$item);
7721: }
7722: } else {
1.26 raeburn 7723: push(@{$changes{'fields'}},$item);
7724: }
7725: } else {
7726: push(@{$changes{'fields'}},$item);
1.1 raeburn 7727: }
7728: }
7729: }
7730: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7731: $dom);
7732: if ($putresult eq 'ok') {
7733: if (keys(%changes) > 0) {
7734: $resulttext = &mt('Changes made:').'<ul>';
7735: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7736: if ($key eq 'lockablenames') {
7737: $resulttext .= '<li>';
7738: if (@lockablenames) {
7739: $usertypes->{'default'} = $othertitle;
7740: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7741: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7742: } else {
7743: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7744: }
7745: $resulttext .= '</li>';
7746: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7747: foreach my $item (@{$changes{$key}}) {
7748: my @newvalues;
7749: foreach my $type (@{$fields{$item}}) {
7750: push(@newvalues,$fieldtitles{$type});
7751: }
1.3 raeburn 7752: my $newvaluestr;
7753: if (@newvalues > 0) {
7754: $newvaluestr = join(', ',@newvalues);
7755: } else {
7756: $newvaluestr = &mt('none');
1.6 raeburn 7757: }
1.1 raeburn 7758: if ($item eq 'default') {
1.26 raeburn 7759: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7760: } else {
1.26 raeburn 7761: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7762: }
7763: }
7764: } else {
7765: my $newvalue;
7766: if ($key eq 'run') {
7767: $newvalue = $offon[$env{'form.autoupdate_run'}];
7768: } else {
7769: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7770: }
1.1 raeburn 7771: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7772: }
7773: }
7774: $resulttext .= '</ul>';
7775: } else {
1.3 raeburn 7776: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7777: }
7778: } else {
1.11 albertel 7779: $resulttext = '<span class="LC_error">'.
7780: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7781: }
1.3 raeburn 7782: return $resulttext;
1.1 raeburn 7783: }
7784:
1.125 raeburn 7785: sub modify_autocreate {
7786: my ($dom,%domconfig) = @_;
7787: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7788: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7789: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7790: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7791: }
7792: }
7793: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7794: req => 'Auto-creation of validated requests for official courses',
7795: xmldc => 'Identity of course creator of courses from XML files',
7796: );
7797: my @types = ('xml','req');
7798: foreach my $item (@types) {
7799: $newvals{$item} = $env{'form.autocreate_'.$item};
7800: $newvals{$item} =~ s/\D//g;
7801: $newvals{$item} = 0 if ($newvals{$item} eq '');
7802: }
7803: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7804: my %domcoords = &get_active_dcs($dom);
7805: unless (exists($domcoords{$newvals{'xmldc'}})) {
7806: $newvals{'xmldc'} = '';
7807: }
7808: %autocreatehash = (
7809: autocreate => { xml => $newvals{'xml'},
7810: req => $newvals{'req'},
7811: }
7812: );
7813: if ($newvals{'xmldc'} ne '') {
7814: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7815: }
7816: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7817: $dom);
7818: if ($putresult eq 'ok') {
7819: my @items = @types;
7820: if ($newvals{'xml'}) {
7821: push(@items,'xmldc');
7822: }
7823: foreach my $item (@items) {
7824: if (exists($currautocreate{$item})) {
7825: if ($currautocreate{$item} ne $newvals{$item}) {
7826: $changes{$item} = 1;
7827: }
7828: } elsif ($newvals{$item}) {
7829: $changes{$item} = 1;
7830: }
7831: }
7832: if (keys(%changes) > 0) {
7833: my @offon = ('off','on');
7834: $resulttext = &mt('Changes made:').'<ul>';
7835: foreach my $item (@types) {
7836: if ($changes{$item}) {
7837: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7838: $resulttext .= '<li>'.
7839: &mt("$title{$item} set to [_1]$newtxt [_2]",
7840: '<b>','</b>').
7841: '</li>';
1.125 raeburn 7842: }
7843: }
7844: if ($changes{'xmldc'}) {
7845: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7846: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7847: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7848: }
7849: $resulttext .= '</ul>';
7850: } else {
7851: $resulttext = &mt('No changes made to auto-creation settings');
7852: }
7853: } else {
7854: $resulttext = '<span class="LC_error">'.
7855: &mt('An error occurred: [_1]',$putresult).'</span>';
7856: }
7857: return $resulttext;
7858: }
7859:
1.23 raeburn 7860: sub modify_directorysrch {
7861: my ($dom,%domconfig) = @_;
7862: my ($resulttext,%changes);
7863: my %currdirsrch;
7864: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7865: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7866: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7867: }
7868: }
7869: my %title = ( available => 'Directory search available',
1.24 raeburn 7870: localonly => 'Other domains can search',
1.23 raeburn 7871: searchby => 'Search types',
7872: searchtypes => 'Search latitude');
7873: my @offon = ('off','on');
1.24 raeburn 7874: my @otherdoms = ('Yes','No');
1.23 raeburn 7875:
1.25 raeburn 7876: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7877: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7878: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7879:
1.44 raeburn 7880: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7881: if (keys(%{$usertypes}) == 0) {
7882: @cansearch = ('default');
7883: } else {
7884: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7885: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7886: if (!grep(/^\Q$type\E$/,@cansearch)) {
7887: push(@{$changes{'cansearch'}},$type);
7888: }
1.23 raeburn 7889: }
1.26 raeburn 7890: foreach my $type (@cansearch) {
7891: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7892: push(@{$changes{'cansearch'}},$type);
7893: }
1.23 raeburn 7894: }
1.26 raeburn 7895: } else {
7896: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7897: }
7898: }
7899:
7900: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7901: foreach my $by (@{$currdirsrch{'searchby'}}) {
7902: if (!grep(/^\Q$by\E$/,@searchby)) {
7903: push(@{$changes{'searchby'}},$by);
7904: }
7905: }
7906: foreach my $by (@searchby) {
7907: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7908: push(@{$changes{'searchby'}},$by);
7909: }
7910: }
7911: } else {
7912: push(@{$changes{'searchby'}},@searchby);
7913: }
1.25 raeburn 7914:
7915: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7916: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7917: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7918: push(@{$changes{'searchtypes'}},$type);
7919: }
7920: }
7921: foreach my $type (@searchtypes) {
7922: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7923: push(@{$changes{'searchtypes'}},$type);
7924: }
7925: }
7926: } else {
7927: if (exists($currdirsrch{'searchtypes'})) {
7928: foreach my $type (@searchtypes) {
7929: if ($type ne $currdirsrch{'searchtypes'}) {
7930: push(@{$changes{'searchtypes'}},$type);
7931: }
7932: }
7933: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7934: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7935: }
7936: } else {
7937: push(@{$changes{'searchtypes'}},@searchtypes);
7938: }
7939: }
7940:
1.23 raeburn 7941: my %dirsrch_hash = (
7942: directorysrch => { available => $env{'form.dirsrch_available'},
7943: cansearch => \@cansearch,
1.24 raeburn 7944: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7945: searchby => \@searchby,
1.25 raeburn 7946: searchtypes => \@searchtypes,
1.23 raeburn 7947: }
7948: );
7949: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7950: $dom);
7951: if ($putresult eq 'ok') {
7952: if (exists($currdirsrch{'available'})) {
7953: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7954: $changes{'available'} = 1;
7955: }
7956: } else {
7957: if ($env{'form.dirsrch_available'} eq '1') {
7958: $changes{'available'} = 1;
7959: }
7960: }
1.24 raeburn 7961: if (exists($currdirsrch{'localonly'})) {
7962: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7963: $changes{'localonly'} = 1;
7964: }
7965: } else {
7966: if ($env{'form.dirsrch_localonly'} eq '1') {
7967: $changes{'localonly'} = 1;
7968: }
7969: }
1.23 raeburn 7970: if (keys(%changes) > 0) {
7971: $resulttext = &mt('Changes made:').'<ul>';
7972: if ($changes{'available'}) {
7973: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7974: }
1.24 raeburn 7975: if ($changes{'localonly'}) {
7976: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7977: }
7978:
1.23 raeburn 7979: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7980: my $chgtext;
1.26 raeburn 7981: if (ref($usertypes) eq 'HASH') {
7982: if (keys(%{$usertypes}) > 0) {
7983: foreach my $type (@{$types}) {
7984: if (grep(/^\Q$type\E$/,@cansearch)) {
7985: $chgtext .= $usertypes->{$type}.'; ';
7986: }
7987: }
7988: if (grep(/^default$/,@cansearch)) {
7989: $chgtext .= $othertitle;
7990: } else {
7991: $chgtext =~ s/\; $//;
7992: }
1.160.6.13 raeburn 7993: $resulttext .=
7994: '<li>'.
7995: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7996: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7997: '</li>';
1.23 raeburn 7998: }
7999: }
8000: }
8001: if (ref($changes{'searchby'}) eq 'ARRAY') {
8002: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8003: my $chgtext;
8004: foreach my $type (@{$titleorder}) {
8005: if (grep(/^\Q$type\E$/,@searchby)) {
8006: if (defined($searchtitles->{$type})) {
8007: $chgtext .= $searchtitles->{$type}.'; ';
8008: }
8009: }
8010: }
8011: $chgtext =~ s/\; $//;
8012: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8013: }
1.25 raeburn 8014: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8015: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8016: my $chgtext;
8017: foreach my $type (@{$srchtypeorder}) {
8018: if (grep(/^\Q$type\E$/,@searchtypes)) {
8019: if (defined($srchtypes_desc->{$type})) {
8020: $chgtext .= $srchtypes_desc->{$type}.'; ';
8021: }
8022: }
8023: }
8024: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8025: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8026: }
8027: $resulttext .= '</ul>';
8028: } else {
8029: $resulttext = &mt('No changes made to institution directory search settings');
8030: }
8031: } else {
8032: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8033: &mt('An error occurred: [_1]',$putresult).'</span>';
8034: }
8035: return $resulttext;
8036: }
8037:
1.28 raeburn 8038: sub modify_contacts {
1.160.6.24 raeburn 8039: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8040: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8041: if (ref($domconfig{'contacts'}) eq 'HASH') {
8042: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8043: $currsetting{$key} = $domconfig{'contacts'}{$key};
8044: }
8045: }
1.134 raeburn 8046: my (%others,%to,%bcc);
1.28 raeburn 8047: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8048: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8049: 'requestsmail','updatesmail','idconflictsmail');
8050: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8051: foreach my $type (@mailings) {
8052: @{$newsetting{$type}} =
8053: &Apache::loncommon::get_env_multiple('form.'.$type);
8054: foreach my $item (@contacts) {
8055: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8056: $contacts_hash{contacts}{$type}{$item} = 1;
8057: } else {
8058: $contacts_hash{contacts}{$type}{$item} = 0;
8059: }
8060: }
8061: $others{$type} = $env{'form.'.$type.'_others'};
8062: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8063: if ($type eq 'helpdeskmail') {
8064: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8065: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8066: }
1.28 raeburn 8067: }
8068: foreach my $item (@contacts) {
8069: $to{$item} = $env{'form.'.$item};
8070: $contacts_hash{'contacts'}{$item} = $to{$item};
8071: }
1.160.6.23 raeburn 8072: foreach my $item (@toggles) {
8073: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8074: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8075: }
8076: }
1.28 raeburn 8077: if (keys(%currsetting) > 0) {
8078: foreach my $item (@contacts) {
8079: if ($to{$item} ne $currsetting{$item}) {
8080: $changes{$item} = 1;
8081: }
8082: }
8083: foreach my $type (@mailings) {
8084: foreach my $item (@contacts) {
8085: if (ref($currsetting{$type}) eq 'HASH') {
8086: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8087: push(@{$changes{$type}},$item);
8088: }
8089: } else {
8090: push(@{$changes{$type}},@{$newsetting{$type}});
8091: }
8092: }
8093: if ($others{$type} ne $currsetting{$type}{'others'}) {
8094: push(@{$changes{$type}},'others');
8095: }
1.134 raeburn 8096: if ($type eq 'helpdeskmail') {
8097: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8098: push(@{$changes{$type}},'bcc');
8099: }
8100: }
1.28 raeburn 8101: }
8102: } else {
8103: my %default;
8104: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8105: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8106: $default{'errormail'} = 'adminemail';
8107: $default{'packagesmail'} = 'adminemail';
8108: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8109: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8110: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8111: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8112: foreach my $item (@contacts) {
8113: if ($to{$item} ne $default{$item}) {
8114: $changes{$item} = 1;
1.160.6.23 raeburn 8115: }
1.28 raeburn 8116: }
8117: foreach my $type (@mailings) {
8118: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8119:
8120: push(@{$changes{$type}},@{$newsetting{$type}});
8121: }
8122: if ($others{$type} ne '') {
8123: push(@{$changes{$type}},'others');
1.134 raeburn 8124: }
8125: if ($type eq 'helpdeskmail') {
8126: if ($bcc{$type} ne '') {
8127: push(@{$changes{$type}},'bcc');
8128: }
8129: }
1.28 raeburn 8130: }
8131: }
1.160.6.23 raeburn 8132: foreach my $item (@toggles) {
8133: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8134: $changes{$item} = 1;
8135: } elsif ((!$env{'form.'.$item}) &&
8136: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8137: $changes{$item} = 1;
8138: }
8139: }
1.28 raeburn 8140: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8141: $dom);
8142: if ($putresult eq 'ok') {
8143: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8144: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8145: if (ref($lastactref) eq 'HASH') {
8146: $lastactref->{'domainconfig'} = 1;
8147: }
1.28 raeburn 8148: my ($titles,$short_titles) = &contact_titles();
8149: $resulttext = &mt('Changes made:').'<ul>';
8150: foreach my $item (@contacts) {
8151: if ($changes{$item}) {
8152: $resulttext .= '<li>'.$titles->{$item}.
8153: &mt(' set to: ').
8154: '<span class="LC_cusr_emph">'.
8155: $to{$item}.'</span></li>';
8156: }
8157: }
8158: foreach my $type (@mailings) {
8159: if (ref($changes{$type}) eq 'ARRAY') {
8160: $resulttext .= '<li>'.$titles->{$type}.': ';
8161: my @text;
8162: foreach my $item (@{$newsetting{$type}}) {
8163: push(@text,$short_titles->{$item});
8164: }
8165: if ($others{$type} ne '') {
8166: push(@text,$others{$type});
8167: }
8168: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8169: join(', ',@text).'</span>';
8170: if ($type eq 'helpdeskmail') {
8171: if ($bcc{$type} ne '') {
8172: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8173: }
8174: }
8175: $resulttext .= '</li>';
1.28 raeburn 8176: }
8177: }
1.160.6.23 raeburn 8178: my @offon = ('off','on');
8179: if ($changes{'reporterrors'}) {
8180: $resulttext .= '<li>'.
8181: &mt('E-mail error reports to [_1] set to "'.
8182: $offon[$env{'form.reporterrors'}].'".',
8183: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8184: &mt('LON-CAPA core group - MSU'),600,500)).
8185: '</li>';
8186: }
8187: if ($changes{'reportupdates'}) {
8188: $resulttext .= '<li>'.
8189: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8190: $offon[$env{'form.reportupdates'}].'".',
8191: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8192: &mt('LON-CAPA core group - MSU'),600,500)).
8193: '</li>';
8194: }
1.28 raeburn 8195: $resulttext .= '</ul>';
8196: } else {
1.34 raeburn 8197: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8198: }
8199: } else {
8200: $resulttext = '<span class="LC_error">'.
8201: &mt('An error occurred: [_1].',$putresult).'</span>';
8202: }
8203: return $resulttext;
8204: }
8205:
8206: sub modify_usercreation {
1.27 raeburn 8207: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8208: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8209: my $warningmsg;
1.27 raeburn 8210: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8211: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8212: if ($key eq 'cancreate') {
8213: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8214: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8215: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8216: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8217: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8218: } else {
8219: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8220: }
1.50 raeburn 8221: }
1.43 raeburn 8222: }
1.160.6.34 raeburn 8223: } elsif ($key eq 'email_rule') {
8224: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8225: } else {
8226: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8227: }
8228: }
1.34 raeburn 8229: }
1.160.6.34 raeburn 8230: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8231: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8232: my @contexts = ('author','course','requestcrs');
8233: foreach my $item(@contexts) {
8234: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8235: }
1.34 raeburn 8236: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8237: foreach my $item (@contexts) {
1.160.6.34 raeburn 8238: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8239: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8240: }
1.27 raeburn 8241: }
1.34 raeburn 8242: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8243: foreach my $item (@contexts) {
1.43 raeburn 8244: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8245: if ($cancreate{$item} ne 'any') {
8246: push(@{$changes{'cancreate'}},$item);
8247: }
8248: } else {
8249: if ($cancreate{$item} ne 'none') {
8250: push(@{$changes{'cancreate'}},$item);
8251: }
1.27 raeburn 8252: }
8253: }
8254: } else {
1.43 raeburn 8255: foreach my $item (@contexts) {
1.34 raeburn 8256: push(@{$changes{'cancreate'}},$item);
8257: }
1.27 raeburn 8258: }
1.34 raeburn 8259:
1.27 raeburn 8260: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8261: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8262: if (!grep(/^\Q$type\E$/,@username_rule)) {
8263: push(@{$changes{'username_rule'}},$type);
8264: }
8265: }
8266: foreach my $type (@username_rule) {
8267: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8268: push(@{$changes{'username_rule'}},$type);
8269: }
8270: }
8271: } else {
8272: push(@{$changes{'username_rule'}},@username_rule);
8273: }
8274:
1.32 raeburn 8275: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8276: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8277: if (!grep(/^\Q$type\E$/,@id_rule)) {
8278: push(@{$changes{'id_rule'}},$type);
8279: }
8280: }
8281: foreach my $type (@id_rule) {
8282: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8283: push(@{$changes{'id_rule'}},$type);
8284: }
8285: }
8286: } else {
8287: push(@{$changes{'id_rule'}},@id_rule);
8288: }
8289:
1.43 raeburn 8290: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8291: my @authtypes = ('int','krb4','krb5','loc');
8292: my %authhash;
1.43 raeburn 8293: foreach my $item (@authen_contexts) {
1.28 raeburn 8294: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8295: foreach my $auth (@authtypes) {
8296: if (grep(/^\Q$auth\E$/,@authallowed)) {
8297: $authhash{$item}{$auth} = 1;
8298: } else {
8299: $authhash{$item}{$auth} = 0;
8300: }
8301: }
8302: }
8303: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8304: foreach my $item (@authen_contexts) {
1.28 raeburn 8305: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8306: foreach my $auth (@authtypes) {
8307: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8308: push(@{$changes{'authtypes'}},$item);
8309: last;
8310: }
8311: }
8312: }
8313: }
8314: } else {
1.43 raeburn 8315: foreach my $item (@authen_contexts) {
1.28 raeburn 8316: push(@{$changes{'authtypes'}},$item);
8317: }
8318: }
8319:
1.160.6.34 raeburn 8320: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8321: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8322: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8323: $save_usercreate{'id_rule'} = \@id_rule;
8324: $save_usercreate{'username_rule'} = \@username_rule,
8325: $save_usercreate{'authtypes'} = \%authhash;
8326:
1.27 raeburn 8327: my %usercreation_hash = (
1.160.6.34 raeburn 8328: usercreation => \%save_usercreate,
8329: );
1.27 raeburn 8330:
8331: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8332: $dom);
1.50 raeburn 8333:
1.160.6.34 raeburn 8334: if ($putresult eq 'ok') {
8335: if (keys(%changes) > 0) {
8336: $resulttext = &mt('Changes made:').'<ul>';
8337: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8338: my %lt = &usercreation_types();
8339: foreach my $type (@{$changes{'cancreate'}}) {
8340: my $chgtext = $lt{$type}.', ';
8341: if ($cancreate{$type} eq 'none') {
8342: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8343: } elsif ($cancreate{$type} eq 'any') {
8344: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8345: } elsif ($cancreate{$type} eq 'official') {
8346: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8347: } elsif ($cancreate{$type} eq 'unofficial') {
8348: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8349: }
8350: $resulttext .= '<li>'.$chgtext.'</li>';
8351: }
8352: }
8353: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8354: my ($rules,$ruleorder) =
8355: &Apache::lonnet::inst_userrules($dom,'username');
8356: my $chgtext = '<ul>';
8357: foreach my $type (@username_rule) {
8358: if (ref($rules->{$type}) eq 'HASH') {
8359: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8360: }
8361: }
8362: $chgtext .= '</ul>';
8363: if (@username_rule > 0) {
8364: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8365: } else {
8366: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8367: }
8368: }
8369: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8370: my ($idrules,$idruleorder) =
8371: &Apache::lonnet::inst_userrules($dom,'id');
8372: my $chgtext = '<ul>';
8373: foreach my $type (@id_rule) {
8374: if (ref($idrules->{$type}) eq 'HASH') {
8375: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8376: }
8377: }
8378: $chgtext .= '</ul>';
8379: if (@id_rule > 0) {
8380: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8381: } else {
8382: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8383: }
8384: }
8385: my %authname = &authtype_names();
8386: my %context_title = &context_names();
8387: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8388: my $chgtext = '<ul>';
8389: foreach my $type (@{$changes{'authtypes'}}) {
8390: my @allowed;
8391: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8392: foreach my $auth (@authtypes) {
8393: if ($authhash{$type}{$auth}) {
8394: push(@allowed,$authname{$auth});
8395: }
8396: }
8397: if (@allowed > 0) {
8398: $chgtext .= join(', ',@allowed).'</li>';
8399: } else {
8400: $chgtext .= &mt('none').'</li>';
8401: }
8402: }
8403: $chgtext .= '</ul>';
8404: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8405: $resulttext .= '</li>';
8406: }
8407: $resulttext .= '</ul>';
8408: } else {
8409: $resulttext = &mt('No changes made to user creation settings');
8410: }
8411: } else {
8412: $resulttext = '<span class="LC_error">'.
8413: &mt('An error occurred: [_1]',$putresult).'</span>';
8414: }
8415: if ($warningmsg ne '') {
8416: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8417: }
8418: return $resulttext;
8419: }
8420:
8421: sub modify_selfcreation {
8422: my ($dom,%domconfig) = @_;
8423: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8424: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8425: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8426: if (ref($types) eq 'ARRAY') {
8427: $usertypes->{'default'} = $othertitle;
8428: push(@{$types},'default');
8429: }
1.160.6.34 raeburn 8430: #
8431: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8432: #
8433: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8434: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8435: if ($key eq 'cancreate') {
8436: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8437: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8438: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8439: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8440: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8441: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8442: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8443: } else {
8444: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8445: }
8446: }
8447: }
8448: } elsif ($key eq 'email_rule') {
8449: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8450: } else {
8451: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8452: }
8453: }
8454: }
8455: #
8456: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8457: #
8458: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8459: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8460: if ($key eq 'selfcreate') {
8461: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8462: } else {
8463: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8464: }
8465: }
8466: }
8467:
8468: my @contexts = ('selfcreate');
8469: @{$cancreate{'selfcreate'}} = ();
8470: %{$cancreate{'emailusername'}} = ();
8471: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8472: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8473: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8474: my %selfcreatetypes = (
8475: sso => 'users authenticated by institutional single sign on',
8476: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8477: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8478: );
1.160.6.34 raeburn 8479: #
8480: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8481: # is permitted.
8482: #
1.160.6.40 raeburn 8483:
8484: my @statuses;
8485: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8486: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8487: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8488: }
8489: }
8490: push(@statuses,'default');
8491:
1.160.6.35 raeburn 8492: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8493: if ($item eq 'email') {
1.160.6.40 raeburn 8494: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8495: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8496: push(@contexts,'selfcreateprocessing');
8497: foreach my $type (@statuses) {
8498: if ($type eq 'default') {
8499: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8500: } else {
8501: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8502: }
8503: }
1.160.6.34 raeburn 8504: }
8505: } else {
8506: if ($env{'form.cancreate_'.$item}) {
8507: push(@{$cancreate{'selfcreate'}},$item);
8508: }
8509: }
8510: }
8511: my (@email_rule,%userinfo,%savecaptcha);
8512: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8513: #
1.160.6.35 raeburn 8514: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8515: # 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 8516: #
1.160.6.40 raeburn 8517:
1.160.6.48 raeburn 8518: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8519: push(@contexts,'emailusername');
1.160.6.35 raeburn 8520: if (ref($types) eq 'ARRAY') {
8521: foreach my $type (@{$types}) {
8522: if (ref($infofields) eq 'ARRAY') {
8523: foreach my $field (@{$infofields}) {
8524: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8525: $cancreate{'emailusername'}{$type}{$field} = $1;
8526: }
8527: }
1.160.6.34 raeburn 8528: }
8529: }
8530: }
8531: #
8532: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8533: # queued requests for self-creation of account using e-mail address as username
8534: #
8535:
8536: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8537: @approvalnotify = sort(@approvalnotify);
8538: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8539: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8540: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8541: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8542: push(@{$changes{'cancreate'}},'notify');
8543: }
8544: } else {
8545: if ($cancreate{'notify'}{'approval'}) {
8546: push(@{$changes{'cancreate'}},'notify');
8547: }
8548: }
8549: } elsif ($cancreate{'notify'}{'approval'}) {
8550: push(@{$changes{'cancreate'}},'notify');
8551: }
8552:
8553: #
8554: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8555: #
8556: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8557: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8558: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8559: if (@{$curr_usercreation{'email_rule'}} > 0) {
8560: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8561: if (!grep(/^\Q$type\E$/,@email_rule)) {
8562: push(@{$changes{'email_rule'}},$type);
8563: }
8564: }
8565: }
8566: if (@email_rule > 0) {
8567: foreach my $type (@email_rule) {
8568: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8569: push(@{$changes{'email_rule'}},$type);
8570: }
8571: }
8572: }
8573: } elsif (@email_rule > 0) {
8574: push(@{$changes{'email_rule'}},@email_rule);
8575: }
8576: }
8577: #
1.160.6.40 raeburn 8578: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8579: # institutional log-in.
8580: #
8581: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8582: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8583: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8584: ($domdefaults{'auth_def'} eq 'localauth'))) {
8585: $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.').' '.
8586: &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.');
8587: }
8588: }
8589: my @fields = ('lastname','firstname','middlename','generation',
8590: 'permanentemail','id');
1.160.6.44 raeburn 8591: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8592: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8593: #
8594: # Where usernames may created for institutional log-in and/or institutional single sign on:
8595: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8596: # may self-create accounts
8597: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8598: # which the user may supply, if institutional data is unavailable.
8599: #
8600: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8601: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8602: if (@{$types} > 1) {
1.160.6.34 raeburn 8603: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8604: push(@contexts,'statustocreate');
8605: } else {
8606: undef($cancreate{'statustocreate'});
8607: }
8608: foreach my $type (@{$types}) {
8609: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8610: foreach my $field (@fields) {
8611: if (grep(/^\Q$field\E$/,@modifiable)) {
8612: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8613: } else {
8614: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8615: }
8616: }
8617: }
8618: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8619: foreach my $type (@{$types}) {
8620: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8621: foreach my $field (@fields) {
8622: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8623: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8624: push(@{$changes{'selfcreate'}},$type);
8625: last;
8626: }
8627: }
8628: }
8629: }
8630: } else {
8631: foreach my $type (@{$types}) {
8632: push(@{$changes{'selfcreate'}},$type);
8633: }
8634: }
8635: }
1.160.6.44 raeburn 8636: foreach my $field (@shibfields) {
8637: if ($env{'form.shibenv_'.$field} ne '') {
8638: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8639: }
8640: }
8641: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8642: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8643: foreach my $field (@shibfields) {
8644: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8645: push(@{$changes{'cancreate'}},'shibenv');
8646: }
8647: }
8648: } else {
8649: foreach my $field (@shibfields) {
8650: if ($env{'form.shibenv_'.$field}) {
8651: push(@{$changes{'cancreate'}},'shibenv');
8652: last;
8653: }
8654: }
8655: }
8656: }
1.160.6.34 raeburn 8657: }
8658: foreach my $item (@contexts) {
8659: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8660: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8661: if (ref($cancreate{$item}) eq 'ARRAY') {
8662: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8663: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8664: push(@{$changes{'cancreate'}},$item);
8665: }
8666: }
8667: }
8668: }
8669: if (ref($cancreate{$item}) eq 'ARRAY') {
8670: foreach my $type (@{$cancreate{$item}}) {
8671: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8672: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8673: push(@{$changes{'cancreate'}},$item);
8674: }
8675: }
8676: }
8677: }
8678: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8679: if (ref($cancreate{$item}) eq 'HASH') {
8680: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8681: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8682: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8683: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8684: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8685: push(@{$changes{'cancreate'}},$item);
8686: }
8687: }
8688: }
1.160.6.40 raeburn 8689: } elsif ($item eq 'selfcreateprocessing') {
8690: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8691: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8692: push(@{$changes{'cancreate'}},$item);
8693: }
8694: }
1.160.6.35 raeburn 8695: } else {
8696: if (!$cancreate{$item}{$curr}) {
8697: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8698: push(@{$changes{'cancreate'}},$item);
8699: }
1.160.6.34 raeburn 8700: }
8701: }
8702: }
8703: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8704: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8705: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8706: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8707: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8708: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8709: push(@{$changes{'cancreate'}},$item);
8710: }
8711: }
8712: } else {
8713: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8714: push(@{$changes{'cancreate'}},$item);
8715: }
8716: }
8717: }
1.160.6.40 raeburn 8718: } elsif ($item eq 'selfcreateprocessing') {
8719: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8720: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8721: push(@{$changes{'cancreate'}},$item);
8722: }
8723: }
1.160.6.35 raeburn 8724: } else {
8725: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8727: push(@{$changes{'cancreate'}},$item);
8728: }
1.160.6.34 raeburn 8729: }
8730: }
8731: }
8732: }
8733: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8734: if (ref($cancreate{$item}) eq 'ARRAY') {
8735: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8736: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8737: push(@{$changes{'cancreate'}},$item);
8738: }
8739: }
8740: } elsif (ref($cancreate{$item}) eq 'HASH') {
8741: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8742: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8743: push(@{$changes{'cancreate'}},$item);
8744: }
8745: }
8746: }
8747: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8748: if (ref($cancreate{$item}) eq 'HASH') {
8749: foreach my $type (keys(%{$cancreate{$item}})) {
8750: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8751: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8752: if ($cancreate{$item}{$type}{$field}) {
8753: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8754: push(@{$changes{'cancreate'}},$item);
8755: }
8756: last;
8757: }
8758: }
8759: }
8760: }
1.160.6.34 raeburn 8761: }
8762: }
8763: }
8764: #
8765: # Populate %save_usercreate hash with updates to self-creation configuration.
8766: #
8767: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8768: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8769: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8770: if (ref($cancreate{'notify'}) eq 'HASH') {
8771: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8772: }
1.160.6.40 raeburn 8773: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8774: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8775: }
1.160.6.34 raeburn 8776: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8777: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8778: }
1.160.6.44 raeburn 8779: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8780: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8781: }
1.160.6.34 raeburn 8782: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8783: $save_usercreate{'emailrule'} = \@email_rule;
8784:
8785: my %userconfig_hash = (
8786: usercreation => \%save_usercreate,
8787: usermodification => \%save_usermodify,
8788: );
8789: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8790: $dom);
8791: #
8792: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8793: #
1.27 raeburn 8794: if ($putresult eq 'ok') {
8795: if (keys(%changes) > 0) {
8796: $resulttext = &mt('Changes made:').'<ul>';
8797: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8798: my %lt = &selfcreation_types();
1.34 raeburn 8799: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8800: my $chgtext;
1.45 raeburn 8801: if ($type eq 'selfcreate') {
1.50 raeburn 8802: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8803: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8804: } else {
1.160.6.34 raeburn 8805: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8806: '<ul>';
1.50 raeburn 8807: foreach my $case (@{$cancreate{$type}}) {
8808: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8809: }
8810: $chgtext .= '</ul>';
1.100 raeburn 8811: if (ref($cancreate{$type}) eq 'ARRAY') {
8812: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8813: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8814: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8815: $chgtext .= '<br />'.
8816: '<span class="LC_warning">'.
8817: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8818: '</span>';
1.100 raeburn 8819: }
8820: }
8821: }
8822: }
1.43 raeburn 8823: }
1.160.6.44 raeburn 8824: } elsif ($type eq 'shibenv') {
8825: if (keys(%{$cancreate{$type}}) == 0) {
8826: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8827: } else {
8828: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8829: '<ul>';
8830: foreach my $field (@shibfields) {
8831: next if ($cancreate{$type}{$field} eq '');
8832: if ($field eq 'inststatus') {
8833: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8834: } else {
8835: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8836: }
8837: }
8838: $chgtext .= '</ul>';
8839: }
1.93 raeburn 8840: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8841: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8842: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8843: if (@{$cancreate{'selfcreate'}} > 0) {
8844: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8845: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8846: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8847: $chgtext .= '<br />'.
8848: '<span class="LC_warning">'.
8849: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8850: '</span>';
8851: }
1.96 raeburn 8852: } elsif (ref($usertypes) eq 'HASH') {
8853: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8854: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8855: } else {
8856: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8857: }
8858: $chgtext .= '<ul>';
8859: foreach my $case (@{$cancreate{$type}}) {
8860: if ($case eq 'default') {
8861: $chgtext .= '<li>'.$othertitle.'</li>';
8862: } else {
8863: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8864: }
8865: }
1.100 raeburn 8866: $chgtext .= '</ul>';
8867: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8868: $chgtext .= '<br /><span class="LC_warning">'.
8869: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8870: '</span>';
1.100 raeburn 8871: }
8872: }
8873: } else {
8874: if (@{$cancreate{$type}} == 0) {
8875: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8876: } else {
8877: $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 8878: }
8879: }
8880: }
1.160.6.40 raeburn 8881: } elsif ($type eq 'selfcreateprocessing') {
8882: my %choices = &Apache::lonlocal::texthash (
8883: automatic => 'Automatic approval',
8884: approval => 'Queued for approval',
8885: );
8886: if (@statuses > 1) {
8887: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8888: '<ul>';
8889: foreach my $type (@statuses) {
8890: if ($type eq 'default') {
8891: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8892: } else {
8893: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8894: }
8895: }
8896: $chgtext .= '</ul>';
8897: } else {
8898: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8899: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8900: }
1.160.6.5 raeburn 8901: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8902: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8903: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8904: } else {
8905: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8906: if ($captchas{$savecaptcha{$type}}) {
8907: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8908: } else {
8909: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8910: }
8911: }
8912: } elsif ($type eq 'recaptchakeys') {
8913: my ($privkey,$pubkey);
1.160.6.34 raeburn 8914: if (ref($savecaptcha{$type}) eq 'HASH') {
8915: $pubkey = $savecaptcha{$type}{'public'};
8916: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8917: }
8918: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8919: if (!$pubkey) {
8920: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8921: } else {
8922: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8923: }
8924: if (!$privkey) {
8925: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8926: } else {
8927: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8928: }
8929: $chgtext .= '</ul>';
1.160.6.34 raeburn 8930: } elsif ($type eq 'emailusername') {
8931: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8932: if (ref($types) eq 'ARRAY') {
8933: foreach my $type (@{$types}) {
8934: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8935: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50! raeburn 8936: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 8937: '<ul>';
8938: foreach my $field (@{$infofields}) {
8939: if ($cancreate{'emailusername'}{$type}{$field}) {
8940: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8941: }
8942: }
1.160.6.50! raeburn 8943: $chgtext .= '</ul>';
! 8944: } else {
! 8945: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35 raeburn 8946: }
8947: } else {
1.160.6.50! raeburn 8948: $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 8949: }
8950: }
8951: }
8952: }
8953: } elsif ($type eq 'notify') {
8954: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8955: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8956: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8957: if ($cancreate{'notify'}{'approval'}) {
8958: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8959: }
8960: }
1.43 raeburn 8961: }
1.34 raeburn 8962: }
1.160.6.34 raeburn 8963: if ($chgtext) {
8964: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8965: }
8966: }
8967: }
1.43 raeburn 8968: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8969: my ($emailrules,$emailruleorder) =
8970: &Apache::lonnet::inst_userrules($dom,'email');
8971: my $chgtext = '<ul>';
8972: foreach my $type (@email_rule) {
8973: if (ref($emailrules->{$type}) eq 'HASH') {
8974: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8975: }
8976: }
8977: $chgtext .= '</ul>';
8978: if (@email_rule > 0) {
1.160.6.34 raeburn 8979: $resulttext .= '<li>'.
8980: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8981: $chgtext.
8982: '</li>';
1.43 raeburn 8983: } else {
1.160.6.34 raeburn 8984: $resulttext .= '<li>'.
8985: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8986: '</li>';
1.43 raeburn 8987: }
8988: }
1.160.6.34 raeburn 8989: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8990: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8991: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8992: foreach my $type (@{$changes{'selfcreate'}}) {
8993: my $typename = $type;
8994: if (ref($usertypes) eq 'HASH') {
8995: if ($usertypes->{$type} ne '') {
8996: $typename = $usertypes->{$type};
1.28 raeburn 8997: }
8998: }
1.160.6.34 raeburn 8999: my @modifiable;
9000: $resulttext .= '<li>'.
9001: &mt('Self-creation of account by users with status: [_1]',
9002: '<span class="LC_cusr_emph">'.$typename.'</span>').
9003: ' - '.&mt('modifiable fields (if institutional data blank): ');
9004: foreach my $field (@fields) {
9005: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9006: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9007: }
9008: }
9009: if (@modifiable > 0) {
9010: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9011: } else {
1.160.6.34 raeburn 9012: $resulttext .= &mt('none');
1.43 raeburn 9013: }
1.160.6.34 raeburn 9014: $resulttext .= '</li>';
1.28 raeburn 9015: }
1.160.6.34 raeburn 9016: $resulttext .= '</ul></li>';
1.28 raeburn 9017: }
1.27 raeburn 9018: $resulttext .= '</ul>';
9019: } else {
1.160.6.34 raeburn 9020: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9021: }
9022: } else {
9023: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9024: &mt('An error occurred: [_1]',$putresult).'</span>';
9025: }
1.43 raeburn 9026: if ($warningmsg ne '') {
9027: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9028: }
1.23 raeburn 9029: return $resulttext;
9030: }
9031:
1.160.6.5 raeburn 9032: sub process_captcha {
9033: my ($container,$changes,$newsettings,$current) = @_;
9034: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9035: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9036: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9037: $newsettings->{'captcha'} = 'original';
9038: }
9039: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9040: if ($container eq 'cancreate') {
9041: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9042: push(@{$changes->{'cancreate'}},'captcha');
9043: } elsif (!defined($changes->{'cancreate'})) {
9044: $changes->{'cancreate'} = ['captcha'];
9045: }
9046: } else {
9047: $changes->{'captcha'} = 1;
9048: }
9049: }
9050: my ($newpub,$newpriv,$currpub,$currpriv);
9051: if ($newsettings->{'captcha'} eq 'recaptcha') {
9052: $newpub = $env{'form.'.$container.'_recaptchapub'};
9053: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9054: $newpub =~ s/\W//g;
9055: $newpriv =~ s/\W//g;
9056: $newsettings->{'recaptchakeys'} = {
9057: public => $newpub,
9058: private => $newpriv,
9059: };
9060: }
9061: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9062: $currpub = $current->{'recaptchakeys'}{'public'};
9063: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9064: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9065: $newsettings->{'recaptchakeys'} = {
9066: public => '',
9067: private => '',
9068: }
9069: }
1.160.6.5 raeburn 9070: }
9071: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9072: if ($container eq 'cancreate') {
9073: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9074: push(@{$changes->{'cancreate'}},'recaptchakeys');
9075: } elsif (!defined($changes->{'cancreate'})) {
9076: $changes->{'cancreate'} = ['recaptchakeys'];
9077: }
9078: } else {
9079: $changes->{'recaptchakeys'} = 1;
9080: }
9081: }
9082: return;
9083: }
9084:
1.33 raeburn 9085: sub modify_usermodification {
9086: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9087: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9088: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9089: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9090: if ($key eq 'selfcreate') {
9091: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9092: } else {
9093: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9094: }
1.33 raeburn 9095: }
9096: }
1.160.6.34 raeburn 9097: my @contexts = ('author','course');
1.33 raeburn 9098: my %context_title = (
9099: author => 'In author context',
9100: course => 'In course context',
9101: );
9102: my @fields = ('lastname','firstname','middlename','generation',
9103: 'permanentemail','id');
9104: my %roles = (
9105: author => ['ca','aa'],
9106: course => ['st','ep','ta','in','cr'],
9107: );
9108: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9109: foreach my $context (@contexts) {
9110: foreach my $role (@{$roles{$context}}) {
9111: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9112: foreach my $item (@fields) {
9113: if (grep(/^\Q$item\E$/,@modifiable)) {
9114: $modifyhash{$context}{$role}{$item} = 1;
9115: } else {
9116: $modifyhash{$context}{$role}{$item} = 0;
9117: }
9118: }
9119: }
9120: if (ref($curr_usermodification{$context}) eq 'HASH') {
9121: foreach my $role (@{$roles{$context}}) {
9122: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9123: foreach my $field (@fields) {
9124: if ($modifyhash{$context}{$role}{$field} ne
9125: $curr_usermodification{$context}{$role}{$field}) {
9126: push(@{$changes{$context}},$role);
9127: last;
9128: }
9129: }
9130: }
9131: }
9132: } else {
9133: foreach my $context (@contexts) {
9134: foreach my $role (@{$roles{$context}}) {
9135: push(@{$changes{$context}},$role);
9136: }
9137: }
9138: }
9139: }
9140: my %usermodification_hash = (
9141: usermodification => \%modifyhash,
9142: );
9143: my $putresult = &Apache::lonnet::put_dom('configuration',
9144: \%usermodification_hash,$dom);
9145: if ($putresult eq 'ok') {
9146: if (keys(%changes) > 0) {
9147: $resulttext = &mt('Changes made: ').'<ul>';
9148: foreach my $context (@contexts) {
9149: if (ref($changes{$context}) eq 'ARRAY') {
9150: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9151: if (ref($changes{$context}) eq 'ARRAY') {
9152: foreach my $role (@{$changes{$context}}) {
9153: my $rolename;
1.160.6.34 raeburn 9154: if ($role eq 'cr') {
9155: $rolename = &mt('Custom');
1.33 raeburn 9156: } else {
1.160.6.34 raeburn 9157: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9158: }
9159: my @modifiable;
1.160.6.34 raeburn 9160: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9161: foreach my $field (@fields) {
9162: if ($modifyhash{$context}{$role}{$field}) {
9163: push(@modifiable,$fieldtitles{$field});
9164: }
9165: }
9166: if (@modifiable > 0) {
9167: $resulttext .= join(', ',@modifiable);
9168: } else {
9169: $resulttext .= &mt('none');
9170: }
9171: $resulttext .= '</li>';
9172: }
9173: $resulttext .= '</ul></li>';
9174: }
9175: }
9176: }
9177: $resulttext .= '</ul>';
9178: } else {
9179: $resulttext = &mt('No changes made to user modification settings');
9180: }
9181: } else {
9182: $resulttext = '<span class="LC_error">'.
9183: &mt('An error occurred: [_1]',$putresult).'</span>';
9184: }
9185: return $resulttext;
9186: }
9187:
1.43 raeburn 9188: sub modify_defaults {
1.160.6.27 raeburn 9189: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9190: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9191: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9192: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9193: my @authtypes = ('internal','krb4','krb5','localauth');
9194: foreach my $item (@items) {
9195: $newvalues{$item} = $env{'form.'.$item};
9196: if ($item eq 'auth_def') {
9197: if ($newvalues{$item} ne '') {
9198: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9199: push(@errors,$item);
9200: }
9201: }
9202: } elsif ($item eq 'lang_def') {
9203: if ($newvalues{$item} ne '') {
9204: if ($newvalues{$item} =~ /^(\w+)/) {
9205: my $langcode = $1;
1.103 raeburn 9206: if ($langcode ne 'x_chef') {
9207: if (code2language($langcode) eq '') {
9208: push(@errors,$item);
9209: }
1.43 raeburn 9210: }
9211: } else {
9212: push(@errors,$item);
9213: }
9214: }
1.54 raeburn 9215: } elsif ($item eq 'timezone_def') {
9216: if ($newvalues{$item} ne '') {
1.62 raeburn 9217: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9218: push(@errors,$item);
9219: }
9220: }
1.68 raeburn 9221: } elsif ($item eq 'datelocale_def') {
9222: if ($newvalues{$item} ne '') {
9223: my @datelocale_ids = DateTime::Locale->ids();
9224: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9225: push(@errors,$item);
9226: }
9227: }
1.141 raeburn 9228: } elsif ($item eq 'portal_def') {
9229: if ($newvalues{$item} ne '') {
9230: 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])\/?$/) {
9231: push(@errors,$item);
9232: }
9233: }
1.43 raeburn 9234: }
9235: if (grep(/^\Q$item\E$/,@errors)) {
9236: $newvalues{$item} = $domdefaults{$item};
9237: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9238: $changes{$item} = 1;
9239: }
1.72 raeburn 9240: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9241: }
9242: my %defaults_hash = (
1.72 raeburn 9243: defaults => \%newvalues,
9244: );
1.43 raeburn 9245: my $title = &defaults_titles();
1.160.6.40 raeburn 9246:
9247: my $currinststatus;
9248: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9249: $currinststatus = $domconfig{'inststatus'};
9250: } else {
9251: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9252: $currinststatus = {
9253: inststatustypes => $usertypes,
9254: inststatusorder => $types,
9255: inststatusguest => [],
9256: };
9257: }
9258: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9259: my @allpos;
9260: my %guests;
9261: my %alltypes;
9262: my ($currtitles,$currguests,$currorder);
9263: if (ref($currinststatus) eq 'HASH') {
9264: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9265: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9266: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9267: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9268: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9269: }
9270: }
9271: unless (grep(/^\Q$type\E$/,@todelete)) {
9272: my $position = $env{'form.inststatus_pos_'.$type};
9273: $position =~ s/\D+//g;
9274: $allpos[$position] = $type;
9275: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9276: $alltypes{$type} =~ s/`//g;
9277: if ($env{'form.inststatus_guest_'.$type}) {
9278: $guests{$type} = 1;
9279: }
9280: }
9281: }
9282: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9283: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9284: }
9285: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9286: $currtitles =~ s/,$//;
9287: }
9288: }
9289: if ($env{'form.addinststatus'}) {
9290: my $newtype = $env{'form.addinststatus'};
9291: $newtype =~ s/\W//g;
9292: unless (exists($alltypes{$newtype})) {
9293: if ($env{'form.addinststatus_guest'}) {
9294: $guests{$newtype} = 1;
9295: }
9296: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9297: $alltypes{$newtype} =~ s/`//g;
9298: my $position = $env{'form.addinststatus_pos'};
9299: $position =~ s/\D+//g;
9300: if ($position ne '') {
9301: $allpos[$position] = $newtype;
9302: }
9303: }
9304: }
9305: my (@orderedstatus,@orderedguests);
9306: foreach my $type (@allpos) {
9307: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9308: push(@orderedstatus,$type);
9309: if ($guests{$type}) {
9310: push(@orderedguests,$type);
9311: }
9312: }
9313: }
9314: foreach my $type (keys(%alltypes)) {
9315: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9316: delete($alltypes{$type});
9317: }
9318: }
9319: $defaults_hash{'inststatus'} = {
9320: inststatustypes => \%alltypes,
9321: inststatusorder => \@orderedstatus,
9322: inststatusguest => \@orderedguests,
9323: };
9324: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9325: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9326: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9327: }
9328: }
9329: if ($currorder ne join(',',@orderedstatus)) {
9330: $changes{'inststatus'}{'inststatusorder'} = 1;
9331: }
9332: if ($currguests ne join(',',@orderedguests)) {
9333: $changes{'inststatus'}{'inststatusguest'} = 1;
9334: }
9335: my $newtitles;
9336: foreach my $item (@orderedstatus) {
9337: $newtitles .= $alltypes{$item}.',';
9338: }
9339: $newtitles =~ s/,$//;
9340: if ($currtitles ne $newtitles) {
9341: $changes{'inststatus'}{'inststatustypes'} = 1;
9342: }
1.43 raeburn 9343: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9344: $dom);
9345: if ($putresult eq 'ok') {
9346: if (keys(%changes) > 0) {
9347: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9348: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9349: 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";
9350: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9351: if ($item eq 'inststatus') {
9352: if (ref($changes{'inststatus'}) eq 'HASH') {
9353: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9354: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9355: foreach my $type (@orderedstatus) {
9356: $resulttext .= $alltypes{$type}.', ';
9357: }
9358: $resulttext =~ s/, $//;
9359: $resulttext .= '</li>';
9360: }
9361: if ($changes{'inststatus'}{'inststatusguest'}) {
9362: $resulttext .= '<li>';
9363: if (@orderedguests) {
9364: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9365: foreach my $type (@orderedguests) {
9366: $resulttext .= $alltypes{$type}.', ';
9367: }
9368: $resulttext =~ s/, $//;
9369: } else {
9370: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9371: }
9372: $resulttext .= '</li>';
9373: }
9374: }
9375: } else {
9376: my $value = $env{'form.'.$item};
9377: if ($value eq '') {
9378: $value = &mt('none');
9379: } elsif ($item eq 'auth_def') {
9380: my %authnames = &authtype_names();
9381: my %shortauth = (
9382: internal => 'int',
9383: krb4 => 'krb4',
9384: krb5 => 'krb5',
9385: localauth => 'loc',
9386: );
9387: $value = $authnames{$shortauth{$value}};
9388: }
9389: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9390: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9391: }
9392: }
9393: $resulttext .= '</ul>';
9394: $mailmsgtext .= "\n";
9395: my $cachetime = 24*60*60;
1.72 raeburn 9396: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9397: if (ref($lastactref) eq 'HASH') {
9398: $lastactref->{'domdefaults'} = 1;
9399: }
1.68 raeburn 9400: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9401: my $notify = 1;
9402: if (ref($domconfig{'contacts'}) eq 'HASH') {
9403: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9404: $notify = 0;
9405: }
9406: }
9407: if ($notify) {
9408: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9409: "LON-CAPA Domain Settings Change - $dom",
9410: $mailmsgtext);
9411: }
1.54 raeburn 9412: }
1.43 raeburn 9413: } else {
1.54 raeburn 9414: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9415: }
9416: } else {
9417: $resulttext = '<span class="LC_error">'.
9418: &mt('An error occurred: [_1]',$putresult).'</span>';
9419: }
9420: if (@errors > 0) {
9421: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9422: foreach my $item (@errors) {
9423: $resulttext .= ' "'.$title->{$item}.'",';
9424: }
9425: $resulttext =~ s/,$//;
9426: }
9427: return $resulttext;
9428: }
9429:
1.46 raeburn 9430: sub modify_scantron {
1.160.6.24 raeburn 9431: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9432: my ($resulttext,%confhash,%changes,$errors);
9433: my $custom = 'custom.tab';
9434: my $default = 'default.tab';
9435: my $servadm = $r->dir_config('lonAdmEMail');
9436: my ($configuserok,$author_ok,$switchserver) =
9437: &config_check($dom,$confname,$servadm);
9438: if ($env{'form.scantronformat.filename'} ne '') {
9439: my $error;
9440: if ($configuserok eq 'ok') {
9441: if ($switchserver) {
1.130 raeburn 9442: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9443: } else {
9444: if ($author_ok eq 'ok') {
9445: my ($result,$scantronurl) =
9446: &publishlogo($r,'upload','scantronformat',$dom,
9447: $confname,'scantron','','',$custom);
9448: if ($result eq 'ok') {
9449: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9450: $changes{'scantronformat'} = 1;
1.46 raeburn 9451: } else {
9452: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9453: }
9454: } else {
9455: $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);
9456: }
9457: }
9458: } else {
9459: $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);
9460: }
9461: if ($error) {
9462: &Apache::lonnet::logthis($error);
9463: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9464: }
9465: }
1.48 raeburn 9466: if (ref($domconfig{'scantron'}) eq 'HASH') {
9467: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9468: if ($env{'form.scantronformat_del'}) {
9469: $confhash{'scantron'}{'scantronformat'} = '';
9470: $changes{'scantronformat'} = 1;
1.46 raeburn 9471: }
9472: }
9473: }
9474: if (keys(%confhash) > 0) {
9475: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9476: $dom);
9477: if ($putresult eq 'ok') {
9478: if (keys(%changes) > 0) {
1.48 raeburn 9479: if (ref($confhash{'scantron'}) eq 'HASH') {
9480: $resulttext = &mt('Changes made:').'<ul>';
9481: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9482: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9483: } else {
1.130 raeburn 9484: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9485: }
1.48 raeburn 9486: $resulttext .= '</ul>';
9487: } else {
1.130 raeburn 9488: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9489: }
9490: $resulttext .= '</ul>';
9491: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9492: if (ref($lastactref) eq 'HASH') {
9493: $lastactref->{'domainconfig'} = 1;
9494: }
1.46 raeburn 9495: } else {
1.130 raeburn 9496: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9497: }
9498: } else {
9499: $resulttext = '<span class="LC_error">'.
9500: &mt('An error occurred: [_1]',$putresult).'</span>';
9501: }
9502: } else {
1.130 raeburn 9503: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9504: }
9505: if ($errors) {
9506: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9507: $errors.'</ul>';
9508: }
9509: return $resulttext;
9510: }
9511:
1.48 raeburn 9512: sub modify_coursecategories {
1.160.6.43 raeburn 9513: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9514: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9515: $cathash);
1.48 raeburn 9516: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9517: my @catitems = ('unauth','auth');
9518: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9519: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9520: $cathash = $domconfig{'coursecategories'}{'cats'};
9521: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9522: $changes{'togglecats'} = 1;
9523: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9524: }
9525: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9526: $changes{'categorize'} = 1;
9527: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9528: }
1.120 raeburn 9529: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9530: $changes{'togglecatscomm'} = 1;
9531: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9532: }
9533: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9534: $changes{'categorizecomm'} = 1;
9535: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9536: }
1.160.6.42 raeburn 9537: foreach my $item (@catitems) {
9538: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9539: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9540: $changes{$item} = 1;
9541: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9542: }
9543: }
9544: }
1.57 raeburn 9545: } else {
9546: $changes{'togglecats'} = 1;
9547: $changes{'categorize'} = 1;
1.124 raeburn 9548: $changes{'togglecatscomm'} = 1;
9549: $changes{'categorizecomm'} = 1;
1.87 raeburn 9550: $domconfig{'coursecategories'} = {
9551: togglecats => $env{'form.togglecats'},
9552: categorize => $env{'form.categorize'},
1.124 raeburn 9553: togglecatscomm => $env{'form.togglecatscomm'},
9554: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9555: };
1.160.6.42 raeburn 9556: foreach my $item (@catitems) {
9557: if ($env{'form.coursecat_'.$item} ne 'std') {
9558: $changes{$item} = 1;
9559: }
9560: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9561: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9562: }
9563: }
1.57 raeburn 9564: }
9565: if (ref($cathash) eq 'HASH') {
9566: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9567: push (@deletecategory,'instcode::0');
9568: }
1.120 raeburn 9569: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9570: push(@deletecategory,'communities::0');
9571: }
1.48 raeburn 9572: }
1.57 raeburn 9573: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9574: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9575: if (@deletecategory > 0) {
9576: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9577: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9578: foreach my $item (@deletecategory) {
1.57 raeburn 9579: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9580: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9581: $deletions{$item} = 1;
1.57 raeburn 9582: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9583: }
9584: }
9585: }
1.57 raeburn 9586: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9587: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9588: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9589: $reorderings{$item} = 1;
1.57 raeburn 9590: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9591: }
9592: if ($env{'form.addcategory_name_'.$item} ne '') {
9593: my $newcat = $env{'form.addcategory_name_'.$item};
9594: my $newdepth = $depth+1;
9595: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9596: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9597: $adds{$newitem} = 1;
9598: }
9599: if ($env{'form.subcat_'.$item} ne '') {
9600: my $newcat = $env{'form.subcat_'.$item};
9601: my $newdepth = $depth+1;
9602: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9603: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9604: $adds{$newitem} = 1;
9605: }
9606: }
9607: }
9608: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9609: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9610: my $newitem = 'instcode::0';
1.57 raeburn 9611: if ($cathash->{$newitem} eq '') {
9612: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9613: $adds{$newitem} = 1;
9614: }
9615: } else {
9616: my $newitem = 'instcode::0';
1.57 raeburn 9617: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9618: $adds{$newitem} = 1;
9619: }
9620: }
1.120 raeburn 9621: if ($env{'form.communities'} eq '1') {
9622: if (ref($cathash) eq 'HASH') {
9623: my $newitem = 'communities::0';
9624: if ($cathash->{$newitem} eq '') {
9625: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9626: $adds{$newitem} = 1;
9627: }
9628: } else {
9629: my $newitem = 'communities::0';
9630: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9631: $adds{$newitem} = 1;
9632: }
9633: }
1.48 raeburn 9634: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9635: if (($env{'form.addcategory_name'} ne 'instcode') &&
9636: ($env{'form.addcategory_name'} ne 'communities')) {
9637: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9638: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9639: $adds{$newitem} = 1;
9640: }
1.48 raeburn 9641: }
1.57 raeburn 9642: my $putresult;
1.48 raeburn 9643: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9644: if (keys(%deletions) > 0) {
9645: foreach my $key (keys(%deletions)) {
9646: if ($predelallitems{$key} ne '') {
9647: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9648: }
9649: }
9650: }
9651: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9652: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9653: if (ref($chkcats[0]) eq 'ARRAY') {
9654: my $depth = 0;
9655: my $chg = 0;
9656: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9657: my $name = $chkcats[0][$i];
9658: my $item;
9659: if ($name eq '') {
9660: $chg ++;
9661: } else {
9662: $item = &escape($name).'::0';
9663: if ($chg) {
1.57 raeburn 9664: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9665: }
9666: $depth ++;
1.57 raeburn 9667: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9668: $depth --;
9669: }
9670: }
9671: }
1.57 raeburn 9672: }
9673: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9674: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9675: if ($putresult eq 'ok') {
1.57 raeburn 9676: my %title = (
1.120 raeburn 9677: togglecats => 'Show/Hide a course in catalog',
9678: categorize => 'Assign a category to a course',
9679: togglecatscomm => 'Show/Hide a community in catalog',
9680: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9681: );
9682: my %level = (
1.120 raeburn 9683: dom => 'set in Domain ("Modify Course/Community")',
9684: crs => 'set in Course ("Course Configuration")',
9685: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9686: none => 'No catalog',
9687: std => 'Standard catalog',
9688: domonly => 'Domain-only catalog',
9689: codesrch => 'Code search form',
1.57 raeburn 9690: );
1.48 raeburn 9691: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9692: if ($changes{'togglecats'}) {
9693: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9694: }
9695: if ($changes{'categorize'}) {
9696: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9697: }
1.120 raeburn 9698: if ($changes{'togglecatscomm'}) {
9699: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9700: }
9701: if ($changes{'categorizecomm'}) {
9702: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9703: }
1.160.6.42 raeburn 9704: if ($changes{'unauth'}) {
9705: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9706: }
9707: if ($changes{'auth'}) {
9708: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9709: }
1.57 raeburn 9710: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9711: my $cathash;
9712: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9713: $cathash = $domconfig{'coursecategories'}{'cats'};
9714: } else {
9715: $cathash = {};
9716: }
9717: my (@cats,@trails,%allitems);
9718: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9719: if (keys(%deletions) > 0) {
9720: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9721: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9722: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9723: }
9724: $resulttext .= '</ul></li>';
9725: }
9726: if (keys(%reorderings) > 0) {
9727: my %sort_by_trail;
9728: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9729: foreach my $key (keys(%reorderings)) {
9730: if ($allitems{$key} ne '') {
9731: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9732: }
1.48 raeburn 9733: }
1.57 raeburn 9734: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9735: $resulttext .= '<li>'.$trails[$trail].'</li>';
9736: }
9737: $resulttext .= '</ul></li>';
1.48 raeburn 9738: }
1.57 raeburn 9739: if (keys(%adds) > 0) {
9740: my %sort_by_trail;
9741: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9742: foreach my $key (keys(%adds)) {
9743: if ($allitems{$key} ne '') {
9744: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9745: }
9746: }
9747: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9748: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9749: }
1.57 raeburn 9750: $resulttext .= '</ul></li>';
1.48 raeburn 9751: }
9752: }
9753: $resulttext .= '</ul>';
1.160.6.43 raeburn 9754: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50! raeburn 9755: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
! 9756: if ($changes{'auth'}) {
! 9757: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
! 9758: }
! 9759: if ($changes{'unauth'}) {
! 9760: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
! 9761: }
! 9762: my $cachetime = 24*60*60;
! 9763: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 9764: if (ref($lastactref) eq 'HASH') {
1.160.6.50! raeburn 9765: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 9766: }
9767: }
1.48 raeburn 9768: } else {
9769: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9770: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9771: }
9772: } else {
1.120 raeburn 9773: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9774: }
9775: return $resulttext;
9776: }
9777:
1.69 raeburn 9778: sub modify_serverstatuses {
9779: my ($dom,%domconfig) = @_;
9780: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9781: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9782: %currserverstatus = %{$domconfig{'serverstatuses'}};
9783: }
9784: my @pages = &serverstatus_pages();
9785: foreach my $type (@pages) {
9786: $newserverstatus{$type}{'namedusers'} = '';
9787: $newserverstatus{$type}{'machines'} = '';
9788: if (defined($env{'form.'.$type.'_namedusers'})) {
9789: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9790: my @okusers;
9791: foreach my $user (@users) {
9792: my ($uname,$udom) = split(/:/,$user);
9793: if (($udom =~ /^$match_domain$/) &&
9794: (&Apache::lonnet::domain($udom)) &&
9795: ($uname =~ /^$match_username$/)) {
9796: if (!grep(/^\Q$user\E/,@okusers)) {
9797: push(@okusers,$user);
9798: }
9799: }
9800: }
9801: if (@okusers > 0) {
9802: @okusers = sort(@okusers);
9803: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9804: }
9805: }
9806: if (defined($env{'form.'.$type.'_machines'})) {
9807: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9808: my @okmachines;
9809: foreach my $ip (@machines) {
9810: my @parts = split(/\./,$ip);
9811: next if (@parts < 4);
9812: my $badip = 0;
9813: for (my $i=0; $i<4; $i++) {
9814: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9815: $badip = 1;
9816: last;
9817: }
9818: }
9819: if (!$badip) {
9820: push(@okmachines,$ip);
9821: }
9822: }
9823: @okmachines = sort(@okmachines);
9824: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9825: }
9826: }
9827: my %serverstatushash = (
9828: serverstatuses => \%newserverstatus,
9829: );
9830: foreach my $type (@pages) {
1.83 raeburn 9831: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9832: my (@current,@new);
1.83 raeburn 9833: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9834: if ($currserverstatus{$type}{$setting} ne '') {
9835: @current = split(/,/,$currserverstatus{$type}{$setting});
9836: }
9837: }
9838: if ($newserverstatus{$type}{$setting} ne '') {
9839: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9840: }
9841: if (@current > 0) {
9842: if (@new > 0) {
9843: foreach my $item (@current) {
9844: if (!grep(/^\Q$item\E$/,@new)) {
9845: $changes{$type}{$setting} = 1;
1.82 raeburn 9846: last;
9847: }
9848: }
1.84 raeburn 9849: foreach my $item (@new) {
9850: if (!grep(/^\Q$item\E$/,@current)) {
9851: $changes{$type}{$setting} = 1;
9852: last;
1.82 raeburn 9853: }
9854: }
9855: } else {
1.83 raeburn 9856: $changes{$type}{$setting} = 1;
1.69 raeburn 9857: }
1.83 raeburn 9858: } elsif (@new > 0) {
9859: $changes{$type}{$setting} = 1;
1.69 raeburn 9860: }
9861: }
9862: }
9863: if (keys(%changes) > 0) {
1.81 raeburn 9864: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9865: my $putresult = &Apache::lonnet::put_dom('configuration',
9866: \%serverstatushash,$dom);
9867: if ($putresult eq 'ok') {
9868: $resulttext .= &mt('Changes made:').'<ul>';
9869: foreach my $type (@pages) {
1.84 raeburn 9870: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9871: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9872: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9873: if ($newserverstatus{$type}{'namedusers'} eq '') {
9874: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9875: } else {
9876: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9877: }
1.84 raeburn 9878: }
9879: if ($changes{$type}{'machines'}) {
1.69 raeburn 9880: if ($newserverstatus{$type}{'machines'} eq '') {
9881: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9882: } else {
9883: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9884: }
9885:
9886: }
9887: $resulttext .= '</ul></li>';
9888: }
9889: }
9890: $resulttext .= '</ul>';
9891: } else {
9892: $resulttext = '<span class="LC_error">'.
9893: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9894:
9895: }
9896: } else {
9897: $resulttext = &mt('No changes made to access to server status pages');
9898: }
9899: return $resulttext;
9900: }
9901:
1.118 jms 9902: sub modify_helpsettings {
1.122 jms 9903: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9904: my ($resulttext,$errors,%changes,%helphash);
9905: my %defaultchecked = ('submitbugs' => 'on');
9906: my @offon = ('off','on');
1.118 jms 9907: my @toggles = ('submitbugs');
9908: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9909: foreach my $item (@toggles) {
1.160.6.5 raeburn 9910: if ($defaultchecked{$item} eq 'on') {
9911: if ($domconfig{'helpsettings'}{$item} eq '') {
9912: if ($env{'form.'.$item} eq '0') {
9913: $changes{$item} = 1;
9914: }
9915: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9916: $changes{$item} = 1;
9917: }
9918: } elsif ($defaultchecked{$item} eq 'off') {
9919: if ($domconfig{'helpsettings'}{$item} eq '') {
9920: if ($env{'form.'.$item} eq '1') {
9921: $changes{$item} = 1;
9922: }
9923: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9924: $changes{$item} = 1;
9925: }
1.160.6.26 raeburn 9926: }
1.160.6.5 raeburn 9927: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9928: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9929: }
9930: }
1.118 jms 9931: }
1.123 jms 9932: my $putresult;
9933: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9934: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9935: if ($putresult eq 'ok') {
9936: $resulttext = &mt('Changes made:').'<ul>';
9937: foreach my $item (sort(keys(%changes))) {
9938: if ($item eq 'submitbugs') {
9939: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9940: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9941: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9942: }
9943: }
9944: $resulttext .= '</ul>';
9945: } else {
9946: $resulttext = &mt('No changes made to help settings');
9947: $errors .= '<li><span class="LC_error">'.
9948: &mt('An error occurred storing the settings: [_1]',
9949: $putresult).'</span></li>';
9950: }
1.118 jms 9951: }
9952: if ($errors) {
1.160.6.5 raeburn 9953: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9954: $errors.'</ul>';
9955: }
9956: return $resulttext;
9957: }
9958:
1.121 raeburn 9959: sub modify_coursedefaults {
1.160.6.27 raeburn 9960: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9961: my ($resulttext,$errors,%changes,%defaultshash);
9962: my %defaultchecked = ('canuse_pdfforms' => 'off');
9963: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9964: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9965: 'uploadquota_community','uploadquota_textbook');
9966: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9967: my %staticdefaults = (
9968: anonsurvey_threshold => 10,
9969: uploadquota => 500,
9970: );
1.121 raeburn 9971:
9972: $defaultshash{'coursedefaults'} = {};
9973:
9974: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9975: if ($domconfig{'coursedefaults'} eq '') {
9976: $domconfig{'coursedefaults'} = {};
9977: }
9978: }
9979:
9980: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9981: foreach my $item (@toggles) {
9982: if ($defaultchecked{$item} eq 'on') {
9983: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9984: ($env{'form.'.$item} eq '0')) {
9985: $changes{$item} = 1;
1.160.6.16 raeburn 9986: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9987: $changes{$item} = 1;
9988: }
9989: } elsif ($defaultchecked{$item} eq 'off') {
9990: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9991: ($env{'form.'.$item} eq '1')) {
9992: $changes{$item} = 1;
9993: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9994: $changes{$item} = 1;
9995: }
9996: }
9997: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9998: }
1.160.6.21 raeburn 9999: foreach my $item (@numbers) {
10000: my ($currdef,$newdef);
1.160.6.26 raeburn 10001: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10002: if ($item eq 'anonsurvey_threshold') {
10003: $currdef = $domconfig{'coursedefaults'}{$item};
10004: $newdef =~ s/\D//g;
10005: if ($newdef eq '' || $newdef < 1) {
10006: $newdef = 1;
10007: }
10008: $defaultshash{'coursedefaults'}{$item} = $newdef;
10009: } else {
10010: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10011: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10012: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10013: }
10014: $newdef =~ s/[^\w.\-]//g;
10015: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10016: }
10017: if ($currdef ne $newdef) {
10018: my $staticdef;
10019: if ($item eq 'anonsurvey_threshold') {
10020: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10021: $changes{$item} = 1;
10022: }
10023: } else {
10024: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10025: $changes{'uploadquota'} = 1;
10026: }
10027: }
1.139 raeburn 10028: }
10029: }
1.160.6.37 raeburn 10030:
1.160.6.16 raeburn 10031: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 10032: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10033: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 10034: $unofficialcreds =~ s/[^\d.]+//g;
10035: my $textbookcreds = $env{'form.textbook_credits'};
10036: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10037: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10038: ($env{'form.coursecredits'} eq '1')) {
10039: $changes{'coursecredits'} = 1;
10040: } else {
10041: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 10042: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10043: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 10044: $changes{'coursecredits'} = 1;
10045: }
10046: }
10047: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10048: official => $officialcreds,
10049: unofficial => $unofficialcreds,
1.160.6.30 raeburn 10050: textbook => $textbookcreds,
1.160.6.16 raeburn 10051: }
1.121 raeburn 10052: }
10053: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10054: $dom);
10055: if ($putresult eq 'ok') {
10056: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10057: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 10058: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
10059: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 10060: if ($changes{'canuse_pdfforms'}) {
10061: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10062: }
10063: if ($changes{'coursecredits'}) {
10064: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10065: $domdefaults{'officialcredits'} =
10066: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10067: $domdefaults{'unofficialcredits'} =
10068: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 10069: $domdefaults{'textbookcredits'} =
10070: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 10071: }
10072: }
1.160.6.21 raeburn 10073: if ($changes{'uploadquota'}) {
10074: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10075: foreach my $type (@types) {
10076: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10077: }
10078: }
10079: }
1.121 raeburn 10080: my $cachetime = 24*60*60;
10081: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10082: if (ref($lastactref) eq 'HASH') {
10083: $lastactref->{'domdefaults'} = 1;
10084: }
1.121 raeburn 10085: }
10086: $resulttext = &mt('Changes made:').'<ul>';
10087: foreach my $item (sort(keys(%changes))) {
10088: if ($item eq 'canuse_pdfforms') {
10089: if ($env{'form.'.$item} eq '1') {
10090: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10091: } else {
10092: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10093: }
1.139 raeburn 10094: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10095: $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 10096: } elsif ($item eq 'uploadquota') {
10097: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10098: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10099: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10100: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10101: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10102:
1.160.6.21 raeburn 10103: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10104: '</ul>'.
10105: '</li>';
10106: } else {
10107: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10108: }
1.160.6.16 raeburn 10109: } elsif ($item eq 'coursecredits') {
10110: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10111: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10112: ($domdefaults{'unofficialcredits'} eq '') &&
10113: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10114: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10115: } else {
10116: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10117: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10118: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10119: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10120: '</ul>'.
10121: '</li>';
10122: }
10123: } else {
10124: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10125: }
1.140 raeburn 10126: }
1.121 raeburn 10127: }
10128: $resulttext .= '</ul>';
10129: } else {
10130: $resulttext = &mt('No changes made to course defaults');
10131: }
10132: } else {
10133: $resulttext = '<span class="LC_error">'.
10134: &mt('An error occurred: [_1]',$putresult).'</span>';
10135: }
10136: return $resulttext;
10137: }
10138:
1.160.6.37 raeburn 10139: sub modify_selfenrollment {
10140: my ($dom,$lastactref,%domconfig) = @_;
10141: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10142: my @types = ('official','unofficial','community','textbook');
10143: my %titles = &tool_titles();
10144: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10145: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10146: $ordered{'default'} = ['types','registered','approval','limit'];
10147:
10148: my (%roles,%shown,%toplevel);
10149: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10150:
10151: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10152: if ($domconfig{'selfenrollment'} eq '') {
10153: $domconfig{'selfenrollment'} = {};
10154: }
10155: }
10156: %toplevel = (
10157: admin => 'Configuration Rights',
10158: default => 'Default settings',
10159: validation => 'Validation of self-enrollment requests',
10160: );
10161: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10162:
10163: if (ref($ordered{'admin'}) eq 'ARRAY') {
10164: foreach my $item (@{$ordered{'admin'}}) {
10165: foreach my $type (@types) {
10166: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10167: $selfenrollhash{'admin'}{$type}{$item} = 1;
10168: } else {
10169: $selfenrollhash{'admin'}{$type}{$item} = 0;
10170: }
10171: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10172: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10173: if ($selfenrollhash{'admin'}{$type}{$item} ne
10174: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10175: push(@{$changes{'admin'}{$type}},$item);
10176: }
10177: } else {
10178: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10179: push(@{$changes{'admin'}{$type}},$item);
10180: }
10181: }
10182: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10183: push(@{$changes{'admin'}{$type}},$item);
10184: }
10185: }
10186: }
10187: }
10188:
10189: foreach my $item (@{$ordered{'default'}}) {
10190: foreach my $type (@types) {
10191: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10192: if ($item eq 'types') {
10193: unless (($value eq 'all') || ($value eq 'dom')) {
10194: $value = '';
10195: }
10196: } elsif ($item eq 'registered') {
10197: unless ($value eq '1') {
10198: $value = 0;
10199: }
10200: } elsif ($item eq 'approval') {
10201: unless ($value =~ /^[012]$/) {
10202: $value = 0;
10203: }
10204: } else {
10205: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10206: $value = 'none';
10207: }
10208: }
10209: $selfenrollhash{'default'}{$type}{$item} = $value;
10210: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10211: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10212: if ($selfenrollhash{'default'}{$type}{$item} ne
10213: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10214: push(@{$changes{'default'}{$type}},$item);
10215: }
10216: } else {
10217: push(@{$changes{'default'}{$type}},$item);
10218: }
10219: } else {
10220: push(@{$changes{'default'}{$type}},$item);
10221: }
10222: if ($item eq 'limit') {
10223: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10224: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10225: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10226: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10227: }
10228: } else {
10229: $selfenrollhash{'default'}{$type}{'cap'} = '';
10230: }
10231: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10232: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10233: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10234: push(@{$changes{'default'}{$type}},'cap');
10235: }
10236: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10237: push(@{$changes{'default'}{$type}},'cap');
10238: }
10239: }
10240: }
10241: }
10242:
10243: foreach my $item (@{$itemsref}) {
10244: if ($item eq 'fields') {
10245: my @changed;
10246: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10247: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10248: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10249: }
10250: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10251: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10252: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10253: $domconfig{'selfenrollment'}{'validation'}{$item});
10254: } else {
10255: @changed = @{$selfenrollhash{'validation'}{$item}};
10256: }
10257: } else {
10258: @changed = @{$selfenrollhash{'validation'}{$item}};
10259: }
10260: if (@changed) {
10261: if ($selfenrollhash{'validation'}{$item}) {
10262: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10263: } else {
10264: $changes{'validation'}{$item} = &mt('None');
10265: }
10266: }
10267: } else {
10268: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10269: if ($item eq 'markup') {
10270: if ($env{'form.selfenroll_validation_'.$item}) {
10271: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10272: }
10273: }
10274: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10275: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10276: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10277: }
10278: }
10279: }
10280: }
10281:
10282: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10283: $dom);
10284: if ($putresult eq 'ok') {
10285: if (keys(%changes) > 0) {
10286: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10287: $resulttext = &mt('Changes made:').'<ul>';
10288: foreach my $key ('admin','default','validation') {
10289: if (ref($changes{$key}) eq 'HASH') {
10290: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10291: if ($key eq 'validation') {
10292: foreach my $item (@{$itemsref}) {
10293: if (exists($changes{$key}{$item})) {
10294: if ($item eq 'markup') {
10295: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10296: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10297: } else {
10298: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10299: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10300: }
10301: }
10302: }
10303: } else {
10304: foreach my $type (@types) {
10305: if ($type eq 'community') {
10306: $roles{'1'} = &mt('Community personnel');
10307: } else {
10308: $roles{'1'} = &mt('Course personnel');
10309: }
10310: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10311: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10312: if ($key eq 'admin') {
10313: my @mgrdc = ();
10314: if (ref($ordered{$key}) eq 'ARRAY') {
10315: foreach my $item (@{$ordered{'admin'}}) {
10316: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10317: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10318: push(@mgrdc,$item);
10319: }
10320: }
10321: }
10322: if (@mgrdc) {
10323: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10324: } else {
10325: delete($domdefaults{$type.'selfenrolladmdc'});
10326: }
10327: }
10328: } else {
10329: if (ref($ordered{$key}) eq 'ARRAY') {
10330: foreach my $item (@{$ordered{$key}}) {
10331: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10332: $domdefaults{$type.'selfenroll'.$item} =
10333: $selfenrollhash{$key}{$type}{$item};
10334: }
10335: }
10336: }
10337: }
10338: }
10339: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10340: foreach my $item (@{$ordered{$key}}) {
10341: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10342: $resulttext .= '<li>';
10343: if ($key eq 'admin') {
10344: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10345: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10346: } else {
10347: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10348: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10349: }
10350: $resulttext .= '</li>';
10351: }
10352: }
10353: $resulttext .= '</ul></li>';
10354: }
10355: }
10356: $resulttext .= '</ul></li>';
10357: }
10358: }
10359: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10360: my $cachetime = 24*60*60;
10361: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10362: if (ref($lastactref) eq 'HASH') {
10363: $lastactref->{'domdefaults'} = 1;
10364: }
10365: }
10366: }
10367: $resulttext .= '</ul>';
10368: } else {
10369: $resulttext = &mt('No changes made to self-enrollment settings');
10370: }
10371: } else {
10372: $resulttext = '<span class="LC_error">'.
10373: &mt('An error occurred: [_1]',$putresult).'</span>';
10374: }
10375: return $resulttext;
10376: }
10377:
1.137 raeburn 10378: sub modify_usersessions {
1.160.6.27 raeburn 10379: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10380: my @hostingtypes = ('version','excludedomain','includedomain');
10381: my @offloadtypes = ('primary','default');
10382: my %types = (
10383: remote => \@hostingtypes,
10384: hosted => \@hostingtypes,
10385: spares => \@offloadtypes,
10386: );
10387: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10388: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10389: my (%by_ip,%by_location,@intdoms);
10390: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10391: my @locations = sort(keys(%by_location));
1.137 raeburn 10392: my (%defaultshash,%changes);
10393: foreach my $prefix (@prefixes) {
10394: $defaultshash{'usersessions'}{$prefix} = {};
10395: }
1.160.6.27 raeburn 10396: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10397: my $resulttext;
1.138 raeburn 10398: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10399: foreach my $prefix (@prefixes) {
1.145 raeburn 10400: next if ($prefix eq 'spares');
10401: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10402: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10403: if ($type eq 'version') {
10404: my $value = $env{'form.'.$prefix.'_'.$type};
10405: my $okvalue;
10406: if ($value ne '') {
10407: if (grep(/^\Q$value\E$/,@lcversions)) {
10408: $okvalue = $value;
10409: }
10410: }
10411: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10412: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10413: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10414: if ($inuse == 0) {
10415: $changes{$prefix}{$type} = 1;
10416: } else {
10417: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10418: $changes{$prefix}{$type} = 1;
10419: }
10420: if ($okvalue ne '') {
10421: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10422: }
10423: }
10424: } else {
10425: if (($inuse == 1) && ($okvalue ne '')) {
10426: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10427: $changes{$prefix}{$type} = 1;
10428: }
10429: }
10430: } else {
10431: if (($inuse == 1) && ($okvalue ne '')) {
10432: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10433: $changes{$prefix}{$type} = 1;
10434: }
10435: }
10436: } else {
10437: if (($inuse == 1) && ($okvalue ne '')) {
10438: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10439: $changes{$prefix}{$type} = 1;
10440: }
10441: }
10442: } else {
10443: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10444: my @okvals;
10445: foreach my $val (@vals) {
1.138 raeburn 10446: if ($val =~ /:/) {
10447: my @items = split(/:/,$val);
10448: foreach my $item (@items) {
10449: if (ref($by_location{$item}) eq 'ARRAY') {
10450: push(@okvals,$item);
10451: }
10452: }
10453: } else {
10454: if (ref($by_location{$val}) eq 'ARRAY') {
10455: push(@okvals,$val);
10456: }
1.137 raeburn 10457: }
10458: }
10459: @okvals = sort(@okvals);
10460: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10461: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10462: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10463: if ($inuse == 0) {
10464: $changes{$prefix}{$type} = 1;
10465: } else {
10466: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10467: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10468: if (@changed > 0) {
10469: $changes{$prefix}{$type} = 1;
10470: }
10471: }
10472: } else {
10473: if ($inuse == 1) {
10474: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10475: $changes{$prefix}{$type} = 1;
10476: }
10477: }
10478: } else {
10479: if ($inuse == 1) {
10480: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10481: $changes{$prefix}{$type} = 1;
10482: }
10483: }
10484: } else {
10485: if ($inuse == 1) {
10486: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10487: $changes{$prefix}{$type} = 1;
10488: }
10489: }
10490: }
10491: }
10492: }
1.145 raeburn 10493:
10494: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10495: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10496: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10497: my $savespares;
10498:
10499: foreach my $lonhost (sort(keys(%servers))) {
10500: my $serverhomeID =
10501: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10502: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10503: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10504: my %spareschg;
10505: foreach my $type (@{$types{'spares'}}) {
10506: my @okspares;
10507: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10508: foreach my $server (@checked) {
1.152 raeburn 10509: if (&Apache::lonnet::hostname($server) ne '') {
10510: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10511: unless (grep(/^\Q$server\E$/,@okspares)) {
10512: push(@okspares,$server);
10513: }
1.145 raeburn 10514: }
10515: }
10516: }
10517: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10518: my $newspare;
1.152 raeburn 10519: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10520: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10521: $newspare = $new;
10522: }
10523: }
1.152 raeburn 10524: my @spares;
10525: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10526: @spares = sort(@okspares,$newspare);
10527: } else {
10528: @spares = sort(@okspares);
10529: }
10530: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10531: if (ref($spareid{$lonhost}) eq 'HASH') {
10532: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10533: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10534: if (@diffs > 0) {
10535: $spareschg{$type} = 1;
10536: }
10537: }
10538: }
10539: }
10540: if (keys(%spareschg) > 0) {
10541: $changes{'spares'}{$lonhost} = \%spareschg;
10542: }
10543: }
10544:
10545: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10546: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10547: if (ref($changes{'spares'}) eq 'HASH') {
10548: if (keys(%{$changes{'spares'}}) > 0) {
10549: $savespares = 1;
10550: }
10551: }
10552: } else {
10553: $savespares = 1;
10554: }
10555: }
10556:
1.147 raeburn 10557: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10558: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10559: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10560: $dom);
10561: if ($putresult eq 'ok') {
10562: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10563: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10564: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10565: }
10566: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10567: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10568: }
10569: }
10570: my $cachetime = 24*60*60;
10571: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10572: if (ref($lastactref) eq 'HASH') {
10573: $lastactref->{'domdefaults'} = 1;
10574: }
1.147 raeburn 10575: if (keys(%changes) > 0) {
10576: my %lt = &usersession_titles();
10577: $resulttext = &mt('Changes made:').'<ul>';
10578: foreach my $prefix (@prefixes) {
10579: if (ref($changes{$prefix}) eq 'HASH') {
10580: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10581: if ($prefix eq 'spares') {
10582: if (ref($changes{$prefix}) eq 'HASH') {
10583: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10584: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10585: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10586: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10587: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10588: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10589: foreach my $type (@{$types{$prefix}}) {
10590: if ($changes{$prefix}{$lonhost}{$type}) {
10591: my $offloadto = &mt('None');
10592: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10593: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10594: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10595: }
1.145 raeburn 10596: }
1.147 raeburn 10597: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10598: }
1.137 raeburn 10599: }
10600: }
1.147 raeburn 10601: $resulttext .= '</li>';
1.137 raeburn 10602: }
10603: }
1.147 raeburn 10604: } else {
10605: foreach my $type (@{$types{$prefix}}) {
10606: if (defined($changes{$prefix}{$type})) {
10607: my $newvalue;
10608: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10609: if (ref($defaultshash{'usersessions'}{$prefix})) {
10610: if ($type eq 'version') {
10611: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10612: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10613: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10614: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10615: }
1.145 raeburn 10616: }
10617: }
10618: }
1.147 raeburn 10619: if ($newvalue eq '') {
10620: if ($type eq 'version') {
10621: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10622: } else {
10623: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10624: }
1.145 raeburn 10625: } else {
1.147 raeburn 10626: if ($type eq 'version') {
10627: $newvalue .= ' '.&mt('(or later)');
10628: }
10629: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10630: }
1.137 raeburn 10631: }
10632: }
10633: }
1.147 raeburn 10634: $resulttext .= '</ul>';
1.137 raeburn 10635: }
10636: }
1.147 raeburn 10637: $resulttext .= '</ul>';
10638: } else {
10639: $resulttext = $nochgmsg;
1.137 raeburn 10640: }
10641: } else {
10642: $resulttext = '<span class="LC_error">'.
10643: &mt('An error occurred: [_1]',$putresult).'</span>';
10644: }
10645: } else {
1.147 raeburn 10646: $resulttext = $nochgmsg;
1.137 raeburn 10647: }
10648: return $resulttext;
10649: }
10650:
1.150 raeburn 10651: sub modify_loadbalancing {
10652: my ($dom,%domconfig) = @_;
10653: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10654: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10655: my ($othertitle,$usertypes,$types) =
10656: &Apache::loncommon::sorted_inst_types($dom);
10657: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10658: my @sparestypes = ('primary','default');
10659: my %typetitles = &sparestype_titles();
10660: my $resulttext;
1.160.6.7 raeburn 10661: my (%currbalancer,%currtargets,%currrules,%existing);
10662: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10663: %existing = %{$domconfig{'loadbalancing'}};
10664: }
10665: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10666: \%currtargets,\%currrules);
10667: my ($saveloadbalancing,%defaultshash,%changes);
10668: my ($alltypes,$othertypes,$titles) =
10669: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10670: my %ruletitles = &offloadtype_text();
10671: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10672: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10673: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10674: if ($balancer eq '') {
10675: next;
10676: }
10677: if (!exists($servers{$balancer})) {
10678: if (exists($currbalancer{$balancer})) {
10679: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10680: }
1.160.6.7 raeburn 10681: next;
10682: }
10683: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10684: push(@{$changes{'delete'}},$balancer);
10685: next;
10686: }
10687: if (!exists($currbalancer{$balancer})) {
10688: push(@{$changes{'add'}},$balancer);
10689: }
10690: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10691: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10692: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10693: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10694: $saveloadbalancing = 1;
10695: }
10696: foreach my $sparetype (@sparestypes) {
10697: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10698: my @offloadto;
10699: foreach my $target (@targets) {
10700: if (($servers{$target}) && ($target ne $balancer)) {
10701: if ($sparetype eq 'default') {
10702: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10703: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10704: }
10705: }
1.160.6.7 raeburn 10706: unless(grep(/^\Q$target\E$/,@offloadto)) {
10707: push(@offloadto,$target);
10708: }
1.150 raeburn 10709: }
1.160.6.7 raeburn 10710: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10711: }
10712: }
1.160.6.7 raeburn 10713: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10714: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10715: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10716: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10717: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10718: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10719: }
1.160.6.7 raeburn 10720: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10721: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10722: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10723: }
10724: }
10725: }
10726: } else {
1.160.6.7 raeburn 10727: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10728: foreach my $sparetype (@sparestypes) {
10729: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10730: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10731: $changes{'curr'}{$balancer}{'targets'} = 1;
10732: }
1.150 raeburn 10733: }
10734: }
1.160.6.7 raeburn 10735: }
1.150 raeburn 10736: }
10737: my $ishomedom;
1.160.6.7 raeburn 10738: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10739: $ishomedom = 1;
1.150 raeburn 10740: }
10741: if (ref($alltypes) eq 'ARRAY') {
10742: foreach my $type (@{$alltypes}) {
10743: my $rule;
1.160.6.7 raeburn 10744: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10745: (!$ishomedom)) {
1.160.6.7 raeburn 10746: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10747: }
10748: if ($rule eq 'specific') {
10749: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10750: }
1.160.6.7 raeburn 10751: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10752: if (ref($currrules{$balancer}) eq 'HASH') {
10753: if ($rule ne $currrules{$balancer}{$type}) {
10754: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10755: }
10756: } elsif ($rule ne '') {
1.160.6.7 raeburn 10757: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10758: }
10759: }
10760: }
1.160.6.7 raeburn 10761: }
10762: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10763: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10764: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10765: $defaultshash{'loadbalancing'} = {};
10766: }
10767: my $putresult = &Apache::lonnet::put_dom('configuration',
10768: \%defaultshash,$dom);
10769: if ($putresult eq 'ok') {
10770: if (keys(%changes) > 0) {
10771: if (ref($changes{'delete'}) eq 'ARRAY') {
10772: foreach my $balancer (sort(@{$changes{'delete'}})) {
10773: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10774: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10775: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10776: }
1.160.6.7 raeburn 10777: }
10778: if (ref($changes{'add'}) eq 'ARRAY') {
10779: foreach my $balancer (sort(@{$changes{'add'}})) {
10780: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10781: }
10782: }
10783: if (ref($changes{'curr'}) eq 'HASH') {
10784: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10785: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10786: if ($changes{'curr'}{$balancer}{'targets'}) {
10787: my %offloadstr;
10788: foreach my $sparetype (@sparestypes) {
10789: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10790: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10791: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10792: }
10793: }
1.150 raeburn 10794: }
1.160.6.7 raeburn 10795: if (keys(%offloadstr) == 0) {
10796: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10797: } else {
1.160.6.7 raeburn 10798: my $showoffload;
10799: foreach my $sparetype (@sparestypes) {
10800: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10801: if (defined($offloadstr{$sparetype})) {
10802: $showoffload .= $offloadstr{$sparetype};
10803: } else {
10804: $showoffload .= &mt('None');
10805: }
10806: $showoffload .= (' 'x3);
10807: }
10808: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10809: }
10810: }
10811: }
1.160.6.7 raeburn 10812: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10813: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10814: foreach my $type (@{$alltypes}) {
10815: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10816: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10817: my $balancetext;
10818: if ($rule eq '') {
10819: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10820: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10821: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10822: $balancetext = $ruletitles{$rule};
10823: } else {
10824: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10825: }
1.160.6.26 raeburn 10826: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10827: }
10828: }
10829: }
10830: }
1.160.6.29 raeburn 10831: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10832: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10833: }
1.160.6.7 raeburn 10834: }
10835: if ($resulttext ne '') {
10836: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10837: } else {
10838: $resulttext = $nochgmsg;
10839: }
10840: } else {
1.160.6.7 raeburn 10841: $resulttext = $nochgmsg;
1.150 raeburn 10842: }
10843: } else {
1.160.6.7 raeburn 10844: $resulttext = '<span class="LC_error">'.
10845: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10846: }
10847: } else {
1.160.6.7 raeburn 10848: $resulttext = $nochgmsg;
1.150 raeburn 10849: }
10850: return $resulttext;
10851: }
10852:
1.48 raeburn 10853: sub recurse_check {
10854: my ($chkcats,$categories,$depth,$name) = @_;
10855: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10856: my $chg = 0;
10857: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10858: my $category = $chkcats->[$depth]{$name}[$j];
10859: my $item;
10860: if ($category eq '') {
10861: $chg ++;
10862: } else {
10863: my $deeper = $depth + 1;
10864: $item = &escape($category).':'.&escape($name).':'.$depth;
10865: if ($chg) {
10866: $categories->{$item} -= $chg;
10867: }
10868: &recurse_check($chkcats,$categories,$deeper,$category);
10869: $deeper --;
10870: }
10871: }
10872: }
10873: return;
10874: }
10875:
10876: sub recurse_cat_deletes {
10877: my ($item,$coursecategories,$deletions) = @_;
10878: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10879: my $subdepth = $depth + 1;
10880: if (ref($coursecategories) eq 'HASH') {
10881: foreach my $subitem (keys(%{$coursecategories})) {
10882: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10883: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10884: delete($coursecategories->{$subitem});
10885: $deletions->{$subitem} = 1;
10886: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10887: }
1.48 raeburn 10888: }
10889: }
10890: return;
10891: }
10892:
1.125 raeburn 10893: sub get_active_dcs {
10894: my ($dom) = @_;
1.160.6.16 raeburn 10895: my $now = time;
10896: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10897: my %domcoords;
10898: my $numdcs = 0;
10899: foreach my $server (keys(%dompersonnel)) {
10900: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10901: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10902: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10903: }
10904: }
10905: return %domcoords;
10906: }
10907:
10908: sub active_dc_picker {
1.160.6.16 raeburn 10909: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10910: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10911: my @domcoord = keys(%domcoords);
10912: if (keys(%currhash)) {
10913: foreach my $dc (keys(%currhash)) {
10914: unless (exists($domcoords{$dc})) {
10915: push(@domcoord,$dc);
10916: }
10917: }
10918: }
10919: @domcoord = sort(@domcoord);
10920: my $numdcs = scalar(@domcoord);
10921: my $rows = 0;
10922: my $table;
1.125 raeburn 10923: if ($numdcs > 1) {
1.160.6.16 raeburn 10924: $table = '<table>';
10925: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10926: my $rem = $i%($numinrow);
10927: if ($rem == 0) {
10928: if ($i > 0) {
1.160.6.16 raeburn 10929: $table .= '</tr>';
1.125 raeburn 10930: }
1.160.6.16 raeburn 10931: $table .= '<tr>';
10932: $rows ++;
1.125 raeburn 10933: }
1.160.6.16 raeburn 10934: my $check = '';
10935: if ($inputtype eq 'radio') {
10936: if (keys(%currhash) == 0) {
10937: if (!$i) {
10938: $check = ' checked="checked"';
10939: }
10940: } elsif (exists($currhash{$domcoord[$i]})) {
10941: $check = ' checked="checked"';
10942: }
10943: } else {
10944: if (exists($currhash{$domcoord[$i]})) {
10945: $check = ' checked="checked"';
1.125 raeburn 10946: }
10947: }
1.160.6.16 raeburn 10948: if ($i == @domcoord - 1) {
1.125 raeburn 10949: my $colsleft = $numinrow - $rem;
10950: if ($colsleft > 1) {
1.160.6.16 raeburn 10951: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10952: } else {
1.160.6.16 raeburn 10953: $table .= '<td class="LC_left_item">';
1.125 raeburn 10954: }
10955: } else {
1.160.6.16 raeburn 10956: $table .= '<td class="LC_left_item">';
10957: }
10958: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10959: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10960: $table .= '<span class="LC_nobreak"><label>'.
10961: '<input type="'.$inputtype.'" name="'.$name.'"'.
10962: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10963: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10964: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10965: }
1.160.6.33 raeburn 10966: $table .= '</label></span></td>';
1.125 raeburn 10967: }
1.160.6.16 raeburn 10968: $table .= '</tr></table>';
10969: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10970: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10971: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10972: if ($inputtype eq 'radio') {
1.160.6.50! raeburn 10973: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 10974: if ($user ne $dcname.':'.$dcdom) {
10975: $table .= ' ('.$dcname.':'.$dcdom.')';
10976: }
1.160.6.16 raeburn 10977: } else {
10978: my $check;
10979: if (exists($currhash{$domcoord[0]})) {
10980: $check = ' checked="checked"';
10981: }
1.160.6.50! raeburn 10982: $table = '<span class="LC_nobreak"><label>'.
! 10983: '<input type="checkbox" name="'.$name.'" '.
! 10984: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 10985: if ($user ne $dcname.':'.$dcdom) {
10986: $table .= ' ('.$dcname.':'.$dcdom.')';
10987: }
10988: $table .= '</label></span>';
1.160.6.16 raeburn 10989: $rows ++;
10990: }
1.125 raeburn 10991: }
1.160.6.16 raeburn 10992: return ($numdcs,$table,$rows);
1.125 raeburn 10993: }
10994:
1.137 raeburn 10995: sub usersession_titles {
10996: return &Apache::lonlocal::texthash(
10997: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10998: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10999: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11000: version => 'LON-CAPA version requirement',
1.138 raeburn 11001: excludedomain => 'Allow all, but exclude specific domains',
11002: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11003: primary => 'Primary (checked first)',
1.154 raeburn 11004: default => 'Default',
1.137 raeburn 11005: );
11006: }
11007:
1.152 raeburn 11008: sub id_for_thisdom {
11009: my (%servers) = @_;
11010: my %altids;
11011: foreach my $server (keys(%servers)) {
11012: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11013: if ($serverhome ne $server) {
11014: $altids{$serverhome} = $server;
11015: }
11016: }
11017: return %altids;
11018: }
11019:
1.150 raeburn 11020: sub count_servers {
11021: my ($currbalancer,%servers) = @_;
11022: my (@spares,$numspares);
11023: foreach my $lonhost (sort(keys(%servers))) {
11024: next if ($currbalancer eq $lonhost);
11025: push(@spares,$lonhost);
11026: }
11027: if ($currbalancer) {
11028: $numspares = scalar(@spares);
11029: } else {
11030: $numspares = scalar(@spares) - 1;
11031: }
11032: return ($numspares,@spares);
11033: }
11034:
11035: sub lonbalance_targets_js {
1.160.6.7 raeburn 11036: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11037: my $select = &mt('Select');
11038: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11039: if (ref($servers) eq 'HASH') {
11040: $alltargets = join("','",sort(keys(%{$servers})));
11041: my @homedoms;
11042: foreach my $server (sort(keys(%{$servers}))) {
11043: if (&Apache::lonnet::host_domain($server) eq $dom) {
11044: push(@homedoms,'1');
11045: } else {
11046: push(@homedoms,'0');
11047: }
11048: }
11049: $allishome = join("','",@homedoms);
11050: }
11051: if (ref($types) eq 'ARRAY') {
11052: if (@{$types} > 0) {
11053: @alltypes = @{$types};
11054: }
11055: }
11056: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11057: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11058: my (%currbalancer,%currtargets,%currrules,%existing);
11059: if (ref($settings) eq 'HASH') {
11060: %existing = %{$settings};
11061: }
11062: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11063: \%currtargets,\%currrules);
11064: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11065: return <<"END";
11066:
11067: <script type="text/javascript">
11068: // <![CDATA[
11069:
1.160.6.7 raeburn 11070: currBalancers = new Array('$balancers');
11071:
11072: function toggleTargets(balnum) {
11073: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11074: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11075: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11076: var prevbalancer = prevhostitem.value;
11077: var baltotal = document.getElementById('loadbalancing_total').value;
11078: prevhostitem.value = balancer;
11079: if (prevbalancer != '') {
11080: var prevIdx = currBalancers.indexOf(prevbalancer);
11081: if (prevIdx != -1) {
11082: currBalancers.splice(prevIdx,1);
11083: }
11084: }
1.150 raeburn 11085: if (balancer == '') {
1.160.6.7 raeburn 11086: hideSpares(balnum);
1.150 raeburn 11087: } else {
1.160.6.7 raeburn 11088: var currIdx = currBalancers.indexOf(balancer);
11089: if (currIdx == -1) {
11090: currBalancers.push(balancer);
11091: }
1.150 raeburn 11092: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11093: var ishomedom = homedoms[lonhostitem.selectedIndex];
11094: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11095: }
1.160.6.7 raeburn 11096: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11097: return;
11098: }
11099:
1.160.6.7 raeburn 11100: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11101: var alltargets = new Array('$alltargets');
11102: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11103: var offloadtypes = new Array('primary','default');
11104:
1.160.6.7 raeburn 11105: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11106: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11107:
1.151 raeburn 11108: for (var i=0; i<offloadtypes.length; i++) {
11109: var count = 0;
11110: for (var j=0; j<alltargets.length; j++) {
11111: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11112: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11113: item.value = alltargets[j];
11114: item.style.textAlign='left';
11115: item.style.textFace='normal';
11116: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11117: if (currBalancers.indexOf(alltargets[j]) == -1) {
11118: item.disabled = '';
11119: } else {
11120: item.disabled = 'disabled';
11121: item.checked = false;
11122: }
1.151 raeburn 11123: count ++;
11124: }
1.150 raeburn 11125: }
11126: }
1.151 raeburn 11127: for (var k=0; k<insttypes.length; k++) {
11128: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11129: if (ishomedom == 1) {
1.160.6.7 raeburn 11130: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11131: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11132: } else {
1.160.6.7 raeburn 11133: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11134: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11135: }
11136: } else {
1.160.6.7 raeburn 11137: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11138: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11139: }
1.151 raeburn 11140: if ((insttypes[k] != '_LC_external') &&
11141: ((insttypes[k] != '_LC_internetdom') ||
11142: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11143: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11144: item.options.length = 0;
11145: item.options[0] = new Option("","",true,true);
11146: var idx = 0;
1.151 raeburn 11147: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11148: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11149: idx ++;
11150: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11151: }
11152: }
11153: }
11154: }
11155: return;
11156: }
11157:
1.160.6.7 raeburn 11158: function hideSpares(balnum) {
1.150 raeburn 11159: var alltargets = new Array('$alltargets');
11160: var insttypes = new Array('$allinsttypes');
11161: var offloadtypes = new Array('primary','default');
11162:
1.160.6.7 raeburn 11163: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11164: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11165:
11166: var total = alltargets.length - 1;
11167: for (var i=0; i<offloadtypes; i++) {
11168: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11169: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11170: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11171: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11172: }
1.150 raeburn 11173: }
11174: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11175: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11176: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11177: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11178: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11179: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11180: }
11181: }
11182: return;
11183: }
11184:
1.160.6.7 raeburn 11185: function checkOffloads(item,balnum,type) {
1.150 raeburn 11186: var alltargets = new Array('$alltargets');
11187: var offloadtypes = new Array('primary','default');
11188: if (item.checked) {
11189: var total = alltargets.length - 1;
11190: var other;
11191: if (type == offloadtypes[0]) {
1.151 raeburn 11192: other = offloadtypes[1];
1.150 raeburn 11193: } else {
1.151 raeburn 11194: other = offloadtypes[0];
1.150 raeburn 11195: }
11196: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11197: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11198: if (server == item.value) {
1.160.6.7 raeburn 11199: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11200: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11201: }
11202: }
11203: }
11204: }
11205: return;
11206: }
11207:
1.160.6.7 raeburn 11208: function singleServerToggle(balnum,type) {
11209: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11210: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11211: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11212: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11213:
11214: } else {
1.160.6.7 raeburn 11215: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11216: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11217: }
11218: return;
11219: }
11220:
1.160.6.7 raeburn 11221: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11222: if (type == '_LC_external') {
1.160.6.26 raeburn 11223: return;
1.150 raeburn 11224: }
1.160.6.7 raeburn 11225: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11226: for (var i=0; i<typesRules.length; i++) {
11227: if (formname.elements[typesRules[i]].checked) {
11228: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11229: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11230: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11231: } else {
1.160.6.7 raeburn 11232: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11233: }
11234: }
11235: }
11236: return;
11237: }
11238:
11239: function balancerDeleteChange(balnum) {
11240: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11241: var baltotal = document.getElementById('loadbalancing_total').value;
11242: var addtarget;
11243: var removetarget;
11244: var action = 'delete';
11245: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11246: var lonhost = hostitem.value;
11247: var currIdx = currBalancers.indexOf(lonhost);
11248: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11249: if (currIdx != -1) {
11250: currBalancers.splice(currIdx,1);
11251: }
11252: addtarget = lonhost;
11253: } else {
11254: if (currIdx == -1) {
11255: currBalancers.push(lonhost);
11256: }
11257: removetarget = lonhost;
11258: action = 'undelete';
11259: }
11260: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11261: }
11262: return;
11263: }
11264:
11265: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11266: if (baltotal > 1) {
11267: var offloadtypes = new Array('primary','default');
11268: var alltargets = new Array('$alltargets');
11269: var insttypes = new Array('$allinsttypes');
11270: for (var i=0; i<baltotal; i++) {
11271: if (i != balnum) {
11272: for (var j=0; j<offloadtypes.length; j++) {
11273: var total = alltargets.length - 1;
11274: for (var k=0; k<total; k++) {
11275: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11276: var server = serveritem.value;
11277: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11278: if (server == addtarget) {
11279: serveritem.disabled = '';
11280: }
11281: }
11282: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11283: if (server == removetarget) {
11284: serveritem.disabled = 'disabled';
11285: serveritem.checked = false;
11286: }
11287: }
11288: }
11289: }
11290: for (var j=0; j<insttypes.length; j++) {
11291: if (insttypes[j] != '_LC_external') {
11292: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11293: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11294: var currSel = singleserver.selectedIndex;
11295: var currVal = singleserver.options[currSel].value;
11296: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11297: var numoptions = singleserver.options.length;
11298: var needsnew = 1;
11299: for (var k=0; k<numoptions; k++) {
11300: if (singleserver.options[k] == addtarget) {
11301: needsnew = 0;
11302: break;
11303: }
11304: }
11305: if (needsnew == 1) {
11306: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11307: }
11308: }
11309: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11310: singleserver.options.length = 0;
11311: if ((currVal) && (currVal != removetarget)) {
11312: singleserver.options[0] = new Option("","",false,false);
11313: } else {
11314: singleserver.options[0] = new Option("","",true,true);
11315: }
11316: var idx = 0;
11317: for (var m=0; m<alltargets.length; m++) {
11318: if (currBalancers.indexOf(alltargets[m]) == -1) {
11319: idx ++;
11320: if (currVal == alltargets[m]) {
11321: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11322: } else {
11323: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11324: }
11325: }
11326: }
11327: }
11328: }
11329: }
11330: }
1.150 raeburn 11331: }
11332: }
11333: }
11334: return;
11335: }
11336:
1.152 raeburn 11337: // ]]>
11338: </script>
11339:
11340: END
11341: }
11342:
11343: sub new_spares_js {
11344: my @sparestypes = ('primary','default');
11345: my $types = join("','",@sparestypes);
11346: my $select = &mt('Select');
11347: return <<"END";
11348:
11349: <script type="text/javascript">
11350: // <![CDATA[
11351:
11352: function updateNewSpares(formname,lonhost) {
11353: var types = new Array('$types');
11354: var include = new Array();
11355: var exclude = new Array();
11356: for (var i=0; i<types.length; i++) {
11357: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11358: for (var j=0; j<spareboxes.length; j++) {
11359: if (formname.elements[spareboxes[j]].checked) {
11360: exclude.push(formname.elements[spareboxes[j]].value);
11361: } else {
11362: include.push(formname.elements[spareboxes[j]].value);
11363: }
11364: }
11365: }
11366: for (var i=0; i<types.length; i++) {
11367: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11368: var selIdx = newSpare.selectedIndex;
11369: var currnew = newSpare.options[selIdx].value;
11370: var okSpares = new Array();
11371: for (var j=0; j<newSpare.options.length; j++) {
11372: var possible = newSpare.options[j].value;
11373: if (possible != '') {
11374: if (exclude.indexOf(possible) == -1) {
11375: okSpares.push(possible);
11376: } else {
11377: if (currnew == possible) {
11378: selIdx = 0;
11379: }
11380: }
11381: }
11382: }
11383: for (var k=0; k<include.length; k++) {
11384: if (okSpares.indexOf(include[k]) == -1) {
11385: okSpares.push(include[k]);
11386: }
11387: }
11388: okSpares.sort();
11389: newSpare.options.length = 0;
11390: if (selIdx == 0) {
11391: newSpare.options[0] = new Option("$select","",true,true);
11392: } else {
11393: newSpare.options[0] = new Option("$select","",false,false);
11394: }
11395: for (var m=0; m<okSpares.length; m++) {
11396: var idx = m+1;
11397: var selThis = 0;
11398: if (selIdx != 0) {
11399: if (okSpares[m] == currnew) {
11400: selThis = 1;
11401: }
11402: }
11403: if (selThis == 1) {
11404: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11405: } else {
11406: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11407: }
11408: }
11409: }
11410: return;
11411: }
11412:
11413: function checkNewSpares(lonhost,type) {
11414: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11415: var chosen = newSpare.options[newSpare.selectedIndex].value;
11416: if (chosen != '') {
11417: var othertype;
11418: var othernewSpare;
11419: if (type == 'primary') {
11420: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11421: }
11422: if (type == 'default') {
11423: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11424: }
11425: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11426: othernewSpare.selectedIndex = 0;
11427: }
11428: }
11429: return;
11430: }
11431:
11432: // ]]>
11433: </script>
11434:
11435: END
11436:
11437: }
11438:
11439: sub common_domprefs_js {
11440: return <<"END";
11441:
11442: <script type="text/javascript">
11443: // <![CDATA[
11444:
1.150 raeburn 11445: function getIndicesByName(formname,item) {
1.152 raeburn 11446: var group = new Array();
1.150 raeburn 11447: for (var i=0;i<formname.elements.length;i++) {
11448: if (formname.elements[i].name == item) {
1.152 raeburn 11449: group.push(formname.elements[i].id);
1.150 raeburn 11450: }
11451: }
1.152 raeburn 11452: return group;
1.150 raeburn 11453: }
11454:
11455: // ]]>
11456: </script>
11457:
11458: END
1.152 raeburn 11459:
1.150 raeburn 11460: }
11461:
1.160.6.5 raeburn 11462: sub recaptcha_js {
11463: my %lt = &captcha_phrases();
11464: return <<"END";
11465:
11466: <script type="text/javascript">
11467: // <![CDATA[
11468:
11469: function updateCaptcha(caller,context) {
11470: var privitem;
11471: var pubitem;
11472: var privtext;
11473: var pubtext;
11474: if (document.getElementById(context+'_recaptchapub')) {
11475: pubitem = document.getElementById(context+'_recaptchapub');
11476: } else {
11477: return;
11478: }
11479: if (document.getElementById(context+'_recaptchapriv')) {
11480: privitem = document.getElementById(context+'_recaptchapriv');
11481: } else {
11482: return;
11483: }
11484: if (document.getElementById(context+'_recaptchapubtxt')) {
11485: pubtext = document.getElementById(context+'_recaptchapubtxt');
11486: } else {
11487: return;
11488: }
11489: if (document.getElementById(context+'_recaptchaprivtxt')) {
11490: privtext = document.getElementById(context+'_recaptchaprivtxt');
11491: } else {
11492: return;
11493: }
11494: if (caller.checked) {
11495: if (caller.value == 'recaptcha') {
11496: pubitem.type = 'text';
11497: privitem.type = 'text';
11498: pubitem.size = '40';
11499: privitem.size = '40';
11500: pubtext.innerHTML = "$lt{'pub'}";
11501: privtext.innerHTML = "$lt{'priv'}";
11502: } else {
11503: pubitem.type = 'hidden';
11504: privitem.type = 'hidden';
11505: pubtext.innerHTML = '';
11506: privtext.innerHTML = '';
11507: }
11508: }
11509: return;
11510: }
11511:
11512: // ]]>
11513: </script>
11514:
11515: END
11516:
11517: }
11518:
1.160.6.40 raeburn 11519: sub toggle_display_js {
1.160.6.16 raeburn 11520: return <<"END";
11521:
11522: <script type="text/javascript">
11523: // <![CDATA[
11524:
1.160.6.40 raeburn 11525: function toggleDisplay(domForm,caller) {
11526: if (document.getElementById(caller)) {
11527: var divitem = document.getElementById(caller);
11528: var optionsElement = domForm.coursecredits;
11529: if (caller == 'emailoptions') {
11530: optionsElement = domForm.cancreate_email;
11531: }
11532: if (optionsElement.length) {
1.160.6.16 raeburn 11533: var currval;
1.160.6.40 raeburn 11534: for (var i=0; i<optionsElement.length; i++) {
11535: if (optionsElement[i].checked) {
11536: currval = optionsElement[i].value;
1.160.6.16 raeburn 11537: }
11538: }
11539: if (currval == 1) {
1.160.6.40 raeburn 11540: divitem.style.display = 'block';
1.160.6.16 raeburn 11541: } else {
1.160.6.40 raeburn 11542: divitem.style.display = 'none';
1.160.6.16 raeburn 11543: }
11544: }
11545: }
11546: return;
11547: }
11548:
11549: // ]]>
11550: </script>
11551:
11552: END
11553:
11554: }
11555:
1.160.6.5 raeburn 11556: sub captcha_phrases {
11557: return &Apache::lonlocal::texthash (
11558: priv => 'Private key',
11559: pub => 'Public key',
11560: original => 'original (CAPTCHA)',
11561: recaptcha => 'successor (ReCAPTCHA)',
11562: notused => 'unused',
11563: );
11564: }
11565:
1.160.6.24 raeburn 11566: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11567: my ($dom,$cachekeys) = @_;
11568: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11569: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11570: my %thismachine;
11571: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11572: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11573: if (keys(%servers) > 1) {
11574: foreach my $server (keys(%servers)) {
11575: next if ($thismachine{$server});
1.160.6.27 raeburn 11576: my @cached;
11577: foreach my $name (@posscached) {
11578: if ($cachekeys->{$name}) {
11579: push(@cached,&escape($name).':'.&escape($dom));
11580: }
11581: }
11582: if (@cached) {
11583: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11584: }
1.160.6.24 raeburn 11585: }
11586: }
11587: return;
11588: }
11589:
1.3 raeburn 11590: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>