Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.48
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.48! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.47 2014/05/09 17:49:47 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.37 raeburn 415: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
416: col2 => 'Value',},
417: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 418: col2 => 'Value',},],
1.160.6.37 raeburn 419: print => \&print_coursedefaults,
420: modify => \&modify_coursedefaults,
421: },
1.160.6.39 raeburn 422: 'selfenrollment' =>
1.160.6.37 raeburn 423: {text => 'Self-enrollment in Course/Community',
424: help => 'Domain_Configuration_Selfenrollment',
425: header => [{col1 => 'Configuration Rights',
426: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
427: {col1 => 'Defaults',
428: col2 => 'Value'},
429: {col1 => 'Self-enrollment validation (optional)',
430: col2 => 'Value'},],
431: print => \&print_selfenrollment,
432: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 433: },
1.141 raeburn 434: 'usersessions' =>
1.145 raeburn 435: {text => 'User session hosting/offloading',
1.137 raeburn 436: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 437: header => [{col1 => 'Domain server',
438: col2 => 'Servers to offload sessions to when busy'},
439: {col1 => 'Hosting of users from other domains',
1.137 raeburn 440: col2 => 'Rules'},
441: {col1 => "Hosting domain's own users elsewhere",
442: col2 => 'Rules'}],
1.160.6.37 raeburn 443: print => \&print_usersessions,
444: modify => \&modify_usersessions,
1.137 raeburn 445: },
1.150 raeburn 446: 'loadbalancing' =>
1.160.6.7 raeburn 447: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 448: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 449: header => [{col1 => 'Balancers',
1.150 raeburn 450: col2 => 'Default destinations',
1.160.6.13 raeburn 451: col3 => 'User affiliation',
1.150 raeburn 452: col4 => 'Overrides'},
453: ],
1.160.6.37 raeburn 454: print => \&print_loadbalancing,
455: modify => \&modify_loadbalancing,
1.150 raeburn 456: },
1.3 raeburn 457: );
1.110 raeburn 458: if (keys(%servers) > 1) {
459: $prefs{'login'} = { text => 'Log-in page options',
460: help => 'Domain_Configuration_Login_Page',
461: header => [{col1 => 'Log-in Service',
462: col2 => 'Server Setting',},
463: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 464: col2 => ''},
465: {col1 => 'Log-in Help',
466: col2 => 'Value'}],
1.160.6.37 raeburn 467: print => \&print_login,
468: modify => \&modify_login,
1.110 raeburn 469: };
470: }
1.160.6.13 raeburn 471:
1.6 raeburn 472: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 473: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 474: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 475: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 476: text=>"Settings to display/modify"});
1.9 raeburn 477: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 478:
1.3 raeburn 479: if ($phase eq 'process') {
1.160.6.27 raeburn 480: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
481: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 482: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 483: $r->rflush();
1.160.6.27 raeburn 484: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 485: }
1.30 raeburn 486: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 487: my $js = &recaptcha_js().
1.160.6.40 raeburn 488: &toggle_display_js();
1.160.6.7 raeburn 489: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 490: my ($othertitle,$usertypes,$types) =
491: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 492: $js .= &lonbalance_targets_js($dom,$types,\%servers,
493: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 494: &new_spares_js().
495: &common_domprefs_js().
496: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 497: }
1.160.6.30 raeburn 498: if (grep(/^requestcourses$/,@actions)) {
499: my $javascript_validations;
500: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
501: $js .= <<END;
502: <script type="text/javascript">
503: $javascript_validations
504: </script>
505: $coursebrowserjs
506: END
507: }
1.150 raeburn 508: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 509: } else {
1.160.6.11 raeburn 510: # check if domconfig user exists for the domain.
511: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 512: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 513: &config_check($dom,$confname,$servadm);
514: unless ($configuserok eq 'ok') {
515: &Apache::lonconfigsettings::print_header($r,$phase,$context);
516: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
517: $confname).
518: '<br />'
519: );
520: if ($switchserver) {
521: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
522: '<br />'.
523: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
524: '<br />'.
525: &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).
526: '<br />'.
527: &mt('To do that now, use the following link: [_1]',$switchserver)
528: );
529: } else {
530: $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.').
531: '<br />'.
532: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
533: );
534: }
535: $r->print(&Apache::loncommon::end_page());
536: return OK;
537: }
1.21 raeburn 538: if (keys(%domconfig) == 0) {
539: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 540: my @ids=&Apache::lonnet::current_machine_ids();
541: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 542: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 543: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 544: my $custom_img_count = 0;
545: foreach my $img (@loginimages) {
546: if ($designhash{$dom.'.login.'.$img} ne '') {
547: $custom_img_count ++;
548: }
549: }
550: foreach my $role (@roles) {
551: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
552: $custom_img_count ++;
553: }
554: }
555: if ($custom_img_count > 0) {
1.94 raeburn 556: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 557: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 558: $r->print(
559: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
560: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
561: &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 />'.
562: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
563: if ($switch_server) {
1.30 raeburn 564: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 565: }
1.91 raeburn 566: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 567: return OK;
568: }
569: }
570: }
1.91 raeburn 571: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 572: }
573: return OK;
574: }
575:
576: sub process_changes {
1.160.6.24 raeburn 577: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 578: my %domconfig;
579: if (ref($values) eq 'HASH') {
580: %domconfig = %{$values};
581: }
1.3 raeburn 582: my $output;
583: if ($action eq 'login') {
1.160.6.24 raeburn 584: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 585: } elsif ($action eq 'rolecolors') {
1.9 raeburn 586: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 587: $lastactref,%domconfig);
1.3 raeburn 588: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 589: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 590: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 591: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 592: } elsif ($action eq 'autoupdate') {
593: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 594: } elsif ($action eq 'autocreate') {
595: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 596: } elsif ($action eq 'directorysrch') {
597: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 598: } elsif ($action eq 'usercreation') {
1.28 raeburn 599: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 600: } elsif ($action eq 'selfcreation') {
601: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 602: } elsif ($action eq 'usermodification') {
603: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 604: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 605: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 606: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 607: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 608: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 609: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 610: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 611: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 612: } elsif ($action eq 'serverstatuses') {
613: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 614: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 616: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 617: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 618: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 619: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 620: } elsif ($action eq 'selfenrollment') {
621: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 622: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 623: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 624: } elsif ($action eq 'loadbalancing') {
625: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 626: }
627: return $output;
628: }
629:
630: sub print_config_box {
1.9 raeburn 631: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 632: my $rowtotal = 0;
1.49 raeburn 633: my $output;
634: if ($action eq 'coursecategories') {
635: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 636: } elsif ($action eq 'defaults') {
637: $output = &defaults_javascript($settings);
1.91 raeburn 638: }
1.160.6.40 raeburn 639: $output .=
1.30 raeburn 640: '<table class="LC_nested_outer">
1.3 raeburn 641: <tr>
1.66 raeburn 642: <th align="left" valign="middle"><span class="LC_nobreak">'.
643: &mt($item->{text}).' '.
644: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
645: '</tr>';
1.30 raeburn 646: $rowtotal ++;
1.110 raeburn 647: my $numheaders = 1;
648: if (ref($item->{'header'}) eq 'ARRAY') {
649: $numheaders = scalar(@{$item->{'header'}});
650: }
651: if ($numheaders > 1) {
1.64 raeburn 652: my $colspan = '';
1.145 raeburn 653: my $rightcolspan = '';
1.160.6.42 raeburn 654: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.5 raeburn 655: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 656: $colspan = ' colspan="2"';
657: }
1.145 raeburn 658: if ($action eq 'usersessions') {
659: $rightcolspan = ' colspan="3"';
660: }
1.30 raeburn 661: $output .= '
1.3 raeburn 662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
1.59 bisitz 666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 667: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 668: </tr>';
1.69 raeburn 669: $rowtotal ++;
1.160.6.37 raeburn 670: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.40 raeburn 671: ($action eq 'usermodification') || ($action eq 'defaults') ||
672: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 673: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 674: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 675: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 676: } elsif ($action eq 'login') {
1.160.6.5 raeburn 677: if ($numheaders == 3) {
678: $colspan = ' colspan="2"';
679: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
680: } else {
681: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
682: }
1.160.6.37 raeburn 683: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 684: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 685: } elsif ($action eq 'rolecolors') {
1.30 raeburn 686: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 687: }
1.30 raeburn 688: $output .= '
1.6 raeburn 689: </table>
690: </td>
691: </tr>
692: <tr>
693: <td>
694: <table class="LC_nested">
695: <tr class="LC_info_row">
1.160.6.37 raeburn 696: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 697: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 698: </tr>';
699: $rowtotal ++;
1.160.6.37 raeburn 700: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
701: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 702: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
703: if ($action eq 'coursecategories') {
704: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
705: $colspan = ' colspan="2"';
706: } else {
707: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
708: }
709: $output .= '
1.63 raeburn 710: </table>
711: </td>
712: </tr>
713: <tr>
714: <td>
715: <table class="LC_nested">
716: <tr class="LC_info_row">
717: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 718: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 719: </tr>'."\n";
720: if ($action eq 'coursecategories') {
721: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
722: } else {
723: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
724: }
1.63 raeburn 725: $rowtotal ++;
1.160.6.40 raeburn 726: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
727: ($action eq 'defaults')) {
1.160.6.37 raeburn 728: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 729: } elsif ($action eq 'login') {
1.160.6.5 raeburn 730: if ($numheaders == 3) {
731: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
732: </table>
733: </td>
734: </tr>
735: <tr>
736: <td>
737: <table class="LC_nested">
738: <tr class="LC_info_row">
739: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 740: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 741: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
742: $rowtotal ++;
743: } else {
744: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
745: }
1.102 raeburn 746: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 747: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
748: &print_studentcode($settings,\$rowtotal).'
749: </table>
750: </td>
751: </tr>
752: <tr>
753: <td>
754: <table class="LC_nested">
755: <tr class="LC_info_row">
756: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
757: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 758: &textbookcourses_javascript($settings).
759: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
760: </table>
761: </td>
762: </tr>
763: <tr>
764: <td>
765: <table class="LC_nested">
766: <tr class="LC_info_row">
767: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
768: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
769: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 770: </table>
771: </td>
772: </tr>
773: <tr>
774: <td>
775: <table class="LC_nested">
776: <tr class="LC_info_row">
1.160.6.46 raeburn 777: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
778: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 779: </tr>'.
780: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 781: } elsif ($action eq 'requestauthor') {
782: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 783: } elsif ($action eq 'rolecolors') {
1.30 raeburn 784: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 785: </table>
786: </td>
787: </tr>
788: <tr>
789: <td>
790: <table class="LC_nested">
791: <tr class="LC_info_row">
1.69 raeburn 792: <td class="LC_left_item"'.$colspan.' valign="top">'.
793: &mt($item->{'header'}->[2]->{'col1'}).'</td>
794: <td class="LC_right_item" valign="top">'.
795: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 796: </tr>'.
1.30 raeburn 797: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 798: </table>
799: </td>
800: </tr>
801: <tr>
802: <td>
803: <table class="LC_nested">
804: <tr class="LC_info_row">
1.59 bisitz 805: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
806: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 807: </tr>'.
1.30 raeburn 808: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
809: $rowtotal += 2;
1.6 raeburn 810: }
1.3 raeburn 811: } else {
1.30 raeburn 812: $output .= '
1.3 raeburn 813: <tr>
814: <td>
815: <table class="LC_nested">
1.30 raeburn 816: <tr class="LC_info_row">';
1.24 raeburn 817: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 818: $output .= '
1.59 bisitz 819: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 820: } elsif ($action eq 'serverstatuses') {
821: $output .= '
822: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
823: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
824:
1.6 raeburn 825: } else {
1.30 raeburn 826: $output .= '
1.69 raeburn 827: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
828: }
1.72 raeburn 829: if (defined($item->{'header'}->[0]->{'col3'})) {
830: $output .= '<td class="LC_left_item" valign="top">'.
831: &mt($item->{'header'}->[0]->{'col2'});
832: if ($action eq 'serverstatuses') {
833: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
834: }
1.69 raeburn 835: } else {
836: $output .= '<td class="LC_right_item" valign="top">'.
837: &mt($item->{'header'}->[0]->{'col2'});
838: }
839: $output .= '</td>';
840: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 841: if (defined($item->{'header'}->[0]->{'col4'})) {
842: $output .= '<td class="LC_left_item" valign="top">'.
843: &mt($item->{'header'}->[0]->{'col3'});
844: } else {
845: $output .= '<td class="LC_right_item" valign="top">'.
846: &mt($item->{'header'}->[0]->{'col3'});
847: }
1.69 raeburn 848: if ($action eq 'serverstatuses') {
849: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
850: }
851: $output .= '</td>';
1.6 raeburn 852: }
1.150 raeburn 853: if ($item->{'header'}->[0]->{'col4'}) {
854: $output .= '<td class="LC_right_item" valign="top">'.
855: &mt($item->{'header'}->[0]->{'col4'});
856: }
1.69 raeburn 857: $output .= '</tr>';
1.48 raeburn 858: $rowtotal ++;
1.160.6.5 raeburn 859: if ($action eq 'quotas') {
1.86 raeburn 860: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 861: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 862: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 863: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 864: } elsif ($action eq 'scantron') {
865: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 866: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 867: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 868: }
1.3 raeburn 869: }
1.30 raeburn 870: $output .= '
1.3 raeburn 871: </table>
872: </td>
873: </tr>
1.30 raeburn 874: </table><br />';
875: return ($output,$rowtotal);
1.1 raeburn 876: }
877:
1.3 raeburn 878: sub print_login {
1.160.6.5 raeburn 879: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 880: my ($css_class,$datatable);
1.6 raeburn 881: my %choices = &login_choices();
1.110 raeburn 882:
1.160.6.5 raeburn 883: if ($caller eq 'service') {
1.149 raeburn 884: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 885: my $choice = $choices{'disallowlogin'};
886: $css_class = ' class="LC_odd_row"';
1.128 raeburn 887: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 888: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 889: '<th>'.$choices{'server'}.'</th>'.
890: '<th>'.$choices{'serverpath'}.'</th>'.
891: '<th>'.$choices{'custompath'}.'</th>'.
892: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 893: my %disallowed;
894: if (ref($settings) eq 'HASH') {
895: if (ref($settings->{'loginvia'}) eq 'HASH') {
896: %disallowed = %{$settings->{'loginvia'}};
897: }
898: }
899: foreach my $lonhost (sort(keys(%servers))) {
900: my $direct = 'selected="selected"';
1.128 raeburn 901: if (ref($disallowed{$lonhost}) eq 'HASH') {
902: if ($disallowed{$lonhost}{'server'} ne '') {
903: $direct = '';
904: }
1.110 raeburn 905: }
1.115 raeburn 906: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 907: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 908: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
909: '</option>';
1.160.6.13 raeburn 910: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 911: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 912: my $selected = '';
1.128 raeburn 913: if (ref($disallowed{$lonhost}) eq 'HASH') {
914: if ($hostid eq $disallowed{$lonhost}{'server'}) {
915: $selected = 'selected="selected"';
916: }
1.110 raeburn 917: }
918: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
919: $servers{$hostid}.'</option>';
920: }
1.128 raeburn 921: $datatable .= '</select></td>'.
922: '<td><select name="'.$lonhost.'_serverpath">';
923: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
924: my $pathname = $path;
925: if ($path eq 'custom') {
926: $pathname = &mt('Custom Path').' ->';
927: }
928: my $selected = '';
929: if (ref($disallowed{$lonhost}) eq 'HASH') {
930: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
931: $selected = 'selected="selected"';
932: }
933: } elsif ($path eq '') {
934: $selected = 'selected="selected"';
935: }
936: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
937: }
938: $datatable .= '</select></td>';
939: my ($custom,$exempt);
940: if (ref($disallowed{$lonhost}) eq 'HASH') {
941: $custom = $disallowed{$lonhost}{'custompath'};
942: $exempt = $disallowed{$lonhost}{'exempt'};
943: }
944: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
945: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
946: '</tr>';
1.110 raeburn 947: }
948: $datatable .= '</table></td></tr>';
949: return $datatable;
1.160.6.5 raeburn 950: } elsif ($caller eq 'page') {
951: my %defaultchecked = (
952: 'coursecatalog' => 'on',
1.160.6.14 raeburn 953: 'helpdesk' => 'on',
1.160.6.5 raeburn 954: 'adminmail' => 'off',
955: 'newuser' => 'off',
956: );
1.160.6.14 raeburn 957: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 958: my (%checkedon,%checkedoff);
1.42 raeburn 959: foreach my $item (@toggles) {
1.160.6.5 raeburn 960: if ($defaultchecked{$item} eq 'on') {
961: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 962: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 963: } elsif ($defaultchecked{$item} eq 'off') {
964: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 965: $checkedon{$item} = ' ';
966: }
1.1 raeburn 967: }
1.160.6.5 raeburn 968: my @images = ('img','logo','domlogo','login');
969: my @logintext = ('textcol','bgcol');
970: my @bgs = ('pgbg','mainbg','sidebg');
971: my @links = ('link','alink','vlink');
972: my %designhash = &Apache::loncommon::get_domainconf($dom);
973: my %defaultdesign = %Apache::loncommon::defaultdesign;
974: my (%is_custom,%designs);
975: my %defaults = (
976: font => $defaultdesign{'login.font'},
977: );
1.6 raeburn 978: foreach my $item (@images) {
1.160.6.5 raeburn 979: $defaults{$item} = $defaultdesign{'login.'.$item};
980: $defaults{'showlogo'}{$item} = 1;
981: }
982: foreach my $item (@bgs) {
983: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 984: }
1.41 raeburn 985: foreach my $item (@logintext) {
1.160.6.5 raeburn 986: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 987: }
1.160.6.5 raeburn 988: foreach my $item (@links) {
989: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 990: }
1.160.6.5 raeburn 991: if (ref($settings) eq 'HASH') {
992: foreach my $item (@toggles) {
993: if ($settings->{$item} eq '1') {
994: $checkedon{$item} = ' checked="checked" ';
995: $checkedoff{$item} = ' ';
996: } elsif ($settings->{$item} eq '0') {
997: $checkedoff{$item} = ' checked="checked" ';
998: $checkedon{$item} = ' ';
999: }
1.6 raeburn 1000: }
1.160.6.5 raeburn 1001: foreach my $item (@images) {
1002: if (defined($settings->{$item})) {
1003: $designs{$item} = $settings->{$item};
1004: $is_custom{$item} = 1;
1005: }
1006: if (defined($settings->{'showlogo'}{$item})) {
1007: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1008: }
1009: }
1010: foreach my $item (@logintext) {
1011: if ($settings->{$item} ne '') {
1012: $designs{'logintext'}{$item} = $settings->{$item};
1013: $is_custom{$item} = 1;
1014: }
1015: }
1016: if ($settings->{'font'} ne '') {
1017: $designs{'font'} = $settings->{'font'};
1018: $is_custom{'font'} = 1;
1019: }
1020: foreach my $item (@bgs) {
1021: if ($settings->{$item} ne '') {
1022: $designs{'bgs'}{$item} = $settings->{$item};
1023: $is_custom{$item} = 1;
1024: }
1025: }
1026: foreach my $item (@links) {
1027: if ($settings->{$item} ne '') {
1028: $designs{'links'}{$item} = $settings->{$item};
1029: $is_custom{$item} = 1;
1030: }
1031: }
1032: } else {
1033: if ($designhash{$dom.'.login.font'} ne '') {
1034: $designs{'font'} = $designhash{$dom.'.login.font'};
1035: $is_custom{'font'} = 1;
1036: }
1037: foreach my $item (@images) {
1038: if ($designhash{$dom.'.login.'.$item} ne '') {
1039: $designs{$item} = $designhash{$dom.'.login.'.$item};
1040: $is_custom{$item} = 1;
1041: }
1042: }
1043: foreach my $item (@bgs) {
1044: if ($designhash{$dom.'.login.'.$item} ne '') {
1045: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1046: $is_custom{$item} = 1;
1047: }
1048: }
1049: foreach my $item (@links) {
1050: if ($designhash{$dom.'.login.'.$item} ne '') {
1051: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1052: $is_custom{$item} = 1;
1053: }
1.6 raeburn 1054: }
1055: }
1.160.6.5 raeburn 1056: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1057: logo => 'Institution Logo',
1058: domlogo => 'Domain Logo',
1059: login => 'Login box');
1060: my $itemcount = 1;
1061: foreach my $item (@toggles) {
1062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1063: $datatable .=
1064: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1065: '</td><td>'.
1066: '<span class="LC_nobreak"><label><input type="radio" name="'.
1067: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1068: '</label> <label><input type="radio" name="'.$item.'"'.
1069: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1070: '</tr>';
1071: $itemcount ++;
1.6 raeburn 1072: }
1.160.6.5 raeburn 1073: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1074: $datatable .= '</tr></table></td></tr>';
1075: } elsif ($caller eq 'help') {
1076: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1077: my $switchserver = &check_switchserver($dom,$confname);
1078: my $itemcount = 1;
1079: $defaulturl = '/adm/loginproblems.html';
1080: $defaulttype = 'default';
1081: %lt = &Apache::lonlocal::texthash (
1082: del => 'Delete?',
1083: rep => 'Replace:',
1084: upl => 'Upload:',
1085: default => 'Default',
1086: custom => 'Custom',
1087: );
1088: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1089: my @currlangs;
1090: if (ref($settings) eq 'HASH') {
1091: if (ref($settings->{'helpurl'}) eq 'HASH') {
1092: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1093: next if ($settings->{'helpurl'}{$key} eq '');
1094: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1095: $type{$key} = 'custom';
1096: unless ($key eq 'nolang') {
1097: push(@currlangs,$key);
1098: }
1099: }
1100: } elsif ($settings->{'helpurl'} ne '') {
1101: $type{'nolang'} = 'custom';
1102: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1103: }
1104: }
1.160.6.5 raeburn 1105: foreach my $lang ('nolang',sort(@currlangs)) {
1106: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1107: $datatable .= '<tr'.$css_class.'>';
1108: if ($url{$lang} eq '') {
1109: $url{$lang} = $defaulturl;
1110: }
1111: if ($type{$lang} eq '') {
1112: $type{$lang} = $defaulttype;
1113: }
1114: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1115: if ($lang eq 'nolang') {
1116: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1117: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1118: } else {
1119: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1120: $langchoices{$lang},
1121: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1122: }
1123: $datatable .= '</span></td>'."\n".
1124: '<td class="LC_left_item">';
1125: if ($type{$lang} eq 'custom') {
1126: $datatable .= '<span class="LC_nobreak"><label>'.
1127: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1128: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1129: } else {
1130: $datatable .= $lt{'upl'};
1131: }
1132: $datatable .='<br />';
1133: if ($switchserver) {
1134: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1135: } else {
1136: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1137: }
1.160.6.5 raeburn 1138: $datatable .= '</td></tr>';
1139: $itemcount ++;
1.6 raeburn 1140: }
1.160.6.5 raeburn 1141: my @addlangs;
1142: foreach my $lang (sort(keys(%langchoices))) {
1143: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1144: push(@addlangs,$lang);
1145: }
1146: if (@addlangs > 0) {
1147: my %toadd;
1148: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1149: $toadd{''} = &mt('Select');
1150: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1151: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1152: &mt('Add log-in help page for a specific language:').' '.
1153: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1154: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1155: if ($switchserver) {
1156: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1157: } else {
1158: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1159: }
1.160.6.5 raeburn 1160: $datatable .= '</td></tr>';
1161: $itemcount ++;
1.6 raeburn 1162: }
1.160.6.5 raeburn 1163: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1164: }
1.6 raeburn 1165: return $datatable;
1166: }
1167:
1168: sub login_choices {
1169: my %choices =
1170: &Apache::lonlocal::texthash (
1.116 bisitz 1171: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1172: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1173: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1174: disallowlogin => "Login page requests redirected",
1175: hostid => "Server",
1.128 raeburn 1176: server => "Redirect to:",
1177: serverpath => "Path",
1178: custompath => "Custom",
1179: exempt => "Exempt IP(s)",
1.110 raeburn 1180: directlogin => "No redirect",
1181: newuser => "Link to create a user account",
1182: img => "Header",
1183: logo => "Main Logo",
1184: domlogo => "Domain Logo",
1185: login => "Log-in Header",
1186: textcol => "Text color",
1187: bgcol => "Box color",
1188: bgs => "Background colors",
1189: links => "Link colors",
1190: font => "Font color",
1191: pgbg => "Header",
1192: mainbg => "Page",
1193: sidebg => "Login box",
1194: link => "Link",
1195: alink => "Active link",
1196: vlink => "Visited link",
1.6 raeburn 1197: );
1198: return %choices;
1199: }
1200:
1201: sub print_rolecolors {
1.30 raeburn 1202: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1203: my %choices = &color_font_choices();
1204: my @bgs = ('pgbg','tabbg','sidebg');
1205: my @links = ('link','alink','vlink');
1206: my @images = ('img');
1207: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1208: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1209: my %defaultdesign = %Apache::loncommon::defaultdesign;
1210: my (%is_custom,%designs);
1.160.6.22 raeburn 1211: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1212: if (ref($settings) eq 'HASH') {
1213: if (ref($settings->{$role}) eq 'HASH') {
1214: if ($settings->{$role}->{'img'} ne '') {
1215: $designs{'img'} = $settings->{$role}->{'img'};
1216: $is_custom{'img'} = 1;
1217: }
1218: if ($settings->{$role}->{'font'} ne '') {
1219: $designs{'font'} = $settings->{$role}->{'font'};
1220: $is_custom{'font'} = 1;
1221: }
1.97 tempelho 1222: if ($settings->{$role}->{'fontmenu'} ne '') {
1223: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1224: $is_custom{'fontmenu'} = 1;
1225: }
1.6 raeburn 1226: foreach my $item (@bgs) {
1227: if ($settings->{$role}->{$item} ne '') {
1228: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1229: $is_custom{$item} = 1;
1230: }
1231: }
1232: foreach my $item (@links) {
1233: if ($settings->{$role}->{$item} ne '') {
1234: $designs{'links'}{$item} = $settings->{$role}->{$item};
1235: $is_custom{$item} = 1;
1236: }
1237: }
1238: }
1239: } else {
1240: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1241: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1242: $is_custom{'img'} = 1;
1243: }
1.97 tempelho 1244: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1245: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1246: $is_custom{'fontmenu'} = 1;
1247: }
1.6 raeburn 1248: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1249: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1250: $is_custom{'font'} = 1;
1251: }
1252: foreach my $item (@bgs) {
1253: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1254: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1255: $is_custom{$item} = 1;
1256:
1257: }
1258: }
1259: foreach my $item (@links) {
1260: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1261: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1262: $is_custom{$item} = 1;
1263: }
1264: }
1265: }
1266: my $itemcount = 1;
1.30 raeburn 1267: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1268: $datatable .= '</tr></table></td></tr>';
1269: return $datatable;
1270: }
1271:
1.160.6.22 raeburn 1272: sub role_defaults {
1273: my ($role,$bgs,$links,$images,$logintext) = @_;
1274: my %defaults;
1275: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1276: return %defaults;
1277: }
1278: my %defaultdesign = %Apache::loncommon::defaultdesign;
1279: if ($role eq 'login') {
1280: %defaults = (
1281: font => $defaultdesign{$role.'.font'},
1282: );
1283: if (ref($logintext) eq 'ARRAY') {
1284: foreach my $item (@{$logintext}) {
1285: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1286: }
1287: }
1288: foreach my $item (@{$images}) {
1289: $defaults{'showlogo'}{$item} = 1;
1290: }
1291: } else {
1292: %defaults = (
1293: img => $defaultdesign{$role.'.img'},
1294: font => $defaultdesign{$role.'.font'},
1295: fontmenu => $defaultdesign{$role.'.fontmenu'},
1296: );
1297: }
1298: foreach my $item (@{$bgs}) {
1299: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1300: }
1301: foreach my $item (@{$links}) {
1302: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1303: }
1304: foreach my $item (@{$images}) {
1305: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1306: }
1307: return %defaults;
1308: }
1309:
1.6 raeburn 1310: sub display_color_options {
1.9 raeburn 1311: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1312: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1313: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1314: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1315: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1316: '<td>'.$choices->{'font'}.'</td>';
1317: if (!$is_custom->{'font'}) {
1.30 raeburn 1318: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1319: } else {
1320: $datatable .= '<td> </td>';
1321: }
1.160.6.9 raeburn 1322: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1323:
1.8 raeburn 1324: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1325: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1326: ' value="'.$current_color.'" /> '.
1327: ' </td></tr>';
1.107 raeburn 1328: unless ($role eq 'login') {
1329: $datatable .= '<tr'.$css_class.'>'.
1330: '<td>'.$choices->{'fontmenu'}.'</td>';
1331: if (!$is_custom->{'fontmenu'}) {
1332: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1333: } else {
1334: $datatable .= '<td> </td>';
1335: }
1.160.6.22 raeburn 1336: $current_color = $designs->{'fontmenu'} ?
1337: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1338: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1339: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1340: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1341: ' value="'.$current_color.'" /> '.
1342: ' </td></tr>';
1.97 tempelho 1343: }
1.9 raeburn 1344: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1345: foreach my $img (@{$images}) {
1.18 albertel 1346: $itemcount ++;
1.6 raeburn 1347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1348: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1349: '<td>'.$choices->{$img};
1.41 raeburn 1350: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1351: if ($role eq 'login') {
1352: if ($img eq 'login') {
1353: $login_hdr_pick =
1.135 bisitz 1354: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1355: $logincolors =
1356: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1357: $designs,$defaults);
1.70 raeburn 1358: } elsif ($img ne 'domlogo') {
1359: $datatable.= &logo_display_options($img,$defaults,$designs);
1360: }
1361: }
1362: $datatable .= '</td>';
1.6 raeburn 1363: if ($designs->{$img} ne '') {
1364: $imgfile = $designs->{$img};
1.18 albertel 1365: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1366: } else {
1367: $imgfile = $defaults->{$img};
1368: }
1369: if ($imgfile) {
1.9 raeburn 1370: my ($showfile,$fullsize);
1371: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1372: my $urldir = $1;
1373: my $filename = $2;
1374: my @info = &Apache::lonnet::stat_file($designs->{$img});
1375: if (@info) {
1376: my $thumbfile = 'tn-'.$filename;
1377: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1378: if (@thumb) {
1379: $showfile = $urldir.'/'.$thumbfile;
1380: } else {
1381: $showfile = $imgfile;
1382: }
1383: } else {
1384: $showfile = '';
1385: }
1386: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1387: $showfile = $imgfile;
1.6 raeburn 1388: my $imgdir = $1;
1389: my $filename = $2;
1.159 raeburn 1390: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1391: $showfile = "/$imgdir/tn-".$filename;
1392: } else {
1.159 raeburn 1393: my $input = $londocroot.$imgfile;
1394: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1395: if (!-e $output) {
1.9 raeburn 1396: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1397: my ($fullwidth,$fullheight) = &check_dimensions($input);
1398: if ($fullwidth ne '' && $fullheight ne '') {
1399: if ($fullwidth > $width && $fullheight > $height) {
1400: my $size = $width.'x'.$height;
1401: system("convert -sample $size $input $output");
1.159 raeburn 1402: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1403: }
1404: }
1.6 raeburn 1405: }
1406: }
1.16 raeburn 1407: }
1.6 raeburn 1408: if ($showfile) {
1.40 raeburn 1409: if ($showfile =~ m{^/(adm|res)/}) {
1410: if ($showfile =~ m{^/res/}) {
1411: my $local_showfile =
1412: &Apache::lonnet::filelocation('',$showfile);
1413: &Apache::lonnet::repcopy($local_showfile);
1414: }
1415: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1416: }
1417: if ($imgfile) {
1418: if ($imgfile =~ m{^/(adm|res)/}) {
1419: if ($imgfile =~ m{^/res/}) {
1420: my $local_imgfile =
1421: &Apache::lonnet::filelocation('',$imgfile);
1422: &Apache::lonnet::repcopy($local_imgfile);
1423: }
1424: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1425: } else {
1426: $fullsize = $imgfile;
1427: }
1428: }
1.41 raeburn 1429: $datatable .= '<td>';
1430: if ($img eq 'login') {
1.135 bisitz 1431: $datatable .= $login_hdr_pick;
1432: }
1.41 raeburn 1433: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1434: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1435: } else {
1.160.6.22 raeburn 1436: $datatable .= '<td> </td><td class="LC_left_item">'.
1437: &mt('Upload:').'<br />';
1.6 raeburn 1438: }
1439: } else {
1.160.6.22 raeburn 1440: $datatable .= '<td> </td><td class="LC_left_item">'.
1441: &mt('Upload:').'<br />';
1.6 raeburn 1442: }
1.9 raeburn 1443: if ($switchserver) {
1444: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1445: } else {
1.135 bisitz 1446: if ($img ne 'login') { # suppress file selection for Log-in header
1447: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1448: }
1.9 raeburn 1449: }
1450: $datatable .= '</td></tr>';
1.6 raeburn 1451: }
1452: $itemcount ++;
1453: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1454: $datatable .= '<tr'.$css_class.'>'.
1455: '<td>'.$choices->{'bgs'}.'</td>';
1456: my $bgs_def;
1457: foreach my $item (@{$bgs}) {
1458: if (!$is_custom->{$item}) {
1.70 raeburn 1459: $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 1460: }
1461: }
1462: if ($bgs_def) {
1.8 raeburn 1463: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1464: } else {
1465: $datatable .= '<td> </td>';
1466: }
1467: $datatable .= '<td class="LC_right_item">'.
1468: '<table border="0"><tr>';
1.160.6.13 raeburn 1469:
1.6 raeburn 1470: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1471: $datatable .= '<td align="center">'.$choices->{$item};
1472: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1473: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1474: $datatable .= ' ';
1.6 raeburn 1475: }
1.160.6.9 raeburn 1476: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1477: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1478: }
1479: $datatable .= '</tr></table></td></tr>';
1480: $itemcount ++;
1481: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1482: $datatable .= '<tr'.$css_class.'>'.
1483: '<td>'.$choices->{'links'}.'</td>';
1484: my $links_def;
1485: foreach my $item (@{$links}) {
1486: if (!$is_custom->{$item}) {
1.30 raeburn 1487: $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 1488: }
1489: }
1490: if ($links_def) {
1.8 raeburn 1491: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1492: } else {
1493: $datatable .= '<td> </td>';
1494: }
1495: $datatable .= '<td class="LC_right_item">'.
1496: '<table border="0"><tr>';
1497: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1498: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1499: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1500: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1501: $datatable.=' ';
1.6 raeburn 1502: }
1.160.6.9 raeburn 1503: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1504: '" /></td>';
1505: }
1.30 raeburn 1506: $$rowtotal += $itemcount;
1.3 raeburn 1507: return $datatable;
1508: }
1509:
1.70 raeburn 1510: sub logo_display_options {
1511: my ($img,$defaults,$designs) = @_;
1512: my $checkedon;
1513: if (ref($defaults) eq 'HASH') {
1514: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1515: if ($defaults->{'showlogo'}{$img}) {
1516: $checkedon = 'checked="checked" ';
1517: }
1518: }
1519: }
1520: if (ref($designs) eq 'HASH') {
1521: if (ref($designs->{'showlogo'}) eq 'HASH') {
1522: if (defined($designs->{'showlogo'}{$img})) {
1523: if ($designs->{'showlogo'}{$img} == 0) {
1524: $checkedon = '';
1525: } elsif ($designs->{'showlogo'}{$img} == 1) {
1526: $checkedon = 'checked="checked" ';
1527: }
1528: }
1529: }
1530: }
1531: return '<br /><label> <input type="checkbox" name="'.
1532: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1533: &mt('show').'</label>'."\n";
1534: }
1535:
1.41 raeburn 1536: sub login_header_options {
1.135 bisitz 1537: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1538: my $output = '';
1.41 raeburn 1539: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1540: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1541: if (!$is_custom->{'textcol'}) {
1542: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1543: ' ';
1544: }
1545: if (!$is_custom->{'bgcol'}) {
1546: $output .= $choices->{'bgcol'}.': '.
1547: '<span id="css_'.$role.'_font" style="background-color: '.
1548: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1549: }
1550: $output .= '<br />';
1551: }
1552: $output .='<br />';
1553: return $output;
1554: }
1555:
1556: sub login_text_colors {
1.160.6.22 raeburn 1557: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1558: my $color_menu = '<table border="0"><tr>';
1559: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1560: $color_menu .= '<td align="center">'.$choices->{$item};
1561: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1562: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1563: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1564: }
1565: $color_menu .= '</tr></table><br />';
1566: return $color_menu;
1567: }
1568:
1569: sub image_changes {
1570: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1571: my $output;
1.135 bisitz 1572: if ($img eq 'login') {
1573: # suppress image for Log-in header
1574: } elsif (!$is_custom) {
1.70 raeburn 1575: if ($img ne 'domlogo') {
1.41 raeburn 1576: $output .= &mt('Default image:').'<br />';
1577: } else {
1578: $output .= &mt('Default in use:').'<br />';
1579: }
1580: }
1.135 bisitz 1581: if ($img eq 'login') { # suppress image for Log-in header
1582: $output .= '<td>'.$logincolors;
1.41 raeburn 1583: } else {
1.135 bisitz 1584: if ($img_import) {
1585: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1586: }
1587: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1588: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1589: if ($is_custom) {
1590: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1591: '<input type="checkbox" name="'.
1592: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1593: '</label> '.&mt('Replace:').'</span><br />';
1594: } else {
1.160.6.22 raeburn 1595: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1596: }
1.41 raeburn 1597: }
1598: return $output;
1599: }
1600:
1.3 raeburn 1601: sub print_quotas {
1.86 raeburn 1602: my ($dom,$settings,$rowtotal,$action) = @_;
1603: my $context;
1604: if ($action eq 'quotas') {
1605: $context = 'tools';
1606: } else {
1607: $context = $action;
1608: }
1.160.6.20 raeburn 1609: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1610: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1611: my $typecount = 0;
1.101 raeburn 1612: my ($css_class,%titles);
1.86 raeburn 1613: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1614: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1615: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1616: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1617: %titles = &courserequest_titles();
1.160.6.5 raeburn 1618: } elsif ($context eq 'requestauthor') {
1619: @usertools = ('author');
1620: @options = ('norequest','approval','automatic');
1621: %titles = &authorrequest_titles();
1.86 raeburn 1622: } else {
1.160.6.4 raeburn 1623: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1624: %titles = &tool_titles();
1.86 raeburn 1625: }
1.26 raeburn 1626: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1627: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1628: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1629: unless (($context eq 'requestcourses') ||
1630: ($context eq 'requestauthor')) {
1.86 raeburn 1631: if (ref($settings) eq 'HASH') {
1632: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1633: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1634: } else {
1635: $currdefquota = $settings->{$type};
1636: }
1.160.6.20 raeburn 1637: if (ref($settings->{authorquota}) eq 'HASH') {
1638: $currauthorquota = $settings->{authorquota}->{$type};
1639: }
1.78 raeburn 1640: }
1.72 raeburn 1641: }
1.3 raeburn 1642: if (defined($usertypes->{$type})) {
1643: $typecount ++;
1644: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1645: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1646: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1647: '<td class="LC_left_item">';
1.101 raeburn 1648: if ($context eq 'requestcourses') {
1649: $datatable .= '<table><tr>';
1650: }
1651: my %cell;
1.72 raeburn 1652: foreach my $item (@usertools) {
1.101 raeburn 1653: if ($context eq 'requestcourses') {
1654: my ($curroption,$currlimit);
1655: if (ref($settings) eq 'HASH') {
1656: if (ref($settings->{$item}) eq 'HASH') {
1657: $curroption = $settings->{$item}->{$type};
1658: if ($curroption =~ /^autolimit=(\d*)$/) {
1659: $currlimit = $1;
1660: }
1661: }
1662: }
1663: if (!$curroption) {
1664: $curroption = 'norequest';
1665: }
1666: $datatable .= '<th>'.$titles{$item}.'</th>';
1667: foreach my $option (@options) {
1668: my $val = $option;
1669: if ($option eq 'norequest') {
1670: $val = 0;
1671: }
1672: if ($option eq 'validate') {
1673: my $canvalidate = 0;
1674: if (ref($validations{$item}) eq 'HASH') {
1675: if ($validations{$item}{$type}) {
1676: $canvalidate = 1;
1677: }
1678: }
1679: next if (!$canvalidate);
1680: }
1681: my $checked = '';
1682: if ($option eq $curroption) {
1683: $checked = ' checked="checked"';
1684: } elsif ($option eq 'autolimit') {
1685: if ($curroption =~ /^autolimit/) {
1686: $checked = ' checked="checked"';
1687: }
1688: }
1689: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1690: '<input type="radio" name="crsreq_'.$item.
1691: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1692: $titles{$option}.'</label>';
1.101 raeburn 1693: if ($option eq 'autolimit') {
1.127 raeburn 1694: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1695: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1696: 'value="'.$currlimit.'" />';
1.101 raeburn 1697: }
1.127 raeburn 1698: $cell{$item} .= '</span> ';
1.103 raeburn 1699: if ($option eq 'autolimit') {
1.127 raeburn 1700: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1701: }
1.101 raeburn 1702: }
1.160.6.5 raeburn 1703: } elsif ($context eq 'requestauthor') {
1704: my $curroption;
1705: if (ref($settings) eq 'HASH') {
1706: $curroption = $settings->{$type};
1707: }
1708: if (!$curroption) {
1709: $curroption = 'norequest';
1710: }
1711: foreach my $option (@options) {
1712: my $val = $option;
1713: if ($option eq 'norequest') {
1714: $val = 0;
1715: }
1716: my $checked = '';
1717: if ($option eq $curroption) {
1718: $checked = ' checked="checked"';
1719: }
1720: $datatable .= '<span class="LC_nobreak"><label>'.
1721: '<input type="radio" name="authorreq_'.$type.
1722: '" value="'.$val.'"'.$checked.' />'.
1723: $titles{$option}.'</label></span> ';
1724: }
1.101 raeburn 1725: } else {
1726: my $checked = 'checked="checked" ';
1727: if (ref($settings) eq 'HASH') {
1728: if (ref($settings->{$item}) eq 'HASH') {
1729: if ($settings->{$item}->{$type} == 0) {
1730: $checked = '';
1731: } elsif ($settings->{$item}->{$type} == 1) {
1732: $checked = 'checked="checked" ';
1733: }
1.78 raeburn 1734: }
1.72 raeburn 1735: }
1.101 raeburn 1736: $datatable .= '<span class="LC_nobreak"><label>'.
1737: '<input type="checkbox" name="'.$context.'_'.$item.
1738: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1739: '</label></span> ';
1.72 raeburn 1740: }
1.101 raeburn 1741: }
1742: if ($context eq 'requestcourses') {
1743: $datatable .= '</tr><tr>';
1744: foreach my $item (@usertools) {
1.106 raeburn 1745: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1746: }
1747: $datatable .= '</tr></table>';
1.72 raeburn 1748: }
1.86 raeburn 1749: $datatable .= '</td>';
1.160.6.5 raeburn 1750: unless (($context eq 'requestcourses') ||
1751: ($context eq 'requestauthor')) {
1.86 raeburn 1752: $datatable .=
1.160.6.20 raeburn 1753: '<td class="LC_right_item">'.
1754: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1755: '<input type="text" name="quota_'.$type.
1.72 raeburn 1756: '" value="'.$currdefquota.
1.160.6.20 raeburn 1757: '" size="5" /></span>'.(' ' x 2).
1758: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1759: '<input type="text" name="authorquota_'.$type.
1760: '" value="'.$currauthorquota.
1761: '" size="5" /></span></td>';
1.86 raeburn 1762: }
1763: $datatable .= '</tr>';
1.3 raeburn 1764: }
1765: }
1766: }
1.160.6.5 raeburn 1767: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1768: $defaultquota = '20';
1.160.6.20 raeburn 1769: $authorquota = '500';
1.86 raeburn 1770: if (ref($settings) eq 'HASH') {
1771: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1772: $defaultquota = $settings->{'defaultquota'}->{'default'};
1773: } elsif (defined($settings->{'default'})) {
1774: $defaultquota = $settings->{'default'};
1775: }
1.160.6.20 raeburn 1776: if (ref($settings->{'authorquota'}) eq 'HASH') {
1777: $authorquota = $settings->{'authorquota'}->{'default'};
1778: }
1.3 raeburn 1779: }
1780: }
1781: $typecount ++;
1782: $css_class = $typecount%2?' class="LC_odd_row"':'';
1783: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1784: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1785: '<td class="LC_left_item">';
1.101 raeburn 1786: if ($context eq 'requestcourses') {
1787: $datatable .= '<table><tr>';
1788: }
1789: my %defcell;
1.72 raeburn 1790: foreach my $item (@usertools) {
1.101 raeburn 1791: if ($context eq 'requestcourses') {
1792: my ($curroption,$currlimit);
1793: if (ref($settings) eq 'HASH') {
1794: if (ref($settings->{$item}) eq 'HASH') {
1795: $curroption = $settings->{$item}->{'default'};
1796: if ($curroption =~ /^autolimit=(\d*)$/) {
1797: $currlimit = $1;
1798: }
1799: }
1800: }
1801: if (!$curroption) {
1802: $curroption = 'norequest';
1803: }
1804: $datatable .= '<th>'.$titles{$item}.'</th>';
1805: foreach my $option (@options) {
1806: my $val = $option;
1807: if ($option eq 'norequest') {
1808: $val = 0;
1809: }
1810: if ($option eq 'validate') {
1811: my $canvalidate = 0;
1812: if (ref($validations{$item}) eq 'HASH') {
1813: if ($validations{$item}{'default'}) {
1814: $canvalidate = 1;
1815: }
1816: }
1817: next if (!$canvalidate);
1818: }
1819: my $checked = '';
1820: if ($option eq $curroption) {
1821: $checked = ' checked="checked"';
1822: } elsif ($option eq 'autolimit') {
1823: if ($curroption =~ /^autolimit/) {
1824: $checked = ' checked="checked"';
1825: }
1826: }
1827: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1828: '<input type="radio" name="crsreq_'.$item.
1829: '_default" value="'.$val.'"'.$checked.' />'.
1830: $titles{$option}.'</label>';
1831: if ($option eq 'autolimit') {
1.127 raeburn 1832: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1833: $item.'_limit_default" size="1" '.
1834: 'value="'.$currlimit.'" />';
1835: }
1.127 raeburn 1836: $defcell{$item} .= '</span> ';
1.104 raeburn 1837: if ($option eq 'autolimit') {
1.127 raeburn 1838: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1839: }
1.101 raeburn 1840: }
1.160.6.5 raeburn 1841: } elsif ($context eq 'requestauthor') {
1842: my $curroption;
1843: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1844: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1845: }
1846: if (!$curroption) {
1847: $curroption = 'norequest';
1848: }
1849: foreach my $option (@options) {
1850: my $val = $option;
1851: if ($option eq 'norequest') {
1852: $val = 0;
1853: }
1854: my $checked = '';
1855: if ($option eq $curroption) {
1856: $checked = ' checked="checked"';
1857: }
1858: $datatable .= '<span class="LC_nobreak"><label>'.
1859: '<input type="radio" name="authorreq_default"'.
1860: ' value="'.$val.'"'.$checked.' />'.
1861: $titles{$option}.'</label></span> ';
1862: }
1.101 raeburn 1863: } else {
1864: my $checked = 'checked="checked" ';
1865: if (ref($settings) eq 'HASH') {
1866: if (ref($settings->{$item}) eq 'HASH') {
1867: if ($settings->{$item}->{'default'} == 0) {
1868: $checked = '';
1869: } elsif ($settings->{$item}->{'default'} == 1) {
1870: $checked = 'checked="checked" ';
1871: }
1.78 raeburn 1872: }
1.72 raeburn 1873: }
1.101 raeburn 1874: $datatable .= '<span class="LC_nobreak"><label>'.
1875: '<input type="checkbox" name="'.$context.'_'.$item.
1876: '" value="default" '.$checked.'/>'.$titles{$item}.
1877: '</label></span> ';
1878: }
1879: }
1880: if ($context eq 'requestcourses') {
1881: $datatable .= '</tr><tr>';
1882: foreach my $item (@usertools) {
1.106 raeburn 1883: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1884: }
1.101 raeburn 1885: $datatable .= '</tr></table>';
1.72 raeburn 1886: }
1.86 raeburn 1887: $datatable .= '</td>';
1.160.6.5 raeburn 1888: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1889: $datatable .= '<td class="LC_right_item">'.
1890: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1891: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1892: $defaultquota.'" size="5" /></span>'.(' ' x2).
1893: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1894: '<input type="text" name="authorquota" value="'.
1895: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1896: }
1897: $datatable .= '</tr>';
1.72 raeburn 1898: $typecount ++;
1899: $css_class = $typecount%2?' class="LC_odd_row"':'';
1900: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1901: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1902: if ($context eq 'requestcourses') {
1.109 raeburn 1903: $datatable .= &mt('(overrides affiliation, if set)').
1904: '</td>'.
1905: '<td class="LC_left_item">'.
1906: '<table><tr>';
1.101 raeburn 1907: } else {
1.109 raeburn 1908: $datatable .= &mt('(overrides affiliation, if checked)').
1909: '</td>'.
1910: '<td class="LC_left_item" colspan="2">'.
1911: '<br />';
1.101 raeburn 1912: }
1913: my %advcell;
1.72 raeburn 1914: foreach my $item (@usertools) {
1.101 raeburn 1915: if ($context eq 'requestcourses') {
1916: my ($curroption,$currlimit);
1917: if (ref($settings) eq 'HASH') {
1918: if (ref($settings->{$item}) eq 'HASH') {
1919: $curroption = $settings->{$item}->{'_LC_adv'};
1920: if ($curroption =~ /^autolimit=(\d*)$/) {
1921: $currlimit = $1;
1922: }
1923: }
1924: }
1925: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1926: my $checked = '';
1927: if ($curroption eq '') {
1928: $checked = ' checked="checked"';
1929: }
1930: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1931: '<input type="radio" name="crsreq_'.$item.
1932: '__LC_adv" value=""'.$checked.' />'.
1933: &mt('No override set').'</label></span> ';
1.101 raeburn 1934: foreach my $option (@options) {
1935: my $val = $option;
1936: if ($option eq 'norequest') {
1937: $val = 0;
1938: }
1939: if ($option eq 'validate') {
1940: my $canvalidate = 0;
1941: if (ref($validations{$item}) eq 'HASH') {
1942: if ($validations{$item}{'_LC_adv'}) {
1943: $canvalidate = 1;
1944: }
1945: }
1946: next if (!$canvalidate);
1947: }
1948: my $checked = '';
1.104 raeburn 1949: if ($val eq $curroption) {
1.101 raeburn 1950: $checked = ' checked="checked"';
1951: } elsif ($option eq 'autolimit') {
1952: if ($curroption =~ /^autolimit/) {
1953: $checked = ' checked="checked"';
1954: }
1955: }
1956: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1957: '<input type="radio" name="crsreq_'.$item.
1958: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1959: $titles{$option}.'</label>';
1960: if ($option eq 'autolimit') {
1.127 raeburn 1961: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1962: $item.'_limit__LC_adv" size="1" '.
1963: 'value="'.$currlimit.'" />';
1964: }
1.127 raeburn 1965: $advcell{$item} .= '</span> ';
1.104 raeburn 1966: if ($option eq 'autolimit') {
1.127 raeburn 1967: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1968: }
1.101 raeburn 1969: }
1.160.6.5 raeburn 1970: } elsif ($context eq 'requestauthor') {
1971: my $curroption;
1972: if (ref($settings) eq 'HASH') {
1973: $curroption = $settings->{'_LC_adv'};
1974: }
1975: my $checked = '';
1976: if ($curroption eq '') {
1977: $checked = ' checked="checked"';
1978: }
1979: $datatable .= '<span class="LC_nobreak"><label>'.
1980: '<input type="radio" name="authorreq__LC_adv"'.
1981: ' value=""'.$checked.' />'.
1982: &mt('No override set').'</label></span> ';
1983: foreach my $option (@options) {
1984: my $val = $option;
1985: if ($option eq 'norequest') {
1986: $val = 0;
1987: }
1988: my $checked = '';
1989: if ($val eq $curroption) {
1990: $checked = ' checked="checked"';
1991: }
1992: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1993: '<input type="radio" name="authorreq__LC_adv"'.
1994: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1995: $titles{$option}.'</label></span> ';
1996: }
1.101 raeburn 1997: } else {
1998: my $checked = 'checked="checked" ';
1999: if (ref($settings) eq 'HASH') {
2000: if (ref($settings->{$item}) eq 'HASH') {
2001: if ($settings->{$item}->{'_LC_adv'} == 0) {
2002: $checked = '';
2003: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2004: $checked = 'checked="checked" ';
2005: }
1.79 raeburn 2006: }
1.72 raeburn 2007: }
1.101 raeburn 2008: $datatable .= '<span class="LC_nobreak"><label>'.
2009: '<input type="checkbox" name="'.$context.'_'.$item.
2010: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2011: '</label></span> ';
2012: }
2013: }
2014: if ($context eq 'requestcourses') {
2015: $datatable .= '</tr><tr>';
2016: foreach my $item (@usertools) {
1.106 raeburn 2017: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2018: }
1.101 raeburn 2019: $datatable .= '</tr></table>';
1.72 raeburn 2020: }
1.98 raeburn 2021: $datatable .= '</td></tr>';
1.30 raeburn 2022: $$rowtotal += $typecount;
1.3 raeburn 2023: return $datatable;
2024: }
2025:
1.160.6.5 raeburn 2026: sub print_requestmail {
2027: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2028: my ($now,$datatable,%currapp);
1.102 raeburn 2029: $now = time;
2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{'notify'}) eq 'HASH') {
2032: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2033: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2034: }
2035: }
2036: }
1.160.6.16 raeburn 2037: my $numinrow = 2;
1.160.6.34 raeburn 2038: my $css_class;
2039: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2040: my $text;
2041: if ($action eq 'requestcourses') {
2042: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2043: } elsif ($action eq 'requestauthor') {
2044: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2045: } else {
1.160.6.34 raeburn 2046: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2047: }
1.160.6.34 raeburn 2048: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2049: ' <td>'.$text.'</td>'.
1.102 raeburn 2050: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2051: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2052: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2053: if ($numdc > 0) {
2054: $datatable .= $table;
1.102 raeburn 2055: } else {
2056: $datatable .= &mt('There are no active Domain Coordinators');
2057: }
2058: $datatable .='</td></tr>';
2059: $$rowtotal += $rows;
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.125 raeburn 2504: if ($numdc > 1) {
1.143 raeburn 2505: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2506: &mt('Course creation processed as: (choose Dom. Coord.)').
2507: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2508: } else {
1.143 raeburn 2509: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2510: }
1.160.6.16 raeburn 2511: $$rowtotal += $rows;
1.125 raeburn 2512: return $datatable;
2513: }
2514:
1.23 raeburn 2515: sub print_directorysrch {
1.30 raeburn 2516: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2517: my $srchon = ' ';
2518: my $srchoff = ' checked="checked" ';
1.25 raeburn 2519: my ($exacton,$containson,$beginson);
1.24 raeburn 2520: my $localon = ' ';
2521: my $localoff = ' checked="checked" ';
1.23 raeburn 2522: if (ref($settings) eq 'HASH') {
2523: if ($settings->{'available'} eq '1') {
2524: $srchon = $srchoff;
2525: $srchoff = ' ';
2526: }
1.24 raeburn 2527: if ($settings->{'localonly'} eq '1') {
2528: $localon = $localoff;
2529: $localoff = ' ';
2530: }
1.25 raeburn 2531: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2532: foreach my $type (@{$settings->{'searchtypes'}}) {
2533: if ($type eq 'exact') {
2534: $exacton = ' checked="checked" ';
2535: } elsif ($type eq 'contains') {
2536: $containson = ' checked="checked" ';
2537: } elsif ($type eq 'begins') {
2538: $beginson = ' checked="checked" ';
2539: }
2540: }
2541: } else {
2542: if ($settings->{'searchtypes'} eq 'exact') {
2543: $exacton = ' checked="checked" ';
2544: } elsif ($settings->{'searchtypes'} eq 'contains') {
2545: $containson = ' checked="checked" ';
2546: } elsif ($settings->{'searchtypes'} eq 'specify') {
2547: $exacton = ' checked="checked" ';
2548: $containson = ' checked="checked" ';
2549: }
1.23 raeburn 2550: }
2551: }
2552: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2553: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2554:
2555: my $numinrow = 4;
1.26 raeburn 2556: my $cansrchrow = 0;
1.23 raeburn 2557: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2558: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2559: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2560: '<input type="radio" name="dirsrch_available"'.
2561: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2562: '<label><input type="radio" name="dirsrch_available"'.
2563: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2564: '</tr><tr>'.
1.30 raeburn 2565: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2566: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2567: '<input type="radio" name="dirsrch_localonly"'.
2568: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2569: '<label><input type="radio" name="dirsrch_localonly"'.
2570: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2571: '</tr>';
1.30 raeburn 2572: $$rowtotal += 2;
1.26 raeburn 2573: if (ref($usertypes) eq 'HASH') {
2574: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2575: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2576: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2577: $cansrchrow = 1;
2578: }
2579: }
2580: if ($cansrchrow) {
1.30 raeburn 2581: $$rowtotal ++;
1.26 raeburn 2582: $datatable .= '<tr>';
2583: } else {
2584: $datatable .= '<tr class="LC_odd_row">';
2585: }
1.30 raeburn 2586: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2587: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2588: foreach my $title (@{$titleorder}) {
2589: if (defined($searchtitles->{$title})) {
2590: my $check = ' ';
1.93 raeburn 2591: if (ref($settings) eq 'HASH') {
1.39 raeburn 2592: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2593: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2594: $check = ' checked="checked" ';
2595: }
1.25 raeburn 2596: }
2597: }
2598: $datatable .= '<td class="LC_left_item">'.
2599: '<span class="LC_nobreak"><label>'.
2600: '<input type="checkbox" name="searchby" '.
2601: 'value="'.$title.'"'.$check.'/>'.
2602: $searchtitles->{$title}.'</label></span></td>';
2603: }
2604: }
1.26 raeburn 2605: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2606: $$rowtotal ++;
1.26 raeburn 2607: if ($cansrchrow) {
2608: $datatable .= '<tr class="LC_odd_row">';
2609: } else {
2610: $datatable .= '<tr>';
2611: }
1.30 raeburn 2612: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2613: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2614: '<span class="LC_nobreak"><label>'.
2615: '<input type="checkbox" name="searchtypes" '.
2616: $exacton.' value="exact" />'.&mt('Exact match').
2617: '</label> '.
2618: '<label><input type="checkbox" name="searchtypes" '.
2619: $beginson.' value="begins" />'.&mt('Begins with').
2620: '</label> '.
2621: '<label><input type="checkbox" name="searchtypes" '.
2622: $containson.' value="contains" />'.&mt('Contains').
2623: '</label></span></td></tr>';
1.30 raeburn 2624: $$rowtotal ++;
1.25 raeburn 2625: return $datatable;
2626: }
2627:
1.28 raeburn 2628: sub print_contacts {
1.30 raeburn 2629: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2630: my $datatable;
2631: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2632: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2633: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2634: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2635: foreach my $type (@mailings) {
2636: $otheremails{$type} = '';
2637: }
1.134 raeburn 2638: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2639: if (ref($settings) eq 'HASH') {
2640: foreach my $item (@contacts) {
2641: if (exists($settings->{$item})) {
2642: $to{$item} = $settings->{$item};
2643: }
2644: }
2645: foreach my $type (@mailings) {
2646: if (exists($settings->{$type})) {
2647: if (ref($settings->{$type}) eq 'HASH') {
2648: foreach my $item (@contacts) {
2649: if ($settings->{$type}{$item}) {
2650: $checked{$type}{$item} = ' checked="checked" ';
2651: }
2652: }
2653: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2654: if ($type eq 'helpdeskmail') {
2655: $bccemails{$type} = $settings->{$type}{'bcc'};
2656: }
1.28 raeburn 2657: }
1.89 raeburn 2658: } elsif ($type eq 'lonstatusmail') {
2659: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2660: }
2661: }
2662: } else {
2663: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2664: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2665: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2666: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2667: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2668: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2669: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2670: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2671: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2672: }
2673: my ($titles,$short_titles) = &contact_titles();
2674: my $rownum = 0;
2675: my $css_class;
2676: foreach my $item (@contacts) {
1.69 raeburn 2677: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2678: $datatable .= '<tr'.$css_class.'>'.
2679: '<td><span class="LC_nobreak">'.$titles->{$item}.
2680: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2681: '<input type="text" name="'.$item.'" value="'.
2682: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2683: $rownum ++;
1.28 raeburn 2684: }
2685: foreach my $type (@mailings) {
1.69 raeburn 2686: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2687: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2688: '<td><span class="LC_nobreak">'.
2689: $titles->{$type}.': </span></td>'.
1.28 raeburn 2690: '<td class="LC_left_item">'.
2691: '<span class="LC_nobreak">';
2692: foreach my $item (@contacts) {
2693: $datatable .= '<label>'.
2694: '<input type="checkbox" name="'.$type.'"'.
2695: $checked{$type}{$item}.
2696: ' value="'.$item.'" />'.$short_titles->{$item}.
2697: '</label> ';
2698: }
2699: $datatable .= '</span><br />'.&mt('Others').': '.
2700: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2701: 'value="'.$otheremails{$type}.'" />';
2702: if ($type eq 'helpdeskmail') {
1.136 raeburn 2703: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2704: '<input type="text" name="'.$type.'_bcc" '.
2705: 'value="'.$bccemails{$type}.'" />';
2706: }
2707: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2708: $rownum ++;
1.28 raeburn 2709: }
1.160.6.23 raeburn 2710: my %choices;
2711: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2712: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2713: &mt('LON-CAPA core group - MSU'),600,500));
2714: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2715: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2716: &mt('LON-CAPA core group - MSU'),600,500));
2717: my @toggles = ('reporterrors','reportupdates');
2718: my %defaultchecked = ('reporterrors' => 'on',
2719: 'reportupdates' => 'on');
2720: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2721: \%choices,$rownum);
2722: $datatable .= $reports;
1.30 raeburn 2723: $$rowtotal += $rownum;
1.28 raeburn 2724: return $datatable;
2725: }
2726:
1.118 jms 2727: sub print_helpsettings {
1.160.6.5 raeburn 2728: my ($dom,$confname,$settings,$rowtotal) = @_;
2729: my ($datatable,$itemcount);
2730: $itemcount = 1;
2731: my (%choices,%defaultchecked,@toggles);
2732: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2733: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2734: &mt('LON-CAPA bug tracker'),600,500));
2735: %defaultchecked = ('submitbugs' => 'on');
2736: @toggles = ('submitbugs',);
1.122 jms 2737:
1.160.6.5 raeburn 2738: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2739: \%choices,$itemcount);
2740: return $datatable;
1.121 raeburn 2741: }
2742:
2743: sub radiobutton_prefs {
1.160.6.16 raeburn 2744: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2745: $additional) = @_;
1.121 raeburn 2746: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2747: (ref($choices) eq 'HASH'));
2748:
2749: my (%checkedon,%checkedoff,$datatable,$css_class);
2750:
2751: foreach my $item (@{$toggles}) {
2752: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2753: $checkedon{$item} = ' checked="checked" ';
2754: $checkedoff{$item} = ' ';
1.121 raeburn 2755: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2756: $checkedoff{$item} = ' checked="checked" ';
2757: $checkedon{$item} = ' ';
2758: }
2759: }
2760: if (ref($settings) eq 'HASH') {
1.121 raeburn 2761: foreach my $item (@{$toggles}) {
1.118 jms 2762: if ($settings->{$item} eq '1') {
2763: $checkedon{$item} = ' checked="checked" ';
2764: $checkedoff{$item} = ' ';
2765: } elsif ($settings->{$item} eq '0') {
2766: $checkedoff{$item} = ' checked="checked" ';
2767: $checkedon{$item} = ' ';
2768: }
2769: }
1.121 raeburn 2770: }
1.160.6.16 raeburn 2771: if ($onclick) {
2772: $onclick = ' onclick="'.$onclick.'"';
2773: }
1.121 raeburn 2774: foreach my $item (@{$toggles}) {
1.118 jms 2775: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2776: $datatable .=
1.160.6.16 raeburn 2777: '<tr'.$css_class.'><td valign="top">'.
2778: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2779: '</span></td>'.
2780: '<td class="LC_right_item"><span class="LC_nobreak">'.
2781: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2782: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2783: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2784: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2785: '</span>'.$additional.
2786: '</td>'.
1.118 jms 2787: '</tr>';
2788: $itemcount ++;
1.121 raeburn 2789: }
2790: return ($datatable,$itemcount);
2791: }
2792:
2793: sub print_coursedefaults {
1.139 raeburn 2794: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2795: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2796: my $itemcount = 1;
1.160.6.16 raeburn 2797: my %choices = &Apache::lonlocal::texthash (
2798: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2799: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2800: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2801: coursecredits => 'Credits can be specified for courses',
2802: );
1.160.6.21 raeburn 2803: my %staticdefaults = (
2804: anonsurvey_threshold => 10,
2805: uploadquota => 500,
2806: );
1.139 raeburn 2807: if ($position eq 'top') {
2808: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2809: @toggles = ('canuse_pdfforms');
1.139 raeburn 2810: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2811: \%choices,$itemcount);
1.139 raeburn 2812: } else {
2813: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2814: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2815: %curruploadquota);
1.160.6.16 raeburn 2816: my $currusecredits = 0;
1.160.6.30 raeburn 2817: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2818: if (ref($settings) eq 'HASH') {
2819: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2820: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2821: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2822: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2823: }
2824: }
1.160.6.16 raeburn 2825: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2826: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2827: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2828: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2829: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2830: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2831: $currusecredits = 1;
2832: }
2833: }
1.139 raeburn 2834: }
2835: if (!$currdefresponder) {
1.160.6.21 raeburn 2836: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2837: } elsif ($currdefresponder < 1) {
2838: $currdefresponder = 1;
2839: }
1.160.6.21 raeburn 2840: foreach my $type (@types) {
2841: if ($curruploadquota{$type} eq '') {
2842: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2843: }
2844: }
1.139 raeburn 2845: $datatable .=
1.160.6.16 raeburn 2846: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2847: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2848: '</span></td>'.
2849: '<td class="LC_right_item"><span class="LC_nobreak">'.
2850: '<input type="text" name="anonsurvey_threshold"'.
2851: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2852: '</td></tr>'."\n";
2853: $itemcount ++;
2854: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2855: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2856: $choices{'uploadquota'}.
2857: '</span></td>'.
2858: '<td align="right" class="LC_right_item">'.
2859: '<table><tr>';
1.160.6.21 raeburn 2860: foreach my $type (@types) {
2861: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2862: '<input type="text" name="uploadquota_'.$type.'"'.
2863: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2864: }
2865: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2866: $itemcount ++;
1.160.6.40 raeburn 2867: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2868: my $display = 'none';
2869: if ($currusecredits) {
2870: $display = 'block';
2871: }
2872: my $additional = '<div id="credits" style="display: '.$display.'">'.
2873: '<span class="LC_nobreak">'.
2874: &mt('Default credits for official courses [_1]',
2875: '<input type="text" name="official_credits" value="'.
2876: $def_official_credits.'" size="3" />').
2877: '</span><br />'.
2878: '<span class="LC_nobreak">'.
2879: &mt('Default credits for unofficial courses [_1]',
2880: '<input type="text" name="unofficial_credits" value="'.
2881: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2882: '</span><br />'.
2883: '<span class="LC_nobreak">'.
2884: &mt('Default credits for textbook courses [_1]',
2885: '<input type="text" name="textbook_credits" value="'.
2886: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2887: '</span></div>'."\n";
2888: %defaultchecked = ('coursecredits' => 'off');
2889: @toggles = ('coursecredits');
2890: my $current = {
2891: 'coursecredits' => $currusecredits,
2892: };
2893: (my $table,$itemcount) =
2894: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2895: \%choices,$itemcount,$onclick,$additional);
2896: $datatable .= $table;
1.160.6.37 raeburn 2897: $itemcount ++;
2898: }
2899: $$rowtotal += $itemcount;
2900: return $datatable;
2901: }
2902:
2903: sub print_selfenrollment {
2904: my ($position,$dom,$settings,$rowtotal) = @_;
2905: my ($css_class,$datatable);
2906: my $itemcount = 1;
2907: my @types = ('official','unofficial','community','textbook');
2908: if (($position eq 'top') || ($position eq 'middle')) {
2909: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2910: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2911: my @rows;
2912: my $key;
2913: if ($position eq 'top') {
2914: $key = 'admin';
2915: if (ref($rowsref) eq 'ARRAY') {
2916: @rows = @{$rowsref};
2917: }
2918: } elsif ($position eq 'middle') {
2919: $key = 'default';
2920: @rows = ('types','registered','approval','limit');
2921: }
2922: foreach my $row (@rows) {
2923: if (defined($titlesref->{$row})) {
2924: $itemcount ++;
2925: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2926: $datatable .= '<tr'.$css_class.'>'.
2927: '<td>'.$titlesref->{$row}.'</td>'.
2928: '<td class="LC_left_item">'.
2929: '<table><tr>';
2930: my (%current,%currentcap);
2931: if (ref($settings) eq 'HASH') {
2932: if (ref($settings->{$key}) eq 'HASH') {
2933: foreach my $type (@types) {
2934: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2935: $current{$type} = $settings->{$key}->{$type}->{$row};
2936: }
2937: if (($row eq 'limit') && ($key eq 'default')) {
2938: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2939: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2940: }
2941: }
2942: }
2943: }
2944: }
2945: my %roles = (
2946: '0' => &Apache::lonnet::plaintext('dc'),
2947: );
2948:
2949: foreach my $type (@types) {
2950: unless (($row eq 'registered') && ($key eq 'default')) {
2951: $datatable .= '<th>'.&mt($type).'</th>';
2952: }
2953: }
2954: unless (($row eq 'registered') && ($key eq 'default')) {
2955: $datatable .= '</tr><tr>';
2956: }
2957: foreach my $type (@types) {
2958: if ($type eq 'community') {
2959: $roles{'1'} = &mt('Community personnel');
2960: } else {
2961: $roles{'1'} = &mt('Course personnel');
2962: }
2963: $datatable .= '<td style="vertical-align: top">';
2964: if ($position eq 'top') {
2965: my %checked;
2966: if ($current{$type} eq '0') {
2967: $checked{'0'} = ' checked="checked"';
2968: } else {
2969: $checked{'1'} = ' checked="checked"';
2970: }
2971: foreach my $role ('1','0') {
2972: $datatable .= '<span class="LC_nobreak"><label>'.
2973: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2974: 'value="'.$role.'"'.$checked{$role}.' />'.
2975: $roles{$role}.'</label></span> ';
2976: }
2977: } else {
2978: if ($row eq 'types') {
2979: my %checked;
2980: if ($current{$type} =~ /^(all|dom)$/) {
2981: $checked{$1} = ' checked="checked"';
2982: } else {
2983: $checked{''} = ' checked="checked"';
2984: }
2985: foreach my $val ('','dom','all') {
2986: $datatable .= '<span class="LC_nobreak"><label>'.
2987: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2988: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2989: }
2990: } elsif ($row eq 'registered') {
2991: my %checked;
2992: if ($current{$type} eq '1') {
2993: $checked{'1'} = ' checked="checked"';
2994: } else {
2995: $checked{'0'} = ' checked="checked"';
2996: }
2997: foreach my $val ('0','1') {
2998: $datatable .= '<span class="LC_nobreak"><label>'.
2999: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3000: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3001: }
3002: } elsif ($row eq 'approval') {
3003: my %checked;
3004: if ($current{$type} =~ /^([12])$/) {
3005: $checked{$1} = ' checked="checked"';
3006: } else {
3007: $checked{'0'} = ' checked="checked"';
3008: }
3009: for my $val (0..2) {
3010: $datatable .= '<span class="LC_nobreak"><label>'.
3011: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3012: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3013: }
3014: } elsif ($row eq 'limit') {
3015: my %checked;
3016: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3017: $checked{$1} = ' checked="checked"';
3018: } else {
3019: $checked{'none'} = ' checked="checked"';
3020: }
3021: my $cap;
3022: if ($currentcap{$type} =~ /^\d+$/) {
3023: $cap = $currentcap{$type};
3024: }
3025: foreach my $val ('none','allstudents','selfenrolled') {
3026: $datatable .= '<span class="LC_nobreak"><label>'.
3027: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3028: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3029: }
3030: $datatable .= '<br />'.
3031: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3032: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3033: '</span>';
3034: }
3035: }
3036: $datatable .= '</td>';
3037: }
3038: $datatable .= '</tr>';
3039: }
3040: $datatable .= '</table></td></tr>';
3041: }
3042: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3043: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3044: }
3045: $$rowtotal += $itemcount;
3046: return $datatable;
3047: }
3048:
3049: sub print_validation_rows {
3050: my ($caller,$dom,$settings,$rowtotal) = @_;
3051: my ($itemsref,$namesref,$fieldsref);
3052: if ($caller eq 'selfenroll') {
3053: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3054: } elsif ($caller eq 'requestcourses') {
3055: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3056: }
3057: my %currvalidation;
3058: if (ref($settings) eq 'HASH') {
3059: if (ref($settings->{'validation'}) eq 'HASH') {
3060: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3061: }
1.160.6.39 raeburn 3062: }
3063: my $datatable;
3064: my $itemcount = 0;
3065: foreach my $item (@{$itemsref}) {
3066: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3067: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3068: $namesref->{$item}.
3069: '</span></td>'.
3070: '<td class="LC_left_item">';
3071: if (($item eq 'url') || ($item eq 'button')) {
3072: $datatable .= '<span class="LC_nobreak">'.
3073: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3074: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3075: } elsif ($item eq 'fields') {
3076: my @currfields;
3077: if (ref($currvalidation{$item}) eq 'ARRAY') {
3078: @currfields = @{$currvalidation{$item}};
3079: }
3080: foreach my $field (@{$fieldsref}) {
3081: my $check = '';
3082: if (grep(/^\Q$field\E$/,@currfields)) {
3083: $check = ' checked="checked"';
3084: }
3085: $datatable .= '<span class="LC_nobreak"><label>'.
3086: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3087: ' value="'.$field.'"'.$check.' />'.$field.
3088: '</label></span> ';
3089: }
3090: } elsif ($item eq 'markup') {
3091: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3092: $currvalidation{$item}.
1.160.6.37 raeburn 3093: '</textarea>';
1.160.6.39 raeburn 3094: }
3095: $datatable .= '</td></tr>'."\n";
3096: if (ref($rowtotal)) {
1.160.6.37 raeburn 3097: $itemcount ++;
3098: }
1.139 raeburn 3099: }
1.160.6.39 raeburn 3100: if ($caller eq 'requestcourses') {
3101: my %currhash;
3102: if (ref($settings->{'validation'}) eq 'HASH') {
3103: if ($settings->{'validation'}{'dc'} ne '') {
3104: $currhash{$settings->{'validation'}{'dc'}} = 1;
3105: }
3106: }
3107: my $numinrow = 2;
3108: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3109: 'validationdc',%currhash);
3110: if ($numdc > 1) {
3111: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3112: &mt('Course creation processed as: (choose Dom. Coord.)').
3113: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3114: } else {
3115: $datatable .= $dctable.'</td></tr>';
3116: }
3117: $itemcount ++;
3118: }
3119: if (ref($rowtotal)) {
3120: $$rowtotal += $itemcount;
3121: }
1.121 raeburn 3122: return $datatable;
1.118 jms 3123: }
3124:
1.137 raeburn 3125: sub print_usersessions {
3126: my ($position,$dom,$settings,$rowtotal) = @_;
3127: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3128: my (%by_ip,%by_location,@intdoms);
3129: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3130:
3131: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3132: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3133: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3134: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3135: my $itemcount = 1;
3136: if ($position eq 'top') {
1.152 raeburn 3137: if (keys(%serverhomes) > 1) {
1.145 raeburn 3138: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3139: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3140: } else {
1.140 raeburn 3141: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3142: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3143: }
1.137 raeburn 3144: } else {
1.145 raeburn 3145: if (keys(%by_location) == 0) {
3146: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3147: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3148: } else {
3149: my %lt = &usersession_titles();
3150: my $numinrow = 5;
3151: my $prefix;
3152: my @types;
3153: if ($position eq 'bottom') {
3154: $prefix = 'remote';
3155: @types = ('version','excludedomain','includedomain');
3156: } else {
3157: $prefix = 'hosted';
3158: @types = ('excludedomain','includedomain');
3159: }
3160: my (%current,%checkedon,%checkedoff);
3161: my @lcversions = &Apache::lonnet::all_loncaparevs();
3162: my @locations = sort(keys(%by_location));
3163: foreach my $type (@types) {
3164: $checkedon{$type} = '';
3165: $checkedoff{$type} = ' checked="checked"';
3166: }
3167: if (ref($settings) eq 'HASH') {
3168: if (ref($settings->{$prefix}) eq 'HASH') {
3169: foreach my $key (keys(%{$settings->{$prefix}})) {
3170: $current{$key} = $settings->{$prefix}{$key};
3171: if ($key eq 'version') {
3172: if ($current{$key} ne '') {
3173: $checkedon{$key} = ' checked="checked"';
3174: $checkedoff{$key} = '';
3175: }
3176: } elsif (ref($current{$key}) eq 'ARRAY') {
3177: $checkedon{$key} = ' checked="checked"';
3178: $checkedoff{$key} = '';
3179: }
1.137 raeburn 3180: }
3181: }
3182: }
1.145 raeburn 3183: foreach my $type (@types) {
3184: next if ($type ne 'version' && !@locations);
3185: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3186: $datatable .= '<tr'.$css_class.'>
3187: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3188: <span class="LC_nobreak">
3189: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3190: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3191: if ($type eq 'version') {
3192: my $selector = '<select name="'.$prefix.'_version">';
3193: foreach my $version (@lcversions) {
3194: my $selected = '';
3195: if ($current{'version'} eq $version) {
3196: $selected = ' selected="selected"';
3197: }
3198: $selector .= ' <option value="'.$version.'"'.
3199: $selected.'>'.$version.'</option>';
3200: }
3201: $selector .= '</select> ';
3202: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3203: } else {
3204: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3205: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3206: ' />'.(' 'x2).
3207: '<input type="button" value="'.&mt('uncheck all').'" '.
3208: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3209: "\n".
3210: '</div><div><table>';
3211: my $rem;
3212: for (my $i=0; $i<@locations; $i++) {
3213: my ($showloc,$value,$checkedtype);
3214: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3215: my $ip = $by_location{$locations[$i]}->[0];
3216: if (ref($by_ip{$ip}) eq 'ARRAY') {
3217: $value = join(':',@{$by_ip{$ip}});
3218: $showloc = join(', ',@{$by_ip{$ip}});
3219: if (ref($current{$type}) eq 'ARRAY') {
3220: foreach my $loc (@{$by_ip{$ip}}) {
3221: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3222: $checkedtype = ' checked="checked"';
3223: last;
3224: }
3225: }
1.138 raeburn 3226: }
3227: }
3228: }
1.145 raeburn 3229: $rem = $i%($numinrow);
3230: if ($rem == 0) {
3231: if ($i > 0) {
3232: $datatable .= '</tr>';
3233: }
3234: $datatable .= '<tr>';
3235: }
3236: $datatable .= '<td class="LC_left_item">'.
3237: '<span class="LC_nobreak"><label>'.
3238: '<input type="checkbox" name="'.$prefix.'_'.$type.
3239: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3240: '</label></span></td>';
1.137 raeburn 3241: }
1.145 raeburn 3242: $rem = @locations%($numinrow);
3243: my $colsleft = $numinrow - $rem;
3244: if ($colsleft > 1 ) {
3245: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3246: ' </td>';
3247: } elsif ($colsleft == 1) {
3248: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3249: }
1.145 raeburn 3250: $datatable .= '</tr></table>';
1.137 raeburn 3251: }
1.145 raeburn 3252: $datatable .= '</td></tr>';
3253: $itemcount ++;
1.137 raeburn 3254: }
3255: }
3256: }
3257: $$rowtotal += $itemcount;
3258: return $datatable;
3259: }
3260:
1.138 raeburn 3261: sub build_location_hashes {
3262: my ($intdoms,$by_ip,$by_location) = @_;
3263: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3264: (ref($by_location) eq 'HASH'));
3265: my %iphost = &Apache::lonnet::get_iphost();
3266: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3267: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3268: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3269: foreach my $id (@{$iphost{$primary_ip}}) {
3270: my $intdom = &Apache::lonnet::internet_dom($id);
3271: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3272: push(@{$intdoms},$intdom);
3273: }
3274: }
3275: }
3276: foreach my $ip (keys(%iphost)) {
3277: if (ref($iphost{$ip}) eq 'ARRAY') {
3278: foreach my $id (@{$iphost{$ip}}) {
3279: my $location = &Apache::lonnet::internet_dom($id);
3280: if ($location) {
3281: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3282: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3283: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3284: push(@{$by_ip->{$ip}},$location);
3285: }
3286: } else {
3287: $by_ip->{$ip} = [$location];
3288: }
3289: }
3290: }
3291: }
3292: }
3293: foreach my $ip (sort(keys(%{$by_ip}))) {
3294: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3295: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3296: my $first = $by_ip->{$ip}->[0];
3297: if (ref($by_location->{$first}) eq 'ARRAY') {
3298: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3299: push(@{$by_location->{$first}},$ip);
3300: }
3301: } else {
3302: $by_location->{$first} = [$ip];
3303: }
3304: }
3305: }
3306: return;
3307: }
3308:
1.145 raeburn 3309: sub current_offloads_to {
3310: my ($dom,$settings,$servers) = @_;
3311: my (%spareid,%otherdomconfigs);
1.152 raeburn 3312: if (ref($servers) eq 'HASH') {
1.145 raeburn 3313: foreach my $lonhost (sort(keys(%{$servers}))) {
3314: my $gotspares;
1.152 raeburn 3315: if (ref($settings) eq 'HASH') {
3316: if (ref($settings->{'spares'}) eq 'HASH') {
3317: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3318: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3319: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3320: $gotspares = 1;
3321: }
1.145 raeburn 3322: }
3323: }
3324: unless ($gotspares) {
3325: my $gotspares;
3326: my $serverhomeID =
3327: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3328: my $serverhomedom =
3329: &Apache::lonnet::host_domain($serverhomeID);
3330: if ($serverhomedom ne $dom) {
3331: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3332: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3333: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3334: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3335: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3336: $gotspares = 1;
3337: }
3338: }
3339: } else {
3340: $otherdomconfigs{$serverhomedom} =
3341: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3342: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3343: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3344: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3345: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3346: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3347: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3348: $gotspares = 1;
3349: }
3350: }
3351: }
3352: }
3353: }
3354: }
3355: }
3356: unless ($gotspares) {
3357: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3358: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3359: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3360: } else {
3361: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3362: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3363: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3364: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3365: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3366: } else {
1.150 raeburn 3367: my %what = (
3368: spareid => 1,
3369: );
3370: my ($result,$returnhash) =
3371: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3372: if ($result eq 'ok') {
3373: if (ref($returnhash) eq 'HASH') {
3374: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3375: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3376: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3377: }
3378: }
1.145 raeburn 3379: }
3380: }
3381: }
3382: }
3383: }
3384: }
3385: return %spareid;
3386: }
3387:
3388: sub spares_row {
1.152 raeburn 3389: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3390: my $css_class;
3391: my $numinrow = 4;
3392: my $itemcount = 1;
3393: my $datatable;
1.152 raeburn 3394: my %typetitles = &sparestype_titles();
3395: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3396: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3397: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3398: my ($othercontrol,$serverdom);
3399: if ($serverhome ne $server) {
3400: $serverdom = &Apache::lonnet::host_domain($serverhome);
3401: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3402: } else {
3403: $serverdom = &Apache::lonnet::host_domain($server);
3404: if ($serverdom ne $dom) {
3405: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3406: }
3407: }
3408: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3409: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3410: $datatable .= '<tr'.$css_class.'>
3411: <td rowspan="2">
1.160.6.13 raeburn 3412: <span class="LC_nobreak">'.
3413: &mt('[_1] when busy, offloads to:'
3414: ,'<b>'.$server.'</b>').
3415: "\n";
1.145 raeburn 3416: my (%current,%canselect);
1.152 raeburn 3417: my @choices =
3418: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3419: foreach my $type ('primary','default') {
3420: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3421: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3422: my @spares = @{$spareid->{$server}{$type}};
3423: if (@spares > 0) {
1.152 raeburn 3424: if ($othercontrol) {
3425: $current{$type} = join(', ',@spares);
3426: } else {
3427: $current{$type} .= '<table>';
3428: my $numspares = scalar(@spares);
3429: for (my $i=0; $i<@spares; $i++) {
3430: my $rem = $i%($numinrow);
3431: if ($rem == 0) {
3432: if ($i > 0) {
3433: $current{$type} .= '</tr>';
3434: }
3435: $current{$type} .= '<tr>';
1.145 raeburn 3436: }
1.152 raeburn 3437: $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'".');" /> '.
3438: $spareid->{$server}{$type}[$i].
3439: '</label></td>'."\n";
3440: }
3441: my $rem = @spares%($numinrow);
3442: my $colsleft = $numinrow - $rem;
3443: if ($colsleft > 1 ) {
3444: $current{$type} .= '<td colspan="'.$colsleft.
3445: '" class="LC_left_item">'.
3446: ' </td>';
3447: } elsif ($colsleft == 1) {
3448: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3449: }
1.152 raeburn 3450: $current{$type} .= '</tr></table>';
1.150 raeburn 3451: }
1.145 raeburn 3452: }
3453: }
3454: if ($current{$type} eq '') {
3455: $current{$type} = &mt('None specified');
3456: }
1.152 raeburn 3457: if ($othercontrol) {
3458: if ($type eq 'primary') {
3459: $canselect{$type} = $othercontrol;
3460: }
3461: } else {
3462: $canselect{$type} =
3463: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3464: '<select name="newspare_'.$type.'_'.$server.'" '.
3465: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3466: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3467: if (@choices > 0) {
3468: foreach my $lonhost (@choices) {
3469: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3470: }
3471: }
3472: $canselect{$type} .= '</select>'."\n";
3473: }
3474: } else {
3475: $current{$type} = &mt('Could not be determined');
3476: if ($type eq 'primary') {
3477: $canselect{$type} = $othercontrol;
3478: }
1.145 raeburn 3479: }
1.152 raeburn 3480: if ($type eq 'default') {
3481: $datatable .= '<tr'.$css_class.'>';
3482: }
3483: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3484: '<td>'.$current{$type}.'</td>'."\n".
3485: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3486: }
3487: $itemcount ++;
3488: }
3489: }
3490: $$rowtotal += $itemcount;
3491: return $datatable;
3492: }
3493:
1.152 raeburn 3494: sub possible_newspares {
3495: my ($server,$currspares,$serverhomes,$altids) = @_;
3496: my $serverhostname = &Apache::lonnet::hostname($server);
3497: my %excluded;
3498: if ($serverhostname ne '') {
3499: %excluded = (
3500: $serverhostname => 1,
3501: );
3502: }
3503: if (ref($currspares) eq 'HASH') {
3504: foreach my $type (keys(%{$currspares})) {
3505: if (ref($currspares->{$type}) eq 'ARRAY') {
3506: if (@{$currspares->{$type}} > 0) {
3507: foreach my $curr (@{$currspares->{$type}}) {
3508: my $hostname = &Apache::lonnet::hostname($curr);
3509: $excluded{$hostname} = 1;
3510: }
3511: }
3512: }
3513: }
3514: }
3515: my @choices;
3516: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3517: if (keys(%{$serverhomes}) > 1) {
3518: foreach my $name (sort(keys(%{$serverhomes}))) {
3519: unless ($excluded{$name}) {
3520: if (exists($altids->{$serverhomes->{$name}})) {
3521: push(@choices,$altids->{$serverhomes->{$name}});
3522: } else {
3523: push(@choices,$serverhomes->{$name});
1.145 raeburn 3524: }
3525: }
3526: }
3527: }
3528: }
1.152 raeburn 3529: return sort(@choices);
1.145 raeburn 3530: }
3531:
1.150 raeburn 3532: sub print_loadbalancing {
3533: my ($dom,$settings,$rowtotal) = @_;
3534: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3535: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3536: my $numinrow = 1;
3537: my $datatable;
3538: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3539: my (%currbalancer,%currtargets,%currrules,%existing);
3540: if (ref($settings) eq 'HASH') {
3541: %existing = %{$settings};
3542: }
3543: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3544: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3545: \%currtargets,\%currrules);
1.150 raeburn 3546: } else {
3547: return;
3548: }
3549: my ($othertitle,$usertypes,$types) =
3550: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3551: my $rownum = 8;
1.150 raeburn 3552: if (ref($types) eq 'ARRAY') {
3553: $rownum += scalar(@{$types});
3554: }
1.160.6.7 raeburn 3555: my @css_class = ('LC_odd_row','LC_even_row');
3556: my $balnum = 0;
3557: my $islast;
3558: my (@toshow,$disabledtext);
3559: if (keys(%currbalancer) > 0) {
3560: @toshow = sort(keys(%currbalancer));
3561: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3562: push(@toshow,'');
3563: }
3564: } else {
3565: @toshow = ('');
3566: $disabledtext = &mt('No existing load balancer');
3567: }
3568: foreach my $lonhost (@toshow) {
3569: if ($balnum == scalar(@toshow)-1) {
3570: $islast = 1;
3571: } else {
3572: $islast = 0;
3573: }
3574: my $cssidx = $balnum%2;
3575: my $targets_div_style = 'display: none';
3576: my $disabled_div_style = 'display: block';
3577: my $homedom_div_style = 'display: none';
3578: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3579: '<td rowspan="'.$rownum.'" valign="top">'.
3580: '<p>';
3581: if ($lonhost eq '') {
3582: $datatable .= '<span class="LC_nobreak">';
3583: if (keys(%currbalancer) > 0) {
3584: $datatable .= &mt('Add balancer:');
3585: } else {
3586: $datatable .= &mt('Enable balancer:');
3587: }
3588: $datatable .= ' '.
3589: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3590: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3591: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3592: '<option value="" selected="selected">'.&mt('None').
3593: '</option>'."\n";
3594: foreach my $server (sort(keys(%servers))) {
3595: next if ($currbalancer{$server});
3596: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3597: }
3598: $datatable .=
3599: '</select>'."\n".
3600: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3601: } else {
3602: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3603: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3604: &mt('Stop balancing').'</label>'.
3605: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3606: $targets_div_style = 'display: block';
3607: $disabled_div_style = 'display: none';
3608: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3609: $homedom_div_style = 'display: block';
3610: }
3611: }
3612: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3613: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3614: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3615: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3616: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3617: my @sparestypes = ('primary','default');
3618: my %typetitles = &sparestype_titles();
3619: foreach my $sparetype (@sparestypes) {
3620: my $targettable;
3621: for (my $i=0; $i<$numspares; $i++) {
3622: my $checked;
3623: if (ref($currtargets{$lonhost}) eq 'HASH') {
3624: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3625: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3626: $checked = ' checked="checked"';
3627: }
3628: }
3629: }
3630: my ($chkboxval,$disabled);
3631: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3632: $chkboxval = $spares[$i];
3633: }
3634: if (exists($currbalancer{$spares[$i]})) {
3635: $disabled = ' disabled="disabled"';
3636: }
3637: $targettable .=
3638: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3639: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3640: '</span></label></td>';
3641: my $rem = $i%($numinrow);
3642: if ($rem == 0) {
3643: if (($i > 0) && ($i < $numspares-1)) {
3644: $targettable .= '</tr>';
3645: }
3646: if ($i < $numspares-1) {
3647: $targettable .= '<tr>';
1.150 raeburn 3648: }
3649: }
3650: }
1.160.6.7 raeburn 3651: if ($targettable ne '') {
3652: my $rem = $numspares%($numinrow);
3653: my $colsleft = $numinrow - $rem;
3654: if ($colsleft > 1 ) {
3655: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3656: ' </td>';
3657: } elsif ($colsleft == 1) {
3658: $targettable .= '<td class="LC_left_item"> </td>';
3659: }
3660: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3661: '<table><tr>'.$targettable.'</tr></table><br />';
3662: }
3663: }
3664: $datatable .= '</div></td></tr>'.
3665: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3666: $othertitle,$usertypes,$types,\%servers,
3667: \%currbalancer,$lonhost,
3668: $targets_div_style,$homedom_div_style,
3669: $css_class[$cssidx],$balnum,$islast);
3670: $$rowtotal += $rownum;
3671: $balnum ++;
3672: }
3673: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3674: return $datatable;
3675: }
3676:
3677: sub get_loadbalancers_config {
3678: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3679: return unless ((ref($servers) eq 'HASH') &&
3680: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3681: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3682: if (keys(%{$existing}) > 0) {
3683: my $oldlonhost;
3684: foreach my $key (sort(keys(%{$existing}))) {
3685: if ($key eq 'lonhost') {
3686: $oldlonhost = $existing->{'lonhost'};
3687: $currbalancer->{$oldlonhost} = 1;
3688: } elsif ($key eq 'targets') {
3689: if ($oldlonhost) {
3690: $currtargets->{$oldlonhost} = $existing->{'targets'};
3691: }
3692: } elsif ($key eq 'rules') {
3693: if ($oldlonhost) {
3694: $currrules->{$oldlonhost} = $existing->{'rules'};
3695: }
3696: } elsif (ref($existing->{$key}) eq 'HASH') {
3697: $currbalancer->{$key} = 1;
3698: $currtargets->{$key} = $existing->{$key}{'targets'};
3699: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3700: }
3701: }
1.160.6.7 raeburn 3702: } else {
3703: my ($balancerref,$targetsref) =
3704: &Apache::lonnet::get_lonbalancer_config($servers);
3705: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3706: foreach my $server (sort(keys(%{$balancerref}))) {
3707: $currbalancer->{$server} = 1;
3708: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3709: }
3710: }
3711: }
1.160.6.7 raeburn 3712: return;
1.150 raeburn 3713: }
3714:
3715: sub loadbalancing_rules {
3716: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3717: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3718: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3719: my $output;
1.160.6.7 raeburn 3720: my $num = 0;
3721: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3722: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3723: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3724: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3725: $num ++;
1.150 raeburn 3726: my $current;
3727: if (ref($currrules) eq 'HASH') {
3728: $current = $currrules->{$type};
3729: }
1.160.6.26 raeburn 3730: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3731: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3732: $current = '';
3733: }
3734: }
3735: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3736: $servers,$currbalancer,$lonhost,$dom,
3737: $targets_div_style,$homedom_div_style,
3738: $css_class,$balnum,$num,$islast);
1.150 raeburn 3739: }
3740: }
3741: return $output;
3742: }
3743:
3744: sub loadbalancing_titles {
3745: my ($dom,$intdom,$usertypes,$types) = @_;
3746: my %othertypes = (
3747: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3748: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3749: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3750: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3751: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3752: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3753: );
1.160.6.26 raeburn 3754: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3755: if (ref($types) eq 'ARRAY') {
3756: unshift(@alltypes,@{$types},'default');
3757: }
3758: my %titles;
3759: foreach my $type (@alltypes) {
3760: if ($type =~ /^_LC_/) {
3761: $titles{$type} = $othertypes{$type};
3762: } elsif ($type eq 'default') {
3763: $titles{$type} = &mt('All users from [_1]',$dom);
3764: if (ref($types) eq 'ARRAY') {
3765: if (@{$types} > 0) {
3766: $titles{$type} = &mt('Other users from [_1]',$dom);
3767: }
3768: }
3769: } elsif (ref($usertypes) eq 'HASH') {
3770: $titles{$type} = $usertypes->{$type};
3771: }
3772: }
3773: return (\@alltypes,\%othertypes,\%titles);
3774: }
3775:
3776: sub loadbalance_rule_row {
1.160.6.7 raeburn 3777: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3778: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3779: my @rulenames;
1.150 raeburn 3780: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3781: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3782: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3783: } else {
1.160.6.26 raeburn 3784: @rulenames = ('default','homeserver');
3785: if ($type eq '_LC_external') {
3786: push(@rulenames,'externalbalancer');
3787: } else {
3788: push(@rulenames,'specific');
3789: }
3790: push(@rulenames,'none');
1.150 raeburn 3791: }
3792: my $style = $targets_div_style;
1.160.6.26 raeburn 3793: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3794: $style = $homedom_div_style;
3795: }
1.160.6.7 raeburn 3796: my $space;
3797: if ($islast && $num == 1) {
3798: $space = '<div display="inline-block"> </div>';
3799: }
3800: my $output =
3801: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3802: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3803: '<td valaign="top">'.$space.
3804: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3805: for (my $i=0; $i<@rulenames; $i++) {
3806: my $rule = $rulenames[$i];
3807: my ($checked,$extra);
3808: if ($rulenames[$i] eq 'default') {
3809: $rule = '';
3810: }
3811: if ($rulenames[$i] eq 'specific') {
3812: if (ref($servers) eq 'HASH') {
3813: my $default;
3814: if (($current ne '') && (exists($servers->{$current}))) {
3815: $checked = ' checked="checked"';
3816: }
3817: unless ($checked) {
3818: $default = ' selected="selected"';
3819: }
1.160.6.7 raeburn 3820: $extra =
3821: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3822: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3823: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3824: '<option value=""'.$default.'></option>'."\n";
3825: foreach my $server (sort(keys(%{$servers}))) {
3826: if (ref($currbalancer) eq 'HASH') {
3827: next if (exists($currbalancer->{$server}));
3828: }
1.150 raeburn 3829: my $selected;
1.160.6.7 raeburn 3830: if ($server eq $current) {
1.150 raeburn 3831: $selected = ' selected="selected"';
3832: }
1.160.6.7 raeburn 3833: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3834: }
3835: $extra .= '</select>';
3836: }
3837: } elsif ($rule eq $current) {
3838: $checked = ' checked="checked"';
3839: }
3840: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3841: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3842: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3843: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3844: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3845: '</label>'.$extra.'</span><br />'."\n";
3846: }
3847: $output .= '</div></td></tr>'."\n";
3848: return $output;
3849: }
3850:
3851: sub offloadtype_text {
3852: my %ruletitles = &Apache::lonlocal::texthash (
3853: 'default' => 'Offloads to default destinations',
3854: 'homeserver' => "Offloads to user's home server",
3855: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3856: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3857: 'none' => 'No offload',
1.160.6.26 raeburn 3858: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3859: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3860: );
3861: return %ruletitles;
3862: }
3863:
3864: sub sparestype_titles {
3865: my %typestitles = &Apache::lonlocal::texthash (
3866: 'primary' => 'primary',
3867: 'default' => 'default',
3868: );
3869: return %typestitles;
3870: }
3871:
1.28 raeburn 3872: sub contact_titles {
3873: my %titles = &Apache::lonlocal::texthash (
3874: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3875: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3876: 'errormail' => 'Error reports to be e-mailed to',
3877: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3878: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3879: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3880: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3881: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3882: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3883: );
3884: my %short_titles = &Apache::lonlocal::texthash (
3885: adminemail => 'Admin E-mail address',
3886: supportemail => 'Support E-mail',
3887: );
3888: return (\%titles,\%short_titles);
3889: }
3890:
1.72 raeburn 3891: sub tool_titles {
3892: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3893: aboutme => 'Personal web page',
1.86 raeburn 3894: blog => 'Blog',
1.160.6.4 raeburn 3895: webdav => 'WebDAV',
1.86 raeburn 3896: portfolio => 'Portfolio',
1.88 bisitz 3897: official => 'Official courses (with institutional codes)',
3898: unofficial => 'Unofficial courses',
1.98 raeburn 3899: community => 'Communities',
1.160.6.30 raeburn 3900: textbook => 'Textbook courses',
1.86 raeburn 3901: );
1.72 raeburn 3902: return %titles;
3903: }
3904:
1.101 raeburn 3905: sub courserequest_titles {
3906: my %titles = &Apache::lonlocal::texthash (
3907: official => 'Official',
3908: unofficial => 'Unofficial',
3909: community => 'Communities',
1.160.6.30 raeburn 3910: textbook => 'Textbook',
1.101 raeburn 3911: norequest => 'Not allowed',
1.104 raeburn 3912: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3913: validate => 'With validation',
3914: autolimit => 'Numerical limit',
1.103 raeburn 3915: unlimited => '(blank for unlimited)',
1.101 raeburn 3916: );
3917: return %titles;
3918: }
3919:
1.160.6.5 raeburn 3920: sub authorrequest_titles {
3921: my %titles = &Apache::lonlocal::texthash (
3922: norequest => 'Not allowed',
3923: approval => 'Approval by Dom. Coord.',
3924: automatic => 'Automatic approval',
3925: );
3926: return %titles;
3927: }
3928:
1.101 raeburn 3929: sub courserequest_conditions {
3930: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3931: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3932: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3933: );
3934: return %conditions;
3935: }
3936:
3937:
1.27 raeburn 3938: sub print_usercreation {
1.30 raeburn 3939: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3940: my $numinrow = 4;
1.28 raeburn 3941: my $datatable;
3942: if ($position eq 'top') {
1.30 raeburn 3943: $$rowtotal ++;
1.34 raeburn 3944: my $rowcount = 0;
1.32 raeburn 3945: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3946: if (ref($rules) eq 'HASH') {
3947: if (keys(%{$rules}) > 0) {
1.32 raeburn 3948: $datatable .= &user_formats_row('username',$settings,$rules,
3949: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3950: $$rowtotal ++;
1.32 raeburn 3951: $rowcount ++;
3952: }
3953: }
3954: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3955: if (ref($idrules) eq 'HASH') {
3956: if (keys(%{$idrules}) > 0) {
3957: $datatable .= &user_formats_row('id',$settings,$idrules,
3958: $idruleorder,$numinrow,$rowcount);
3959: $$rowtotal ++;
3960: $rowcount ++;
1.28 raeburn 3961: }
3962: }
1.39 raeburn 3963: if ($rowcount == 0) {
3964: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3965: $$rowtotal ++;
3966: $rowcount ++;
3967: }
1.34 raeburn 3968: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3969: my @creators = ('author','course','requestcrs');
1.37 raeburn 3970: my ($rules,$ruleorder) =
3971: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3972: my %lt = &usercreation_types();
3973: my %checked;
3974: if (ref($settings) eq 'HASH') {
3975: if (ref($settings->{'cancreate'}) eq 'HASH') {
3976: foreach my $item (@creators) {
3977: $checked{$item} = $settings->{'cancreate'}{$item};
3978: }
3979: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3980: foreach my $item (@creators) {
3981: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3982: $checked{$item} = 'none';
3983: }
3984: }
3985: }
3986: }
3987: my $rownum = 0;
3988: foreach my $item (@creators) {
3989: $rownum ++;
1.160.6.34 raeburn 3990: if ($checked{$item} eq '') {
3991: $checked{$item} = 'any';
1.34 raeburn 3992: }
3993: my $css_class;
3994: if ($rownum%2) {
3995: $css_class = '';
3996: } else {
3997: $css_class = ' class="LC_odd_row" ';
3998: }
3999: $datatable .= '<tr'.$css_class.'>'.
4000: '<td><span class="LC_nobreak">'.$lt{$item}.
4001: '</span></td><td align="right">';
1.160.6.34 raeburn 4002: my @options = ('any');
4003: if (ref($rules) eq 'HASH') {
4004: if (keys(%{$rules}) > 0) {
4005: push(@options,('official','unofficial'));
1.37 raeburn 4006: }
4007: }
1.160.6.34 raeburn 4008: push(@options,'none');
1.37 raeburn 4009: foreach my $option (@options) {
1.50 raeburn 4010: my $type = 'radio';
1.34 raeburn 4011: my $check = ' ';
1.160.6.34 raeburn 4012: if ($checked{$item} eq $option) {
4013: $check = ' checked="checked" ';
1.34 raeburn 4014: }
4015: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4016: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4017: $item.'" value="'.$option.'"'.$check.'/> '.
4018: $lt{$option}.'</label> </span>';
4019: }
4020: $datatable .= '</td></tr>';
4021: }
1.28 raeburn 4022: } else {
4023: my @contexts = ('author','course','domain');
4024: my @authtypes = ('int','krb4','krb5','loc');
4025: my %checked;
4026: if (ref($settings) eq 'HASH') {
4027: if (ref($settings->{'authtypes'}) eq 'HASH') {
4028: foreach my $item (@contexts) {
4029: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4030: foreach my $auth (@authtypes) {
4031: if ($settings->{'authtypes'}{$item}{$auth}) {
4032: $checked{$item}{$auth} = ' checked="checked" ';
4033: }
4034: }
4035: }
4036: }
1.27 raeburn 4037: }
1.35 raeburn 4038: } else {
4039: foreach my $item (@contexts) {
1.36 raeburn 4040: foreach my $auth (@authtypes) {
1.35 raeburn 4041: $checked{$item}{$auth} = ' checked="checked" ';
4042: }
4043: }
1.27 raeburn 4044: }
1.28 raeburn 4045: my %title = &context_names();
4046: my %authname = &authtype_names();
4047: my $rownum = 0;
4048: my $css_class;
4049: foreach my $item (@contexts) {
4050: if ($rownum%2) {
4051: $css_class = '';
4052: } else {
4053: $css_class = ' class="LC_odd_row" ';
4054: }
1.30 raeburn 4055: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4056: '<td>'.$title{$item}.
4057: '</td><td class="LC_left_item">'.
4058: '<span class="LC_nobreak">';
4059: foreach my $auth (@authtypes) {
4060: $datatable .= '<label>'.
4061: '<input type="checkbox" name="'.$item.'_auth" '.
4062: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4063: $authname{$auth}.'</label> ';
4064: }
4065: $datatable .= '</span></td></tr>';
4066: $rownum ++;
1.27 raeburn 4067: }
1.30 raeburn 4068: $$rowtotal += $rownum;
1.27 raeburn 4069: }
4070: return $datatable;
4071: }
4072:
1.160.6.34 raeburn 4073: sub print_selfcreation {
4074: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4075: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4076: if (ref($settings) eq 'HASH') {
4077: if (ref($settings->{'cancreate'}) eq 'HASH') {
4078: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4079: if (ref($createsettings) eq 'HASH') {
4080: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4081: @selfcreate = @{$createsettings->{'selfcreate'}};
4082: } elsif ($createsettings->{'selfcreate'} ne '') {
4083: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4084: @selfcreate = ('email','login','sso');
4085: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4086: @selfcreate = ($createsettings->{'selfcreate'});
4087: }
4088: }
4089: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4090: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4091: }
4092: }
4093: }
4094: }
4095: my %radiohash;
4096: my $numinrow = 4;
4097: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4098: if ($position eq 'top') {
4099: my %choices = &Apache::lonlocal::texthash (
4100: cancreate_login => 'Institutional Login',
4101: cancreate_sso => 'Institutional Single Sign On',
4102: );
4103: my @toggles = sort(keys(%choices));
4104: my %defaultchecked = (
4105: 'cancreate_login' => 'off',
4106: 'cancreate_sso' => 'off',
4107: );
1.160.6.35 raeburn 4108: my ($onclick,$itemcount);
1.160.6.34 raeburn 4109: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4110: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4111: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4112:
1.160.6.34 raeburn 4113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4114:
4115: if (ref($usertypes) eq 'HASH') {
4116: if (keys(%{$usertypes}) > 0) {
4117: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4118: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4119: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4120: $$rowtotal ++;
4121: }
4122: }
1.160.6.44 raeburn 4123: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4124: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4125: $fieldtitles{'inststatus'} = &mt('Institutional status');
4126: my $rem;
4127: my $numperrow = 2;
4128: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4129: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4130: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4131: '<td class="LC_left_item">'."\n".
4132: '<table><tr><td>'."\n";
4133: for (my $i=0; $i<@fields; $i++) {
4134: $rem = $i%($numperrow);
4135: if ($rem == 0) {
4136: if ($i > 0) {
4137: $datatable .= '</tr>';
4138: }
4139: $datatable .= '<tr>';
4140: }
4141: my $currval;
4142: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4143: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4144: }
4145: $datatable .= '<td class="LC_left_item">'.
4146: '<span class="LC_nobreak">'.
4147: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4148: 'value="'.$currval.'" size="10" /> '.
4149: $fieldtitles{$fields[$i]}.'</span></td>';
4150: }
4151: my $colsleft = $numperrow - $rem;
4152: if ($colsleft > 1 ) {
4153: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4154: ' </td>';
4155: } elsif ($colsleft == 1) {
4156: $datatable .= '<td class="LC_left_item"> </td>';
4157: }
4158: $datatable .= '</tr></table></td></tr>';
4159: $$rowtotal ++;
1.160.6.34 raeburn 4160: } elsif ($position eq 'middle') {
4161: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4162: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4163: $usertypes->{'default'} = $othertitle;
4164: if (ref($types) eq 'ARRAY') {
4165: push(@{$types},'default');
4166: $usertypes->{'default'} = $othertitle;
4167: foreach my $status (@{$types}) {
4168: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4169: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4170: $$rowtotal ++;
1.160.6.34 raeburn 4171: }
4172: }
4173: } else {
1.160.6.40 raeburn 4174: my %choices = &Apache::lonlocal::texthash (
4175: cancreate_email => 'E-mail address as username',
4176: );
4177: my @toggles = sort(keys(%choices));
4178: my %defaultchecked = (
4179: 'cancreate_email' => 'off',
4180: );
4181: my $itemcount = 0;
4182: my $display = 'none';
4183: if (grep(/^\Qemail\E$/,@selfcreate)) {
4184: $display = 'block';
4185: }
4186: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4187: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4188: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4189: my $usertypes = {};
4190: my $order = [];
4191: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4192: $usertypes = $domdefaults{'inststatustypes'};
4193: $order = $domdefaults{'inststatusguest'};
4194: }
4195: if (ref($order) eq 'ARRAY') {
4196: push(@{$order},'default');
4197: if (@{$order} > 1) {
4198: $usertypes->{'default'} = &mt('Other users');
4199: $additional .= '<table><tr>';
4200: foreach my $status (@{$order}) {
4201: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4202: }
4203: $additional .= '</tr><tr>';
4204: foreach my $status (@{$order}) {
4205: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4206: }
1.160.6.40 raeburn 4207: $additional .= '</tr></table>';
1.160.6.34 raeburn 4208: } else {
1.160.6.40 raeburn 4209: $usertypes->{'default'} = &mt('All users');
4210: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4211: }
4212: }
1.160.6.40 raeburn 4213: $additional .= '</div>'."\n";
4214:
4215: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4216: \%choices,$$rowtotal,$onclick,$additional);
4217: $$rowtotal ++;
1.160.6.40 raeburn 4218: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4219: $$rowtotal ++;
1.160.6.35 raeburn 4220: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4221: $numinrow = 1;
1.160.6.40 raeburn 4222: if (ref($order) eq 'ARRAY') {
4223: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4225: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4226: $$rowtotal ++;
4227: }
4228: }
1.160.6.34 raeburn 4229: my ($emailrules,$emailruleorder) =
4230: &Apache::lonnet::inst_userrules($dom,'email');
4231: if (ref($emailrules) eq 'HASH') {
4232: if (keys(%{$emailrules}) > 0) {
4233: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4234: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4235: $$rowtotal ++;
4236: }
4237: }
1.160.6.35 raeburn 4238: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4239: }
4240: return $datatable;
4241: }
4242:
1.160.6.40 raeburn 4243: sub email_as_username {
4244: my ($rowtotal,$processing,$type) = @_;
4245: my %choices =
4246: &Apache::lonlocal::texthash (
4247: automatic => 'Automatic approval',
4248: approval => 'Queued for approval',
4249: );
4250: my $output;
4251: foreach my $option ('automatic','approval') {
4252: my $checked;
4253: if (ref($processing) eq 'HASH') {
4254: if ($type eq '') {
4255: if (!exists($processing->{'default'})) {
4256: if ($option eq 'automatic') {
4257: $checked = ' checked="checked"';
4258: }
4259: } else {
4260: if ($processing->{'default'} eq $option) {
4261: $checked = ' checked="checked"';
4262: }
4263: }
4264: } else {
4265: if (!exists($processing->{$type})) {
4266: if ($option eq 'automatic') {
4267: $checked = ' checked="checked"';
4268: }
4269: } else {
4270: if ($processing->{$type} eq $option) {
4271: $checked = ' checked="checked"';
4272: }
4273: }
4274: }
4275: } elsif ($option eq 'automatic') {
4276: $checked = ' checked="checked"';
4277: }
4278: my $name = 'cancreate_emailprocess';
4279: if (($type ne '') && ($type ne 'default')) {
4280: $name .= '_'.$type;
4281: }
4282: $output .= '<span class="LC_nobreak"><label>'.
4283: '<input type="radio" name="'.$name.'"'.
4284: $checked.' value="'.$option.'" />'.
4285: $choices{$option}.'</label></span>';
4286: if ($type eq '') {
4287: $output .= ' ';
4288: } else {
4289: $output .= '<br />';
4290: }
4291: }
4292: $$rowtotal ++;
4293: return $output;
4294: }
4295:
1.160.6.5 raeburn 4296: sub captcha_choice {
4297: my ($context,$settings,$itemcount) = @_;
4298: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4299: my %lt = &captcha_phrases();
4300: $keyentry = 'hidden';
4301: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4302: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4303: } elsif ($context eq 'login') {
4304: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4305: }
4306: if (ref($settings) eq 'HASH') {
4307: if ($settings->{'captcha'}) {
4308: $checked{$settings->{'captcha'}} = ' checked="checked"';
4309: } else {
4310: $checked{'original'} = ' checked="checked"';
4311: }
4312: if ($settings->{'captcha'} eq 'recaptcha') {
4313: $pubtext = $lt{'pub'};
4314: $privtext = $lt{'priv'};
4315: $keyentry = 'text';
4316: }
4317: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4318: $currpub = $settings->{'recaptchakeys'}{'public'};
4319: $currpriv = $settings->{'recaptchakeys'}{'private'};
4320: }
4321: } else {
4322: $checked{'original'} = ' checked="checked"';
4323: }
4324: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4325: my $output = '<tr'.$css_class.'>'.
4326: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4327: '<table><tr><td>'."\n";
4328: foreach my $option ('original','recaptcha','notused') {
4329: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4330: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4331: $lt{$option}.'</label></span>';
4332: unless ($option eq 'notused') {
4333: $output .= (' 'x2)."\n";
4334: }
4335: }
4336: #
4337: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4338: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4339: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4340: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4341: #
4342: $output .= '</td></tr>'."\n".
4343: '<tr><td>'."\n".
4344: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4345: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4346: $currpub.'" size="40" /></span><br />'."\n".
4347: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4348: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4349: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4350: '</td></tr>';
4351: return $output;
4352: }
4353:
1.32 raeburn 4354: sub user_formats_row {
4355: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4356: my $output;
4357: my %text = (
4358: 'username' => 'new usernames',
4359: 'id' => 'IDs',
1.45 raeburn 4360: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4361: );
4362: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4363: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4364: '<td><span class="LC_nobreak">';
4365: if ($type eq 'email') {
4366: $output .= &mt("Formats disallowed for $text{$type}: ");
4367: } else {
4368: $output .= &mt("Format rules to check for $text{$type}: ");
4369: }
4370: $output .= '</span></td>'.
4371: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4372: my $rem;
4373: if (ref($ruleorder) eq 'ARRAY') {
4374: for (my $i=0; $i<@{$ruleorder}; $i++) {
4375: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4376: my $rem = $i%($numinrow);
4377: if ($rem == 0) {
4378: if ($i > 0) {
4379: $output .= '</tr>';
4380: }
4381: $output .= '<tr>';
4382: }
4383: my $check = ' ';
1.39 raeburn 4384: if (ref($settings) eq 'HASH') {
4385: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4386: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4387: $check = ' checked="checked" ';
4388: }
1.27 raeburn 4389: }
4390: }
4391: $output .= '<td class="LC_left_item">'.
4392: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4393: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4394: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4395: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4396: }
4397: }
4398: $rem = @{$ruleorder}%($numinrow);
4399: }
4400: my $colsleft = $numinrow - $rem;
4401: if ($colsleft > 1 ) {
4402: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4403: ' </td>';
4404: } elsif ($colsleft == 1) {
4405: $output .= '<td class="LC_left_item"> </td>';
4406: }
4407: $output .= '</tr></table></td></tr>';
4408: return $output;
4409: }
4410:
1.34 raeburn 4411: sub usercreation_types {
4412: my %lt = &Apache::lonlocal::texthash (
4413: author => 'When adding a co-author',
4414: course => 'When adding a user to a course',
1.100 raeburn 4415: requestcrs => 'When requesting a course',
1.34 raeburn 4416: any => 'Any',
4417: official => 'Institutional only ',
4418: unofficial => 'Non-institutional only',
4419: none => 'None',
4420: );
4421: return %lt;
1.48 raeburn 4422: }
1.34 raeburn 4423:
1.160.6.34 raeburn 4424: sub selfcreation_types {
4425: my %lt = &Apache::lonlocal::texthash (
4426: selfcreate => 'User creates own account',
4427: any => 'Any',
4428: official => 'Institutional only ',
4429: unofficial => 'Non-institutional only',
4430: email => 'E-mail address',
4431: login => 'Institutional Login',
4432: sso => 'SSO',
4433: );
4434: }
4435:
1.28 raeburn 4436: sub authtype_names {
4437: my %lt = &Apache::lonlocal::texthash(
4438: int => 'Internal',
4439: krb4 => 'Kerberos 4',
4440: krb5 => 'Kerberos 5',
4441: loc => 'Local',
4442: );
4443: return %lt;
4444: }
4445:
4446: sub context_names {
4447: my %context_title = &Apache::lonlocal::texthash(
4448: author => 'Creating users when an Author',
4449: course => 'Creating users when in a course',
4450: domain => 'Creating users when a Domain Coordinator',
4451: );
4452: return %context_title;
4453: }
4454:
1.33 raeburn 4455: sub print_usermodification {
4456: my ($position,$dom,$settings,$rowtotal) = @_;
4457: my $numinrow = 4;
4458: my ($context,$datatable,$rowcount);
4459: if ($position eq 'top') {
4460: $rowcount = 0;
4461: $context = 'author';
4462: foreach my $role ('ca','aa') {
4463: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4464: $numinrow,$rowcount);
4465: $$rowtotal ++;
4466: $rowcount ++;
4467: }
1.160.6.37 raeburn 4468: } elsif ($position eq 'bottom') {
1.33 raeburn 4469: $context = 'course';
4470: $rowcount = 0;
4471: foreach my $role ('st','ep','ta','in','cr') {
4472: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4473: $numinrow,$rowcount);
4474: $$rowtotal ++;
4475: $rowcount ++;
4476: }
4477: }
4478: return $datatable;
4479: }
4480:
1.43 raeburn 4481: sub print_defaults {
1.160.6.40 raeburn 4482: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4483: my $rownum = 0;
4484: my ($datatable,$css_class);
1.160.6.40 raeburn 4485: if ($position eq 'top') {
4486: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4487: 'datelocale_def','portal_def');
4488: my %defaults;
4489: if (ref($settings) eq 'HASH') {
4490: %defaults = %{$settings};
1.43 raeburn 4491: } else {
1.160.6.40 raeburn 4492: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4493: foreach my $item (@items) {
4494: $defaults{$item} = $domdefaults{$item};
4495: }
1.43 raeburn 4496: }
1.160.6.40 raeburn 4497: my $titles = &defaults_titles($dom);
4498: foreach my $item (@items) {
4499: if ($rownum%2) {
4500: $css_class = '';
4501: } else {
4502: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4503: }
1.160.6.40 raeburn 4504: $datatable .= '<tr'.$css_class.'>'.
4505: '<td><span class="LC_nobreak">'.$titles->{$item}.
4506: '</span></td><td class="LC_right_item" colspan="3">';
4507: if ($item eq 'auth_def') {
4508: my @authtypes = ('internal','krb4','krb5','localauth');
4509: my %shortauth = (
4510: internal => 'int',
4511: krb4 => 'krb4',
4512: krb5 => 'krb5',
4513: localauth => 'loc'
4514: );
4515: my %authnames = &authtype_names();
4516: foreach my $auth (@authtypes) {
4517: my $checked = ' ';
4518: if ($defaults{$item} eq $auth) {
4519: $checked = ' checked="checked" ';
4520: }
4521: $datatable .= '<label><input type="radio" name="'.$item.
4522: '" value="'.$auth.'"'.$checked.'/>'.
4523: $authnames{$shortauth{$auth}}.'</label> ';
4524: }
4525: } elsif ($item eq 'timezone_def') {
4526: my $includeempty = 1;
4527: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4528: } elsif ($item eq 'datelocale_def') {
4529: my $includeempty = 1;
4530: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4531: } elsif ($item eq 'lang_def') {
4532: my %langchoices = &get_languages_hash();
4533: $langchoices{''} = 'No language preference';
4534: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4535: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4536: \%langchoices);
4537: } else {
4538: my $size;
4539: if ($item eq 'portal_def') {
4540: $size = ' size="25"';
4541: }
4542: $datatable .= '<input type="text" name="'.$item.'" value="'.
4543: $defaults{$item}.'"'.$size.' />';
4544: }
4545: $datatable .= '</td></tr>';
4546: $rownum ++;
4547: }
4548: } else {
4549: my (%defaults);
4550: if (ref($settings) eq 'HASH') {
4551: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4552: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4553: my $maxnum = @{$settings->{'inststatusorder'}};
4554: for (my $i=0; $i<$maxnum; $i++) {
4555: $css_class = $rownum%2?' class="LC_odd_row"':'';
4556: my $item = $settings->{'inststatusorder'}->[$i];
4557: my $title = $settings->{'inststatustypes'}->{$item};
4558: my $guestok;
4559: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4560: $guestok = 1;
4561: }
4562: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4563: $datatable .= '<tr'.$css_class.'>'.
4564: '<td><span class="LC_nobreak">'.
4565: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4566: for (my $k=0; $k<=$maxnum; $k++) {
4567: my $vpos = $k+1;
4568: my $selstr;
4569: if ($k == $i) {
4570: $selstr = ' selected="selected" ';
4571: }
4572: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4573: }
4574: my ($checkedon,$checkedoff);
4575: $checkedoff = ' checked="checked"';
4576: if ($guestok) {
4577: $checkedon = $checkedoff;
4578: $checkedoff = '';
4579: }
4580: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4581: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4582: &mt('delete').'</span></td>'.
4583: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4584: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4585: '</span></td>'.
4586: '<td class="LC_right_item"><span class="LC_nobreak">'.
4587: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4588: &mt('Yes').'</label>'.(' 'x2).
4589: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4590: &mt('No').'</label></span></td></tr>';
4591: }
4592: $css_class = $rownum%2?' class="LC_odd_row"':'';
4593: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4594: $datatable .= '<tr '.$css_class.'>'.
4595: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4596: for (my $k=0; $k<=$maxnum; $k++) {
4597: my $vpos = $k+1;
4598: my $selstr;
4599: if ($k == $maxnum) {
4600: $selstr = ' selected="selected" ';
4601: }
4602: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4603: }
4604: $datatable .= '</select> '.&mt('Internal ID:').
4605: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4606: ' '.&mt('(new)').
4607: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4608: &mt('Name displayed:').
4609: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4610: '<td class="LC_right_item"><span class="LC_nobreak">'.
4611: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4612: &mt('Yes').'</label>'.(' 'x2).
4613: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4614: &mt('No').'</label></span></td></tr>';
4615: '</tr>'."\n";
4616: $rownum ++;
1.141 raeburn 4617: }
1.43 raeburn 4618: }
4619: }
4620: $$rowtotal += $rownum;
4621: return $datatable;
4622: }
4623:
1.160.6.5 raeburn 4624: sub get_languages_hash {
4625: my %langchoices;
4626: foreach my $id (&Apache::loncommon::languageids()) {
4627: my $code = &Apache::loncommon::supportedlanguagecode($id);
4628: if ($code ne '') {
4629: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4630: }
4631: }
4632: return %langchoices;
4633: }
4634:
1.43 raeburn 4635: sub defaults_titles {
1.141 raeburn 4636: my ($dom) = @_;
1.43 raeburn 4637: my %titles = &Apache::lonlocal::texthash (
4638: 'auth_def' => 'Default authentication type',
4639: 'auth_arg_def' => 'Default authentication argument',
4640: 'lang_def' => 'Default language',
1.54 raeburn 4641: 'timezone_def' => 'Default timezone',
1.68 raeburn 4642: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4643: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4644: );
1.141 raeburn 4645: if ($dom) {
4646: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4647: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4648: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4649: $protocol = 'http' if ($protocol ne 'https');
4650: if ($uint_dom) {
4651: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4652: $uint_dom);
4653: }
4654: }
1.43 raeburn 4655: return (\%titles);
4656: }
4657:
1.46 raeburn 4658: sub print_scantronformat {
4659: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4660: my $itemcount = 1;
1.60 raeburn 4661: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4662: %confhash);
1.46 raeburn 4663: my $switchserver = &check_switchserver($dom,$confname);
4664: my %lt = &Apache::lonlocal::texthash (
1.95 www 4665: default => 'Default bubblesheet format file error',
4666: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4667: );
4668: my %scantronfiles = (
4669: default => 'default.tab',
4670: custom => 'custom.tab',
4671: );
4672: foreach my $key (keys(%scantronfiles)) {
4673: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4674: .$scantronfiles{$key};
4675: }
4676: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4677: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4678: if (!$switchserver) {
4679: my $servadm = $r->dir_config('lonAdmEMail');
4680: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4681: if ($configuserok eq 'ok') {
4682: if ($author_ok eq 'ok') {
4683: my %legacyfile = (
4684: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4685: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4686: );
4687: my %md5chk;
4688: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4689: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4690: chomp($md5chk{$type});
1.46 raeburn 4691: }
4692: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4693: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4694: ($scantronurls{$type},my $error) =
1.46 raeburn 4695: &legacy_scantronformat($r,$dom,$confname,
4696: $type,$legacyfile{$type},
4697: $scantronurls{$type},
4698: $scantronfiles{$type});
1.60 raeburn 4699: if ($error ne '') {
4700: $error{$type} = $error;
4701: }
4702: }
4703: if (keys(%error) == 0) {
4704: $is_custom = 1;
4705: $confhash{'scantron'}{'scantronformat'} =
4706: $scantronurls{'custom'};
4707: my $putresult =
4708: &Apache::lonnet::put_dom('configuration',
4709: \%confhash,$dom);
4710: if ($putresult ne 'ok') {
4711: $error{'custom'} =
4712: '<span class="LC_error">'.
4713: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4714: }
1.46 raeburn 4715: }
4716: } else {
1.60 raeburn 4717: ($scantronurls{'default'},my $error) =
1.46 raeburn 4718: &legacy_scantronformat($r,$dom,$confname,
4719: 'default',$legacyfile{'default'},
4720: $scantronurls{'default'},
4721: $scantronfiles{'default'});
1.60 raeburn 4722: if ($error eq '') {
4723: $confhash{'scantron'}{'scantronformat'} = '';
4724: my $putresult =
4725: &Apache::lonnet::put_dom('configuration',
4726: \%confhash,$dom);
4727: if ($putresult ne 'ok') {
4728: $error{'default'} =
4729: '<span class="LC_error">'.
4730: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4731: }
4732: } else {
4733: $error{'default'} = $error;
4734: }
1.46 raeburn 4735: }
4736: }
4737: }
4738: } else {
1.95 www 4739: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4740: }
4741: }
4742: if (ref($settings) eq 'HASH') {
4743: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4744: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4745: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4746: $scantronurl = '';
4747: } else {
4748: $scantronurl = $settings->{'scantronformat'};
4749: }
4750: $is_custom = 1;
4751: } else {
4752: $scantronurl = $scantronurls{'default'};
4753: }
4754: } else {
1.60 raeburn 4755: if ($is_custom) {
4756: $scantronurl = $scantronurls{'custom'};
4757: } else {
4758: $scantronurl = $scantronurls{'default'};
4759: }
1.46 raeburn 4760: }
4761: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4762: $datatable .= '<tr'.$css_class.'>';
4763: if (!$is_custom) {
1.65 raeburn 4764: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4765: '<span class="LC_nobreak">';
1.46 raeburn 4766: if ($scantronurl) {
1.160.6.21 raeburn 4767: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4768: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4769: } else {
4770: $datatable = &mt('File unavailable for display');
4771: }
1.65 raeburn 4772: $datatable .= '</span></td>';
1.60 raeburn 4773: if (keys(%error) == 0) {
4774: $datatable .= '<td valign="bottom">';
4775: if (!$switchserver) {
4776: $datatable .= &mt('Upload:').'<br />';
4777: }
4778: } else {
4779: my $errorstr;
4780: foreach my $key (sort(keys(%error))) {
4781: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4782: }
4783: $datatable .= '<td>'.$errorstr;
4784: }
1.46 raeburn 4785: } else {
4786: if (keys(%error) > 0) {
4787: my $errorstr;
4788: foreach my $key (sort(keys(%error))) {
4789: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4790: }
1.60 raeburn 4791: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4792: } elsif ($scantronurl) {
1.160.6.26 raeburn 4793: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4794: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4795: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4796: $link.
4797: '<label><input type="checkbox" name="scantronformat_del"'.
4798: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4799: '<td><span class="LC_nobreak"> '.
4800: &mt('Replace:').'</span><br />';
1.46 raeburn 4801: }
4802: }
4803: if (keys(%error) == 0) {
4804: if ($switchserver) {
4805: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4806: } else {
1.65 raeburn 4807: $datatable .='<span class="LC_nobreak"> '.
4808: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4809: }
4810: }
4811: $datatable .= '</td></tr>';
4812: $$rowtotal ++;
4813: return $datatable;
4814: }
4815:
4816: sub legacy_scantronformat {
4817: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4818: my ($url,$error);
4819: my @statinfo = &Apache::lonnet::stat_file($newurl);
4820: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4821: (my $result,$url) =
4822: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4823: '','',$newfile);
4824: if ($result ne 'ok') {
1.130 raeburn 4825: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4826: }
4827: }
4828: return ($url,$error);
4829: }
1.43 raeburn 4830:
1.49 raeburn 4831: sub print_coursecategories {
1.57 raeburn 4832: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4833: my $datatable;
4834: if ($position eq 'top') {
1.160.6.42 raeburn 4835: my (%checked);
4836: my @catitems = ('unauth','auth');
4837: my @cattypes = ('std','domonly','codesrch','none');
4838: $checked{'unauth'} = 'std';
4839: $checked{'auth'} = 'std';
4840: if (ref($settings) eq 'HASH') {
4841: foreach my $type (@cattypes) {
4842: if ($type eq $settings->{'unauth'}) {
4843: $checked{'unauth'} = $type;
4844: }
4845: if ($type eq $settings->{'auth'}) {
4846: $checked{'auth'} = $type;
4847: }
4848: }
4849: }
4850: my %lt = &Apache::lonlocal::texthash (
4851: unauth => 'Catalog type for unauthenticated users',
4852: auth => 'Catalog type for authenticated users',
4853: none => 'No catalog',
4854: std => 'Standard catalog',
4855: domonly => 'Domain-only catalog',
4856: codesrch => "Code search form",
4857: );
4858: my $itemcount = 0;
4859: foreach my $item (@catitems) {
4860: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4861: $datatable .= '<tr '.$css_class.'>'.
4862: '<td>'.$lt{$item}.'</td>'.
4863: '<td class="LC_right_item"><span class="LC_nobreak">';
4864: foreach my $type (@cattypes) {
4865: my $ischecked;
4866: if ($checked{$item} eq $type) {
4867: $ischecked=' checked="checked"';
4868: }
4869: $datatable .= '<label>'.
4870: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4871: ' />'.$lt{$type}.'</label> ';
4872: }
4873: $datatable .= '</td></tr>';
4874: $itemcount ++;
4875: }
4876: $$rowtotal += $itemcount;
4877: } elsif ($position eq 'middle') {
1.57 raeburn 4878: my $toggle_cats_crs = ' ';
4879: my $toggle_cats_dom = ' checked="checked" ';
4880: my $can_cat_crs = ' ';
4881: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4882: my $toggle_catscomm_comm = ' ';
4883: my $toggle_catscomm_dom = ' checked="checked" ';
4884: my $can_catcomm_comm = ' ';
4885: my $can_catcomm_dom = ' checked="checked" ';
4886:
1.57 raeburn 4887: if (ref($settings) eq 'HASH') {
4888: if ($settings->{'togglecats'} eq 'crs') {
4889: $toggle_cats_crs = $toggle_cats_dom;
4890: $toggle_cats_dom = ' ';
4891: }
4892: if ($settings->{'categorize'} eq 'crs') {
4893: $can_cat_crs = $can_cat_dom;
4894: $can_cat_dom = ' ';
4895: }
1.120 raeburn 4896: if ($settings->{'togglecatscomm'} eq 'comm') {
4897: $toggle_catscomm_comm = $toggle_catscomm_dom;
4898: $toggle_catscomm_dom = ' ';
4899: }
4900: if ($settings->{'categorizecomm'} eq 'comm') {
4901: $can_catcomm_comm = $can_catcomm_dom;
4902: $can_catcomm_dom = ' ';
4903: }
1.57 raeburn 4904: }
4905: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4906: togglecats => 'Show/Hide a course in catalog',
4907: togglecatscomm => 'Show/Hide a community in catalog',
4908: categorize => 'Assign a category to a course',
4909: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4910: );
4911: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4912: dom => 'Set in Domain',
4913: crs => 'Set in Course',
4914: comm => 'Set in Community',
1.57 raeburn 4915: );
4916: $datatable = '<tr class="LC_odd_row">'.
4917: '<td>'.$title{'togglecats'}.'</td>'.
4918: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4919: '<input type="radio" name="togglecats"'.
4920: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4921: '<label><input type="radio" name="togglecats"'.
4922: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4923: '</tr><tr>'.
4924: '<td>'.$title{'categorize'}.'</td>'.
4925: '<td class="LC_right_item"><span class="LC_nobreak">'.
4926: '<label><input type="radio" name="categorize"'.
4927: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4928: '<label><input type="radio" name="categorize"'.
4929: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4930: '</tr><tr class="LC_odd_row">'.
4931: '<td>'.$title{'togglecatscomm'}.'</td>'.
4932: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4933: '<input type="radio" name="togglecatscomm"'.
4934: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4935: '<label><input type="radio" name="togglecatscomm"'.
4936: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4937: '</tr><tr>'.
4938: '<td>'.$title{'categorizecomm'}.'</td>'.
4939: '<td class="LC_right_item"><span class="LC_nobreak">'.
4940: '<label><input type="radio" name="categorizecomm"'.
4941: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4942: '<label><input type="radio" name="categorizecomm"'.
4943: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4944: '</tr>';
1.120 raeburn 4945: $$rowtotal += 4;
1.57 raeburn 4946: } else {
4947: my $css_class;
4948: my $itemcount = 1;
4949: my $cathash;
4950: if (ref($settings) eq 'HASH') {
4951: $cathash = $settings->{'cats'};
4952: }
4953: if (ref($cathash) eq 'HASH') {
4954: my (@cats,@trails,%allitems,%idx,@jsarray);
4955: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4956: \%allitems,\%idx,\@jsarray);
4957: my $maxdepth = scalar(@cats);
4958: my $colattrib = '';
4959: if ($maxdepth > 2) {
4960: $colattrib = ' colspan="2" ';
4961: }
4962: my @path;
4963: if (@cats > 0) {
4964: if (ref($cats[0]) eq 'ARRAY') {
4965: my $numtop = @{$cats[0]};
4966: my $maxnum = $numtop;
1.120 raeburn 4967: my %default_names = (
4968: instcode => &mt('Official courses'),
4969: communities => &mt('Communities'),
4970: );
4971:
4972: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4973: ($cathash->{'instcode::0'} eq '') ||
4974: (!grep(/^communities$/,@{$cats[0]})) ||
4975: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4976: $maxnum ++;
4977: }
4978: my $lastidx;
4979: for (my $i=0; $i<$numtop; $i++) {
4980: my $parent = $cats[0][$i];
4981: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4982: my $item = &escape($parent).'::0';
4983: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4984: $lastidx = $idx{$item};
4985: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4986: .'<select name="'.$item.'"'.$chgstr.'>';
4987: for (my $k=0; $k<=$maxnum; $k++) {
4988: my $vpos = $k+1;
4989: my $selstr;
4990: if ($k == $i) {
4991: $selstr = ' selected="selected" ';
4992: }
4993: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4994: }
1.160.6.29 raeburn 4995: $datatable .= '</select></span></td><td>';
1.120 raeburn 4996: if ($parent eq 'instcode' || $parent eq 'communities') {
4997: $datatable .= '<span class="LC_nobreak">'
4998: .$default_names{$parent}.'</span>';
4999: if ($parent eq 'instcode') {
5000: $datatable .= '<br /><span class="LC_nobreak">('
5001: .&mt('with institutional codes')
5002: .')</span></td><td'.$colattrib.'>';
5003: } else {
5004: $datatable .= '<table><tr><td>';
5005: }
5006: $datatable .= '<span class="LC_nobreak">'
5007: .'<label><input type="radio" name="'
5008: .$parent.'" value="1" checked="checked" />'
5009: .&mt('Display').'</label>';
5010: if ($parent eq 'instcode') {
5011: $datatable .= ' ';
5012: } else {
5013: $datatable .= '</span></td></tr><tr><td>'
5014: .'<span class="LC_nobreak">';
5015: }
5016: $datatable .= '<label><input type="radio" name="'
5017: .$parent.'" value="0" />'
5018: .&mt('Do not display').'</label></span>';
5019: if ($parent eq 'communities') {
5020: $datatable .= '</td></tr></table>';
5021: }
5022: $datatable .= '</td>';
1.57 raeburn 5023: } else {
5024: $datatable .= $parent
1.160.6.29 raeburn 5025: .' <span class="LC_nobreak"><label>'
5026: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5027: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5028: }
5029: my $depth = 1;
5030: push(@path,$parent);
5031: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5032: pop(@path);
5033: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5034: $itemcount ++;
5035: }
1.48 raeburn 5036: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5037: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5038: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5039: for (my $k=0; $k<=$maxnum; $k++) {
5040: my $vpos = $k+1;
5041: my $selstr;
1.57 raeburn 5042: if ($k == $numtop) {
1.48 raeburn 5043: $selstr = ' selected="selected" ';
5044: }
5045: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5046: }
1.59 bisitz 5047: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5048: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5049: .'</tr>'."\n";
1.48 raeburn 5050: $itemcount ++;
1.120 raeburn 5051: foreach my $default ('instcode','communities') {
5052: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5053: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5054: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5055: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5056: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5057: for (my $k=0; $k<=$maxnum; $k++) {
5058: my $vpos = $k+1;
5059: my $selstr;
5060: if ($k == $maxnum) {
5061: $selstr = ' selected="selected" ';
5062: }
5063: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5064: }
1.120 raeburn 5065: $datatable .= '</select></span></td>'.
5066: '<td><span class="LC_nobreak">'.
5067: $default_names{$default}.'</span>';
5068: if ($default eq 'instcode') {
5069: $datatable .= '<br /><span class="LC_nobreak">('
5070: .&mt('with institutional codes').')</span>';
5071: }
5072: $datatable .= '</td>'
5073: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5074: .&mt('Display').'</label> '
5075: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5076: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5077: }
5078: }
5079: }
1.57 raeburn 5080: } else {
5081: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5082: }
5083: } else {
1.160.6.42 raeburn 5084: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5085: .&initialize_categories($itemcount);
1.48 raeburn 5086: }
1.57 raeburn 5087: $$rowtotal += $itemcount;
1.48 raeburn 5088: }
5089: return $datatable;
5090: }
5091:
1.69 raeburn 5092: sub print_serverstatuses {
5093: my ($dom,$settings,$rowtotal) = @_;
5094: my $datatable;
5095: my @pages = &serverstatus_pages();
5096: my (%namedaccess,%machineaccess);
5097: foreach my $type (@pages) {
5098: $namedaccess{$type} = '';
5099: $machineaccess{$type}= '';
5100: }
5101: if (ref($settings) eq 'HASH') {
5102: foreach my $type (@pages) {
5103: if (exists($settings->{$type})) {
5104: if (ref($settings->{$type}) eq 'HASH') {
5105: foreach my $key (keys(%{$settings->{$type}})) {
5106: if ($key eq 'namedusers') {
5107: $namedaccess{$type} = $settings->{$type}->{$key};
5108: } elsif ($key eq 'machines') {
5109: $machineaccess{$type} = $settings->{$type}->{$key};
5110: }
5111: }
5112: }
5113: }
5114: }
5115: }
1.81 raeburn 5116: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5117: my $rownum = 0;
5118: my $css_class;
5119: foreach my $type (@pages) {
5120: $rownum ++;
5121: $css_class = $rownum%2?' class="LC_odd_row"':'';
5122: $datatable .= '<tr'.$css_class.'>'.
5123: '<td><span class="LC_nobreak">'.
5124: $titles->{$type}.'</span></td>'.
5125: '<td class="LC_left_item">'.
5126: '<input type="text" name="'.$type.'_namedusers" '.
5127: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5128: '<td class="LC_right_item">'.
5129: '<span class="LC_nobreak">'.
5130: '<input type="text" name="'.$type.'_machines" '.
5131: 'value="'.$machineaccess{$type}.'" size="10" />'.
5132: '</td></tr>'."\n";
5133: }
5134: $$rowtotal += $rownum;
5135: return $datatable;
5136: }
5137:
5138: sub serverstatus_pages {
5139: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5140: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5141: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5142: 'uniquecodes','diskusage');
1.69 raeburn 5143: }
5144:
1.160.6.40 raeburn 5145: sub defaults_javascript {
5146: my ($settings) = @_;
5147: my ($output,$jstext);
5148: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5149: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5150: if ($maxnum eq '') {
5151: $maxnum = 0;
5152: }
5153: $maxnum ++;
5154: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5155: return <<"ENDSCRIPT";
5156: <script type="text/javascript">
5157: // <![CDATA[
5158: function reorderTypes(form,caller) {
5159: var changedVal;
5160: $jstext
5161: var newpos = 'addinststatus_pos';
5162: var current = new Array;
5163: var maxh = $maxnum;
5164: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5165: var oldVal;
5166: if (caller == newpos) {
5167: changedVal = newitemVal;
5168: } else {
5169: var curritem = 'inststatus_pos_'+caller;
5170: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5171: current[newitemVal] = newpos;
5172: }
5173: for (var i=0; i<inststatuses.length; i++) {
5174: if (inststatuses[i] != caller) {
5175: var elementName = 'inststatus_pos_'+inststatuses[i];
5176: if (form.elements[elementName]) {
5177: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5178: current[currVal] = elementName;
5179: }
5180: }
5181: }
5182: for (var j=0; j<maxh; j++) {
5183: if (current[j] == undefined) {
5184: oldVal = j;
5185: }
5186: }
5187: if (oldVal < changedVal) {
5188: for (var k=oldVal+1; k<=changedVal ; k++) {
5189: var elementName = current[k];
5190: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5191: }
5192: } else {
5193: for (var k=changedVal; k<oldVal; k++) {
5194: var elementName = current[k];
5195: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5196: }
5197: }
5198: return;
5199: }
5200:
5201: // ]]>
5202: </script>
5203:
5204: ENDSCRIPT
5205: }
5206: }
5207:
1.49 raeburn 5208: sub coursecategories_javascript {
5209: my ($settings) = @_;
1.57 raeburn 5210: my ($output,$jstext,$cathash);
1.49 raeburn 5211: if (ref($settings) eq 'HASH') {
1.57 raeburn 5212: $cathash = $settings->{'cats'};
5213: }
5214: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5215: my (@cats,@jsarray,%idx);
1.57 raeburn 5216: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5217: if (@jsarray > 0) {
5218: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5219: for (my $i=0; $i<@jsarray; $i++) {
5220: if (ref($jsarray[$i]) eq 'ARRAY') {
5221: my $catstr = join('","',@{$jsarray[$i]});
5222: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5223: }
5224: }
5225: }
5226: } else {
5227: $jstext = ' var categories = Array(1);'."\n".
5228: ' categories[0] = Array("instcode_pos");'."\n";
5229: }
1.160.6.42 raeburn 5230: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5231: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5232: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5233: $output = <<"ENDSCRIPT";
5234: <script type="text/javascript">
1.109 raeburn 5235: // <![CDATA[
1.49 raeburn 5236: function reorderCats(form,parent,item,idx) {
5237: var changedVal;
5238: $jstext
5239: var newpos = 'addcategory_pos';
5240: if (parent == '') {
5241: var has_instcode = 0;
5242: var maxtop = categories[idx].length;
5243: for (var j=0; j<maxtop; j++) {
5244: if (categories[idx][j] == 'instcode::0') {
5245: has_instcode == 1;
5246: }
5247: }
5248: if (has_instcode == 0) {
5249: categories[idx][maxtop] = 'instcode_pos';
5250: }
5251: } else {
5252: newpos += '_'+parent;
5253: }
5254: var maxh = 1 + categories[idx].length;
5255: var current = new Array;
5256: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5257: if (item == newpos) {
5258: changedVal = newitemVal;
5259: } else {
5260: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5261: current[newitemVal] = newpos;
5262: }
5263: for (var i=0; i<categories[idx].length; i++) {
5264: var elementName = categories[idx][i];
5265: if (elementName != item) {
5266: if (form.elements[elementName]) {
5267: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5268: current[currVal] = elementName;
5269: }
5270: }
5271: }
5272: var oldVal;
5273: for (var j=0; j<maxh; j++) {
5274: if (current[j] == undefined) {
5275: oldVal = j;
5276: }
5277: }
5278: if (oldVal < changedVal) {
5279: for (var k=oldVal+1; k<=changedVal ; k++) {
5280: var elementName = current[k];
5281: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5282: }
5283: } else {
5284: for (var k=changedVal; k<oldVal; k++) {
5285: var elementName = current[k];
5286: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5287: }
5288: }
5289: return;
5290: }
1.120 raeburn 5291:
5292: function categoryCheck(form) {
5293: if (form.elements['addcategory_name'].value == 'instcode') {
5294: alert('$instcode_reserved\\n$choose_again');
5295: return false;
5296: }
5297: if (form.elements['addcategory_name'].value == 'communities') {
5298: alert('$communities_reserved\\n$choose_again');
5299: return false;
5300: }
5301: return true;
5302: }
5303:
1.109 raeburn 5304: // ]]>
1.49 raeburn 5305: </script>
5306:
5307: ENDSCRIPT
5308: return $output;
5309: }
5310:
1.48 raeburn 5311: sub initialize_categories {
5312: my ($itemcount) = @_;
1.120 raeburn 5313: my ($datatable,$css_class,$chgstr);
5314: my %default_names = (
5315: instcode => 'Official courses (with institutional codes)',
5316: communities => 'Communities',
5317: );
5318: my $select0 = ' selected="selected"';
5319: my $select1 = '';
5320: foreach my $default ('instcode','communities') {
5321: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5322: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5323: if ($default eq 'communities') {
5324: $select1 = $select0;
5325: $select0 = '';
5326: }
5327: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5328: .'<select name="'.$default.'_pos">'
5329: .'<option value="0"'.$select0.'>1</option>'
5330: .'<option value="1"'.$select1.'>2</option>'
5331: .'<option value="2">3</option></select> '
5332: .$default_names{$default}
5333: .'</span></td><td><span class="LC_nobreak">'
5334: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5335: .&mt('Display').'</label> <label>'
5336: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5337: .'</label></span></td></tr>';
1.120 raeburn 5338: $itemcount ++;
5339: }
1.48 raeburn 5340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5341: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5342: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5343: .'<select name="addcategory_pos"'.$chgstr.'>'
5344: .'<option value="0">1</option>'
5345: .'<option value="1">2</option>'
5346: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5347: .&mt('Add category').'</td><td>'.&mt('Name:')
5348: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5349: return $datatable;
5350: }
5351:
5352: sub build_category_rows {
1.49 raeburn 5353: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5354: my ($text,$name,$item,$chgstr);
1.48 raeburn 5355: if (ref($cats) eq 'ARRAY') {
5356: my $maxdepth = scalar(@{$cats});
5357: if (ref($cats->[$depth]) eq 'HASH') {
5358: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5359: my $numchildren = @{$cats->[$depth]{$parent}};
5360: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5361: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5362: my ($idxnum,$parent_name,$parent_item);
5363: my $higher = $depth - 1;
5364: if ($higher == 0) {
5365: $parent_name = &escape($parent).'::'.$higher;
5366: } else {
5367: if (ref($path) eq 'ARRAY') {
5368: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5369: }
5370: }
5371: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5372: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5373: if ($j < $numchildren) {
1.48 raeburn 5374: $name = $cats->[$depth]{$parent}[$j];
5375: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5376: $idxnum = $idx->{$item};
5377: } else {
5378: $name = $parent_name;
5379: $item = $parent_item;
1.48 raeburn 5380: }
1.49 raeburn 5381: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5382: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5383: for (my $i=0; $i<=$numchildren; $i++) {
5384: my $vpos = $i+1;
5385: my $selstr;
5386: if ($j == $i) {
5387: $selstr = ' selected="selected" ';
5388: }
5389: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5390: }
5391: $text .= '</select> ';
5392: if ($j < $numchildren) {
5393: my $deeper = $depth+1;
5394: $text .= $name.' '
5395: .'<label><input type="checkbox" name="deletecategory" value="'
5396: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5397: if(ref($path) eq 'ARRAY') {
5398: push(@{$path},$name);
1.49 raeburn 5399: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5400: pop(@{$path});
5401: }
5402: } else {
1.59 bisitz 5403: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5404: if ($j == $numchildren) {
5405: $text .= $name;
5406: } else {
5407: $text .= $item;
5408: }
5409: $text .= '" value="" />';
5410: }
5411: $text .= '</td></tr>';
5412: }
5413: $text .= '</table></td>';
5414: } else {
5415: my $higher = $depth-1;
5416: if ($higher == 0) {
5417: $name = &escape($parent).'::'.$higher;
5418: } else {
5419: if (ref($path) eq 'ARRAY') {
5420: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5421: }
5422: }
5423: my $colspan;
5424: if ($parent ne 'instcode') {
5425: $colspan = $maxdepth - $depth - 1;
5426: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5427: }
5428: }
5429: }
5430: }
5431: return $text;
5432: }
5433:
1.33 raeburn 5434: sub modifiable_userdata_row {
1.160.6.35 raeburn 5435: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5436: my ($role,$rolename,$statustype);
5437: $role = $item;
1.160.6.34 raeburn 5438: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5439: if ($item =~ /^emailusername_(.+)$/) {
5440: $statustype = $1;
5441: $role = 'emailusername';
5442: if (ref($usertypes) eq 'HASH') {
5443: if ($usertypes->{$statustype}) {
5444: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5445: } else {
5446: $rolename = &mt('Data provided by user');
5447: }
5448: }
1.160.6.34 raeburn 5449: }
5450: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5451: if (ref($usertypes) eq 'HASH') {
5452: $rolename = $usertypes->{$role};
5453: } else {
5454: $rolename = $role;
5455: }
1.33 raeburn 5456: } else {
1.63 raeburn 5457: if ($role eq 'cr') {
5458: $rolename = &mt('Custom role');
5459: } else {
5460: $rolename = &Apache::lonnet::plaintext($role);
5461: }
1.33 raeburn 5462: }
1.160.6.34 raeburn 5463: my (@fields,%fieldtitles);
5464: if (ref($fieldsref) eq 'ARRAY') {
5465: @fields = @{$fieldsref};
5466: } else {
5467: @fields = ('lastname','firstname','middlename','generation',
5468: 'permanentemail','id');
5469: }
5470: if ((ref($titlesref) eq 'HASH')) {
5471: %fieldtitles = %{$titlesref};
5472: } else {
5473: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5474: }
1.33 raeburn 5475: my $output;
5476: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5477: $output = '<tr '.$css_class.'>'.
5478: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5479: '<td class="LC_left_item" colspan="2"><table>';
5480: my $rem;
5481: my %checks;
5482: if (ref($settings) eq 'HASH') {
5483: if (ref($settings->{$context}) eq 'HASH') {
5484: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5485: my $hashref = $settings->{$context}->{$role};
5486: if ($role eq 'emailusername') {
5487: if ($statustype) {
5488: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5489: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5490: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5491: foreach my $field (@fields) {
5492: if ($hashref->{$field}) {
5493: $checks{$field} = $hashref->{$field};
5494: }
5495: }
5496: }
5497: }
5498: }
5499: } else {
5500: if (ref($hashref) eq 'HASH') {
5501: foreach my $field (@fields) {
5502: if ($hashref->{$field}) {
5503: $checks{$field} = ' checked="checked" ';
5504: }
5505: }
1.33 raeburn 5506: }
5507: }
5508: }
5509: }
5510: }
1.160.6.39 raeburn 5511:
1.33 raeburn 5512: for (my $i=0; $i<@fields; $i++) {
5513: my $rem = $i%($numinrow);
5514: if ($rem == 0) {
5515: if ($i > 0) {
5516: $output .= '</tr>';
5517: }
5518: $output .= '<tr>';
5519: }
5520: my $check = ' ';
1.160.6.35 raeburn 5521: unless ($role eq 'emailusername') {
5522: if (exists($checks{$fields[$i]})) {
5523: $check = $checks{$fields[$i]}
5524: } else {
5525: if ($role eq 'st') {
5526: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5527: $check = ' checked="checked" ';
1.160.6.35 raeburn 5528: }
1.33 raeburn 5529: }
5530: }
5531: }
5532: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5533: '<span class="LC_nobreak">';
5534: if ($role eq 'emailusername') {
5535: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5536: $checks{$fields[$i]} = 'omit';
5537: }
5538: foreach my $option ('required','optional','omit') {
5539: my $checked='';
5540: if ($checks{$fields[$i]} eq $option) {
5541: $checked='checked="checked" ';
5542: }
5543: $output .= '<label>'.
5544: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5545: &mt($option).'</label>'.(' ' x2);
5546: }
5547: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5548: } else {
5549: $output .= '<label>'.
5550: '<input type="checkbox" name="canmodify_'.$role.'" '.
5551: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5552: '</label>';
5553: }
5554: $output .= '</span></td>';
1.33 raeburn 5555: $rem = @fields%($numinrow);
5556: }
5557: my $colsleft = $numinrow - $rem;
5558: if ($colsleft > 1 ) {
5559: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5560: ' </td>';
5561: } elsif ($colsleft == 1) {
5562: $output .= '<td class="LC_left_item"> </td>';
5563: }
5564: $output .= '</tr></table></td></tr>';
5565: return $output;
5566: }
1.28 raeburn 5567:
1.93 raeburn 5568: sub insttypes_row {
1.160.6.34 raeburn 5569: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5570: my %lt = &Apache::lonlocal::texthash (
5571: cansearch => 'Users allowed to search',
5572: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5573: lockablenames => 'User preference to lock name',
1.93 raeburn 5574: );
5575: my $showdom;
5576: if ($context eq 'cansearch') {
5577: $showdom = ' ('.$dom.')';
5578: }
1.160.6.5 raeburn 5579: my $class = 'LC_left_item';
5580: if ($context eq 'statustocreate') {
5581: $class = 'LC_right_item';
5582: }
1.160.6.34 raeburn 5583: my $css_class = ' class="LC_odd_row"';
5584: if ($rownum ne '') {
5585: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5586: }
5587: my $output = '<tr'.$css_class.'>'.
5588: '<td>'.$lt{$context}.$showdom.
5589: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5590: my $rem;
5591: if (ref($types) eq 'ARRAY') {
5592: for (my $i=0; $i<@{$types}; $i++) {
5593: if (defined($usertypes->{$types->[$i]})) {
5594: my $rem = $i%($numinrow);
5595: if ($rem == 0) {
5596: if ($i > 0) {
5597: $output .= '</tr>';
5598: }
5599: $output .= '<tr>';
1.23 raeburn 5600: }
1.26 raeburn 5601: my $check = ' ';
1.99 raeburn 5602: if (ref($settings) eq 'HASH') {
5603: if (ref($settings->{$context}) eq 'ARRAY') {
5604: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5605: $check = ' checked="checked" ';
5606: }
5607: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5608: $check = ' checked="checked" ';
5609: }
1.23 raeburn 5610: }
1.26 raeburn 5611: $output .= '<td class="LC_left_item">'.
5612: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5613: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5614: 'value="'.$types->[$i].'"'.$check.'/>'.
5615: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5616: }
5617: }
1.26 raeburn 5618: $rem = @{$types}%($numinrow);
1.23 raeburn 5619: }
5620: my $colsleft = $numinrow - $rem;
1.131 raeburn 5621: if (($rem == 0) && (@{$types} > 0)) {
5622: $output .= '<tr>';
5623: }
1.23 raeburn 5624: if ($colsleft > 1) {
1.25 raeburn 5625: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5626: } else {
1.25 raeburn 5627: $output .= '<td class="LC_left_item">';
1.23 raeburn 5628: }
5629: my $defcheck = ' ';
1.99 raeburn 5630: if (ref($settings) eq 'HASH') {
5631: if (ref($settings->{$context}) eq 'ARRAY') {
5632: if (grep(/^default$/,@{$settings->{$context}})) {
5633: $defcheck = ' checked="checked" ';
5634: }
5635: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5636: $defcheck = ' checked="checked" ';
5637: }
1.23 raeburn 5638: }
1.25 raeburn 5639: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5640: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5641: 'value="default"'.$defcheck.'/>'.
5642: $othertitle.'</label></span></td>'.
5643: '</tr></table></td></tr>';
5644: return $output;
1.23 raeburn 5645: }
5646:
5647: sub sorted_searchtitles {
5648: my %searchtitles = &Apache::lonlocal::texthash(
5649: 'uname' => 'username',
5650: 'lastname' => 'last name',
5651: 'lastfirst' => 'last name, first name',
5652: );
5653: my @titleorder = ('uname','lastname','lastfirst');
5654: return (\%searchtitles,\@titleorder);
5655: }
5656:
1.25 raeburn 5657: sub sorted_searchtypes {
5658: my %srchtypes_desc = (
5659: exact => 'is exact match',
5660: contains => 'contains ..',
5661: begins => 'begins with ..',
5662: );
5663: my @srchtypeorder = ('exact','begins','contains');
5664: return (\%srchtypes_desc,\@srchtypeorder);
5665: }
5666:
1.3 raeburn 5667: sub usertype_update_row {
5668: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5669: my $datatable;
5670: my $numinrow = 4;
5671: foreach my $type (@{$types}) {
5672: if (defined($usertypes->{$type})) {
5673: $$rownums ++;
5674: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5675: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5676: '</td><td class="LC_left_item"><table>';
5677: for (my $i=0; $i<@{$fields}; $i++) {
5678: my $rem = $i%($numinrow);
5679: if ($rem == 0) {
5680: if ($i > 0) {
5681: $datatable .= '</tr>';
5682: }
5683: $datatable .= '<tr>';
5684: }
5685: my $check = ' ';
1.39 raeburn 5686: if (ref($settings) eq 'HASH') {
5687: if (ref($settings->{'fields'}) eq 'HASH') {
5688: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5689: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5690: $check = ' checked="checked" ';
5691: }
1.3 raeburn 5692: }
5693: }
5694: }
5695:
5696: if ($i == @{$fields}-1) {
5697: my $colsleft = $numinrow - $rem;
5698: if ($colsleft > 1) {
5699: $datatable .= '<td colspan="'.$colsleft.'">';
5700: } else {
5701: $datatable .= '<td>';
5702: }
5703: } else {
5704: $datatable .= '<td>';
5705: }
1.8 raeburn 5706: $datatable .= '<span class="LC_nobreak"><label>'.
5707: '<input type="checkbox" name="updateable_'.$type.
5708: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5709: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5710: }
5711: $datatable .= '</tr></table></td></tr>';
5712: }
5713: }
5714: return $datatable;
1.1 raeburn 5715: }
5716:
5717: sub modify_login {
1.160.6.24 raeburn 5718: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5719: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5720: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5721: %title = ( coursecatalog => 'Display course catalog',
5722: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5723: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5724: newuser => 'Link for visitors to create a user account',
5725: loginheader => 'Log-in box header');
5726: @offon = ('off','on');
1.112 raeburn 5727: if (ref($domconfig{login}) eq 'HASH') {
5728: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5729: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5730: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5731: }
5732: }
5733: }
1.9 raeburn 5734: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5735: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5736: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5737: foreach my $item (@toggles) {
5738: $loginhash{login}{$item} = $env{'form.'.$item};
5739: }
1.41 raeburn 5740: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5741: if (ref($colchanges{'login'}) eq 'HASH') {
5742: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5743: \%loginhash);
5744: }
1.110 raeburn 5745:
1.149 raeburn 5746: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5747: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5748: if (keys(%servers) > 1) {
5749: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5750: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5751: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5752: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5753: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5754: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5757: $changes{'loginvia'}{$lonhost} = 1;
5758: } else {
5759: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5760: $changes{'loginvia'}{$lonhost} = 1;
5761: }
5762: } else {
5763: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5764: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5765: $changes{'loginvia'}{$lonhost} = 1;
5766: }
5767: }
5768: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5769: foreach my $item (@loginvia_attribs) {
5770: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5771: }
5772: } else {
5773: foreach my $item (@loginvia_attribs) {
5774: my $new = $env{'form.'.$lonhost.'_'.$item};
5775: if (($item eq 'serverpath') && ($new eq 'custom')) {
5776: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5777: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5778: $new = '/';
5779: }
5780: }
5781: if (($item eq 'custompath') &&
5782: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5783: $new = '';
5784: }
5785: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5786: $changes{'loginvia'}{$lonhost} = 1;
5787: }
5788: if ($item eq 'exempt') {
5789: $new =~ s/^\s+//;
5790: $new =~ s/\s+$//;
5791: my @poss_ips = split(/\s*[,:]\s*/,$new);
5792: my @okips;
5793: foreach my $ip (@poss_ips) {
5794: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5795: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5796: push(@okips,$ip);
5797: }
5798: }
5799: }
5800: if (@okips > 0) {
5801: $new = join(',',@okips);
5802: } else {
5803: $new = '';
5804: }
5805: }
5806: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5807: }
5808: }
1.112 raeburn 5809: } else {
1.128 raeburn 5810: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5811: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5812: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5813: foreach my $item (@loginvia_attribs) {
5814: my $new = $env{'form.'.$lonhost.'_'.$item};
5815: if (($item eq 'serverpath') && ($new eq 'custom')) {
5816: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5817: $new = '/';
5818: }
5819: }
5820: if (($item eq 'custompath') &&
5821: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5822: $new = '';
5823: }
5824: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5825: }
1.110 raeburn 5826: }
5827: }
5828: }
5829: }
1.119 raeburn 5830:
1.160.6.5 raeburn 5831: my $servadm = $r->dir_config('lonAdmEMail');
5832: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5833: if (ref($domconfig{'login'}) eq 'HASH') {
5834: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5835: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5836: if ($lang eq 'nolang') {
5837: push(@currlangs,$lang);
5838: } elsif (defined($langchoices{$lang})) {
5839: push(@currlangs,$lang);
5840: } else {
5841: next;
5842: }
5843: }
5844: }
5845: }
5846: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5847: if (@currlangs > 0) {
5848: foreach my $lang (@currlangs) {
5849: if (grep(/^\Q$lang\E$/,@delurls)) {
5850: $changes{'helpurl'}{$lang} = 1;
5851: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5852: $changes{'helpurl'}{$lang} = 1;
5853: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5854: push(@newlangs,$lang);
5855: } else {
5856: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5857: }
5858: }
5859: }
5860: unless (grep(/^nolang$/,@currlangs)) {
5861: if ($env{'form.loginhelpurl_nolang.filename'}) {
5862: $changes{'helpurl'}{'nolang'} = 1;
5863: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5864: push(@newlangs,'nolang');
5865: }
5866: }
5867: if ($env{'form.loginhelpurl_add_lang'}) {
5868: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5869: ($env{'form.loginhelpurl_add_file.filename'})) {
5870: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5871: $addedfile = $env{'form.loginhelpurl_add_lang'};
5872: }
5873: }
5874: if ((@newlangs > 0) || ($addedfile)) {
5875: my $error;
5876: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5877: if ($configuserok eq 'ok') {
5878: if ($switchserver) {
5879: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5880: } elsif ($author_ok eq 'ok') {
5881: my @allnew = @newlangs;
5882: if ($addedfile ne '') {
5883: push(@allnew,$addedfile);
5884: }
5885: foreach my $lang (@allnew) {
5886: my $formelem = 'loginhelpurl_'.$lang;
5887: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5888: $formelem = 'loginhelpurl_add_file';
5889: }
5890: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5891: "help/$lang",'','',$newfile{$lang});
5892: if ($result eq 'ok') {
5893: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5894: $changes{'helpurl'}{$lang} = 1;
5895: } else {
5896: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5897: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5898: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5899: (!grep(/^\Q$lang\E$/,@delurls))) {
5900:
5901: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5902: }
5903: }
5904: }
5905: } else {
5906: $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);
5907: }
5908: } else {
5909: $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);
5910: }
5911: if ($error) {
5912: &Apache::lonnet::logthis($error);
5913: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5914: }
5915: }
5916: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5917:
5918: my $defaulthelpfile = '/adm/loginproblems.html';
5919: my $defaulttext = &mt('Default in use');
5920:
1.1 raeburn 5921: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5922: $dom);
5923: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5924: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5925: my %defaultchecked = (
5926: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5927: 'helpdesk' => 'on',
1.42 raeburn 5928: 'adminmail' => 'off',
1.43 raeburn 5929: 'newuser' => 'off',
1.42 raeburn 5930: );
1.55 raeburn 5931: if (ref($domconfig{'login'}) eq 'HASH') {
5932: foreach my $item (@toggles) {
5933: if ($defaultchecked{$item} eq 'on') {
5934: if (($domconfig{'login'}{$item} eq '0') &&
5935: ($env{'form.'.$item} eq '1')) {
5936: $changes{$item} = 1;
5937: } elsif (($domconfig{'login'}{$item} eq '' ||
5938: $domconfig{'login'}{$item} eq '1') &&
5939: ($env{'form.'.$item} eq '0')) {
5940: $changes{$item} = 1;
5941: }
5942: } elsif ($defaultchecked{$item} eq 'off') {
5943: if (($domconfig{'login'}{$item} eq '1') &&
5944: ($env{'form.'.$item} eq '0')) {
5945: $changes{$item} = 1;
5946: } elsif (($domconfig{'login'}{$item} eq '' ||
5947: $domconfig{'login'}{$item} eq '0') &&
5948: ($env{'form.'.$item} eq '1')) {
5949: $changes{$item} = 1;
5950: }
1.42 raeburn 5951: }
5952: }
1.41 raeburn 5953: }
1.6 raeburn 5954: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5955: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5956: if (ref($lastactref) eq 'HASH') {
5957: $lastactref->{'domainconfig'} = 1;
5958: }
1.1 raeburn 5959: $resulttext = &mt('Changes made:').'<ul>';
5960: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5961: if ($item eq 'loginvia') {
1.112 raeburn 5962: if (ref($changes{$item}) eq 'HASH') {
5963: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5964: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5965: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5966: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5967: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5968: $protocol = 'http' if ($protocol ne 'https');
5969: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5970:
5971: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5972: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5973: } else {
5974: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5975: }
5976: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5977: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5978: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5979: }
5980: $resulttext .= '</li>';
5981: } else {
5982: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5983: }
1.112 raeburn 5984: } else {
1.128 raeburn 5985: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5986: }
5987: }
1.128 raeburn 5988: $resulttext .= '</ul></li>';
1.112 raeburn 5989: }
1.160.6.5 raeburn 5990: } elsif ($item eq 'helpurl') {
5991: if (ref($changes{$item}) eq 'HASH') {
5992: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5993: if (grep(/^\Q$lang\E$/,@delurls)) {
5994: my ($chg,$link);
5995: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5996: if ($lang eq 'nolang') {
5997: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5998: } else {
5999: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6000: }
6001: $resulttext .= '<li>'.$chg.'</li>';
6002: } else {
6003: my $chg;
6004: if ($lang eq 'nolang') {
6005: $chg = &mt('custom log-in help file for no preferred language');
6006: } else {
6007: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6008: }
6009: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6010: $loginhash{'login'}{'helpurl'}{$lang}.
6011: '?inhibitmenu=yes',$chg,600,500).
6012: '</li>';
6013: }
6014: }
6015: }
6016: } elsif ($item eq 'captcha') {
6017: if (ref($loginhash{'login'}) eq 'HASH') {
6018: my $chgtxt;
6019: if ($loginhash{'login'}{$item} eq 'notused') {
6020: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6021: } else {
6022: my %captchas = &captcha_phrases();
6023: if ($captchas{$loginhash{'login'}{$item}}) {
6024: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6025: } else {
6026: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6027: }
6028: }
6029: $resulttext .= '<li>'.$chgtxt.'</li>';
6030: }
6031: } elsif ($item eq 'recaptchakeys') {
6032: if (ref($loginhash{'login'}) eq 'HASH') {
6033: my ($privkey,$pubkey);
6034: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6035: $pubkey = $loginhash{'login'}{$item}{'public'};
6036: $privkey = $loginhash{'login'}{$item}{'private'};
6037: }
6038: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6039: if (!$pubkey) {
6040: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6041: } else {
6042: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6043: }
6044: if (!$privkey) {
6045: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6046: } else {
6047: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6048: }
6049: $chgtxt .= '</ul>';
6050: $resulttext .= '<li>'.$chgtxt.'</li>';
6051: }
1.41 raeburn 6052: } else {
6053: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6054: }
1.1 raeburn 6055: }
1.6 raeburn 6056: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6057: } else {
6058: $resulttext = &mt('No changes made to log-in page settings');
6059: }
6060: } else {
1.11 albertel 6061: $resulttext = '<span class="LC_error">'.
6062: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6063: }
1.6 raeburn 6064: if ($errors) {
1.9 raeburn 6065: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6066: $errors.'</ul>';
6067: }
6068: return $resulttext;
6069: }
6070:
6071: sub color_font_choices {
6072: my %choices =
6073: &Apache::lonlocal::texthash (
6074: img => "Header",
6075: bgs => "Background colors",
6076: links => "Link colors",
1.55 raeburn 6077: images => "Images",
1.6 raeburn 6078: font => "Font color",
1.160.6.22 raeburn 6079: fontmenu => "Font menu",
1.76 raeburn 6080: pgbg => "Page",
1.6 raeburn 6081: tabbg => "Header",
6082: sidebg => "Border",
6083: link => "Link",
6084: alink => "Active link",
6085: vlink => "Visited link",
6086: );
6087: return %choices;
6088: }
6089:
6090: sub modify_rolecolors {
1.160.6.24 raeburn 6091: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6092: my ($resulttext,%rolehash);
6093: $rolehash{'rolecolors'} = {};
1.55 raeburn 6094: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6095: if ($domconfig{'rolecolors'} eq '') {
6096: $domconfig{'rolecolors'} = {};
6097: }
6098: }
1.9 raeburn 6099: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6100: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6101: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6102: $dom);
6103: if ($putresult eq 'ok') {
6104: if (keys(%changes) > 0) {
1.41 raeburn 6105: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6106: if (ref($lastactref) eq 'HASH') {
6107: $lastactref->{'domainconfig'} = 1;
6108: }
1.6 raeburn 6109: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6110: $rolehash{'rolecolors'});
6111: } else {
6112: $resulttext = &mt('No changes made to default color schemes');
6113: }
6114: } else {
1.11 albertel 6115: $resulttext = '<span class="LC_error">'.
6116: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6117: }
6118: if ($errors) {
6119: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6120: $errors.'</ul>';
6121: }
6122: return $resulttext;
6123: }
6124:
6125: sub modify_colors {
1.9 raeburn 6126: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6127: my (%changes,%choices);
1.51 raeburn 6128: my @bgs;
1.6 raeburn 6129: my @links = ('link','alink','vlink');
1.41 raeburn 6130: my @logintext;
1.6 raeburn 6131: my @images;
6132: my $servadm = $r->dir_config('lonAdmEMail');
6133: my $errors;
1.160.6.22 raeburn 6134: my %defaults;
1.6 raeburn 6135: foreach my $role (@{$roles}) {
6136: if ($role eq 'login') {
1.12 raeburn 6137: %choices = &login_choices();
1.41 raeburn 6138: @logintext = ('textcol','bgcol');
1.12 raeburn 6139: } else {
6140: %choices = &color_font_choices();
6141: }
6142: if ($role eq 'login') {
1.41 raeburn 6143: @images = ('img','logo','domlogo','login');
1.51 raeburn 6144: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6145: } else {
6146: @images = ('img');
1.160.6.22 raeburn 6147: @bgs = ('pgbg','tabbg','sidebg');
6148: }
6149: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6150: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6151: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6152: }
6153: if ($role eq 'login') {
6154: foreach my $item (@logintext) {
1.160.6.39 raeburn 6155: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6156: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6157: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6158: }
6159: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6160: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6161: }
6162: }
6163: } else {
1.160.6.39 raeburn 6164: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6165: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6166: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6167: }
6168: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6169: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6170: }
1.6 raeburn 6171: }
1.160.6.22 raeburn 6172: foreach my $item (@bgs) {
1.160.6.39 raeburn 6173: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6174: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6175: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6176: }
6177: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6178: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6179: }
6180: }
6181: foreach my $item (@links) {
1.160.6.39 raeburn 6182: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6183: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6184: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6185: }
6186: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6187: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6188: }
1.6 raeburn 6189: }
1.46 raeburn 6190: my ($configuserok,$author_ok,$switchserver) =
6191: &config_check($dom,$confname,$servadm);
1.9 raeburn 6192: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6193: if (ref($domconfig->{$role}) ne 'HASH') {
6194: $domconfig->{$role} = {};
6195: }
1.8 raeburn 6196: foreach my $img (@images) {
1.70 raeburn 6197: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6198: if (defined($env{'form.login_showlogo_'.$img})) {
6199: $confhash->{$role}{'showlogo'}{$img} = 1;
6200: } else {
6201: $confhash->{$role}{'showlogo'}{$img} = 0;
6202: }
6203: }
1.18 albertel 6204: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6205: && !defined($domconfig->{$role}{$img})
6206: && !$env{'form.'.$role.'_del_'.$img}
6207: && $env{'form.'.$role.'_import_'.$img}) {
6208: # import the old configured image from the .tab setting
6209: # if they haven't provided a new one
6210: $domconfig->{$role}{$img} =
6211: $env{'form.'.$role.'_import_'.$img};
6212: }
1.6 raeburn 6213: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6214: my $error;
1.6 raeburn 6215: if ($configuserok eq 'ok') {
1.9 raeburn 6216: if ($switchserver) {
1.12 raeburn 6217: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6218: } else {
6219: if ($author_ok eq 'ok') {
6220: my ($result,$logourl) =
6221: &publishlogo($r,'upload',$role.'_'.$img,
6222: $dom,$confname,$img,$width,$height);
6223: if ($result eq 'ok') {
6224: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6225: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6226: } else {
1.12 raeburn 6227: $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 6228: }
6229: } else {
1.46 raeburn 6230: $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 6231: }
6232: }
6233: } else {
1.46 raeburn 6234: $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 6235: }
6236: if ($error) {
1.8 raeburn 6237: &Apache::lonnet::logthis($error);
1.11 albertel 6238: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6239: }
6240: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6241: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6242: my $error;
6243: if ($configuserok eq 'ok') {
6244: # is confname an author?
6245: if ($switchserver eq '') {
6246: if ($author_ok eq 'ok') {
6247: my ($result,$logourl) =
6248: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6249: $dom,$confname,$img,$width,$height);
6250: if ($result eq 'ok') {
6251: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6252: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6253: }
6254: }
6255: }
6256: }
1.6 raeburn 6257: }
6258: }
6259: }
6260: if (ref($domconfig) eq 'HASH') {
6261: if (ref($domconfig->{$role}) eq 'HASH') {
6262: foreach my $img (@images) {
6263: if ($domconfig->{$role}{$img} ne '') {
6264: if ($env{'form.'.$role.'_del_'.$img}) {
6265: $confhash->{$role}{$img} = '';
1.12 raeburn 6266: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6267: } else {
1.9 raeburn 6268: if ($confhash->{$role}{$img} eq '') {
6269: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6270: }
1.6 raeburn 6271: }
6272: } else {
6273: if ($env{'form.'.$role.'_del_'.$img}) {
6274: $confhash->{$role}{$img} = '';
1.12 raeburn 6275: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6276: }
6277: }
1.70 raeburn 6278: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6279: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6280: if ($confhash->{$role}{'showlogo'}{$img} ne
6281: $domconfig->{$role}{'showlogo'}{$img}) {
6282: $changes{$role}{'showlogo'}{$img} = 1;
6283: }
6284: } else {
6285: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6286: $changes{$role}{'showlogo'}{$img} = 1;
6287: }
6288: }
6289: }
6290: }
1.6 raeburn 6291: if ($domconfig->{$role}{'font'} ne '') {
6292: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6293: $changes{$role}{'font'} = 1;
6294: }
6295: } else {
6296: if ($confhash->{$role}{'font'}) {
6297: $changes{$role}{'font'} = 1;
6298: }
6299: }
1.107 raeburn 6300: if ($role ne 'login') {
6301: if ($domconfig->{$role}{'fontmenu'} ne '') {
6302: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6303: $changes{$role}{'fontmenu'} = 1;
6304: }
6305: } else {
6306: if ($confhash->{$role}{'fontmenu'}) {
6307: $changes{$role}{'fontmenu'} = 1;
6308: }
1.97 tempelho 6309: }
6310: }
1.6 raeburn 6311: foreach my $item (@bgs) {
6312: if ($domconfig->{$role}{$item} ne '') {
6313: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6314: $changes{$role}{'bgs'}{$item} = 1;
6315: }
6316: } else {
6317: if ($confhash->{$role}{$item}) {
6318: $changes{$role}{'bgs'}{$item} = 1;
6319: }
6320: }
6321: }
6322: foreach my $item (@links) {
6323: if ($domconfig->{$role}{$item} ne '') {
6324: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6325: $changes{$role}{'links'}{$item} = 1;
6326: }
6327: } else {
6328: if ($confhash->{$role}{$item}) {
6329: $changes{$role}{'links'}{$item} = 1;
6330: }
6331: }
6332: }
1.41 raeburn 6333: foreach my $item (@logintext) {
6334: if ($domconfig->{$role}{$item} ne '') {
6335: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6336: $changes{$role}{'logintext'}{$item} = 1;
6337: }
6338: } else {
6339: if ($confhash->{$role}{$item}) {
6340: $changes{$role}{'logintext'}{$item} = 1;
6341: }
6342: }
6343: }
1.6 raeburn 6344: } else {
6345: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6346: \@logintext,$confhash,\%changes);
1.6 raeburn 6347: }
6348: } else {
6349: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6350: \@logintext,$confhash,\%changes);
1.6 raeburn 6351: }
6352: }
6353: return ($errors,%changes);
6354: }
6355:
1.46 raeburn 6356: sub config_check {
6357: my ($dom,$confname,$servadm) = @_;
6358: my ($configuserok,$author_ok,$switchserver,%currroles);
6359: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6360: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6361: $confname,$servadm);
6362: if ($configuserok eq 'ok') {
6363: $switchserver = &check_switchserver($dom,$confname);
6364: if ($switchserver eq '') {
6365: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6366: }
6367: }
6368: return ($configuserok,$author_ok,$switchserver);
6369: }
6370:
1.6 raeburn 6371: sub default_change_checker {
1.41 raeburn 6372: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6373: foreach my $item (@{$links}) {
6374: if ($confhash->{$role}{$item}) {
6375: $changes->{$role}{'links'}{$item} = 1;
6376: }
6377: }
6378: foreach my $item (@{$bgs}) {
6379: if ($confhash->{$role}{$item}) {
6380: $changes->{$role}{'bgs'}{$item} = 1;
6381: }
6382: }
1.41 raeburn 6383: foreach my $item (@{$logintext}) {
6384: if ($confhash->{$role}{$item}) {
6385: $changes->{$role}{'logintext'}{$item} = 1;
6386: }
6387: }
1.6 raeburn 6388: foreach my $img (@{$images}) {
6389: if ($env{'form.'.$role.'_del_'.$img}) {
6390: $confhash->{$role}{$img} = '';
1.12 raeburn 6391: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6392: }
1.70 raeburn 6393: if ($role eq 'login') {
6394: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6395: $changes->{$role}{'showlogo'}{$img} = 1;
6396: }
6397: }
1.6 raeburn 6398: }
6399: if ($confhash->{$role}{'font'}) {
6400: $changes->{$role}{'font'} = 1;
6401: }
1.48 raeburn 6402: }
1.6 raeburn 6403:
6404: sub display_colorchgs {
6405: my ($dom,$changes,$roles,$confhash) = @_;
6406: my (%choices,$resulttext);
6407: if (!grep(/^login$/,@{$roles})) {
6408: $resulttext = &mt('Changes made:').'<br />';
6409: }
6410: foreach my $role (@{$roles}) {
6411: if ($role eq 'login') {
6412: %choices = &login_choices();
6413: } else {
6414: %choices = &color_font_choices();
6415: }
6416: if (ref($changes->{$role}) eq 'HASH') {
6417: if ($role ne 'login') {
6418: $resulttext .= '<h4>'.&mt($role).'</h4>';
6419: }
6420: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6421: if ($role ne 'login') {
6422: $resulttext .= '<ul>';
6423: }
6424: if (ref($changes->{$role}{$key}) eq 'HASH') {
6425: if ($role ne 'login') {
6426: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6427: }
6428: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6429: if (($role eq 'login') && ($key eq 'showlogo')) {
6430: if ($confhash->{$role}{$key}{$item}) {
6431: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6432: } else {
6433: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6434: }
6435: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6436: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6437: } else {
1.12 raeburn 6438: my $newitem = $confhash->{$role}{$item};
6439: if ($key eq 'images') {
6440: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6441: }
6442: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6443: }
6444: }
6445: if ($role ne 'login') {
6446: $resulttext .= '</ul></li>';
6447: }
6448: } else {
6449: if ($confhash->{$role}{$key} eq '') {
6450: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6451: } else {
6452: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6453: }
6454: }
6455: if ($role ne 'login') {
6456: $resulttext .= '</ul>';
6457: }
6458: }
6459: }
6460: }
1.3 raeburn 6461: return $resulttext;
1.1 raeburn 6462: }
6463:
1.9 raeburn 6464: sub thumb_dimensions {
6465: return ('200','50');
6466: }
6467:
1.16 raeburn 6468: sub check_dimensions {
6469: my ($inputfile) = @_;
6470: my ($fullwidth,$fullheight);
6471: if ($inputfile =~ m|^[/\w.\-]+$|) {
6472: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6473: my $imageinfo = <PIPE>;
6474: if (!close(PIPE)) {
6475: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6476: }
6477: chomp($imageinfo);
6478: my ($fullsize) =
1.21 raeburn 6479: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6480: if ($fullsize) {
6481: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6482: }
6483: }
6484: }
6485: return ($fullwidth,$fullheight);
6486: }
6487:
1.9 raeburn 6488: sub check_configuser {
6489: my ($uhome,$dom,$confname,$servadm) = @_;
6490: my ($configuserok,%currroles);
6491: if ($uhome eq 'no_host') {
6492: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6493: my $configpass = &LONCAPA::Enrollment::create_password();
6494: $configuserok =
6495: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6496: $configpass,'','','','','',undef,$servadm);
6497: } else {
6498: $configuserok = 'ok';
6499: %currroles =
6500: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6501: }
6502: return ($configuserok,%currroles);
6503: }
6504:
6505: sub check_authorstatus {
6506: my ($dom,$confname,%currroles) = @_;
6507: my $author_ok;
1.40 raeburn 6508: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6509: my $start = time;
6510: my $end = 0;
6511: $author_ok =
6512: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6513: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6514: } else {
6515: $author_ok = 'ok';
6516: }
6517: return $author_ok;
6518: }
6519:
6520: sub publishlogo {
1.46 raeburn 6521: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6522: my ($output,$fname,$logourl);
6523: if ($action eq 'upload') {
6524: $fname=$env{'form.'.$formname.'.filename'};
6525: chop($env{'form.'.$formname});
6526: } else {
6527: ($fname) = ($formname =~ /([^\/]+)$/);
6528: }
1.46 raeburn 6529: if ($savefileas ne '') {
6530: $fname = $savefileas;
6531: }
1.9 raeburn 6532: $fname=&Apache::lonnet::clean_filename($fname);
6533: # See if there is anything left
6534: unless ($fname) { return ('error: no uploaded file'); }
6535: $fname="$subdir/$fname";
1.160.6.5 raeburn 6536: my $docroot=$r->dir_config('lonDocRoot');
6537: my $filepath="$docroot/priv";
6538: my $relpath = "$dom/$confname";
1.9 raeburn 6539: my ($fnamepath,$file,$fetchthumb);
6540: $file=$fname;
6541: if ($fname=~m|/|) {
6542: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6543: }
1.160.6.26 raeburn 6544: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6545: my $count;
1.160.6.5 raeburn 6546: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6547: $filepath.="/$parts[$count]";
6548: if ((-e $filepath)!=1) {
6549: mkdir($filepath,02770);
6550: }
6551: }
6552: # Check for bad extension and disallow upload
6553: if ($file=~/\.(\w+)$/ &&
6554: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6555: $output =
1.160.6.25 raeburn 6556: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6557: } elsif ($file=~/\.(\w+)$/ &&
6558: !defined(&Apache::loncommon::fileembstyle($1))) {
6559: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6560: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6561: $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 6562: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6563: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6564: } else {
6565: my $source = $filepath.'/'.$file;
6566: my $logfile;
6567: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6568: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6569: }
6570: print $logfile
6571: "\n================= Publish ".localtime()." ================\n".
6572: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6573: # Save the file
6574: if (!open(FH,'>'.$source)) {
6575: &Apache::lonnet::logthis('Failed to create '.$source);
6576: return (&mt('Failed to create file'));
6577: }
6578: if ($action eq 'upload') {
6579: if (!print FH ($env{'form.'.$formname})) {
6580: &Apache::lonnet::logthis('Failed to write to '.$source);
6581: return (&mt('Failed to write file'));
6582: }
6583: } else {
6584: my $original = &Apache::lonnet::filelocation('',$formname);
6585: if(!copy($original,$source)) {
6586: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6587: return (&mt('Failed to write file'));
6588: }
6589: }
6590: close(FH);
6591: chmod(0660, $source); # Permissions to rw-rw---.
6592:
6593: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6594: my $copyfile=$targetdir.'/'.$file;
6595:
6596: my @parts=split(/\//,$targetdir);
6597: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6598: for (my $count=5;$count<=$#parts;$count++) {
6599: $path.="/$parts[$count]";
6600: if (!-e $path) {
6601: print $logfile "\nCreating directory ".$path;
6602: mkdir($path,02770);
6603: }
6604: }
6605: my $versionresult;
6606: if (-e $copyfile) {
6607: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6608: } else {
6609: $versionresult = 'ok';
6610: }
6611: if ($versionresult eq 'ok') {
6612: if (copy($source,$copyfile)) {
6613: print $logfile "\nCopied original source to ".$copyfile."\n";
6614: $output = 'ok';
6615: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6616: push(@{$modified_urls},[$copyfile,$source]);
6617: my $metaoutput =
6618: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6619: unless ($registered_cleanup) {
6620: my $handlers = $r->get_handlers('PerlCleanupHandler');
6621: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6622: $registered_cleanup=1;
6623: }
1.9 raeburn 6624: } else {
6625: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6626: $output = &mt('Failed to copy file to RES space').", $!";
6627: }
6628: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6629: my $inputfile = $filepath.'/'.$file;
6630: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6631: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6632: if ($fullwidth ne '' && $fullheight ne '') {
6633: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6634: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6635: system("convert -sample $thumbsize $inputfile $outfile");
6636: chmod(0660, $filepath.'/tn-'.$file);
6637: if (-e $outfile) {
6638: my $copyfile=$targetdir.'/tn-'.$file;
6639: if (copy($outfile,$copyfile)) {
6640: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6641: my $thumb_metaoutput =
6642: &write_metadata($dom,$confname,$formname,
6643: $targetdir,'tn-'.$file,$logfile);
6644: push(@{$modified_urls},[$copyfile,$outfile]);
6645: unless ($registered_cleanup) {
6646: my $handlers = $r->get_handlers('PerlCleanupHandler');
6647: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6648: $registered_cleanup=1;
6649: }
1.16 raeburn 6650: } else {
6651: print $logfile "\nUnable to write ".$copyfile.
6652: ':'.$!."\n";
6653: }
6654: }
1.9 raeburn 6655: }
6656: }
6657: }
6658: } else {
6659: $output = $versionresult;
6660: }
6661: }
6662: return ($output,$logourl);
6663: }
6664:
6665: sub logo_versioning {
6666: my ($targetdir,$file,$logfile) = @_;
6667: my $target = $targetdir.'/'.$file;
6668: my ($maxversion,$fn,$extn,$output);
6669: $maxversion = 0;
6670: if ($file =~ /^(.+)\.(\w+)$/) {
6671: $fn=$1;
6672: $extn=$2;
6673: }
6674: opendir(DIR,$targetdir);
6675: while (my $filename=readdir(DIR)) {
6676: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6677: $maxversion=($1>$maxversion)?$1:$maxversion;
6678: }
6679: }
6680: $maxversion++;
6681: print $logfile "\nCreating old version ".$maxversion."\n";
6682: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6683: if (copy($target,$copyfile)) {
6684: print $logfile "Copied old target to ".$copyfile."\n";
6685: $copyfile=$copyfile.'.meta';
6686: if (copy($target.'.meta',$copyfile)) {
6687: print $logfile "Copied old target metadata to ".$copyfile."\n";
6688: $output = 'ok';
6689: } else {
6690: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6691: $output = &mt('Failed to copy old meta').", $!, ";
6692: }
6693: } else {
6694: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6695: $output = &mt('Failed to copy old target').", $!, ";
6696: }
6697: return $output;
6698: }
6699:
6700: sub write_metadata {
6701: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6702: my (%metadatafields,%metadatakeys,$output);
6703: $metadatafields{'title'}=$formname;
6704: $metadatafields{'creationdate'}=time;
6705: $metadatafields{'lastrevisiondate'}=time;
6706: $metadatafields{'copyright'}='public';
6707: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6708: $env{'user.domain'};
6709: $metadatafields{'authorspace'}=$confname.':'.$dom;
6710: $metadatafields{'domain'}=$dom;
6711: {
6712: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6713: my $mfh;
1.155 raeburn 6714: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6715: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6716: unless ($_=~/\./) {
6717: my $unikey=$_;
6718: $unikey=~/^([A-Za-z]+)/;
6719: my $tag=$1;
6720: $tag=~tr/A-Z/a-z/;
6721: print $mfh "\n\<$tag";
6722: foreach (split(/\,/,$metadatakeys{$unikey})) {
6723: my $value=$metadatafields{$unikey.'.'.$_};
6724: $value=~s/\"/\'\'/g;
6725: print $mfh ' '.$_.'="'.$value.'"';
6726: }
6727: print $mfh '>'.
6728: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6729: .'</'.$tag.'>';
6730: }
6731: }
6732: $output = 'ok';
6733: print $logfile "\nWrote metadata";
6734: close($mfh);
6735: } else {
6736: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6737: $output = &mt('Could not write metadata');
6738: }
6739: }
1.155 raeburn 6740: return $output;
6741: }
6742:
6743: sub notifysubscribed {
6744: foreach my $targetsource (@{$modified_urls}){
6745: next unless (ref($targetsource) eq 'ARRAY');
6746: my ($target,$source)=@{$targetsource};
6747: if ($source ne '') {
6748: if (open(my $logfh,'>>'.$source.'.log')) {
6749: print $logfh "\nCleanup phase: Notifications\n";
6750: my @subscribed=&subscribed_hosts($target);
6751: foreach my $subhost (@subscribed) {
6752: print $logfh "\nNotifying host ".$subhost.':';
6753: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6754: print $logfh $reply;
6755: }
6756: my @subscribedmeta=&subscribed_hosts("$target.meta");
6757: foreach my $subhost (@subscribedmeta) {
6758: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6759: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6760: $subhost);
6761: print $logfh $reply;
6762: }
6763: print $logfh "\n============ Done ============\n";
1.160 raeburn 6764: close($logfh);
1.155 raeburn 6765: }
6766: }
6767: }
6768: return OK;
6769: }
6770:
6771: sub subscribed_hosts {
6772: my ($target) = @_;
6773: my @subscribed;
6774: if (open(my $fh,"<$target.subscription")) {
6775: while (my $subline=<$fh>) {
6776: if ($subline =~ /^($match_lonid):/) {
6777: my $host = $1;
6778: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6779: unless (grep(/^\Q$host\E$/,@subscribed)) {
6780: push(@subscribed,$host);
6781: }
6782: }
6783: }
6784: }
6785: }
6786: return @subscribed;
1.9 raeburn 6787: }
6788:
6789: sub check_switchserver {
6790: my ($dom,$confname) = @_;
6791: my ($allowed,$switchserver);
6792: my $home = &Apache::lonnet::homeserver($confname,$dom);
6793: if ($home eq 'no_host') {
6794: $home = &Apache::lonnet::domain($dom,'primary');
6795: }
6796: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6797: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6798: if (!$allowed) {
1.160.6.11 raeburn 6799: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6800: }
6801: return $switchserver;
6802: }
6803:
1.1 raeburn 6804: sub modify_quotas {
1.160.6.30 raeburn 6805: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6806: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6807: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6808: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6809: $validationfieldsref);
1.86 raeburn 6810: if ($action eq 'quotas') {
6811: $context = 'tools';
1.160.6.26 raeburn 6812: } else {
1.86 raeburn 6813: $context = $action;
6814: }
6815: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6816: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6817: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6818: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6819: %titles = &courserequest_titles();
6820: $toolregexp = join('|',@usertools);
6821: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6822: $confname = $dom.'-domainconfig';
6823: my $servadm = $r->dir_config('lonAdmEMail');
6824: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6825: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6826: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6827: } elsif ($context eq 'requestauthor') {
6828: @usertools = ('author');
6829: %titles = &authorrequest_titles();
1.86 raeburn 6830: } else {
1.160.6.4 raeburn 6831: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6832: %titles = &tool_titles();
1.86 raeburn 6833: }
1.160.6.27 raeburn 6834: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6835: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6836: foreach my $key (keys(%env)) {
1.101 raeburn 6837: if ($context eq 'requestcourses') {
6838: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6839: my $item = $1;
6840: my $type = $2;
6841: if ($type =~ /^limit_(.+)/) {
6842: $limithash{$item}{$1} = $env{$key};
6843: } else {
6844: $confhash{$item}{$type} = $env{$key};
6845: }
6846: }
1.160.6.5 raeburn 6847: } elsif ($context eq 'requestauthor') {
6848: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6849: $confhash{$1} = $env{$key};
6850: }
1.101 raeburn 6851: } else {
1.86 raeburn 6852: if ($key =~ /^form\.quota_(.+)$/) {
6853: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6854: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6855: $confhash{'authorquota'}{$1} = $env{$key};
6856: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6857: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6858: }
1.72 raeburn 6859: }
6860: }
1.160.6.5 raeburn 6861: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6862: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6863: @approvalnotify = sort(@approvalnotify);
6864: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6865: my @crstypes = ('official','unofficial','community','textbook');
6866: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6867: foreach my $type (@hasuniquecode) {
6868: if (grep(/^\Q$type\E$/,@crstypes)) {
6869: $confhash{'uniquecode'}{$type} = 1;
6870: }
6871: }
1.160.6.46 raeburn 6872: my (%newbook,%allpos);
1.160.6.30 raeburn 6873: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6874: foreach my $type ('textbooks','templates') {
6875: @{$allpos{$type}} = ();
6876: my $invalid;
6877: if ($type eq 'textbooks') {
6878: $invalid = &mt('Invalid LON-CAPA course for textbook');
6879: } else {
6880: $invalid = &mt('Invalid LON-CAPA course for template');
6881: }
6882: if ($env{'form.'.$type.'_addbook'}) {
6883: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
6884: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
6885: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
6886: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
6887: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
6888: } else {
6889: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
6890: my $position = $env{'form.'.$type.'_addbook_pos'};
6891: $position =~ s/\D+//g;
6892: if ($position ne '') {
6893: $allpos{$type}[$position] = $newbook{$type};
6894: }
1.160.6.30 raeburn 6895: }
1.160.6.46 raeburn 6896: } else {
6897: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 6898: }
6899: }
1.160.6.46 raeburn 6900: }
1.160.6.30 raeburn 6901: }
1.102 raeburn 6902: if (ref($domconfig{$action}) eq 'HASH') {
6903: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6904: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6905: $changes{'notify'}{'approval'} = 1;
6906: }
6907: } else {
1.144 raeburn 6908: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6909: $changes{'notify'}{'approval'} = 1;
6910: }
6911: }
1.160.6.30 raeburn 6912: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6913: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6914: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6915: unless ($confhash{'uniquecode'}{$crstype}) {
6916: $changes{'uniquecode'} = 1;
6917: }
6918: }
6919: unless ($changes{'uniquecode'}) {
6920: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6921: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6922: $changes{'uniquecode'} = 1;
6923: }
6924: }
6925: }
6926: } else {
6927: $changes{'uniquecode'} = 1;
6928: }
6929: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6930: $changes{'uniquecode'} = 1;
6931: }
6932: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 6933: foreach my $type ('textbooks','templates') {
6934: if (ref($domconfig{$action}{$type}) eq 'HASH') {
6935: my %deletions;
6936: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
6937: if (@todelete) {
6938: map { $deletions{$_} = 1; } @todelete;
6939: }
6940: my %imgdeletions;
6941: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
6942: if (@todeleteimages) {
6943: map { $imgdeletions{$_} = 1; } @todeleteimages;
6944: }
6945: my $maxnum = $env{'form.'.$type.'_maxnum'};
6946: for (my $i=0; $i<=$maxnum; $i++) {
6947: my $itemid = $env{'form.'.$type.'_id_'.$i};
6948: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
6949: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
6950: if ($deletions{$key}) {
6951: if ($domconfig{$action}{$type}{$key}{'image'}) {
6952: #FIXME need to obsolete item in RES space
6953: }
6954: next;
6955: } else {
6956: my $newpos = $env{'form.'.$itemid};
6957: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 6958: foreach my $item ('subject','title','publisher','author') {
6959: next if ((($item eq 'author') || ($item eq 'publisher')) &&
6960: ($type eq 'templates'));
1.160.6.46 raeburn 6961: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
6962: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
6963: $changes{$type}{$key} = 1;
6964: }
6965: }
6966: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 6967: }
1.160.6.46 raeburn 6968: if ($imgdeletions{$key}) {
6969: $changes{$type}{$key} = 1;
6970: #FIXME need to obsolete item in RES space
6971: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
6972: my ($cdom,$cnum) = split(/_/,$key);
6973: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
6974: $cdom,$cnum,$type,$configuserok,
6975: $switchserver,$author_ok);
6976: if ($imgurl) {
6977: $confhash{$type}{$key}{'image'} = $imgurl;
6978: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 6979: }
1.160.6.46 raeburn 6980: if ($error) {
6981: &Apache::lonnet::logthis($error);
6982: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6983: }
6984: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
6985: $confhash{$type}{$key}{'image'} =
6986: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 6987: }
6988: }
6989: }
6990: }
6991: }
6992: }
1.102 raeburn 6993: } else {
1.144 raeburn 6994: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6995: $changes{'notify'}{'approval'} = 1;
6996: }
1.160.6.30 raeburn 6997: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6998: $changes{'uniquecode'} = 1;
6999: }
7000: }
7001: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7002: foreach my $type ('textbooks','templates') {
7003: if ($newbook{$type}) {
7004: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7005: foreach my $item ('subject','title','publisher','author') {
7006: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7007: ($type eq 'template'));
1.160.6.46 raeburn 7008: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7009: if ($env{'form.'.$type.'_addbook_'.$item}) {
7010: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7011: }
7012: }
7013: if ($type eq 'textbooks') {
7014: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7015: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7016: my ($imageurl,$error) =
7017: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7018: $configuserok,$switchserver,$author_ok);
7019: if ($imageurl) {
7020: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7021: }
7022: if ($error) {
7023: &Apache::lonnet::logthis($error);
7024: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7025: }
7026: }
1.160.6.30 raeburn 7027: }
7028: }
1.160.6.46 raeburn 7029: if (@{$allpos{$type}} > 0) {
7030: my $idx = 0;
7031: foreach my $item (@{$allpos{$type}}) {
7032: if ($item ne '') {
7033: $confhash{$type}{$item}{'order'} = $idx;
7034: if (ref($domconfig{$action}) eq 'HASH') {
7035: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7036: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7037: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7038: $changes{$type}{$item} = 1;
7039: }
1.160.6.30 raeburn 7040: }
7041: }
7042: }
1.160.6.46 raeburn 7043: $idx ++;
1.160.6.30 raeburn 7044: }
7045: }
7046: }
7047: }
1.160.6.39 raeburn 7048: if (ref($validationitemsref) eq 'ARRAY') {
7049: foreach my $item (@{$validationitemsref}) {
7050: if ($item eq 'fields') {
7051: my @changed;
7052: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7053: if (@{$confhash{'validation'}{$item}} > 0) {
7054: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7055: }
7056: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7057: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7058: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7059: $domconfig{'requestcourses'}{'validation'}{$item});
7060: } else {
7061: @changed = @{$confhash{'validation'}{$item}};
7062: }
7063: } else {
7064: @changed = @{$confhash{'validation'}{$item}};
7065: }
7066: if (@changed) {
7067: if ($confhash{'validation'}{$item}) {
7068: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7069: } else {
7070: $changes{'validation'}{$item} = &mt('None');
7071: }
7072: }
7073: } else {
7074: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7075: if ($item eq 'markup') {
7076: if ($env{'form.requestcourses_validation_'.$item}) {
7077: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7078: }
7079: }
7080: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7081: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7082: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7083: }
7084: } else {
7085: if ($confhash{'validation'}{$item} ne '') {
7086: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7087: }
7088: }
7089: }
7090: }
7091: }
7092: if ($env{'form.validationdc'}) {
7093: my $newval = $env{'form.validationdc'};
7094: my %domcoords = &get_active_dcs($dom);
7095: if (exists($domcoords{$newval})) {
7096: $confhash{'validation'}{'dc'} = $newval;
7097: }
7098: }
7099: if (ref($confhash{'validation'}) eq 'HASH') {
7100: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7101: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7102: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7103: if ($confhash{'validation'}{'dc'} eq '') {
7104: $changes{'validation'}{'dc'} = &mt('None');
7105: } else {
7106: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7107: }
7108: }
7109: } elsif ($confhash{'validation'}{'dc'} ne '') {
7110: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7111: }
7112: } elsif ($confhash{'validation'}{'dc'} ne '') {
7113: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7114: }
7115: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7116: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7117: $changes{'validation'}{'dc'} = &mt('None');
7118: }
7119: }
1.102 raeburn 7120: }
7121: } else {
1.86 raeburn 7122: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7123: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7124: }
1.72 raeburn 7125: foreach my $item (@usertools) {
7126: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7127: my $unset;
1.101 raeburn 7128: if ($context eq 'requestcourses') {
1.104 raeburn 7129: $unset = '0';
7130: if ($type eq '_LC_adv') {
7131: $unset = '';
7132: }
1.101 raeburn 7133: if ($confhash{$item}{$type} eq 'autolimit') {
7134: $confhash{$item}{$type} .= '=';
7135: unless ($limithash{$item}{$type} =~ /\D/) {
7136: $confhash{$item}{$type} .= $limithash{$item}{$type};
7137: }
7138: }
1.160.6.5 raeburn 7139: } elsif ($context eq 'requestauthor') {
7140: $unset = '0';
7141: if ($type eq '_LC_adv') {
7142: $unset = '';
7143: }
1.72 raeburn 7144: } else {
1.101 raeburn 7145: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7146: $confhash{$item}{$type} = 1;
7147: } else {
7148: $confhash{$item}{$type} = 0;
7149: }
1.72 raeburn 7150: }
1.86 raeburn 7151: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7152: if ($action eq 'requestauthor') {
7153: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7154: $changes{$type} = 1;
7155: }
7156: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7157: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7158: $changes{$item}{$type} = 1;
7159: }
7160: } else {
7161: if ($context eq 'requestcourses') {
1.104 raeburn 7162: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7163: $changes{$item}{$type} = 1;
7164: }
7165: } else {
7166: if (!$confhash{$item}{$type}) {
7167: $changes{$item}{$type} = 1;
7168: }
7169: }
7170: }
7171: } else {
7172: if ($context eq 'requestcourses') {
1.104 raeburn 7173: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7174: $changes{$item}{$type} = 1;
7175: }
1.160.6.5 raeburn 7176: } elsif ($context eq 'requestauthor') {
7177: if ($confhash{$type} ne $unset) {
7178: $changes{$type} = 1;
7179: }
1.72 raeburn 7180: } else {
7181: if (!$confhash{$item}{$type}) {
7182: $changes{$item}{$type} = 1;
7183: }
7184: }
7185: }
1.1 raeburn 7186: }
7187: }
1.160.6.5 raeburn 7188: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7189: if (ref($domconfig{'quotas'}) eq 'HASH') {
7190: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7191: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7192: if (exists($confhash{'defaultquota'}{$key})) {
7193: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7194: $changes{'defaultquota'}{$key} = 1;
7195: }
7196: } else {
7197: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7198: }
7199: }
1.86 raeburn 7200: } else {
7201: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7202: if (exists($confhash{'defaultquota'}{$key})) {
7203: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7204: $changes{'defaultquota'}{$key} = 1;
7205: }
7206: } else {
7207: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7208: }
1.1 raeburn 7209: }
7210: }
1.160.6.20 raeburn 7211: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7212: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7213: if (exists($confhash{'authorquota'}{$key})) {
7214: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7215: $changes{'authorquota'}{$key} = 1;
7216: }
7217: } else {
7218: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7219: }
7220: }
7221: }
1.1 raeburn 7222: }
1.86 raeburn 7223: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7224: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7225: if (ref($domconfig{'quotas'}) eq 'HASH') {
7226: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7227: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7228: $changes{'defaultquota'}{$key} = 1;
7229: }
7230: } else {
7231: if (!exists($domconfig{'quotas'}{$key})) {
7232: $changes{'defaultquota'}{$key} = 1;
7233: }
1.72 raeburn 7234: }
7235: } else {
1.86 raeburn 7236: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7237: }
1.1 raeburn 7238: }
7239: }
1.160.6.20 raeburn 7240: if (ref($confhash{'authorquota'}) eq 'HASH') {
7241: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7242: if (ref($domconfig{'quotas'}) eq 'HASH') {
7243: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7244: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7245: $changes{'authorquota'}{$key} = 1;
7246: }
7247: } else {
7248: $changes{'authorquota'}{$key} = 1;
7249: }
7250: } else {
7251: $changes{'authorquota'}{$key} = 1;
7252: }
7253: }
7254: }
1.1 raeburn 7255: }
1.72 raeburn 7256:
1.160.6.5 raeburn 7257: if ($context eq 'requestauthor') {
7258: $domdefaults{'requestauthor'} = \%confhash;
7259: } else {
7260: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7261: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7262: $domdefaults{$key} = $confhash{$key};
7263: }
1.160.6.5 raeburn 7264: }
1.72 raeburn 7265: }
1.160.6.5 raeburn 7266:
1.1 raeburn 7267: my %quotahash = (
1.86 raeburn 7268: $action => { %confhash }
1.1 raeburn 7269: );
7270: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7271: $dom);
7272: if ($putresult eq 'ok') {
7273: if (keys(%changes) > 0) {
1.72 raeburn 7274: my $cachetime = 24*60*60;
7275: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7276: if (ref($lastactref) eq 'HASH') {
7277: $lastactref->{'domdefaults'} = 1;
7278: }
1.1 raeburn 7279: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7280: unless (($context eq 'requestcourses') ||
7281: ($context eq 'requestauthor')) {
1.86 raeburn 7282: if (ref($changes{'defaultquota'}) eq 'HASH') {
7283: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7284: foreach my $type (@{$types},'default') {
7285: if (defined($changes{'defaultquota'}{$type})) {
7286: my $typetitle = $usertypes->{$type};
7287: if ($type eq 'default') {
7288: $typetitle = $othertitle;
7289: }
1.160.6.28 raeburn 7290: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7291: }
7292: }
1.86 raeburn 7293: $resulttext .= '</ul></li>';
1.72 raeburn 7294: }
1.160.6.20 raeburn 7295: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7296: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7297: foreach my $type (@{$types},'default') {
7298: if (defined($changes{'authorquota'}{$type})) {
7299: my $typetitle = $usertypes->{$type};
7300: if ($type eq 'default') {
7301: $typetitle = $othertitle;
7302: }
1.160.6.28 raeburn 7303: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7304: }
7305: }
7306: $resulttext .= '</ul></li>';
7307: }
1.72 raeburn 7308: }
1.80 raeburn 7309: my %newenv;
1.72 raeburn 7310: foreach my $item (@usertools) {
1.160.6.5 raeburn 7311: my (%haschgs,%inconf);
7312: if ($context eq 'requestauthor') {
7313: %haschgs = %changes;
7314: %inconf = %confhash;
7315: } else {
7316: if (ref($changes{$item}) eq 'HASH') {
7317: %haschgs = %{$changes{$item}};
7318: }
7319: if (ref($confhash{$item}) eq 'HASH') {
7320: %inconf = %{$confhash{$item}};
7321: }
7322: }
7323: if (keys(%haschgs) > 0) {
1.80 raeburn 7324: my $newacc =
7325: &Apache::lonnet::usertools_access($env{'user.name'},
7326: $env{'user.domain'},
1.86 raeburn 7327: $item,'reload',$context);
1.160.6.5 raeburn 7328: if (($context eq 'requestcourses') ||
7329: ($context eq 'requestauthor')) {
1.108 raeburn 7330: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7331: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7332: }
7333: } else {
7334: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7335: $newenv{'environment.availabletools.'.$item} = $newacc;
7336: }
1.80 raeburn 7337: }
1.160.6.5 raeburn 7338: unless ($context eq 'requestauthor') {
7339: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7340: }
1.72 raeburn 7341: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7342: if ($haschgs{$type}) {
1.72 raeburn 7343: my $typetitle = $usertypes->{$type};
7344: if ($type eq 'default') {
7345: $typetitle = $othertitle;
7346: } elsif ($type eq '_LC_adv') {
7347: $typetitle = 'LON-CAPA Advanced Users';
7348: }
1.160.6.5 raeburn 7349: if ($inconf{$type}) {
1.101 raeburn 7350: if ($context eq 'requestcourses') {
7351: my $cond;
1.160.6.5 raeburn 7352: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7353: if ($1 eq '') {
7354: $cond = &mt('(Automatic processing of any request).');
7355: } else {
7356: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7357: }
7358: } else {
1.160.6.5 raeburn 7359: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7360: }
7361: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7362: } elsif ($context eq 'requestauthor') {
7363: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7364: $titles{$inconf{$type}},$typetitle);
7365:
1.101 raeburn 7366: } else {
7367: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7368: }
1.72 raeburn 7369: } else {
1.104 raeburn 7370: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7371: if ($inconf{$type} eq '0') {
1.104 raeburn 7372: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7373: } else {
7374: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7375: }
7376: } else {
7377: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7378: }
1.72 raeburn 7379: }
7380: }
1.26 raeburn 7381: }
1.160.6.5 raeburn 7382: unless ($context eq 'requestauthor') {
7383: $resulttext .= '</ul></li>';
7384: }
1.26 raeburn 7385: }
1.1 raeburn 7386: }
1.160.6.5 raeburn 7387: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7388: if (ref($changes{'notify'}) eq 'HASH') {
7389: if ($changes{'notify'}{'approval'}) {
7390: if (ref($confhash{'notify'}) eq 'HASH') {
7391: if ($confhash{'notify'}{'approval'}) {
7392: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7393: } else {
1.160.6.5 raeburn 7394: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7395: }
7396: }
7397: }
7398: }
7399: }
1.160.6.30 raeburn 7400: if ($action eq 'requestcourses') {
7401: my @offon = ('off','on');
7402: if ($changes{'uniquecode'}) {
7403: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7404: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7405: $resulttext .= '<li>'.
7406: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7407: '</li>';
7408: } else {
7409: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7410: '</li>';
7411: }
7412: }
1.160.6.46 raeburn 7413: foreach my $type ('textbooks','templates') {
7414: if (ref($changes{$type}) eq 'HASH') {
7415: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7416: foreach my $key (sort(keys(%{$changes{$type}}))) {
7417: my %coursehash = &Apache::lonnet::coursedescription($key);
7418: my $coursetitle = $coursehash{'description'};
7419: my $position = $confhash{$type}{$key}{'order'} + 1;
7420: $resulttext .= '<li>';
1.160.6.47 raeburn 7421: foreach my $item ('subject','title','publisher','author') {
7422: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7423: ($type eq 'templates'));
1.160.6.46 raeburn 7424: my $name = $item.':';
7425: $name =~ s/^(\w)/\U$1/;
7426: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7427: }
7428: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7429: if ($type eq 'textbooks') {
7430: if ($confhash{$type}{$key}{'image'}) {
7431: $resulttext .= ' '.&mt('Image: [_1]',
7432: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7433: ' alt="Textbook cover" />').'<br />';
7434: }
7435: }
7436: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7437: }
1.160.6.46 raeburn 7438: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7439: }
7440: }
1.160.6.39 raeburn 7441: if (ref($changes{'validation'}) eq 'HASH') {
7442: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7443: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7444: foreach my $item (@{$validationitemsref}) {
7445: if (exists($changes{'validation'}{$item})) {
7446: if ($item eq 'markup') {
7447: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7448: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7449: } else {
7450: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7451: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7452: }
7453: }
7454: }
7455: if (exists($changes{'validation'}{'dc'})) {
7456: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7457: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7458: }
7459: }
7460: }
1.160.6.30 raeburn 7461: }
1.1 raeburn 7462: $resulttext .= '</ul>';
1.80 raeburn 7463: if (keys(%newenv)) {
7464: &Apache::lonnet::appenv(\%newenv);
7465: }
1.1 raeburn 7466: } else {
1.86 raeburn 7467: if ($context eq 'requestcourses') {
7468: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7469: } elsif ($context eq 'requestauthor') {
7470: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7471: } else {
1.90 weissno 7472: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7473: }
1.1 raeburn 7474: }
7475: } else {
1.11 albertel 7476: $resulttext = '<span class="LC_error">'.
7477: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7478: }
1.160.6.30 raeburn 7479: if ($errors) {
7480: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7481: '<ul>'.$errors.'</ul></p>';
7482: }
1.3 raeburn 7483: return $resulttext;
1.1 raeburn 7484: }
7485:
1.160.6.30 raeburn 7486: sub process_textbook_image {
1.160.6.46 raeburn 7487: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7488: my $filename = $env{'form.'.$caller.'.filename'};
7489: my ($error,$url);
7490: my ($width,$height) = (50,50);
7491: if ($configuserok eq 'ok') {
7492: if ($switchserver) {
7493: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7494: $switchserver);
7495: } elsif ($author_ok eq 'ok') {
7496: my ($result,$imageurl) =
7497: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7498: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7499: if ($result eq 'ok') {
7500: $url = $imageurl;
7501: } else {
7502: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7503: }
7504: } else {
7505: $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);
7506: }
7507: } else {
7508: $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);
7509: }
7510: return ($url,$error);
7511: }
7512:
1.3 raeburn 7513: sub modify_autoenroll {
1.160.6.24 raeburn 7514: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7515: my ($resulttext,%changes);
7516: my %currautoenroll;
7517: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7518: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7519: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7520: }
7521: }
7522: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7523: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7524: sender => 'Sender for notification messages',
7525: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7526: my @offon = ('off','on');
1.17 raeburn 7527: my $sender_uname = $env{'form.sender_uname'};
7528: my $sender_domain = $env{'form.sender_domain'};
7529: if ($sender_domain eq '') {
7530: $sender_uname = '';
7531: } elsif ($sender_uname eq '') {
7532: $sender_domain = '';
7533: }
1.129 raeburn 7534: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7535: my %autoenrollhash = (
1.129 raeburn 7536: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7537: 'sender_uname' => $sender_uname,
7538: 'sender_domain' => $sender_domain,
7539: 'co-owners' => $coowners,
1.1 raeburn 7540: }
7541: );
1.4 raeburn 7542: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7543: $dom);
1.1 raeburn 7544: if ($putresult eq 'ok') {
7545: if (exists($currautoenroll{'run'})) {
7546: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7547: $changes{'run'} = 1;
7548: }
7549: } elsif ($autorun) {
7550: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7551: $changes{'run'} = 1;
1.1 raeburn 7552: }
7553: }
1.17 raeburn 7554: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7555: $changes{'sender'} = 1;
7556: }
1.17 raeburn 7557: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7558: $changes{'sender'} = 1;
7559: }
1.129 raeburn 7560: if ($currautoenroll{'co-owners'} ne '') {
7561: if ($currautoenroll{'co-owners'} ne $coowners) {
7562: $changes{'coowners'} = 1;
7563: }
7564: } elsif ($coowners) {
7565: $changes{'coowners'} = 1;
7566: }
1.1 raeburn 7567: if (keys(%changes) > 0) {
7568: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7569: if ($changes{'run'}) {
1.1 raeburn 7570: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7571: }
7572: if ($changes{'sender'}) {
1.17 raeburn 7573: if ($sender_uname eq '' || $sender_domain eq '') {
7574: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7575: } else {
7576: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7577: }
1.1 raeburn 7578: }
1.129 raeburn 7579: if ($changes{'coowners'}) {
7580: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7581: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7582: if (ref($lastactref) eq 'HASH') {
7583: $lastactref->{'domainconfig'} = 1;
7584: }
1.129 raeburn 7585: }
1.1 raeburn 7586: $resulttext .= '</ul>';
7587: } else {
7588: $resulttext = &mt('No changes made to auto-enrollment settings');
7589: }
7590: } else {
1.11 albertel 7591: $resulttext = '<span class="LC_error">'.
7592: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7593: }
1.3 raeburn 7594: return $resulttext;
1.1 raeburn 7595: }
7596:
7597: sub modify_autoupdate {
1.3 raeburn 7598: my ($dom,%domconfig) = @_;
1.1 raeburn 7599: my ($resulttext,%currautoupdate,%fields,%changes);
7600: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7601: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7602: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7603: }
7604: }
7605: my @offon = ('off','on');
7606: my %title = &Apache::lonlocal::texthash (
7607: run => 'Auto-update:',
7608: classlists => 'Updates to user information in classlists?'
7609: );
1.44 raeburn 7610: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7611: my %fieldtitles = &Apache::lonlocal::texthash (
7612: id => 'Student/Employee ID',
1.20 raeburn 7613: permanentemail => 'E-mail address',
1.1 raeburn 7614: lastname => 'Last Name',
7615: firstname => 'First Name',
7616: middlename => 'Middle Name',
1.132 raeburn 7617: generation => 'Generation',
1.1 raeburn 7618: );
1.142 raeburn 7619: $othertitle = &mt('All users');
1.1 raeburn 7620: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7621: $othertitle = &mt('Other users');
1.1 raeburn 7622: }
7623: foreach my $key (keys(%env)) {
7624: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7625: my ($usertype,$item) = ($1,$2);
7626: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7627: if ($usertype eq 'default') {
7628: push(@{$fields{$1}},$2);
7629: } elsif (ref($types) eq 'ARRAY') {
7630: if (grep(/^\Q$usertype\E$/,@{$types})) {
7631: push(@{$fields{$1}},$2);
7632: }
7633: }
7634: }
1.1 raeburn 7635: }
7636: }
1.131 raeburn 7637: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7638: @lockablenames = sort(@lockablenames);
7639: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7640: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7641: if (@changed) {
7642: $changes{'lockablenames'} = 1;
7643: }
7644: } else {
7645: if (@lockablenames) {
7646: $changes{'lockablenames'} = 1;
7647: }
7648: }
1.1 raeburn 7649: my %updatehash = (
7650: autoupdate => { run => $env{'form.autoupdate_run'},
7651: classlists => $env{'form.classlists'},
7652: fields => {%fields},
1.131 raeburn 7653: lockablenames => \@lockablenames,
1.1 raeburn 7654: }
7655: );
7656: foreach my $key (keys(%currautoupdate)) {
7657: if (($key eq 'run') || ($key eq 'classlists')) {
7658: if (exists($updatehash{autoupdate}{$key})) {
7659: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7660: $changes{$key} = 1;
7661: }
7662: }
7663: } elsif ($key eq 'fields') {
7664: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7665: foreach my $item (@{$types},'default') {
1.1 raeburn 7666: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7667: my $change = 0;
7668: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7669: if (!exists($fields{$item})) {
7670: $change = 1;
1.132 raeburn 7671: last;
1.1 raeburn 7672: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7673: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7674: $change = 1;
1.132 raeburn 7675: last;
1.1 raeburn 7676: }
7677: }
7678: }
7679: if ($change) {
7680: push(@{$changes{$key}},$item);
7681: }
1.26 raeburn 7682: }
1.1 raeburn 7683: }
7684: }
1.131 raeburn 7685: } elsif ($key eq 'lockablenames') {
7686: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7687: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7688: if (@changed) {
7689: $changes{'lockablenames'} = 1;
7690: }
7691: } else {
7692: if (@lockablenames) {
7693: $changes{'lockablenames'} = 1;
7694: }
7695: }
7696: }
7697: }
7698: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7699: if (@lockablenames) {
7700: $changes{'lockablenames'} = 1;
1.1 raeburn 7701: }
7702: }
1.26 raeburn 7703: foreach my $item (@{$types},'default') {
7704: if (defined($fields{$item})) {
7705: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7706: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7707: my $change = 0;
7708: if (ref($fields{$item}) eq 'ARRAY') {
7709: foreach my $type (@{$fields{$item}}) {
7710: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7711: $change = 1;
7712: last;
7713: }
7714: }
7715: }
7716: if ($change) {
7717: push(@{$changes{'fields'}},$item);
7718: }
7719: } else {
1.26 raeburn 7720: push(@{$changes{'fields'}},$item);
7721: }
7722: } else {
7723: push(@{$changes{'fields'}},$item);
1.1 raeburn 7724: }
7725: }
7726: }
7727: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7728: $dom);
7729: if ($putresult eq 'ok') {
7730: if (keys(%changes) > 0) {
7731: $resulttext = &mt('Changes made:').'<ul>';
7732: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7733: if ($key eq 'lockablenames') {
7734: $resulttext .= '<li>';
7735: if (@lockablenames) {
7736: $usertypes->{'default'} = $othertitle;
7737: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7738: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7739: } else {
7740: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7741: }
7742: $resulttext .= '</li>';
7743: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7744: foreach my $item (@{$changes{$key}}) {
7745: my @newvalues;
7746: foreach my $type (@{$fields{$item}}) {
7747: push(@newvalues,$fieldtitles{$type});
7748: }
1.3 raeburn 7749: my $newvaluestr;
7750: if (@newvalues > 0) {
7751: $newvaluestr = join(', ',@newvalues);
7752: } else {
7753: $newvaluestr = &mt('none');
1.6 raeburn 7754: }
1.1 raeburn 7755: if ($item eq 'default') {
1.26 raeburn 7756: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7757: } else {
1.26 raeburn 7758: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7759: }
7760: }
7761: } else {
7762: my $newvalue;
7763: if ($key eq 'run') {
7764: $newvalue = $offon[$env{'form.autoupdate_run'}];
7765: } else {
7766: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7767: }
1.1 raeburn 7768: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7769: }
7770: }
7771: $resulttext .= '</ul>';
7772: } else {
1.3 raeburn 7773: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7774: }
7775: } else {
1.11 albertel 7776: $resulttext = '<span class="LC_error">'.
7777: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7778: }
1.3 raeburn 7779: return $resulttext;
1.1 raeburn 7780: }
7781:
1.125 raeburn 7782: sub modify_autocreate {
7783: my ($dom,%domconfig) = @_;
7784: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7785: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7786: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7787: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7788: }
7789: }
7790: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7791: req => 'Auto-creation of validated requests for official courses',
7792: xmldc => 'Identity of course creator of courses from XML files',
7793: );
7794: my @types = ('xml','req');
7795: foreach my $item (@types) {
7796: $newvals{$item} = $env{'form.autocreate_'.$item};
7797: $newvals{$item} =~ s/\D//g;
7798: $newvals{$item} = 0 if ($newvals{$item} eq '');
7799: }
7800: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7801: my %domcoords = &get_active_dcs($dom);
7802: unless (exists($domcoords{$newvals{'xmldc'}})) {
7803: $newvals{'xmldc'} = '';
7804: }
7805: %autocreatehash = (
7806: autocreate => { xml => $newvals{'xml'},
7807: req => $newvals{'req'},
7808: }
7809: );
7810: if ($newvals{'xmldc'} ne '') {
7811: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7812: }
7813: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7814: $dom);
7815: if ($putresult eq 'ok') {
7816: my @items = @types;
7817: if ($newvals{'xml'}) {
7818: push(@items,'xmldc');
7819: }
7820: foreach my $item (@items) {
7821: if (exists($currautocreate{$item})) {
7822: if ($currautocreate{$item} ne $newvals{$item}) {
7823: $changes{$item} = 1;
7824: }
7825: } elsif ($newvals{$item}) {
7826: $changes{$item} = 1;
7827: }
7828: }
7829: if (keys(%changes) > 0) {
7830: my @offon = ('off','on');
7831: $resulttext = &mt('Changes made:').'<ul>';
7832: foreach my $item (@types) {
7833: if ($changes{$item}) {
7834: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7835: $resulttext .= '<li>'.
7836: &mt("$title{$item} set to [_1]$newtxt [_2]",
7837: '<b>','</b>').
7838: '</li>';
1.125 raeburn 7839: }
7840: }
7841: if ($changes{'xmldc'}) {
7842: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7843: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7844: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7845: }
7846: $resulttext .= '</ul>';
7847: } else {
7848: $resulttext = &mt('No changes made to auto-creation settings');
7849: }
7850: } else {
7851: $resulttext = '<span class="LC_error">'.
7852: &mt('An error occurred: [_1]',$putresult).'</span>';
7853: }
7854: return $resulttext;
7855: }
7856:
1.23 raeburn 7857: sub modify_directorysrch {
7858: my ($dom,%domconfig) = @_;
7859: my ($resulttext,%changes);
7860: my %currdirsrch;
7861: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7862: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7863: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7864: }
7865: }
7866: my %title = ( available => 'Directory search available',
1.24 raeburn 7867: localonly => 'Other domains can search',
1.23 raeburn 7868: searchby => 'Search types',
7869: searchtypes => 'Search latitude');
7870: my @offon = ('off','on');
1.24 raeburn 7871: my @otherdoms = ('Yes','No');
1.23 raeburn 7872:
1.25 raeburn 7873: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7874: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7875: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7876:
1.44 raeburn 7877: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7878: if (keys(%{$usertypes}) == 0) {
7879: @cansearch = ('default');
7880: } else {
7881: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7882: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7883: if (!grep(/^\Q$type\E$/,@cansearch)) {
7884: push(@{$changes{'cansearch'}},$type);
7885: }
1.23 raeburn 7886: }
1.26 raeburn 7887: foreach my $type (@cansearch) {
7888: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7889: push(@{$changes{'cansearch'}},$type);
7890: }
1.23 raeburn 7891: }
1.26 raeburn 7892: } else {
7893: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7894: }
7895: }
7896:
7897: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7898: foreach my $by (@{$currdirsrch{'searchby'}}) {
7899: if (!grep(/^\Q$by\E$/,@searchby)) {
7900: push(@{$changes{'searchby'}},$by);
7901: }
7902: }
7903: foreach my $by (@searchby) {
7904: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7905: push(@{$changes{'searchby'}},$by);
7906: }
7907: }
7908: } else {
7909: push(@{$changes{'searchby'}},@searchby);
7910: }
1.25 raeburn 7911:
7912: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7913: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7914: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7915: push(@{$changes{'searchtypes'}},$type);
7916: }
7917: }
7918: foreach my $type (@searchtypes) {
7919: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7920: push(@{$changes{'searchtypes'}},$type);
7921: }
7922: }
7923: } else {
7924: if (exists($currdirsrch{'searchtypes'})) {
7925: foreach my $type (@searchtypes) {
7926: if ($type ne $currdirsrch{'searchtypes'}) {
7927: push(@{$changes{'searchtypes'}},$type);
7928: }
7929: }
7930: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7931: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7932: }
7933: } else {
7934: push(@{$changes{'searchtypes'}},@searchtypes);
7935: }
7936: }
7937:
1.23 raeburn 7938: my %dirsrch_hash = (
7939: directorysrch => { available => $env{'form.dirsrch_available'},
7940: cansearch => \@cansearch,
1.24 raeburn 7941: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7942: searchby => \@searchby,
1.25 raeburn 7943: searchtypes => \@searchtypes,
1.23 raeburn 7944: }
7945: );
7946: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7947: $dom);
7948: if ($putresult eq 'ok') {
7949: if (exists($currdirsrch{'available'})) {
7950: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7951: $changes{'available'} = 1;
7952: }
7953: } else {
7954: if ($env{'form.dirsrch_available'} eq '1') {
7955: $changes{'available'} = 1;
7956: }
7957: }
1.24 raeburn 7958: if (exists($currdirsrch{'localonly'})) {
7959: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7960: $changes{'localonly'} = 1;
7961: }
7962: } else {
7963: if ($env{'form.dirsrch_localonly'} eq '1') {
7964: $changes{'localonly'} = 1;
7965: }
7966: }
1.23 raeburn 7967: if (keys(%changes) > 0) {
7968: $resulttext = &mt('Changes made:').'<ul>';
7969: if ($changes{'available'}) {
7970: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7971: }
1.24 raeburn 7972: if ($changes{'localonly'}) {
7973: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7974: }
7975:
1.23 raeburn 7976: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7977: my $chgtext;
1.26 raeburn 7978: if (ref($usertypes) eq 'HASH') {
7979: if (keys(%{$usertypes}) > 0) {
7980: foreach my $type (@{$types}) {
7981: if (grep(/^\Q$type\E$/,@cansearch)) {
7982: $chgtext .= $usertypes->{$type}.'; ';
7983: }
7984: }
7985: if (grep(/^default$/,@cansearch)) {
7986: $chgtext .= $othertitle;
7987: } else {
7988: $chgtext =~ s/\; $//;
7989: }
1.160.6.13 raeburn 7990: $resulttext .=
7991: '<li>'.
7992: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7993: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7994: '</li>';
1.23 raeburn 7995: }
7996: }
7997: }
7998: if (ref($changes{'searchby'}) eq 'ARRAY') {
7999: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8000: my $chgtext;
8001: foreach my $type (@{$titleorder}) {
8002: if (grep(/^\Q$type\E$/,@searchby)) {
8003: if (defined($searchtitles->{$type})) {
8004: $chgtext .= $searchtitles->{$type}.'; ';
8005: }
8006: }
8007: }
8008: $chgtext =~ s/\; $//;
8009: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8010: }
1.25 raeburn 8011: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8012: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8013: my $chgtext;
8014: foreach my $type (@{$srchtypeorder}) {
8015: if (grep(/^\Q$type\E$/,@searchtypes)) {
8016: if (defined($srchtypes_desc->{$type})) {
8017: $chgtext .= $srchtypes_desc->{$type}.'; ';
8018: }
8019: }
8020: }
8021: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8022: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8023: }
8024: $resulttext .= '</ul>';
8025: } else {
8026: $resulttext = &mt('No changes made to institution directory search settings');
8027: }
8028: } else {
8029: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8030: &mt('An error occurred: [_1]',$putresult).'</span>';
8031: }
8032: return $resulttext;
8033: }
8034:
1.28 raeburn 8035: sub modify_contacts {
1.160.6.24 raeburn 8036: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8037: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8038: if (ref($domconfig{'contacts'}) eq 'HASH') {
8039: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8040: $currsetting{$key} = $domconfig{'contacts'}{$key};
8041: }
8042: }
1.134 raeburn 8043: my (%others,%to,%bcc);
1.28 raeburn 8044: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8045: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8046: 'requestsmail','updatesmail','idconflictsmail');
8047: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8048: foreach my $type (@mailings) {
8049: @{$newsetting{$type}} =
8050: &Apache::loncommon::get_env_multiple('form.'.$type);
8051: foreach my $item (@contacts) {
8052: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8053: $contacts_hash{contacts}{$type}{$item} = 1;
8054: } else {
8055: $contacts_hash{contacts}{$type}{$item} = 0;
8056: }
8057: }
8058: $others{$type} = $env{'form.'.$type.'_others'};
8059: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8060: if ($type eq 'helpdeskmail') {
8061: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8062: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8063: }
1.28 raeburn 8064: }
8065: foreach my $item (@contacts) {
8066: $to{$item} = $env{'form.'.$item};
8067: $contacts_hash{'contacts'}{$item} = $to{$item};
8068: }
1.160.6.23 raeburn 8069: foreach my $item (@toggles) {
8070: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8071: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8072: }
8073: }
1.28 raeburn 8074: if (keys(%currsetting) > 0) {
8075: foreach my $item (@contacts) {
8076: if ($to{$item} ne $currsetting{$item}) {
8077: $changes{$item} = 1;
8078: }
8079: }
8080: foreach my $type (@mailings) {
8081: foreach my $item (@contacts) {
8082: if (ref($currsetting{$type}) eq 'HASH') {
8083: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8084: push(@{$changes{$type}},$item);
8085: }
8086: } else {
8087: push(@{$changes{$type}},@{$newsetting{$type}});
8088: }
8089: }
8090: if ($others{$type} ne $currsetting{$type}{'others'}) {
8091: push(@{$changes{$type}},'others');
8092: }
1.134 raeburn 8093: if ($type eq 'helpdeskmail') {
8094: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8095: push(@{$changes{$type}},'bcc');
8096: }
8097: }
1.28 raeburn 8098: }
8099: } else {
8100: my %default;
8101: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8102: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8103: $default{'errormail'} = 'adminemail';
8104: $default{'packagesmail'} = 'adminemail';
8105: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8106: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8107: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8108: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8109: foreach my $item (@contacts) {
8110: if ($to{$item} ne $default{$item}) {
8111: $changes{$item} = 1;
1.160.6.23 raeburn 8112: }
1.28 raeburn 8113: }
8114: foreach my $type (@mailings) {
8115: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8116:
8117: push(@{$changes{$type}},@{$newsetting{$type}});
8118: }
8119: if ($others{$type} ne '') {
8120: push(@{$changes{$type}},'others');
1.134 raeburn 8121: }
8122: if ($type eq 'helpdeskmail') {
8123: if ($bcc{$type} ne '') {
8124: push(@{$changes{$type}},'bcc');
8125: }
8126: }
1.28 raeburn 8127: }
8128: }
1.160.6.23 raeburn 8129: foreach my $item (@toggles) {
8130: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8131: $changes{$item} = 1;
8132: } elsif ((!$env{'form.'.$item}) &&
8133: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8134: $changes{$item} = 1;
8135: }
8136: }
1.28 raeburn 8137: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8138: $dom);
8139: if ($putresult eq 'ok') {
8140: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8141: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8142: if (ref($lastactref) eq 'HASH') {
8143: $lastactref->{'domainconfig'} = 1;
8144: }
1.28 raeburn 8145: my ($titles,$short_titles) = &contact_titles();
8146: $resulttext = &mt('Changes made:').'<ul>';
8147: foreach my $item (@contacts) {
8148: if ($changes{$item}) {
8149: $resulttext .= '<li>'.$titles->{$item}.
8150: &mt(' set to: ').
8151: '<span class="LC_cusr_emph">'.
8152: $to{$item}.'</span></li>';
8153: }
8154: }
8155: foreach my $type (@mailings) {
8156: if (ref($changes{$type}) eq 'ARRAY') {
8157: $resulttext .= '<li>'.$titles->{$type}.': ';
8158: my @text;
8159: foreach my $item (@{$newsetting{$type}}) {
8160: push(@text,$short_titles->{$item});
8161: }
8162: if ($others{$type} ne '') {
8163: push(@text,$others{$type});
8164: }
8165: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8166: join(', ',@text).'</span>';
8167: if ($type eq 'helpdeskmail') {
8168: if ($bcc{$type} ne '') {
8169: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8170: }
8171: }
8172: $resulttext .= '</li>';
1.28 raeburn 8173: }
8174: }
1.160.6.23 raeburn 8175: my @offon = ('off','on');
8176: if ($changes{'reporterrors'}) {
8177: $resulttext .= '<li>'.
8178: &mt('E-mail error reports to [_1] set to "'.
8179: $offon[$env{'form.reporterrors'}].'".',
8180: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8181: &mt('LON-CAPA core group - MSU'),600,500)).
8182: '</li>';
8183: }
8184: if ($changes{'reportupdates'}) {
8185: $resulttext .= '<li>'.
8186: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8187: $offon[$env{'form.reportupdates'}].'".',
8188: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8189: &mt('LON-CAPA core group - MSU'),600,500)).
8190: '</li>';
8191: }
1.28 raeburn 8192: $resulttext .= '</ul>';
8193: } else {
1.34 raeburn 8194: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8195: }
8196: } else {
8197: $resulttext = '<span class="LC_error">'.
8198: &mt('An error occurred: [_1].',$putresult).'</span>';
8199: }
8200: return $resulttext;
8201: }
8202:
8203: sub modify_usercreation {
1.27 raeburn 8204: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8205: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8206: my $warningmsg;
1.27 raeburn 8207: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8208: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8209: if ($key eq 'cancreate') {
8210: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8211: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8212: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8213: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8214: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8215: } else {
8216: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8217: }
1.50 raeburn 8218: }
1.43 raeburn 8219: }
1.160.6.34 raeburn 8220: } elsif ($key eq 'email_rule') {
8221: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8222: } else {
8223: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8224: }
8225: }
1.34 raeburn 8226: }
1.160.6.34 raeburn 8227: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8228: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8229: my @contexts = ('author','course','requestcrs');
8230: foreach my $item(@contexts) {
8231: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8232: }
1.34 raeburn 8233: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8234: foreach my $item (@contexts) {
1.160.6.34 raeburn 8235: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8236: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8237: }
1.27 raeburn 8238: }
1.34 raeburn 8239: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8240: foreach my $item (@contexts) {
1.43 raeburn 8241: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8242: if ($cancreate{$item} ne 'any') {
8243: push(@{$changes{'cancreate'}},$item);
8244: }
8245: } else {
8246: if ($cancreate{$item} ne 'none') {
8247: push(@{$changes{'cancreate'}},$item);
8248: }
1.27 raeburn 8249: }
8250: }
8251: } else {
1.43 raeburn 8252: foreach my $item (@contexts) {
1.34 raeburn 8253: push(@{$changes{'cancreate'}},$item);
8254: }
1.27 raeburn 8255: }
1.34 raeburn 8256:
1.27 raeburn 8257: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8258: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8259: if (!grep(/^\Q$type\E$/,@username_rule)) {
8260: push(@{$changes{'username_rule'}},$type);
8261: }
8262: }
8263: foreach my $type (@username_rule) {
8264: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8265: push(@{$changes{'username_rule'}},$type);
8266: }
8267: }
8268: } else {
8269: push(@{$changes{'username_rule'}},@username_rule);
8270: }
8271:
1.32 raeburn 8272: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8273: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8274: if (!grep(/^\Q$type\E$/,@id_rule)) {
8275: push(@{$changes{'id_rule'}},$type);
8276: }
8277: }
8278: foreach my $type (@id_rule) {
8279: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8280: push(@{$changes{'id_rule'}},$type);
8281: }
8282: }
8283: } else {
8284: push(@{$changes{'id_rule'}},@id_rule);
8285: }
8286:
1.43 raeburn 8287: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8288: my @authtypes = ('int','krb4','krb5','loc');
8289: my %authhash;
1.43 raeburn 8290: foreach my $item (@authen_contexts) {
1.28 raeburn 8291: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8292: foreach my $auth (@authtypes) {
8293: if (grep(/^\Q$auth\E$/,@authallowed)) {
8294: $authhash{$item}{$auth} = 1;
8295: } else {
8296: $authhash{$item}{$auth} = 0;
8297: }
8298: }
8299: }
8300: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8301: foreach my $item (@authen_contexts) {
1.28 raeburn 8302: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8303: foreach my $auth (@authtypes) {
8304: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8305: push(@{$changes{'authtypes'}},$item);
8306: last;
8307: }
8308: }
8309: }
8310: }
8311: } else {
1.43 raeburn 8312: foreach my $item (@authen_contexts) {
1.28 raeburn 8313: push(@{$changes{'authtypes'}},$item);
8314: }
8315: }
8316:
1.160.6.34 raeburn 8317: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8318: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8319: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8320: $save_usercreate{'id_rule'} = \@id_rule;
8321: $save_usercreate{'username_rule'} = \@username_rule,
8322: $save_usercreate{'authtypes'} = \%authhash;
8323:
1.27 raeburn 8324: my %usercreation_hash = (
1.160.6.34 raeburn 8325: usercreation => \%save_usercreate,
8326: );
1.27 raeburn 8327:
8328: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8329: $dom);
1.50 raeburn 8330:
1.160.6.34 raeburn 8331: if ($putresult eq 'ok') {
8332: if (keys(%changes) > 0) {
8333: $resulttext = &mt('Changes made:').'<ul>';
8334: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8335: my %lt = &usercreation_types();
8336: foreach my $type (@{$changes{'cancreate'}}) {
8337: my $chgtext = $lt{$type}.', ';
8338: if ($cancreate{$type} eq 'none') {
8339: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8340: } elsif ($cancreate{$type} eq 'any') {
8341: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8342: } elsif ($cancreate{$type} eq 'official') {
8343: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8344: } elsif ($cancreate{$type} eq 'unofficial') {
8345: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8346: }
8347: $resulttext .= '<li>'.$chgtext.'</li>';
8348: }
8349: }
8350: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8351: my ($rules,$ruleorder) =
8352: &Apache::lonnet::inst_userrules($dom,'username');
8353: my $chgtext = '<ul>';
8354: foreach my $type (@username_rule) {
8355: if (ref($rules->{$type}) eq 'HASH') {
8356: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8357: }
8358: }
8359: $chgtext .= '</ul>';
8360: if (@username_rule > 0) {
8361: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8362: } else {
8363: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8364: }
8365: }
8366: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8367: my ($idrules,$idruleorder) =
8368: &Apache::lonnet::inst_userrules($dom,'id');
8369: my $chgtext = '<ul>';
8370: foreach my $type (@id_rule) {
8371: if (ref($idrules->{$type}) eq 'HASH') {
8372: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8373: }
8374: }
8375: $chgtext .= '</ul>';
8376: if (@id_rule > 0) {
8377: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8378: } else {
8379: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8380: }
8381: }
8382: my %authname = &authtype_names();
8383: my %context_title = &context_names();
8384: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8385: my $chgtext = '<ul>';
8386: foreach my $type (@{$changes{'authtypes'}}) {
8387: my @allowed;
8388: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8389: foreach my $auth (@authtypes) {
8390: if ($authhash{$type}{$auth}) {
8391: push(@allowed,$authname{$auth});
8392: }
8393: }
8394: if (@allowed > 0) {
8395: $chgtext .= join(', ',@allowed).'</li>';
8396: } else {
8397: $chgtext .= &mt('none').'</li>';
8398: }
8399: }
8400: $chgtext .= '</ul>';
8401: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8402: $resulttext .= '</li>';
8403: }
8404: $resulttext .= '</ul>';
8405: } else {
8406: $resulttext = &mt('No changes made to user creation settings');
8407: }
8408: } else {
8409: $resulttext = '<span class="LC_error">'.
8410: &mt('An error occurred: [_1]',$putresult).'</span>';
8411: }
8412: if ($warningmsg ne '') {
8413: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8414: }
8415: return $resulttext;
8416: }
8417:
8418: sub modify_selfcreation {
8419: my ($dom,%domconfig) = @_;
8420: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8421: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8422: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8423: if (ref($types) eq 'ARRAY') {
8424: $usertypes->{'default'} = $othertitle;
8425: push(@{$types},'default');
8426: }
1.160.6.34 raeburn 8427: #
8428: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8429: #
8430: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8431: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8432: if ($key eq 'cancreate') {
8433: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8434: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8435: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8436: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8437: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8438: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8439: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8440: } else {
8441: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8442: }
8443: }
8444: }
8445: } elsif ($key eq 'email_rule') {
8446: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8447: } else {
8448: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8449: }
8450: }
8451: }
8452: #
8453: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8454: #
8455: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8456: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8457: if ($key eq 'selfcreate') {
8458: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8459: } else {
8460: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8461: }
8462: }
8463: }
8464:
8465: my @contexts = ('selfcreate');
8466: @{$cancreate{'selfcreate'}} = ();
8467: %{$cancreate{'emailusername'}} = ();
8468: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8469: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8470: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8471: my %selfcreatetypes = (
8472: sso => 'users authenticated by institutional single sign on',
8473: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8474: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8475: );
1.160.6.34 raeburn 8476: #
8477: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8478: # is permitted.
8479: #
1.160.6.40 raeburn 8480:
8481: my @statuses;
8482: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8483: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8484: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8485: }
8486: }
8487: push(@statuses,'default');
8488:
1.160.6.35 raeburn 8489: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8490: if ($item eq 'email') {
1.160.6.40 raeburn 8491: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8492: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8493: push(@contexts,'selfcreateprocessing');
8494: foreach my $type (@statuses) {
8495: if ($type eq 'default') {
8496: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8497: } else {
8498: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8499: }
8500: }
1.160.6.34 raeburn 8501: }
8502: } else {
8503: if ($env{'form.cancreate_'.$item}) {
8504: push(@{$cancreate{'selfcreate'}},$item);
8505: }
8506: }
8507: }
8508: my (@email_rule,%userinfo,%savecaptcha);
8509: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8510: #
1.160.6.35 raeburn 8511: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8512: # 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 8513: #
1.160.6.40 raeburn 8514:
1.160.6.48! raeburn 8515: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 8516: push(@contexts,'emailusername');
1.160.6.35 raeburn 8517: if (ref($types) eq 'ARRAY') {
8518: foreach my $type (@{$types}) {
8519: if (ref($infofields) eq 'ARRAY') {
8520: foreach my $field (@{$infofields}) {
8521: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8522: $cancreate{'emailusername'}{$type}{$field} = $1;
8523: }
8524: }
1.160.6.34 raeburn 8525: }
8526: }
8527: }
8528: #
8529: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8530: # queued requests for self-creation of account using e-mail address as username
8531: #
8532:
8533: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8534: @approvalnotify = sort(@approvalnotify);
8535: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8536: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8537: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8538: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8539: push(@{$changes{'cancreate'}},'notify');
8540: }
8541: } else {
8542: if ($cancreate{'notify'}{'approval'}) {
8543: push(@{$changes{'cancreate'}},'notify');
8544: }
8545: }
8546: } elsif ($cancreate{'notify'}{'approval'}) {
8547: push(@{$changes{'cancreate'}},'notify');
8548: }
8549:
8550: #
8551: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8552: #
8553: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8554: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8555: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8556: if (@{$curr_usercreation{'email_rule'}} > 0) {
8557: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8558: if (!grep(/^\Q$type\E$/,@email_rule)) {
8559: push(@{$changes{'email_rule'}},$type);
8560: }
8561: }
8562: }
8563: if (@email_rule > 0) {
8564: foreach my $type (@email_rule) {
8565: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8566: push(@{$changes{'email_rule'}},$type);
8567: }
8568: }
8569: }
8570: } elsif (@email_rule > 0) {
8571: push(@{$changes{'email_rule'}},@email_rule);
8572: }
8573: }
8574: #
1.160.6.40 raeburn 8575: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8576: # institutional log-in.
8577: #
8578: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8580: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8581: ($domdefaults{'auth_def'} eq 'localauth'))) {
8582: $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.').' '.
8583: &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.');
8584: }
8585: }
8586: my @fields = ('lastname','firstname','middlename','generation',
8587: 'permanentemail','id');
1.160.6.44 raeburn 8588: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8589: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8590: #
8591: # Where usernames may created for institutional log-in and/or institutional single sign on:
8592: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8593: # may self-create accounts
8594: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8595: # which the user may supply, if institutional data is unavailable.
8596: #
8597: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8598: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8599: if (@{$types} > 1) {
1.160.6.34 raeburn 8600: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8601: push(@contexts,'statustocreate');
8602: } else {
8603: undef($cancreate{'statustocreate'});
8604: }
8605: foreach my $type (@{$types}) {
8606: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8607: foreach my $field (@fields) {
8608: if (grep(/^\Q$field\E$/,@modifiable)) {
8609: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8610: } else {
8611: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8612: }
8613: }
8614: }
8615: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8616: foreach my $type (@{$types}) {
8617: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8618: foreach my $field (@fields) {
8619: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8620: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8621: push(@{$changes{'selfcreate'}},$type);
8622: last;
8623: }
8624: }
8625: }
8626: }
8627: } else {
8628: foreach my $type (@{$types}) {
8629: push(@{$changes{'selfcreate'}},$type);
8630: }
8631: }
8632: }
1.160.6.44 raeburn 8633: foreach my $field (@shibfields) {
8634: if ($env{'form.shibenv_'.$field} ne '') {
8635: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8636: }
8637: }
8638: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8639: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8640: foreach my $field (@shibfields) {
8641: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8642: push(@{$changes{'cancreate'}},'shibenv');
8643: }
8644: }
8645: } else {
8646: foreach my $field (@shibfields) {
8647: if ($env{'form.shibenv_'.$field}) {
8648: push(@{$changes{'cancreate'}},'shibenv');
8649: last;
8650: }
8651: }
8652: }
8653: }
1.160.6.34 raeburn 8654: }
8655: foreach my $item (@contexts) {
8656: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8657: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8658: if (ref($cancreate{$item}) eq 'ARRAY') {
8659: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8660: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8661: push(@{$changes{'cancreate'}},$item);
8662: }
8663: }
8664: }
8665: }
8666: if (ref($cancreate{$item}) eq 'ARRAY') {
8667: foreach my $type (@{$cancreate{$item}}) {
8668: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8669: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8670: push(@{$changes{'cancreate'}},$item);
8671: }
8672: }
8673: }
8674: }
8675: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8676: if (ref($cancreate{$item}) eq 'HASH') {
8677: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8678: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8679: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8680: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8681: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8682: push(@{$changes{'cancreate'}},$item);
8683: }
8684: }
8685: }
1.160.6.40 raeburn 8686: } elsif ($item eq 'selfcreateprocessing') {
8687: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8688: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8689: push(@{$changes{'cancreate'}},$item);
8690: }
8691: }
1.160.6.35 raeburn 8692: } else {
8693: if (!$cancreate{$item}{$curr}) {
8694: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8695: push(@{$changes{'cancreate'}},$item);
8696: }
1.160.6.34 raeburn 8697: }
8698: }
8699: }
8700: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8701: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8702: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8703: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8704: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8705: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8706: push(@{$changes{'cancreate'}},$item);
8707: }
8708: }
8709: } else {
8710: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8711: push(@{$changes{'cancreate'}},$item);
8712: }
8713: }
8714: }
1.160.6.40 raeburn 8715: } elsif ($item eq 'selfcreateprocessing') {
8716: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8717: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8718: push(@{$changes{'cancreate'}},$item);
8719: }
8720: }
1.160.6.35 raeburn 8721: } else {
8722: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8723: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8724: push(@{$changes{'cancreate'}},$item);
8725: }
1.160.6.34 raeburn 8726: }
8727: }
8728: }
8729: }
8730: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8731: if (ref($cancreate{$item}) eq 'ARRAY') {
8732: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8733: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8734: push(@{$changes{'cancreate'}},$item);
8735: }
8736: }
8737: } elsif (ref($cancreate{$item}) eq 'HASH') {
8738: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8739: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8740: push(@{$changes{'cancreate'}},$item);
8741: }
8742: }
8743: }
8744: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8745: if (ref($cancreate{$item}) eq 'HASH') {
8746: foreach my $type (keys(%{$cancreate{$item}})) {
8747: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8748: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8749: if ($cancreate{$item}{$type}{$field}) {
8750: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8751: push(@{$changes{'cancreate'}},$item);
8752: }
8753: last;
8754: }
8755: }
8756: }
8757: }
1.160.6.34 raeburn 8758: }
8759: }
8760: }
8761: #
8762: # Populate %save_usercreate hash with updates to self-creation configuration.
8763: #
8764: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8765: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8766: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8767: if (ref($cancreate{'notify'}) eq 'HASH') {
8768: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8769: }
1.160.6.40 raeburn 8770: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8771: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8772: }
1.160.6.34 raeburn 8773: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8774: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8775: }
1.160.6.44 raeburn 8776: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8777: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8778: }
1.160.6.34 raeburn 8779: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8780: $save_usercreate{'emailrule'} = \@email_rule;
8781:
8782: my %userconfig_hash = (
8783: usercreation => \%save_usercreate,
8784: usermodification => \%save_usermodify,
8785: );
8786: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8787: $dom);
8788: #
8789: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8790: #
1.27 raeburn 8791: if ($putresult eq 'ok') {
8792: if (keys(%changes) > 0) {
8793: $resulttext = &mt('Changes made:').'<ul>';
8794: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8795: my %lt = &selfcreation_types();
1.34 raeburn 8796: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8797: my $chgtext;
1.45 raeburn 8798: if ($type eq 'selfcreate') {
1.50 raeburn 8799: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8800: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8801: } else {
1.160.6.34 raeburn 8802: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8803: '<ul>';
1.50 raeburn 8804: foreach my $case (@{$cancreate{$type}}) {
8805: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8806: }
8807: $chgtext .= '</ul>';
1.100 raeburn 8808: if (ref($cancreate{$type}) eq 'ARRAY') {
8809: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8810: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8811: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8812: $chgtext .= '<br />'.
8813: '<span class="LC_warning">'.
8814: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8815: '</span>';
1.100 raeburn 8816: }
8817: }
8818: }
8819: }
1.43 raeburn 8820: }
1.160.6.44 raeburn 8821: } elsif ($type eq 'shibenv') {
8822: if (keys(%{$cancreate{$type}}) == 0) {
8823: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8824: } else {
8825: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8826: '<ul>';
8827: foreach my $field (@shibfields) {
8828: next if ($cancreate{$type}{$field} eq '');
8829: if ($field eq 'inststatus') {
8830: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8831: } else {
8832: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8833: }
8834: }
8835: $chgtext .= '</ul>';
8836: }
1.93 raeburn 8837: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8838: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8839: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8840: if (@{$cancreate{'selfcreate'}} > 0) {
8841: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8842: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8843: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8844: $chgtext .= '<br />'.
8845: '<span class="LC_warning">'.
8846: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8847: '</span>';
8848: }
1.96 raeburn 8849: } elsif (ref($usertypes) eq 'HASH') {
8850: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8851: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8852: } else {
8853: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8854: }
8855: $chgtext .= '<ul>';
8856: foreach my $case (@{$cancreate{$type}}) {
8857: if ($case eq 'default') {
8858: $chgtext .= '<li>'.$othertitle.'</li>';
8859: } else {
8860: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8861: }
8862: }
1.100 raeburn 8863: $chgtext .= '</ul>';
8864: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8865: $chgtext .= '<br /><span class="LC_warning">'.
8866: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8867: '</span>';
1.100 raeburn 8868: }
8869: }
8870: } else {
8871: if (@{$cancreate{$type}} == 0) {
8872: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8873: } else {
8874: $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 8875: }
8876: }
8877: }
1.160.6.40 raeburn 8878: } elsif ($type eq 'selfcreateprocessing') {
8879: my %choices = &Apache::lonlocal::texthash (
8880: automatic => 'Automatic approval',
8881: approval => 'Queued for approval',
8882: );
8883: if (@statuses > 1) {
8884: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8885: '<ul>';
8886: foreach my $type (@statuses) {
8887: if ($type eq 'default') {
8888: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8889: } else {
8890: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8891: }
8892: }
8893: $chgtext .= '</ul>';
8894: } else {
8895: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8896: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8897: }
1.160.6.5 raeburn 8898: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8899: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8900: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8901: } else {
8902: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8903: if ($captchas{$savecaptcha{$type}}) {
8904: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8905: } else {
8906: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8907: }
8908: }
8909: } elsif ($type eq 'recaptchakeys') {
8910: my ($privkey,$pubkey);
1.160.6.34 raeburn 8911: if (ref($savecaptcha{$type}) eq 'HASH') {
8912: $pubkey = $savecaptcha{$type}{'public'};
8913: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8914: }
8915: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8916: if (!$pubkey) {
8917: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8918: } else {
8919: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8920: }
8921: if (!$privkey) {
8922: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8923: } else {
8924: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8925: }
8926: $chgtext .= '</ul>';
1.160.6.34 raeburn 8927: } elsif ($type eq 'emailusername') {
8928: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8929: if (ref($types) eq 'ARRAY') {
8930: foreach my $type (@{$types}) {
8931: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8932: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8933: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8934: '<ul>';
8935: foreach my $field (@{$infofields}) {
8936: if ($cancreate{'emailusername'}{$type}{$field}) {
8937: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8938: }
8939: }
8940: }
8941: $chgtext .= '</ul>';
8942: } else {
8943: $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 8944: }
8945: }
8946: }
8947: }
8948: } elsif ($type eq 'notify') {
8949: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8950: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8951: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8952: if ($cancreate{'notify'}{'approval'}) {
8953: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8954: }
8955: }
1.43 raeburn 8956: }
1.34 raeburn 8957: }
1.160.6.34 raeburn 8958: if ($chgtext) {
8959: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8960: }
8961: }
8962: }
1.43 raeburn 8963: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8964: my ($emailrules,$emailruleorder) =
8965: &Apache::lonnet::inst_userrules($dom,'email');
8966: my $chgtext = '<ul>';
8967: foreach my $type (@email_rule) {
8968: if (ref($emailrules->{$type}) eq 'HASH') {
8969: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8970: }
8971: }
8972: $chgtext .= '</ul>';
8973: if (@email_rule > 0) {
1.160.6.34 raeburn 8974: $resulttext .= '<li>'.
8975: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8976: $chgtext.
8977: '</li>';
1.43 raeburn 8978: } else {
1.160.6.34 raeburn 8979: $resulttext .= '<li>'.
8980: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8981: '</li>';
1.43 raeburn 8982: }
8983: }
1.160.6.34 raeburn 8984: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8985: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8986: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8987: foreach my $type (@{$changes{'selfcreate'}}) {
8988: my $typename = $type;
8989: if (ref($usertypes) eq 'HASH') {
8990: if ($usertypes->{$type} ne '') {
8991: $typename = $usertypes->{$type};
1.28 raeburn 8992: }
8993: }
1.160.6.34 raeburn 8994: my @modifiable;
8995: $resulttext .= '<li>'.
8996: &mt('Self-creation of account by users with status: [_1]',
8997: '<span class="LC_cusr_emph">'.$typename.'</span>').
8998: ' - '.&mt('modifiable fields (if institutional data blank): ');
8999: foreach my $field (@fields) {
9000: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9001: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9002: }
9003: }
9004: if (@modifiable > 0) {
9005: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9006: } else {
1.160.6.34 raeburn 9007: $resulttext .= &mt('none');
1.43 raeburn 9008: }
1.160.6.34 raeburn 9009: $resulttext .= '</li>';
1.28 raeburn 9010: }
1.160.6.34 raeburn 9011: $resulttext .= '</ul></li>';
1.28 raeburn 9012: }
1.27 raeburn 9013: $resulttext .= '</ul>';
9014: } else {
1.160.6.34 raeburn 9015: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9016: }
9017: } else {
9018: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9019: &mt('An error occurred: [_1]',$putresult).'</span>';
9020: }
1.43 raeburn 9021: if ($warningmsg ne '') {
9022: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9023: }
1.23 raeburn 9024: return $resulttext;
9025: }
9026:
1.160.6.5 raeburn 9027: sub process_captcha {
9028: my ($container,$changes,$newsettings,$current) = @_;
9029: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9030: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9031: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9032: $newsettings->{'captcha'} = 'original';
9033: }
9034: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9035: if ($container eq 'cancreate') {
9036: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9037: push(@{$changes->{'cancreate'}},'captcha');
9038: } elsif (!defined($changes->{'cancreate'})) {
9039: $changes->{'cancreate'} = ['captcha'];
9040: }
9041: } else {
9042: $changes->{'captcha'} = 1;
9043: }
9044: }
9045: my ($newpub,$newpriv,$currpub,$currpriv);
9046: if ($newsettings->{'captcha'} eq 'recaptcha') {
9047: $newpub = $env{'form.'.$container.'_recaptchapub'};
9048: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9049: $newpub =~ s/\W//g;
9050: $newpriv =~ s/\W//g;
9051: $newsettings->{'recaptchakeys'} = {
9052: public => $newpub,
9053: private => $newpriv,
9054: };
9055: }
9056: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9057: $currpub = $current->{'recaptchakeys'}{'public'};
9058: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9059: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9060: $newsettings->{'recaptchakeys'} = {
9061: public => '',
9062: private => '',
9063: }
9064: }
1.160.6.5 raeburn 9065: }
9066: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9067: if ($container eq 'cancreate') {
9068: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9069: push(@{$changes->{'cancreate'}},'recaptchakeys');
9070: } elsif (!defined($changes->{'cancreate'})) {
9071: $changes->{'cancreate'} = ['recaptchakeys'];
9072: }
9073: } else {
9074: $changes->{'recaptchakeys'} = 1;
9075: }
9076: }
9077: return;
9078: }
9079:
1.33 raeburn 9080: sub modify_usermodification {
9081: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9082: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9083: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9084: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9085: if ($key eq 'selfcreate') {
9086: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9087: } else {
9088: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9089: }
1.33 raeburn 9090: }
9091: }
1.160.6.34 raeburn 9092: my @contexts = ('author','course');
1.33 raeburn 9093: my %context_title = (
9094: author => 'In author context',
9095: course => 'In course context',
9096: );
9097: my @fields = ('lastname','firstname','middlename','generation',
9098: 'permanentemail','id');
9099: my %roles = (
9100: author => ['ca','aa'],
9101: course => ['st','ep','ta','in','cr'],
9102: );
9103: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9104: foreach my $context (@contexts) {
9105: foreach my $role (@{$roles{$context}}) {
9106: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9107: foreach my $item (@fields) {
9108: if (grep(/^\Q$item\E$/,@modifiable)) {
9109: $modifyhash{$context}{$role}{$item} = 1;
9110: } else {
9111: $modifyhash{$context}{$role}{$item} = 0;
9112: }
9113: }
9114: }
9115: if (ref($curr_usermodification{$context}) eq 'HASH') {
9116: foreach my $role (@{$roles{$context}}) {
9117: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9118: foreach my $field (@fields) {
9119: if ($modifyhash{$context}{$role}{$field} ne
9120: $curr_usermodification{$context}{$role}{$field}) {
9121: push(@{$changes{$context}},$role);
9122: last;
9123: }
9124: }
9125: }
9126: }
9127: } else {
9128: foreach my $context (@contexts) {
9129: foreach my $role (@{$roles{$context}}) {
9130: push(@{$changes{$context}},$role);
9131: }
9132: }
9133: }
9134: }
9135: my %usermodification_hash = (
9136: usermodification => \%modifyhash,
9137: );
9138: my $putresult = &Apache::lonnet::put_dom('configuration',
9139: \%usermodification_hash,$dom);
9140: if ($putresult eq 'ok') {
9141: if (keys(%changes) > 0) {
9142: $resulttext = &mt('Changes made: ').'<ul>';
9143: foreach my $context (@contexts) {
9144: if (ref($changes{$context}) eq 'ARRAY') {
9145: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9146: if (ref($changes{$context}) eq 'ARRAY') {
9147: foreach my $role (@{$changes{$context}}) {
9148: my $rolename;
1.160.6.34 raeburn 9149: if ($role eq 'cr') {
9150: $rolename = &mt('Custom');
1.33 raeburn 9151: } else {
1.160.6.34 raeburn 9152: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9153: }
9154: my @modifiable;
1.160.6.34 raeburn 9155: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9156: foreach my $field (@fields) {
9157: if ($modifyhash{$context}{$role}{$field}) {
9158: push(@modifiable,$fieldtitles{$field});
9159: }
9160: }
9161: if (@modifiable > 0) {
9162: $resulttext .= join(', ',@modifiable);
9163: } else {
9164: $resulttext .= &mt('none');
9165: }
9166: $resulttext .= '</li>';
9167: }
9168: $resulttext .= '</ul></li>';
9169: }
9170: }
9171: }
9172: $resulttext .= '</ul>';
9173: } else {
9174: $resulttext = &mt('No changes made to user modification settings');
9175: }
9176: } else {
9177: $resulttext = '<span class="LC_error">'.
9178: &mt('An error occurred: [_1]',$putresult).'</span>';
9179: }
9180: return $resulttext;
9181: }
9182:
1.43 raeburn 9183: sub modify_defaults {
1.160.6.27 raeburn 9184: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9185: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9186: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9187: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9188: my @authtypes = ('internal','krb4','krb5','localauth');
9189: foreach my $item (@items) {
9190: $newvalues{$item} = $env{'form.'.$item};
9191: if ($item eq 'auth_def') {
9192: if ($newvalues{$item} ne '') {
9193: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9194: push(@errors,$item);
9195: }
9196: }
9197: } elsif ($item eq 'lang_def') {
9198: if ($newvalues{$item} ne '') {
9199: if ($newvalues{$item} =~ /^(\w+)/) {
9200: my $langcode = $1;
1.103 raeburn 9201: if ($langcode ne 'x_chef') {
9202: if (code2language($langcode) eq '') {
9203: push(@errors,$item);
9204: }
1.43 raeburn 9205: }
9206: } else {
9207: push(@errors,$item);
9208: }
9209: }
1.54 raeburn 9210: } elsif ($item eq 'timezone_def') {
9211: if ($newvalues{$item} ne '') {
1.62 raeburn 9212: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9213: push(@errors,$item);
9214: }
9215: }
1.68 raeburn 9216: } elsif ($item eq 'datelocale_def') {
9217: if ($newvalues{$item} ne '') {
9218: my @datelocale_ids = DateTime::Locale->ids();
9219: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9220: push(@errors,$item);
9221: }
9222: }
1.141 raeburn 9223: } elsif ($item eq 'portal_def') {
9224: if ($newvalues{$item} ne '') {
9225: 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])\/?$/) {
9226: push(@errors,$item);
9227: }
9228: }
1.43 raeburn 9229: }
9230: if (grep(/^\Q$item\E$/,@errors)) {
9231: $newvalues{$item} = $domdefaults{$item};
9232: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9233: $changes{$item} = 1;
9234: }
1.72 raeburn 9235: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9236: }
9237: my %defaults_hash = (
1.72 raeburn 9238: defaults => \%newvalues,
9239: );
1.43 raeburn 9240: my $title = &defaults_titles();
1.160.6.40 raeburn 9241:
9242: my $currinststatus;
9243: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9244: $currinststatus = $domconfig{'inststatus'};
9245: } else {
9246: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9247: $currinststatus = {
9248: inststatustypes => $usertypes,
9249: inststatusorder => $types,
9250: inststatusguest => [],
9251: };
9252: }
9253: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9254: my @allpos;
9255: my %guests;
9256: my %alltypes;
9257: my ($currtitles,$currguests,$currorder);
9258: if (ref($currinststatus) eq 'HASH') {
9259: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9260: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9261: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9262: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9263: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9264: }
9265: }
9266: unless (grep(/^\Q$type\E$/,@todelete)) {
9267: my $position = $env{'form.inststatus_pos_'.$type};
9268: $position =~ s/\D+//g;
9269: $allpos[$position] = $type;
9270: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9271: $alltypes{$type} =~ s/`//g;
9272: if ($env{'form.inststatus_guest_'.$type}) {
9273: $guests{$type} = 1;
9274: }
9275: }
9276: }
9277: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9278: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9279: }
9280: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9281: $currtitles =~ s/,$//;
9282: }
9283: }
9284: if ($env{'form.addinststatus'}) {
9285: my $newtype = $env{'form.addinststatus'};
9286: $newtype =~ s/\W//g;
9287: unless (exists($alltypes{$newtype})) {
9288: if ($env{'form.addinststatus_guest'}) {
9289: $guests{$newtype} = 1;
9290: }
9291: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9292: $alltypes{$newtype} =~ s/`//g;
9293: my $position = $env{'form.addinststatus_pos'};
9294: $position =~ s/\D+//g;
9295: if ($position ne '') {
9296: $allpos[$position] = $newtype;
9297: }
9298: }
9299: }
9300: my (@orderedstatus,@orderedguests);
9301: foreach my $type (@allpos) {
9302: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9303: push(@orderedstatus,$type);
9304: if ($guests{$type}) {
9305: push(@orderedguests,$type);
9306: }
9307: }
9308: }
9309: foreach my $type (keys(%alltypes)) {
9310: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9311: delete($alltypes{$type});
9312: }
9313: }
9314: $defaults_hash{'inststatus'} = {
9315: inststatustypes => \%alltypes,
9316: inststatusorder => \@orderedstatus,
9317: inststatusguest => \@orderedguests,
9318: };
9319: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9320: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9321: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9322: }
9323: }
9324: if ($currorder ne join(',',@orderedstatus)) {
9325: $changes{'inststatus'}{'inststatusorder'} = 1;
9326: }
9327: if ($currguests ne join(',',@orderedguests)) {
9328: $changes{'inststatus'}{'inststatusguest'} = 1;
9329: }
9330: my $newtitles;
9331: foreach my $item (@orderedstatus) {
9332: $newtitles .= $alltypes{$item}.',';
9333: }
9334: $newtitles =~ s/,$//;
9335: if ($currtitles ne $newtitles) {
9336: $changes{'inststatus'}{'inststatustypes'} = 1;
9337: }
1.43 raeburn 9338: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9339: $dom);
9340: if ($putresult eq 'ok') {
9341: if (keys(%changes) > 0) {
9342: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9343: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9344: 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";
9345: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9346: if ($item eq 'inststatus') {
9347: if (ref($changes{'inststatus'}) eq 'HASH') {
9348: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9349: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9350: foreach my $type (@orderedstatus) {
9351: $resulttext .= $alltypes{$type}.', ';
9352: }
9353: $resulttext =~ s/, $//;
9354: $resulttext .= '</li>';
9355: }
9356: if ($changes{'inststatus'}{'inststatusguest'}) {
9357: $resulttext .= '<li>';
9358: if (@orderedguests) {
9359: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9360: foreach my $type (@orderedguests) {
9361: $resulttext .= $alltypes{$type}.', ';
9362: }
9363: $resulttext =~ s/, $//;
9364: } else {
9365: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9366: }
9367: $resulttext .= '</li>';
9368: }
9369: }
9370: } else {
9371: my $value = $env{'form.'.$item};
9372: if ($value eq '') {
9373: $value = &mt('none');
9374: } elsif ($item eq 'auth_def') {
9375: my %authnames = &authtype_names();
9376: my %shortauth = (
9377: internal => 'int',
9378: krb4 => 'krb4',
9379: krb5 => 'krb5',
9380: localauth => 'loc',
9381: );
9382: $value = $authnames{$shortauth{$value}};
9383: }
9384: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9385: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9386: }
9387: }
9388: $resulttext .= '</ul>';
9389: $mailmsgtext .= "\n";
9390: my $cachetime = 24*60*60;
1.72 raeburn 9391: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9392: if (ref($lastactref) eq 'HASH') {
9393: $lastactref->{'domdefaults'} = 1;
9394: }
1.68 raeburn 9395: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9396: my $notify = 1;
9397: if (ref($domconfig{'contacts'}) eq 'HASH') {
9398: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9399: $notify = 0;
9400: }
9401: }
9402: if ($notify) {
9403: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9404: "LON-CAPA Domain Settings Change - $dom",
9405: $mailmsgtext);
9406: }
1.54 raeburn 9407: }
1.43 raeburn 9408: } else {
1.54 raeburn 9409: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9410: }
9411: } else {
9412: $resulttext = '<span class="LC_error">'.
9413: &mt('An error occurred: [_1]',$putresult).'</span>';
9414: }
9415: if (@errors > 0) {
9416: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9417: foreach my $item (@errors) {
9418: $resulttext .= ' "'.$title->{$item}.'",';
9419: }
9420: $resulttext =~ s/,$//;
9421: }
9422: return $resulttext;
9423: }
9424:
1.46 raeburn 9425: sub modify_scantron {
1.160.6.24 raeburn 9426: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9427: my ($resulttext,%confhash,%changes,$errors);
9428: my $custom = 'custom.tab';
9429: my $default = 'default.tab';
9430: my $servadm = $r->dir_config('lonAdmEMail');
9431: my ($configuserok,$author_ok,$switchserver) =
9432: &config_check($dom,$confname,$servadm);
9433: if ($env{'form.scantronformat.filename'} ne '') {
9434: my $error;
9435: if ($configuserok eq 'ok') {
9436: if ($switchserver) {
1.130 raeburn 9437: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9438: } else {
9439: if ($author_ok eq 'ok') {
9440: my ($result,$scantronurl) =
9441: &publishlogo($r,'upload','scantronformat',$dom,
9442: $confname,'scantron','','',$custom);
9443: if ($result eq 'ok') {
9444: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9445: $changes{'scantronformat'} = 1;
1.46 raeburn 9446: } else {
9447: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9448: }
9449: } else {
9450: $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);
9451: }
9452: }
9453: } else {
9454: $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);
9455: }
9456: if ($error) {
9457: &Apache::lonnet::logthis($error);
9458: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9459: }
9460: }
1.48 raeburn 9461: if (ref($domconfig{'scantron'}) eq 'HASH') {
9462: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9463: if ($env{'form.scantronformat_del'}) {
9464: $confhash{'scantron'}{'scantronformat'} = '';
9465: $changes{'scantronformat'} = 1;
1.46 raeburn 9466: }
9467: }
9468: }
9469: if (keys(%confhash) > 0) {
9470: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9471: $dom);
9472: if ($putresult eq 'ok') {
9473: if (keys(%changes) > 0) {
1.48 raeburn 9474: if (ref($confhash{'scantron'}) eq 'HASH') {
9475: $resulttext = &mt('Changes made:').'<ul>';
9476: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9477: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9478: } else {
1.130 raeburn 9479: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9480: }
1.48 raeburn 9481: $resulttext .= '</ul>';
9482: } else {
1.130 raeburn 9483: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9484: }
9485: $resulttext .= '</ul>';
9486: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9487: if (ref($lastactref) eq 'HASH') {
9488: $lastactref->{'domainconfig'} = 1;
9489: }
1.46 raeburn 9490: } else {
1.130 raeburn 9491: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9492: }
9493: } else {
9494: $resulttext = '<span class="LC_error">'.
9495: &mt('An error occurred: [_1]',$putresult).'</span>';
9496: }
9497: } else {
1.130 raeburn 9498: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9499: }
9500: if ($errors) {
9501: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9502: $errors.'</ul>';
9503: }
9504: return $resulttext;
9505: }
9506:
1.48 raeburn 9507: sub modify_coursecategories {
1.160.6.43 raeburn 9508: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9509: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9510: $cathash);
1.48 raeburn 9511: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9512: my @catitems = ('unauth','auth');
9513: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9514: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9515: $cathash = $domconfig{'coursecategories'}{'cats'};
9516: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9517: $changes{'togglecats'} = 1;
9518: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9519: }
9520: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9521: $changes{'categorize'} = 1;
9522: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9523: }
1.120 raeburn 9524: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9525: $changes{'togglecatscomm'} = 1;
9526: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9527: }
9528: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9529: $changes{'categorizecomm'} = 1;
9530: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9531: }
1.160.6.42 raeburn 9532: foreach my $item (@catitems) {
9533: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9534: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9535: $changes{$item} = 1;
9536: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9537: }
9538: }
9539: }
1.57 raeburn 9540: } else {
9541: $changes{'togglecats'} = 1;
9542: $changes{'categorize'} = 1;
1.124 raeburn 9543: $changes{'togglecatscomm'} = 1;
9544: $changes{'categorizecomm'} = 1;
1.87 raeburn 9545: $domconfig{'coursecategories'} = {
9546: togglecats => $env{'form.togglecats'},
9547: categorize => $env{'form.categorize'},
1.124 raeburn 9548: togglecatscomm => $env{'form.togglecatscomm'},
9549: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9550: };
1.160.6.42 raeburn 9551: foreach my $item (@catitems) {
9552: if ($env{'form.coursecat_'.$item} ne 'std') {
9553: $changes{$item} = 1;
9554: }
9555: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9556: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9557: }
9558: }
1.57 raeburn 9559: }
9560: if (ref($cathash) eq 'HASH') {
9561: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9562: push (@deletecategory,'instcode::0');
9563: }
1.120 raeburn 9564: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9565: push(@deletecategory,'communities::0');
9566: }
1.48 raeburn 9567: }
1.57 raeburn 9568: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9569: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9570: if (@deletecategory > 0) {
9571: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9572: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9573: foreach my $item (@deletecategory) {
1.57 raeburn 9574: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9575: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9576: $deletions{$item} = 1;
1.57 raeburn 9577: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9578: }
9579: }
9580: }
1.57 raeburn 9581: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9582: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9583: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9584: $reorderings{$item} = 1;
1.57 raeburn 9585: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9586: }
9587: if ($env{'form.addcategory_name_'.$item} ne '') {
9588: my $newcat = $env{'form.addcategory_name_'.$item};
9589: my $newdepth = $depth+1;
9590: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9591: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9592: $adds{$newitem} = 1;
9593: }
9594: if ($env{'form.subcat_'.$item} ne '') {
9595: my $newcat = $env{'form.subcat_'.$item};
9596: my $newdepth = $depth+1;
9597: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9598: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9599: $adds{$newitem} = 1;
9600: }
9601: }
9602: }
9603: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9604: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9605: my $newitem = 'instcode::0';
1.57 raeburn 9606: if ($cathash->{$newitem} eq '') {
9607: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9608: $adds{$newitem} = 1;
9609: }
9610: } else {
9611: my $newitem = 'instcode::0';
1.57 raeburn 9612: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9613: $adds{$newitem} = 1;
9614: }
9615: }
1.120 raeburn 9616: if ($env{'form.communities'} eq '1') {
9617: if (ref($cathash) eq 'HASH') {
9618: my $newitem = 'communities::0';
9619: if ($cathash->{$newitem} eq '') {
9620: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9621: $adds{$newitem} = 1;
9622: }
9623: } else {
9624: my $newitem = 'communities::0';
9625: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9626: $adds{$newitem} = 1;
9627: }
9628: }
1.48 raeburn 9629: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9630: if (($env{'form.addcategory_name'} ne 'instcode') &&
9631: ($env{'form.addcategory_name'} ne 'communities')) {
9632: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9633: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9634: $adds{$newitem} = 1;
9635: }
1.48 raeburn 9636: }
1.57 raeburn 9637: my $putresult;
1.48 raeburn 9638: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9639: if (keys(%deletions) > 0) {
9640: foreach my $key (keys(%deletions)) {
9641: if ($predelallitems{$key} ne '') {
9642: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9643: }
9644: }
9645: }
9646: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9647: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9648: if (ref($chkcats[0]) eq 'ARRAY') {
9649: my $depth = 0;
9650: my $chg = 0;
9651: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9652: my $name = $chkcats[0][$i];
9653: my $item;
9654: if ($name eq '') {
9655: $chg ++;
9656: } else {
9657: $item = &escape($name).'::0';
9658: if ($chg) {
1.57 raeburn 9659: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9660: }
9661: $depth ++;
1.57 raeburn 9662: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9663: $depth --;
9664: }
9665: }
9666: }
1.57 raeburn 9667: }
9668: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9669: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9670: if ($putresult eq 'ok') {
1.57 raeburn 9671: my %title = (
1.120 raeburn 9672: togglecats => 'Show/Hide a course in catalog',
9673: categorize => 'Assign a category to a course',
9674: togglecatscomm => 'Show/Hide a community in catalog',
9675: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9676: );
9677: my %level = (
1.120 raeburn 9678: dom => 'set in Domain ("Modify Course/Community")',
9679: crs => 'set in Course ("Course Configuration")',
9680: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9681: none => 'No catalog',
9682: std => 'Standard catalog',
9683: domonly => 'Domain-only catalog',
9684: codesrch => 'Code search form',
1.57 raeburn 9685: );
1.48 raeburn 9686: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9687: if ($changes{'togglecats'}) {
9688: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9689: }
9690: if ($changes{'categorize'}) {
9691: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9692: }
1.120 raeburn 9693: if ($changes{'togglecatscomm'}) {
9694: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9695: }
9696: if ($changes{'categorizecomm'}) {
9697: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9698: }
1.160.6.42 raeburn 9699: if ($changes{'unauth'}) {
9700: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9701: }
9702: if ($changes{'auth'}) {
9703: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9704: }
1.57 raeburn 9705: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9706: my $cathash;
9707: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9708: $cathash = $domconfig{'coursecategories'}{'cats'};
9709: } else {
9710: $cathash = {};
9711: }
9712: my (@cats,@trails,%allitems);
9713: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9714: if (keys(%deletions) > 0) {
9715: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9716: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9717: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9718: }
9719: $resulttext .= '</ul></li>';
9720: }
9721: if (keys(%reorderings) > 0) {
9722: my %sort_by_trail;
9723: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9724: foreach my $key (keys(%reorderings)) {
9725: if ($allitems{$key} ne '') {
9726: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9727: }
1.48 raeburn 9728: }
1.57 raeburn 9729: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9730: $resulttext .= '<li>'.$trails[$trail].'</li>';
9731: }
9732: $resulttext .= '</ul></li>';
1.48 raeburn 9733: }
1.57 raeburn 9734: if (keys(%adds) > 0) {
9735: my %sort_by_trail;
9736: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9737: foreach my $key (keys(%adds)) {
9738: if ($allitems{$key} ne '') {
9739: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9740: }
9741: }
9742: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9743: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9744: }
1.57 raeburn 9745: $resulttext .= '</ul></li>';
1.48 raeburn 9746: }
9747: }
9748: $resulttext .= '</ul>';
1.160.6.43 raeburn 9749: if ($changes{'unauth'} || $changes{'auth'}) {
9750: &Apache::loncommon::devalidate_domconfig_cache($dom);
9751: if (ref($lastactref) eq 'HASH') {
9752: $lastactref->{'domainconfig'} = 1;
9753: }
9754: }
1.48 raeburn 9755: } else {
9756: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9757: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9758: }
9759: } else {
1.120 raeburn 9760: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9761: }
9762: return $resulttext;
9763: }
9764:
1.69 raeburn 9765: sub modify_serverstatuses {
9766: my ($dom,%domconfig) = @_;
9767: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9768: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9769: %currserverstatus = %{$domconfig{'serverstatuses'}};
9770: }
9771: my @pages = &serverstatus_pages();
9772: foreach my $type (@pages) {
9773: $newserverstatus{$type}{'namedusers'} = '';
9774: $newserverstatus{$type}{'machines'} = '';
9775: if (defined($env{'form.'.$type.'_namedusers'})) {
9776: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9777: my @okusers;
9778: foreach my $user (@users) {
9779: my ($uname,$udom) = split(/:/,$user);
9780: if (($udom =~ /^$match_domain$/) &&
9781: (&Apache::lonnet::domain($udom)) &&
9782: ($uname =~ /^$match_username$/)) {
9783: if (!grep(/^\Q$user\E/,@okusers)) {
9784: push(@okusers,$user);
9785: }
9786: }
9787: }
9788: if (@okusers > 0) {
9789: @okusers = sort(@okusers);
9790: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9791: }
9792: }
9793: if (defined($env{'form.'.$type.'_machines'})) {
9794: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9795: my @okmachines;
9796: foreach my $ip (@machines) {
9797: my @parts = split(/\./,$ip);
9798: next if (@parts < 4);
9799: my $badip = 0;
9800: for (my $i=0; $i<4; $i++) {
9801: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9802: $badip = 1;
9803: last;
9804: }
9805: }
9806: if (!$badip) {
9807: push(@okmachines,$ip);
9808: }
9809: }
9810: @okmachines = sort(@okmachines);
9811: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9812: }
9813: }
9814: my %serverstatushash = (
9815: serverstatuses => \%newserverstatus,
9816: );
9817: foreach my $type (@pages) {
1.83 raeburn 9818: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9819: my (@current,@new);
1.83 raeburn 9820: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9821: if ($currserverstatus{$type}{$setting} ne '') {
9822: @current = split(/,/,$currserverstatus{$type}{$setting});
9823: }
9824: }
9825: if ($newserverstatus{$type}{$setting} ne '') {
9826: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9827: }
9828: if (@current > 0) {
9829: if (@new > 0) {
9830: foreach my $item (@current) {
9831: if (!grep(/^\Q$item\E$/,@new)) {
9832: $changes{$type}{$setting} = 1;
1.82 raeburn 9833: last;
9834: }
9835: }
1.84 raeburn 9836: foreach my $item (@new) {
9837: if (!grep(/^\Q$item\E$/,@current)) {
9838: $changes{$type}{$setting} = 1;
9839: last;
1.82 raeburn 9840: }
9841: }
9842: } else {
1.83 raeburn 9843: $changes{$type}{$setting} = 1;
1.69 raeburn 9844: }
1.83 raeburn 9845: } elsif (@new > 0) {
9846: $changes{$type}{$setting} = 1;
1.69 raeburn 9847: }
9848: }
9849: }
9850: if (keys(%changes) > 0) {
1.81 raeburn 9851: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9852: my $putresult = &Apache::lonnet::put_dom('configuration',
9853: \%serverstatushash,$dom);
9854: if ($putresult eq 'ok') {
9855: $resulttext .= &mt('Changes made:').'<ul>';
9856: foreach my $type (@pages) {
1.84 raeburn 9857: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9858: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9859: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9860: if ($newserverstatus{$type}{'namedusers'} eq '') {
9861: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9862: } else {
9863: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9864: }
1.84 raeburn 9865: }
9866: if ($changes{$type}{'machines'}) {
1.69 raeburn 9867: if ($newserverstatus{$type}{'machines'} eq '') {
9868: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9869: } else {
9870: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9871: }
9872:
9873: }
9874: $resulttext .= '</ul></li>';
9875: }
9876: }
9877: $resulttext .= '</ul>';
9878: } else {
9879: $resulttext = '<span class="LC_error">'.
9880: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9881:
9882: }
9883: } else {
9884: $resulttext = &mt('No changes made to access to server status pages');
9885: }
9886: return $resulttext;
9887: }
9888:
1.118 jms 9889: sub modify_helpsettings {
1.122 jms 9890: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9891: my ($resulttext,$errors,%changes,%helphash);
9892: my %defaultchecked = ('submitbugs' => 'on');
9893: my @offon = ('off','on');
1.118 jms 9894: my @toggles = ('submitbugs');
9895: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9896: foreach my $item (@toggles) {
1.160.6.5 raeburn 9897: if ($defaultchecked{$item} eq 'on') {
9898: if ($domconfig{'helpsettings'}{$item} eq '') {
9899: if ($env{'form.'.$item} eq '0') {
9900: $changes{$item} = 1;
9901: }
9902: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9903: $changes{$item} = 1;
9904: }
9905: } elsif ($defaultchecked{$item} eq 'off') {
9906: if ($domconfig{'helpsettings'}{$item} eq '') {
9907: if ($env{'form.'.$item} eq '1') {
9908: $changes{$item} = 1;
9909: }
9910: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9911: $changes{$item} = 1;
9912: }
1.160.6.26 raeburn 9913: }
1.160.6.5 raeburn 9914: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9915: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9916: }
9917: }
1.118 jms 9918: }
1.123 jms 9919: my $putresult;
9920: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9921: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9922: if ($putresult eq 'ok') {
9923: $resulttext = &mt('Changes made:').'<ul>';
9924: foreach my $item (sort(keys(%changes))) {
9925: if ($item eq 'submitbugs') {
9926: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9927: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9928: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9929: }
9930: }
9931: $resulttext .= '</ul>';
9932: } else {
9933: $resulttext = &mt('No changes made to help settings');
9934: $errors .= '<li><span class="LC_error">'.
9935: &mt('An error occurred storing the settings: [_1]',
9936: $putresult).'</span></li>';
9937: }
1.118 jms 9938: }
9939: if ($errors) {
1.160.6.5 raeburn 9940: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9941: $errors.'</ul>';
9942: }
9943: return $resulttext;
9944: }
9945:
1.121 raeburn 9946: sub modify_coursedefaults {
1.160.6.27 raeburn 9947: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9948: my ($resulttext,$errors,%changes,%defaultshash);
9949: my %defaultchecked = ('canuse_pdfforms' => 'off');
9950: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9951: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9952: 'uploadquota_community','uploadquota_textbook');
9953: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9954: my %staticdefaults = (
9955: anonsurvey_threshold => 10,
9956: uploadquota => 500,
9957: );
1.121 raeburn 9958:
9959: $defaultshash{'coursedefaults'} = {};
9960:
9961: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9962: if ($domconfig{'coursedefaults'} eq '') {
9963: $domconfig{'coursedefaults'} = {};
9964: }
9965: }
9966:
9967: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9968: foreach my $item (@toggles) {
9969: if ($defaultchecked{$item} eq 'on') {
9970: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9971: ($env{'form.'.$item} eq '0')) {
9972: $changes{$item} = 1;
1.160.6.16 raeburn 9973: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9974: $changes{$item} = 1;
9975: }
9976: } elsif ($defaultchecked{$item} eq 'off') {
9977: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9978: ($env{'form.'.$item} eq '1')) {
9979: $changes{$item} = 1;
9980: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9981: $changes{$item} = 1;
9982: }
9983: }
9984: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9985: }
1.160.6.21 raeburn 9986: foreach my $item (@numbers) {
9987: my ($currdef,$newdef);
1.160.6.26 raeburn 9988: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 9989: if ($item eq 'anonsurvey_threshold') {
9990: $currdef = $domconfig{'coursedefaults'}{$item};
9991: $newdef =~ s/\D//g;
9992: if ($newdef eq '' || $newdef < 1) {
9993: $newdef = 1;
9994: }
9995: $defaultshash{'coursedefaults'}{$item} = $newdef;
9996: } else {
9997: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9998: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9999: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10000: }
10001: $newdef =~ s/[^\w.\-]//g;
10002: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10003: }
10004: if ($currdef ne $newdef) {
10005: my $staticdef;
10006: if ($item eq 'anonsurvey_threshold') {
10007: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10008: $changes{$item} = 1;
10009: }
10010: } else {
10011: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10012: $changes{'uploadquota'} = 1;
10013: }
10014: }
1.139 raeburn 10015: }
10016: }
1.160.6.37 raeburn 10017:
1.160.6.16 raeburn 10018: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 10019: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10020: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 10021: $unofficialcreds =~ s/[^\d.]+//g;
10022: my $textbookcreds = $env{'form.textbook_credits'};
10023: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10024: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10025: ($env{'form.coursecredits'} eq '1')) {
10026: $changes{'coursecredits'} = 1;
10027: } else {
10028: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 10029: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10030: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 10031: $changes{'coursecredits'} = 1;
10032: }
10033: }
10034: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10035: official => $officialcreds,
10036: unofficial => $unofficialcreds,
1.160.6.30 raeburn 10037: textbook => $textbookcreds,
1.160.6.16 raeburn 10038: }
1.121 raeburn 10039: }
10040: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10041: $dom);
10042: if ($putresult eq 'ok') {
10043: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 10045: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
10046: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 10047: if ($changes{'canuse_pdfforms'}) {
10048: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10049: }
10050: if ($changes{'coursecredits'}) {
10051: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10052: $domdefaults{'officialcredits'} =
10053: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10054: $domdefaults{'unofficialcredits'} =
10055: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 10056: $domdefaults{'textbookcredits'} =
10057: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 10058: }
10059: }
1.160.6.21 raeburn 10060: if ($changes{'uploadquota'}) {
10061: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10062: foreach my $type (@types) {
10063: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10064: }
10065: }
10066: }
1.121 raeburn 10067: my $cachetime = 24*60*60;
10068: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10069: if (ref($lastactref) eq 'HASH') {
10070: $lastactref->{'domdefaults'} = 1;
10071: }
1.121 raeburn 10072: }
10073: $resulttext = &mt('Changes made:').'<ul>';
10074: foreach my $item (sort(keys(%changes))) {
10075: if ($item eq 'canuse_pdfforms') {
10076: if ($env{'form.'.$item} eq '1') {
10077: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10078: } else {
10079: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10080: }
1.139 raeburn 10081: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10082: $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 10083: } elsif ($item eq 'uploadquota') {
10084: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10085: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10086: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10087: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10088: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10089:
1.160.6.21 raeburn 10090: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10091: '</ul>'.
10092: '</li>';
10093: } else {
10094: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10095: }
1.160.6.16 raeburn 10096: } elsif ($item eq 'coursecredits') {
10097: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10098: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10099: ($domdefaults{'unofficialcredits'} eq '') &&
10100: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10101: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10102: } else {
10103: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10104: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10105: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10106: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10107: '</ul>'.
10108: '</li>';
10109: }
10110: } else {
10111: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10112: }
1.140 raeburn 10113: }
1.121 raeburn 10114: }
10115: $resulttext .= '</ul>';
10116: } else {
10117: $resulttext = &mt('No changes made to course defaults');
10118: }
10119: } else {
10120: $resulttext = '<span class="LC_error">'.
10121: &mt('An error occurred: [_1]',$putresult).'</span>';
10122: }
10123: return $resulttext;
10124: }
10125:
1.160.6.37 raeburn 10126: sub modify_selfenrollment {
10127: my ($dom,$lastactref,%domconfig) = @_;
10128: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10129: my @types = ('official','unofficial','community','textbook');
10130: my %titles = &tool_titles();
10131: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10132: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10133: $ordered{'default'} = ['types','registered','approval','limit'];
10134:
10135: my (%roles,%shown,%toplevel);
10136: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10137:
10138: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10139: if ($domconfig{'selfenrollment'} eq '') {
10140: $domconfig{'selfenrollment'} = {};
10141: }
10142: }
10143: %toplevel = (
10144: admin => 'Configuration Rights',
10145: default => 'Default settings',
10146: validation => 'Validation of self-enrollment requests',
10147: );
10148: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10149:
10150: if (ref($ordered{'admin'}) eq 'ARRAY') {
10151: foreach my $item (@{$ordered{'admin'}}) {
10152: foreach my $type (@types) {
10153: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10154: $selfenrollhash{'admin'}{$type}{$item} = 1;
10155: } else {
10156: $selfenrollhash{'admin'}{$type}{$item} = 0;
10157: }
10158: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10159: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10160: if ($selfenrollhash{'admin'}{$type}{$item} ne
10161: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10162: push(@{$changes{'admin'}{$type}},$item);
10163: }
10164: } else {
10165: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10166: push(@{$changes{'admin'}{$type}},$item);
10167: }
10168: }
10169: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10170: push(@{$changes{'admin'}{$type}},$item);
10171: }
10172: }
10173: }
10174: }
10175:
10176: foreach my $item (@{$ordered{'default'}}) {
10177: foreach my $type (@types) {
10178: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10179: if ($item eq 'types') {
10180: unless (($value eq 'all') || ($value eq 'dom')) {
10181: $value = '';
10182: }
10183: } elsif ($item eq 'registered') {
10184: unless ($value eq '1') {
10185: $value = 0;
10186: }
10187: } elsif ($item eq 'approval') {
10188: unless ($value =~ /^[012]$/) {
10189: $value = 0;
10190: }
10191: } else {
10192: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10193: $value = 'none';
10194: }
10195: }
10196: $selfenrollhash{'default'}{$type}{$item} = $value;
10197: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10198: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10199: if ($selfenrollhash{'default'}{$type}{$item} ne
10200: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10201: push(@{$changes{'default'}{$type}},$item);
10202: }
10203: } else {
10204: push(@{$changes{'default'}{$type}},$item);
10205: }
10206: } else {
10207: push(@{$changes{'default'}{$type}},$item);
10208: }
10209: if ($item eq 'limit') {
10210: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10211: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10212: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10213: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10214: }
10215: } else {
10216: $selfenrollhash{'default'}{$type}{'cap'} = '';
10217: }
10218: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10219: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10220: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10221: push(@{$changes{'default'}{$type}},'cap');
10222: }
10223: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10224: push(@{$changes{'default'}{$type}},'cap');
10225: }
10226: }
10227: }
10228: }
10229:
10230: foreach my $item (@{$itemsref}) {
10231: if ($item eq 'fields') {
10232: my @changed;
10233: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10234: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10235: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10236: }
10237: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10238: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10239: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10240: $domconfig{'selfenrollment'}{'validation'}{$item});
10241: } else {
10242: @changed = @{$selfenrollhash{'validation'}{$item}};
10243: }
10244: } else {
10245: @changed = @{$selfenrollhash{'validation'}{$item}};
10246: }
10247: if (@changed) {
10248: if ($selfenrollhash{'validation'}{$item}) {
10249: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10250: } else {
10251: $changes{'validation'}{$item} = &mt('None');
10252: }
10253: }
10254: } else {
10255: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10256: if ($item eq 'markup') {
10257: if ($env{'form.selfenroll_validation_'.$item}) {
10258: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10259: }
10260: }
10261: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10262: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10263: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10264: }
10265: }
10266: }
10267: }
10268:
10269: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10270: $dom);
10271: if ($putresult eq 'ok') {
10272: if (keys(%changes) > 0) {
10273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10274: $resulttext = &mt('Changes made:').'<ul>';
10275: foreach my $key ('admin','default','validation') {
10276: if (ref($changes{$key}) eq 'HASH') {
10277: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10278: if ($key eq 'validation') {
10279: foreach my $item (@{$itemsref}) {
10280: if (exists($changes{$key}{$item})) {
10281: if ($item eq 'markup') {
10282: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10283: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10284: } else {
10285: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10286: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10287: }
10288: }
10289: }
10290: } else {
10291: foreach my $type (@types) {
10292: if ($type eq 'community') {
10293: $roles{'1'} = &mt('Community personnel');
10294: } else {
10295: $roles{'1'} = &mt('Course personnel');
10296: }
10297: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10298: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10299: if ($key eq 'admin') {
10300: my @mgrdc = ();
10301: if (ref($ordered{$key}) eq 'ARRAY') {
10302: foreach my $item (@{$ordered{'admin'}}) {
10303: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10304: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10305: push(@mgrdc,$item);
10306: }
10307: }
10308: }
10309: if (@mgrdc) {
10310: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10311: } else {
10312: delete($domdefaults{$type.'selfenrolladmdc'});
10313: }
10314: }
10315: } else {
10316: if (ref($ordered{$key}) eq 'ARRAY') {
10317: foreach my $item (@{$ordered{$key}}) {
10318: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10319: $domdefaults{$type.'selfenroll'.$item} =
10320: $selfenrollhash{$key}{$type}{$item};
10321: }
10322: }
10323: }
10324: }
10325: }
10326: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10327: foreach my $item (@{$ordered{$key}}) {
10328: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10329: $resulttext .= '<li>';
10330: if ($key eq 'admin') {
10331: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10332: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10333: } else {
10334: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10335: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10336: }
10337: $resulttext .= '</li>';
10338: }
10339: }
10340: $resulttext .= '</ul></li>';
10341: }
10342: }
10343: $resulttext .= '</ul></li>';
10344: }
10345: }
10346: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10347: my $cachetime = 24*60*60;
10348: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10349: if (ref($lastactref) eq 'HASH') {
10350: $lastactref->{'domdefaults'} = 1;
10351: }
10352: }
10353: }
10354: $resulttext .= '</ul>';
10355: } else {
10356: $resulttext = &mt('No changes made to self-enrollment settings');
10357: }
10358: } else {
10359: $resulttext = '<span class="LC_error">'.
10360: &mt('An error occurred: [_1]',$putresult).'</span>';
10361: }
10362: return $resulttext;
10363: }
10364:
1.137 raeburn 10365: sub modify_usersessions {
1.160.6.27 raeburn 10366: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10367: my @hostingtypes = ('version','excludedomain','includedomain');
10368: my @offloadtypes = ('primary','default');
10369: my %types = (
10370: remote => \@hostingtypes,
10371: hosted => \@hostingtypes,
10372: spares => \@offloadtypes,
10373: );
10374: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10375: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10376: my (%by_ip,%by_location,@intdoms);
10377: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10378: my @locations = sort(keys(%by_location));
1.137 raeburn 10379: my (%defaultshash,%changes);
10380: foreach my $prefix (@prefixes) {
10381: $defaultshash{'usersessions'}{$prefix} = {};
10382: }
1.160.6.27 raeburn 10383: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10384: my $resulttext;
1.138 raeburn 10385: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10386: foreach my $prefix (@prefixes) {
1.145 raeburn 10387: next if ($prefix eq 'spares');
10388: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10389: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10390: if ($type eq 'version') {
10391: my $value = $env{'form.'.$prefix.'_'.$type};
10392: my $okvalue;
10393: if ($value ne '') {
10394: if (grep(/^\Q$value\E$/,@lcversions)) {
10395: $okvalue = $value;
10396: }
10397: }
10398: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10399: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10400: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10401: if ($inuse == 0) {
10402: $changes{$prefix}{$type} = 1;
10403: } else {
10404: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10405: $changes{$prefix}{$type} = 1;
10406: }
10407: if ($okvalue ne '') {
10408: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10409: }
10410: }
10411: } else {
10412: if (($inuse == 1) && ($okvalue ne '')) {
10413: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10414: $changes{$prefix}{$type} = 1;
10415: }
10416: }
10417: } else {
10418: if (($inuse == 1) && ($okvalue ne '')) {
10419: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10420: $changes{$prefix}{$type} = 1;
10421: }
10422: }
10423: } else {
10424: if (($inuse == 1) && ($okvalue ne '')) {
10425: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10426: $changes{$prefix}{$type} = 1;
10427: }
10428: }
10429: } else {
10430: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10431: my @okvals;
10432: foreach my $val (@vals) {
1.138 raeburn 10433: if ($val =~ /:/) {
10434: my @items = split(/:/,$val);
10435: foreach my $item (@items) {
10436: if (ref($by_location{$item}) eq 'ARRAY') {
10437: push(@okvals,$item);
10438: }
10439: }
10440: } else {
10441: if (ref($by_location{$val}) eq 'ARRAY') {
10442: push(@okvals,$val);
10443: }
1.137 raeburn 10444: }
10445: }
10446: @okvals = sort(@okvals);
10447: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10448: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10449: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10450: if ($inuse == 0) {
10451: $changes{$prefix}{$type} = 1;
10452: } else {
10453: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10454: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10455: if (@changed > 0) {
10456: $changes{$prefix}{$type} = 1;
10457: }
10458: }
10459: } else {
10460: if ($inuse == 1) {
10461: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10462: $changes{$prefix}{$type} = 1;
10463: }
10464: }
10465: } else {
10466: if ($inuse == 1) {
10467: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10468: $changes{$prefix}{$type} = 1;
10469: }
10470: }
10471: } else {
10472: if ($inuse == 1) {
10473: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10474: $changes{$prefix}{$type} = 1;
10475: }
10476: }
10477: }
10478: }
10479: }
1.145 raeburn 10480:
10481: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10482: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10483: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10484: my $savespares;
10485:
10486: foreach my $lonhost (sort(keys(%servers))) {
10487: my $serverhomeID =
10488: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10489: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10490: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10491: my %spareschg;
10492: foreach my $type (@{$types{'spares'}}) {
10493: my @okspares;
10494: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10495: foreach my $server (@checked) {
1.152 raeburn 10496: if (&Apache::lonnet::hostname($server) ne '') {
10497: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10498: unless (grep(/^\Q$server\E$/,@okspares)) {
10499: push(@okspares,$server);
10500: }
1.145 raeburn 10501: }
10502: }
10503: }
10504: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10505: my $newspare;
1.152 raeburn 10506: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10507: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10508: $newspare = $new;
10509: }
10510: }
1.152 raeburn 10511: my @spares;
10512: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10513: @spares = sort(@okspares,$newspare);
10514: } else {
10515: @spares = sort(@okspares);
10516: }
10517: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10518: if (ref($spareid{$lonhost}) eq 'HASH') {
10519: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10520: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10521: if (@diffs > 0) {
10522: $spareschg{$type} = 1;
10523: }
10524: }
10525: }
10526: }
10527: if (keys(%spareschg) > 0) {
10528: $changes{'spares'}{$lonhost} = \%spareschg;
10529: }
10530: }
10531:
10532: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10533: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10534: if (ref($changes{'spares'}) eq 'HASH') {
10535: if (keys(%{$changes{'spares'}}) > 0) {
10536: $savespares = 1;
10537: }
10538: }
10539: } else {
10540: $savespares = 1;
10541: }
10542: }
10543:
1.147 raeburn 10544: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10545: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10546: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10547: $dom);
10548: if ($putresult eq 'ok') {
10549: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10550: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10551: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10552: }
10553: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10554: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10555: }
10556: }
10557: my $cachetime = 24*60*60;
10558: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10559: if (ref($lastactref) eq 'HASH') {
10560: $lastactref->{'domdefaults'} = 1;
10561: }
1.147 raeburn 10562: if (keys(%changes) > 0) {
10563: my %lt = &usersession_titles();
10564: $resulttext = &mt('Changes made:').'<ul>';
10565: foreach my $prefix (@prefixes) {
10566: if (ref($changes{$prefix}) eq 'HASH') {
10567: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10568: if ($prefix eq 'spares') {
10569: if (ref($changes{$prefix}) eq 'HASH') {
10570: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10571: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10572: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10573: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10574: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10575: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10576: foreach my $type (@{$types{$prefix}}) {
10577: if ($changes{$prefix}{$lonhost}{$type}) {
10578: my $offloadto = &mt('None');
10579: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10580: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10581: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10582: }
1.145 raeburn 10583: }
1.147 raeburn 10584: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10585: }
1.137 raeburn 10586: }
10587: }
1.147 raeburn 10588: $resulttext .= '</li>';
1.137 raeburn 10589: }
10590: }
1.147 raeburn 10591: } else {
10592: foreach my $type (@{$types{$prefix}}) {
10593: if (defined($changes{$prefix}{$type})) {
10594: my $newvalue;
10595: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10596: if (ref($defaultshash{'usersessions'}{$prefix})) {
10597: if ($type eq 'version') {
10598: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10599: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10600: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10601: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10602: }
1.145 raeburn 10603: }
10604: }
10605: }
1.147 raeburn 10606: if ($newvalue eq '') {
10607: if ($type eq 'version') {
10608: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10609: } else {
10610: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10611: }
1.145 raeburn 10612: } else {
1.147 raeburn 10613: if ($type eq 'version') {
10614: $newvalue .= ' '.&mt('(or later)');
10615: }
10616: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10617: }
1.137 raeburn 10618: }
10619: }
10620: }
1.147 raeburn 10621: $resulttext .= '</ul>';
1.137 raeburn 10622: }
10623: }
1.147 raeburn 10624: $resulttext .= '</ul>';
10625: } else {
10626: $resulttext = $nochgmsg;
1.137 raeburn 10627: }
10628: } else {
10629: $resulttext = '<span class="LC_error">'.
10630: &mt('An error occurred: [_1]',$putresult).'</span>';
10631: }
10632: } else {
1.147 raeburn 10633: $resulttext = $nochgmsg;
1.137 raeburn 10634: }
10635: return $resulttext;
10636: }
10637:
1.150 raeburn 10638: sub modify_loadbalancing {
10639: my ($dom,%domconfig) = @_;
10640: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10641: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10642: my ($othertitle,$usertypes,$types) =
10643: &Apache::loncommon::sorted_inst_types($dom);
10644: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10645: my @sparestypes = ('primary','default');
10646: my %typetitles = &sparestype_titles();
10647: my $resulttext;
1.160.6.7 raeburn 10648: my (%currbalancer,%currtargets,%currrules,%existing);
10649: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10650: %existing = %{$domconfig{'loadbalancing'}};
10651: }
10652: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10653: \%currtargets,\%currrules);
10654: my ($saveloadbalancing,%defaultshash,%changes);
10655: my ($alltypes,$othertypes,$titles) =
10656: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10657: my %ruletitles = &offloadtype_text();
10658: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10659: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10660: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10661: if ($balancer eq '') {
10662: next;
10663: }
10664: if (!exists($servers{$balancer})) {
10665: if (exists($currbalancer{$balancer})) {
10666: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10667: }
1.160.6.7 raeburn 10668: next;
10669: }
10670: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10671: push(@{$changes{'delete'}},$balancer);
10672: next;
10673: }
10674: if (!exists($currbalancer{$balancer})) {
10675: push(@{$changes{'add'}},$balancer);
10676: }
10677: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10678: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10679: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10680: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10681: $saveloadbalancing = 1;
10682: }
10683: foreach my $sparetype (@sparestypes) {
10684: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10685: my @offloadto;
10686: foreach my $target (@targets) {
10687: if (($servers{$target}) && ($target ne $balancer)) {
10688: if ($sparetype eq 'default') {
10689: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10690: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10691: }
10692: }
1.160.6.7 raeburn 10693: unless(grep(/^\Q$target\E$/,@offloadto)) {
10694: push(@offloadto,$target);
10695: }
1.150 raeburn 10696: }
1.160.6.7 raeburn 10697: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10698: }
10699: }
1.160.6.7 raeburn 10700: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10701: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10702: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10703: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10704: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10705: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10706: }
1.160.6.7 raeburn 10707: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10708: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10709: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10710: }
10711: }
10712: }
10713: } else {
1.160.6.7 raeburn 10714: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10715: foreach my $sparetype (@sparestypes) {
10716: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10717: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10718: $changes{'curr'}{$balancer}{'targets'} = 1;
10719: }
1.150 raeburn 10720: }
10721: }
1.160.6.7 raeburn 10722: }
1.150 raeburn 10723: }
10724: my $ishomedom;
1.160.6.7 raeburn 10725: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10726: $ishomedom = 1;
1.150 raeburn 10727: }
10728: if (ref($alltypes) eq 'ARRAY') {
10729: foreach my $type (@{$alltypes}) {
10730: my $rule;
1.160.6.7 raeburn 10731: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10732: (!$ishomedom)) {
1.160.6.7 raeburn 10733: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10734: }
10735: if ($rule eq 'specific') {
10736: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10737: }
1.160.6.7 raeburn 10738: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10739: if (ref($currrules{$balancer}) eq 'HASH') {
10740: if ($rule ne $currrules{$balancer}{$type}) {
10741: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10742: }
10743: } elsif ($rule ne '') {
1.160.6.7 raeburn 10744: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10745: }
10746: }
10747: }
1.160.6.7 raeburn 10748: }
10749: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10750: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10751: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10752: $defaultshash{'loadbalancing'} = {};
10753: }
10754: my $putresult = &Apache::lonnet::put_dom('configuration',
10755: \%defaultshash,$dom);
10756: if ($putresult eq 'ok') {
10757: if (keys(%changes) > 0) {
10758: if (ref($changes{'delete'}) eq 'ARRAY') {
10759: foreach my $balancer (sort(@{$changes{'delete'}})) {
10760: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10761: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10762: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10763: }
1.160.6.7 raeburn 10764: }
10765: if (ref($changes{'add'}) eq 'ARRAY') {
10766: foreach my $balancer (sort(@{$changes{'add'}})) {
10767: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10768: }
10769: }
10770: if (ref($changes{'curr'}) eq 'HASH') {
10771: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10772: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10773: if ($changes{'curr'}{$balancer}{'targets'}) {
10774: my %offloadstr;
10775: foreach my $sparetype (@sparestypes) {
10776: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10777: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10778: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10779: }
10780: }
1.150 raeburn 10781: }
1.160.6.7 raeburn 10782: if (keys(%offloadstr) == 0) {
10783: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10784: } else {
1.160.6.7 raeburn 10785: my $showoffload;
10786: foreach my $sparetype (@sparestypes) {
10787: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10788: if (defined($offloadstr{$sparetype})) {
10789: $showoffload .= $offloadstr{$sparetype};
10790: } else {
10791: $showoffload .= &mt('None');
10792: }
10793: $showoffload .= (' 'x3);
10794: }
10795: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10796: }
10797: }
10798: }
1.160.6.7 raeburn 10799: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10800: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10801: foreach my $type (@{$alltypes}) {
10802: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10803: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10804: my $balancetext;
10805: if ($rule eq '') {
10806: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10807: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10808: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10809: $balancetext = $ruletitles{$rule};
10810: } else {
10811: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10812: }
1.160.6.26 raeburn 10813: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10814: }
10815: }
10816: }
10817: }
1.160.6.29 raeburn 10818: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10819: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10820: }
1.160.6.7 raeburn 10821: }
10822: if ($resulttext ne '') {
10823: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10824: } else {
10825: $resulttext = $nochgmsg;
10826: }
10827: } else {
1.160.6.7 raeburn 10828: $resulttext = $nochgmsg;
1.150 raeburn 10829: }
10830: } else {
1.160.6.7 raeburn 10831: $resulttext = '<span class="LC_error">'.
10832: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10833: }
10834: } else {
1.160.6.7 raeburn 10835: $resulttext = $nochgmsg;
1.150 raeburn 10836: }
10837: return $resulttext;
10838: }
10839:
1.48 raeburn 10840: sub recurse_check {
10841: my ($chkcats,$categories,$depth,$name) = @_;
10842: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10843: my $chg = 0;
10844: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10845: my $category = $chkcats->[$depth]{$name}[$j];
10846: my $item;
10847: if ($category eq '') {
10848: $chg ++;
10849: } else {
10850: my $deeper = $depth + 1;
10851: $item = &escape($category).':'.&escape($name).':'.$depth;
10852: if ($chg) {
10853: $categories->{$item} -= $chg;
10854: }
10855: &recurse_check($chkcats,$categories,$deeper,$category);
10856: $deeper --;
10857: }
10858: }
10859: }
10860: return;
10861: }
10862:
10863: sub recurse_cat_deletes {
10864: my ($item,$coursecategories,$deletions) = @_;
10865: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10866: my $subdepth = $depth + 1;
10867: if (ref($coursecategories) eq 'HASH') {
10868: foreach my $subitem (keys(%{$coursecategories})) {
10869: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10870: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10871: delete($coursecategories->{$subitem});
10872: $deletions->{$subitem} = 1;
10873: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10874: }
1.48 raeburn 10875: }
10876: }
10877: return;
10878: }
10879:
1.125 raeburn 10880: sub get_active_dcs {
10881: my ($dom) = @_;
1.160.6.16 raeburn 10882: my $now = time;
10883: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10884: my %domcoords;
10885: my $numdcs = 0;
10886: foreach my $server (keys(%dompersonnel)) {
10887: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10888: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10889: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10890: }
10891: }
10892: return %domcoords;
10893: }
10894:
10895: sub active_dc_picker {
1.160.6.16 raeburn 10896: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10897: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10898: my @domcoord = keys(%domcoords);
10899: if (keys(%currhash)) {
10900: foreach my $dc (keys(%currhash)) {
10901: unless (exists($domcoords{$dc})) {
10902: push(@domcoord,$dc);
10903: }
10904: }
10905: }
10906: @domcoord = sort(@domcoord);
10907: my $numdcs = scalar(@domcoord);
10908: my $rows = 0;
10909: my $table;
1.125 raeburn 10910: if ($numdcs > 1) {
1.160.6.16 raeburn 10911: $table = '<table>';
10912: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10913: my $rem = $i%($numinrow);
10914: if ($rem == 0) {
10915: if ($i > 0) {
1.160.6.16 raeburn 10916: $table .= '</tr>';
1.125 raeburn 10917: }
1.160.6.16 raeburn 10918: $table .= '<tr>';
10919: $rows ++;
1.125 raeburn 10920: }
1.160.6.16 raeburn 10921: my $check = '';
10922: if ($inputtype eq 'radio') {
10923: if (keys(%currhash) == 0) {
10924: if (!$i) {
10925: $check = ' checked="checked"';
10926: }
10927: } elsif (exists($currhash{$domcoord[$i]})) {
10928: $check = ' checked="checked"';
10929: }
10930: } else {
10931: if (exists($currhash{$domcoord[$i]})) {
10932: $check = ' checked="checked"';
1.125 raeburn 10933: }
10934: }
1.160.6.16 raeburn 10935: if ($i == @domcoord - 1) {
1.125 raeburn 10936: my $colsleft = $numinrow - $rem;
10937: if ($colsleft > 1) {
1.160.6.16 raeburn 10938: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10939: } else {
1.160.6.16 raeburn 10940: $table .= '<td class="LC_left_item">';
1.125 raeburn 10941: }
10942: } else {
1.160.6.16 raeburn 10943: $table .= '<td class="LC_left_item">';
10944: }
10945: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10946: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10947: $table .= '<span class="LC_nobreak"><label>'.
10948: '<input type="'.$inputtype.'" name="'.$name.'"'.
10949: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10950: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10951: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10952: }
1.160.6.33 raeburn 10953: $table .= '</label></span></td>';
1.125 raeburn 10954: }
1.160.6.16 raeburn 10955: $table .= '</tr></table>';
10956: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10957: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10958: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10959: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 10960: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10961: if ($user ne $dcname.':'.$dcdom) {
10962: $table .= ' ('.$dcname.':'.$dcdom.')';
10963: }
1.160.6.16 raeburn 10964: } else {
10965: my $check;
10966: if (exists($currhash{$domcoord[0]})) {
10967: $check = ' checked="checked"';
10968: }
1.160.6.31 raeburn 10969: $table .= '<span class="LC_nobreak"><label>'.
10970: '<input type="checkbox" name="'.$name.'" '.
10971: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10972: if ($user ne $dcname.':'.$dcdom) {
10973: $table .= ' ('.$dcname.':'.$dcdom.')';
10974: }
10975: $table .= '</label></span>';
1.160.6.16 raeburn 10976: $rows ++;
10977: }
1.125 raeburn 10978: }
1.160.6.16 raeburn 10979: return ($numdcs,$table,$rows);
1.125 raeburn 10980: }
10981:
1.137 raeburn 10982: sub usersession_titles {
10983: return &Apache::lonlocal::texthash(
10984: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10985: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10986: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10987: version => 'LON-CAPA version requirement',
1.138 raeburn 10988: excludedomain => 'Allow all, but exclude specific domains',
10989: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10990: primary => 'Primary (checked first)',
1.154 raeburn 10991: default => 'Default',
1.137 raeburn 10992: );
10993: }
10994:
1.152 raeburn 10995: sub id_for_thisdom {
10996: my (%servers) = @_;
10997: my %altids;
10998: foreach my $server (keys(%servers)) {
10999: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11000: if ($serverhome ne $server) {
11001: $altids{$serverhome} = $server;
11002: }
11003: }
11004: return %altids;
11005: }
11006:
1.150 raeburn 11007: sub count_servers {
11008: my ($currbalancer,%servers) = @_;
11009: my (@spares,$numspares);
11010: foreach my $lonhost (sort(keys(%servers))) {
11011: next if ($currbalancer eq $lonhost);
11012: push(@spares,$lonhost);
11013: }
11014: if ($currbalancer) {
11015: $numspares = scalar(@spares);
11016: } else {
11017: $numspares = scalar(@spares) - 1;
11018: }
11019: return ($numspares,@spares);
11020: }
11021:
11022: sub lonbalance_targets_js {
1.160.6.7 raeburn 11023: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11024: my $select = &mt('Select');
11025: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11026: if (ref($servers) eq 'HASH') {
11027: $alltargets = join("','",sort(keys(%{$servers})));
11028: my @homedoms;
11029: foreach my $server (sort(keys(%{$servers}))) {
11030: if (&Apache::lonnet::host_domain($server) eq $dom) {
11031: push(@homedoms,'1');
11032: } else {
11033: push(@homedoms,'0');
11034: }
11035: }
11036: $allishome = join("','",@homedoms);
11037: }
11038: if (ref($types) eq 'ARRAY') {
11039: if (@{$types} > 0) {
11040: @alltypes = @{$types};
11041: }
11042: }
11043: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11044: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11045: my (%currbalancer,%currtargets,%currrules,%existing);
11046: if (ref($settings) eq 'HASH') {
11047: %existing = %{$settings};
11048: }
11049: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11050: \%currtargets,\%currrules);
11051: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11052: return <<"END";
11053:
11054: <script type="text/javascript">
11055: // <![CDATA[
11056:
1.160.6.7 raeburn 11057: currBalancers = new Array('$balancers');
11058:
11059: function toggleTargets(balnum) {
11060: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11061: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11062: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11063: var prevbalancer = prevhostitem.value;
11064: var baltotal = document.getElementById('loadbalancing_total').value;
11065: prevhostitem.value = balancer;
11066: if (prevbalancer != '') {
11067: var prevIdx = currBalancers.indexOf(prevbalancer);
11068: if (prevIdx != -1) {
11069: currBalancers.splice(prevIdx,1);
11070: }
11071: }
1.150 raeburn 11072: if (balancer == '') {
1.160.6.7 raeburn 11073: hideSpares(balnum);
1.150 raeburn 11074: } else {
1.160.6.7 raeburn 11075: var currIdx = currBalancers.indexOf(balancer);
11076: if (currIdx == -1) {
11077: currBalancers.push(balancer);
11078: }
1.150 raeburn 11079: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11080: var ishomedom = homedoms[lonhostitem.selectedIndex];
11081: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11082: }
1.160.6.7 raeburn 11083: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11084: return;
11085: }
11086:
1.160.6.7 raeburn 11087: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11088: var alltargets = new Array('$alltargets');
11089: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11090: var offloadtypes = new Array('primary','default');
11091:
1.160.6.7 raeburn 11092: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11093: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11094:
1.151 raeburn 11095: for (var i=0; i<offloadtypes.length; i++) {
11096: var count = 0;
11097: for (var j=0; j<alltargets.length; j++) {
11098: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11099: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11100: item.value = alltargets[j];
11101: item.style.textAlign='left';
11102: item.style.textFace='normal';
11103: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11104: if (currBalancers.indexOf(alltargets[j]) == -1) {
11105: item.disabled = '';
11106: } else {
11107: item.disabled = 'disabled';
11108: item.checked = false;
11109: }
1.151 raeburn 11110: count ++;
11111: }
1.150 raeburn 11112: }
11113: }
1.151 raeburn 11114: for (var k=0; k<insttypes.length; k++) {
11115: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11116: if (ishomedom == 1) {
1.160.6.7 raeburn 11117: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11118: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11119: } else {
1.160.6.7 raeburn 11120: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11121: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11122: }
11123: } else {
1.160.6.7 raeburn 11124: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11125: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11126: }
1.151 raeburn 11127: if ((insttypes[k] != '_LC_external') &&
11128: ((insttypes[k] != '_LC_internetdom') ||
11129: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11130: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11131: item.options.length = 0;
11132: item.options[0] = new Option("","",true,true);
11133: var idx = 0;
1.151 raeburn 11134: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11135: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11136: idx ++;
11137: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11138: }
11139: }
11140: }
11141: }
11142: return;
11143: }
11144:
1.160.6.7 raeburn 11145: function hideSpares(balnum) {
1.150 raeburn 11146: var alltargets = new Array('$alltargets');
11147: var insttypes = new Array('$allinsttypes');
11148: var offloadtypes = new Array('primary','default');
11149:
1.160.6.7 raeburn 11150: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11151: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11152:
11153: var total = alltargets.length - 1;
11154: for (var i=0; i<offloadtypes; i++) {
11155: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11156: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11157: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11158: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11159: }
1.150 raeburn 11160: }
11161: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11162: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11163: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11164: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11165: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11166: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11167: }
11168: }
11169: return;
11170: }
11171:
1.160.6.7 raeburn 11172: function checkOffloads(item,balnum,type) {
1.150 raeburn 11173: var alltargets = new Array('$alltargets');
11174: var offloadtypes = new Array('primary','default');
11175: if (item.checked) {
11176: var total = alltargets.length - 1;
11177: var other;
11178: if (type == offloadtypes[0]) {
1.151 raeburn 11179: other = offloadtypes[1];
1.150 raeburn 11180: } else {
1.151 raeburn 11181: other = offloadtypes[0];
1.150 raeburn 11182: }
11183: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11184: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11185: if (server == item.value) {
1.160.6.7 raeburn 11186: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11187: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11188: }
11189: }
11190: }
11191: }
11192: return;
11193: }
11194:
1.160.6.7 raeburn 11195: function singleServerToggle(balnum,type) {
11196: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11197: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11198: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11199: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11200:
11201: } else {
1.160.6.7 raeburn 11202: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11203: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11204: }
11205: return;
11206: }
11207:
1.160.6.7 raeburn 11208: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11209: if (type == '_LC_external') {
1.160.6.26 raeburn 11210: return;
1.150 raeburn 11211: }
1.160.6.7 raeburn 11212: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11213: for (var i=0; i<typesRules.length; i++) {
11214: if (formname.elements[typesRules[i]].checked) {
11215: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11216: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11217: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11218: } else {
1.160.6.7 raeburn 11219: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11220: }
11221: }
11222: }
11223: return;
11224: }
11225:
11226: function balancerDeleteChange(balnum) {
11227: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11228: var baltotal = document.getElementById('loadbalancing_total').value;
11229: var addtarget;
11230: var removetarget;
11231: var action = 'delete';
11232: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11233: var lonhost = hostitem.value;
11234: var currIdx = currBalancers.indexOf(lonhost);
11235: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11236: if (currIdx != -1) {
11237: currBalancers.splice(currIdx,1);
11238: }
11239: addtarget = lonhost;
11240: } else {
11241: if (currIdx == -1) {
11242: currBalancers.push(lonhost);
11243: }
11244: removetarget = lonhost;
11245: action = 'undelete';
11246: }
11247: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11248: }
11249: return;
11250: }
11251:
11252: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11253: if (baltotal > 1) {
11254: var offloadtypes = new Array('primary','default');
11255: var alltargets = new Array('$alltargets');
11256: var insttypes = new Array('$allinsttypes');
11257: for (var i=0; i<baltotal; i++) {
11258: if (i != balnum) {
11259: for (var j=0; j<offloadtypes.length; j++) {
11260: var total = alltargets.length - 1;
11261: for (var k=0; k<total; k++) {
11262: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11263: var server = serveritem.value;
11264: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11265: if (server == addtarget) {
11266: serveritem.disabled = '';
11267: }
11268: }
11269: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11270: if (server == removetarget) {
11271: serveritem.disabled = 'disabled';
11272: serveritem.checked = false;
11273: }
11274: }
11275: }
11276: }
11277: for (var j=0; j<insttypes.length; j++) {
11278: if (insttypes[j] != '_LC_external') {
11279: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11280: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11281: var currSel = singleserver.selectedIndex;
11282: var currVal = singleserver.options[currSel].value;
11283: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11284: var numoptions = singleserver.options.length;
11285: var needsnew = 1;
11286: for (var k=0; k<numoptions; k++) {
11287: if (singleserver.options[k] == addtarget) {
11288: needsnew = 0;
11289: break;
11290: }
11291: }
11292: if (needsnew == 1) {
11293: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11294: }
11295: }
11296: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11297: singleserver.options.length = 0;
11298: if ((currVal) && (currVal != removetarget)) {
11299: singleserver.options[0] = new Option("","",false,false);
11300: } else {
11301: singleserver.options[0] = new Option("","",true,true);
11302: }
11303: var idx = 0;
11304: for (var m=0; m<alltargets.length; m++) {
11305: if (currBalancers.indexOf(alltargets[m]) == -1) {
11306: idx ++;
11307: if (currVal == alltargets[m]) {
11308: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11309: } else {
11310: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11311: }
11312: }
11313: }
11314: }
11315: }
11316: }
11317: }
1.150 raeburn 11318: }
11319: }
11320: }
11321: return;
11322: }
11323:
1.152 raeburn 11324: // ]]>
11325: </script>
11326:
11327: END
11328: }
11329:
11330: sub new_spares_js {
11331: my @sparestypes = ('primary','default');
11332: my $types = join("','",@sparestypes);
11333: my $select = &mt('Select');
11334: return <<"END";
11335:
11336: <script type="text/javascript">
11337: // <![CDATA[
11338:
11339: function updateNewSpares(formname,lonhost) {
11340: var types = new Array('$types');
11341: var include = new Array();
11342: var exclude = new Array();
11343: for (var i=0; i<types.length; i++) {
11344: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11345: for (var j=0; j<spareboxes.length; j++) {
11346: if (formname.elements[spareboxes[j]].checked) {
11347: exclude.push(formname.elements[spareboxes[j]].value);
11348: } else {
11349: include.push(formname.elements[spareboxes[j]].value);
11350: }
11351: }
11352: }
11353: for (var i=0; i<types.length; i++) {
11354: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11355: var selIdx = newSpare.selectedIndex;
11356: var currnew = newSpare.options[selIdx].value;
11357: var okSpares = new Array();
11358: for (var j=0; j<newSpare.options.length; j++) {
11359: var possible = newSpare.options[j].value;
11360: if (possible != '') {
11361: if (exclude.indexOf(possible) == -1) {
11362: okSpares.push(possible);
11363: } else {
11364: if (currnew == possible) {
11365: selIdx = 0;
11366: }
11367: }
11368: }
11369: }
11370: for (var k=0; k<include.length; k++) {
11371: if (okSpares.indexOf(include[k]) == -1) {
11372: okSpares.push(include[k]);
11373: }
11374: }
11375: okSpares.sort();
11376: newSpare.options.length = 0;
11377: if (selIdx == 0) {
11378: newSpare.options[0] = new Option("$select","",true,true);
11379: } else {
11380: newSpare.options[0] = new Option("$select","",false,false);
11381: }
11382: for (var m=0; m<okSpares.length; m++) {
11383: var idx = m+1;
11384: var selThis = 0;
11385: if (selIdx != 0) {
11386: if (okSpares[m] == currnew) {
11387: selThis = 1;
11388: }
11389: }
11390: if (selThis == 1) {
11391: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11392: } else {
11393: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11394: }
11395: }
11396: }
11397: return;
11398: }
11399:
11400: function checkNewSpares(lonhost,type) {
11401: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11402: var chosen = newSpare.options[newSpare.selectedIndex].value;
11403: if (chosen != '') {
11404: var othertype;
11405: var othernewSpare;
11406: if (type == 'primary') {
11407: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11408: }
11409: if (type == 'default') {
11410: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11411: }
11412: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11413: othernewSpare.selectedIndex = 0;
11414: }
11415: }
11416: return;
11417: }
11418:
11419: // ]]>
11420: </script>
11421:
11422: END
11423:
11424: }
11425:
11426: sub common_domprefs_js {
11427: return <<"END";
11428:
11429: <script type="text/javascript">
11430: // <![CDATA[
11431:
1.150 raeburn 11432: function getIndicesByName(formname,item) {
1.152 raeburn 11433: var group = new Array();
1.150 raeburn 11434: for (var i=0;i<formname.elements.length;i++) {
11435: if (formname.elements[i].name == item) {
1.152 raeburn 11436: group.push(formname.elements[i].id);
1.150 raeburn 11437: }
11438: }
1.152 raeburn 11439: return group;
1.150 raeburn 11440: }
11441:
11442: // ]]>
11443: </script>
11444:
11445: END
1.152 raeburn 11446:
1.150 raeburn 11447: }
11448:
1.160.6.5 raeburn 11449: sub recaptcha_js {
11450: my %lt = &captcha_phrases();
11451: return <<"END";
11452:
11453: <script type="text/javascript">
11454: // <![CDATA[
11455:
11456: function updateCaptcha(caller,context) {
11457: var privitem;
11458: var pubitem;
11459: var privtext;
11460: var pubtext;
11461: if (document.getElementById(context+'_recaptchapub')) {
11462: pubitem = document.getElementById(context+'_recaptchapub');
11463: } else {
11464: return;
11465: }
11466: if (document.getElementById(context+'_recaptchapriv')) {
11467: privitem = document.getElementById(context+'_recaptchapriv');
11468: } else {
11469: return;
11470: }
11471: if (document.getElementById(context+'_recaptchapubtxt')) {
11472: pubtext = document.getElementById(context+'_recaptchapubtxt');
11473: } else {
11474: return;
11475: }
11476: if (document.getElementById(context+'_recaptchaprivtxt')) {
11477: privtext = document.getElementById(context+'_recaptchaprivtxt');
11478: } else {
11479: return;
11480: }
11481: if (caller.checked) {
11482: if (caller.value == 'recaptcha') {
11483: pubitem.type = 'text';
11484: privitem.type = 'text';
11485: pubitem.size = '40';
11486: privitem.size = '40';
11487: pubtext.innerHTML = "$lt{'pub'}";
11488: privtext.innerHTML = "$lt{'priv'}";
11489: } else {
11490: pubitem.type = 'hidden';
11491: privitem.type = 'hidden';
11492: pubtext.innerHTML = '';
11493: privtext.innerHTML = '';
11494: }
11495: }
11496: return;
11497: }
11498:
11499: // ]]>
11500: </script>
11501:
11502: END
11503:
11504: }
11505:
1.160.6.40 raeburn 11506: sub toggle_display_js {
1.160.6.16 raeburn 11507: return <<"END";
11508:
11509: <script type="text/javascript">
11510: // <![CDATA[
11511:
1.160.6.40 raeburn 11512: function toggleDisplay(domForm,caller) {
11513: if (document.getElementById(caller)) {
11514: var divitem = document.getElementById(caller);
11515: var optionsElement = domForm.coursecredits;
11516: if (caller == 'emailoptions') {
11517: optionsElement = domForm.cancreate_email;
11518: }
11519: if (optionsElement.length) {
1.160.6.16 raeburn 11520: var currval;
1.160.6.40 raeburn 11521: for (var i=0; i<optionsElement.length; i++) {
11522: if (optionsElement[i].checked) {
11523: currval = optionsElement[i].value;
1.160.6.16 raeburn 11524: }
11525: }
11526: if (currval == 1) {
1.160.6.40 raeburn 11527: divitem.style.display = 'block';
1.160.6.16 raeburn 11528: } else {
1.160.6.40 raeburn 11529: divitem.style.display = 'none';
1.160.6.16 raeburn 11530: }
11531: }
11532: }
11533: return;
11534: }
11535:
11536: // ]]>
11537: </script>
11538:
11539: END
11540:
11541: }
11542:
1.160.6.5 raeburn 11543: sub captcha_phrases {
11544: return &Apache::lonlocal::texthash (
11545: priv => 'Private key',
11546: pub => 'Public key',
11547: original => 'original (CAPTCHA)',
11548: recaptcha => 'successor (ReCAPTCHA)',
11549: notused => 'unused',
11550: );
11551: }
11552:
1.160.6.24 raeburn 11553: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11554: my ($dom,$cachekeys) = @_;
11555: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11556: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11557: my %thismachine;
11558: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11559: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11560: if (keys(%servers) > 1) {
11561: foreach my $server (keys(%servers)) {
11562: next if ($thismachine{$server});
1.160.6.27 raeburn 11563: my @cached;
11564: foreach my $name (@posscached) {
11565: if ($cachekeys->{$name}) {
11566: push(@cached,&escape($name).':'.&escape($dom));
11567: }
11568: }
11569: if (@cached) {
11570: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11571: }
1.160.6.24 raeburn 11572: }
11573: }
11574: return;
11575: }
11576:
1.3 raeburn 11577: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>