Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.46
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.46! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.45 2014/05/05 23:34:42 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'};
2120: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
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') {
! 2125: $author = $bookshash->{$key}->{'author'};
! 2126: $image = $bookshash->{$key}->{'image'};
! 2127: if ($image ne '') {
! 2128: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
! 2129: my $imagethumb = "$path/tn-".$imagefile;
! 2130: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
! 2131: }
1.160.6.30 raeburn 2132: }
2133: }
1.160.6.46! raeburn 2134: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2135: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46! raeburn 2136: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2137: for (my $k=0; $k<=$maxnum; $k++) {
2138: my $vpos = $k+1;
2139: my $selstr;
2140: if ($k == $i) {
2141: $selstr = ' selected="selected" ';
2142: }
2143: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2144: }
2145: $datatable .= '</select>'.(' 'x2).
1.160.6.46! raeburn 2146: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2147: &mt('Delete?').'</label></span></td>'.
2148: '<td colspan="2">'.
1.160.6.46! raeburn 2149: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2150: (' 'x2).
1.160.6.46! raeburn 2151: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
! 2152: if ($type eq 'textbooks') {
! 2153: $datatable .= (' 'x2).
! 2154: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
! 2155: (' 'x2).
! 2156: '<span class="LC_nobreak">'.&mt('Thumbnail:');
! 2157: if ($image) {
! 2158: $datatable .= '<span class="LC_nobreak">'.
! 2159: $imgsrc.
! 2160: '<label><input type="checkbox" name="'.$type.'_image_del"'.
! 2161: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
! 2162: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
! 2163: }
! 2164: if ($switchserver) {
! 2165: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2166: } else {
! 2167: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
! 2168: }
1.160.6.30 raeburn 2169: }
1.160.6.46! raeburn 2170: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2171: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2172: $coursetitle.'</span></td></tr>'."\n";
2173: $itemcount ++;
2174: }
2175: }
2176: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46! raeburn 2177: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2178: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46! raeburn 2179: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
! 2180: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2181: for (my $k=0; $k<$maxnum+1; $k++) {
2182: my $vpos = $k+1;
2183: my $selstr;
2184: if ($k == $maxnum) {
2185: $selstr = ' selected="selected" ';
2186: }
2187: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2188: }
2189: $datatable .= '</select> '."\n".
1.160.6.46! raeburn 2190: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2191: '<td colspan="2">'.
1.160.6.46! raeburn 2192: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2193: (' 'x2).
1.160.6.46! raeburn 2194: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
! 2195: (' 'x2);
! 2196: if ($type eq 'textbooks') {
! 2197: $datatable .= '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
! 2198: (' 'x2).
! 2199: '<span class="LC_nobreak">'.&mt('Image:').' ';
! 2200: if ($switchserver) {
! 2201: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
! 2202: } else {
! 2203: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
! 2204: }
1.160.6.30 raeburn 2205: }
2206: $datatable .= '</span>'."\n".
2207: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46! raeburn 2208: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
! 2209: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2210: &Apache::loncommon::selectcourse_link
1.160.6.46! raeburn 2211: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2212: '</span></td>'."\n".
2213: '</tr>'."\n";
2214: $itemcount ++;
2215: return $datatable;
2216: }
2217:
2218: sub textbookcourses_javascript {
1.160.6.46! raeburn 2219: my ($settings) = @_;
! 2220: return unless(ref($settings) eq 'HASH');
! 2221: my (%ordered,%total,%jstext);
! 2222: foreach my $type ('textbooks','templates') {
! 2223: $total{$type} = 0;
! 2224: if (ref($settings->{$type}) eq 'HASH') {
! 2225: foreach my $item (keys(%{$settings->{$type}})) {
! 2226: if (ref($settings->{$type}->{$item}) eq 'HASH') {
! 2227: my $num = $settings->{$type}->{$item}{'order'};
! 2228: $ordered{$type}{$num} = $item;
! 2229: }
! 2230: }
! 2231: $total{$type} = scalar(keys(%{$settings->{$type}}));
! 2232: }
! 2233: my @jsarray = ();
! 2234: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
! 2235: push(@jsarray,$ordered{$type}{$item});
! 2236: }
! 2237: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2238: }
2239: return <<"ENDSCRIPT";
2240: <script type="text/javascript">
2241: // <![CDATA[
1.160.6.46! raeburn 2242: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2243: var changedVal;
1.160.6.46! raeburn 2244: $jstext{'textbooks'};
! 2245: $jstext{'templates'};
! 2246: var newpos;
! 2247: var maxh;
! 2248: if (caller == 'textbooks') {
! 2249: newpos = 'textbooks_addbook_pos';
! 2250: maxh = 1 + $total{'textbooks'};
! 2251: } else {
! 2252: newpos = 'templates_addbook_pos';
! 2253: maxh = 1 + $total{'templates'};
! 2254: }
1.160.6.30 raeburn 2255: var current = new Array;
2256: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2257: if (item == newpos) {
2258: changedVal = newitemVal;
2259: } else {
2260: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2261: current[newitemVal] = newpos;
2262: }
1.160.6.46! raeburn 2263: if (caller == 'textbooks') {
! 2264: for (var i=0; i<textbooks.length; i++) {
! 2265: var elementName = 'textbooks_'+textbooks[i];
! 2266: if (elementName != item) {
! 2267: if (form.elements[elementName]) {
! 2268: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
! 2269: current[currVal] = elementName;
! 2270: }
! 2271: }
! 2272: }
! 2273: }
! 2274: if (caller == 'templates') {
! 2275: for (var i=0; i<templates.length; i++) {
! 2276: var elementName = 'templates_'+templates[i];
! 2277: if (elementName != item) {
! 2278: if (form.elements[elementName]) {
! 2279: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
! 2280: current[currVal] = elementName;
! 2281: }
1.160.6.30 raeburn 2282: }
2283: }
2284: }
2285: var oldVal;
2286: for (var j=0; j<maxh; j++) {
2287: if (current[j] == undefined) {
2288: oldVal = j;
2289: }
2290: }
2291: if (oldVal < changedVal) {
2292: for (var k=oldVal+1; k<=changedVal ; k++) {
2293: var elementName = current[k];
2294: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2295: }
2296: } else {
2297: for (var k=changedVal; k<oldVal; k++) {
2298: var elementName = current[k];
2299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2300: }
2301: }
2302: return;
2303: }
2304:
2305: // ]]>
2306: </script>
2307:
2308: ENDSCRIPT
2309: }
2310:
1.3 raeburn 2311: sub print_autoenroll {
1.30 raeburn 2312: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2313: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2314: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2315: if (ref($settings) eq 'HASH') {
2316: if (exists($settings->{'run'})) {
2317: if ($settings->{'run'} eq '0') {
2318: $runoff = ' checked="checked" ';
2319: $runon = ' ';
2320: } else {
2321: $runon = ' checked="checked" ';
2322: $runoff = ' ';
2323: }
2324: } else {
2325: if ($autorun) {
2326: $runon = ' checked="checked" ';
2327: $runoff = ' ';
2328: } else {
2329: $runoff = ' checked="checked" ';
2330: $runon = ' ';
2331: }
2332: }
1.129 raeburn 2333: if (exists($settings->{'co-owners'})) {
2334: if ($settings->{'co-owners'} eq '0') {
2335: $coownersoff = ' checked="checked" ';
2336: $coownerson = ' ';
2337: } else {
2338: $coownerson = ' checked="checked" ';
2339: $coownersoff = ' ';
2340: }
2341: } else {
2342: $coownersoff = ' checked="checked" ';
2343: $coownerson = ' ';
2344: }
1.3 raeburn 2345: if (exists($settings->{'sender_domain'})) {
2346: $defdom = $settings->{'sender_domain'};
2347: }
1.14 raeburn 2348: } else {
2349: if ($autorun) {
2350: $runon = ' checked="checked" ';
2351: $runoff = ' ';
2352: } else {
2353: $runoff = ' checked="checked" ';
2354: $runon = ' ';
2355: }
1.3 raeburn 2356: }
2357: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2358: my $notif_sender;
2359: if (ref($settings) eq 'HASH') {
2360: $notif_sender = $settings->{'sender_uname'};
2361: }
1.3 raeburn 2362: my $datatable='<tr class="LC_odd_row">'.
2363: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2364: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2365: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2366: $runon.' value="1" />'.&mt('Yes').'</label> '.
2367: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2368: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2369: '</tr><tr>'.
2370: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2371: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2372: &mt('username').': '.
2373: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2374: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2375: ': '.$domform.'</span></td></tr>'.
2376: '<tr class="LC_odd_row">'.
2377: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2378: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2379: '<input type="radio" name="autoassign_coowners"'.
2380: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2381: '<label><input type="radio" name="autoassign_coowners"'.
2382: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2383: '</tr>';
2384: $$rowtotal += 3;
1.3 raeburn 2385: return $datatable;
2386: }
2387:
2388: sub print_autoupdate {
1.30 raeburn 2389: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2390: my $datatable;
2391: if ($position eq 'top') {
2392: my $updateon = ' ';
2393: my $updateoff = ' checked="checked" ';
2394: my $classlistson = ' ';
2395: my $classlistsoff = ' checked="checked" ';
2396: if (ref($settings) eq 'HASH') {
2397: if ($settings->{'run'} eq '1') {
2398: $updateon = $updateoff;
2399: $updateoff = ' ';
2400: }
2401: if ($settings->{'classlists'} eq '1') {
2402: $classlistson = $classlistsoff;
2403: $classlistsoff = ' ';
2404: }
2405: }
2406: my %title = (
2407: run => 'Auto-update active?',
2408: classlists => 'Update information in classlists?',
2409: );
2410: $datatable = '<tr class="LC_odd_row">'.
2411: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2412: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2413: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2414: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2415: '<label><input type="radio" name="autoupdate_run"'.
2416: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2417: '</tr><tr>'.
2418: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2419: '<td class="LC_right_item"><span class="LC_nobreak">'.
2420: '<label><input type="radio" name="classlists"'.
2421: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2422: '<label><input type="radio" name="classlists"'.
2423: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2424: '</tr>';
1.30 raeburn 2425: $$rowtotal += 2;
1.131 raeburn 2426: } elsif ($position eq 'middle') {
2427: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2428: my $numinrow = 3;
2429: my $locknamesettings;
2430: $datatable .= &insttypes_row($settings,$types,$usertypes,
2431: $dom,$numinrow,$othertitle,
2432: 'lockablenames');
2433: $$rowtotal ++;
1.3 raeburn 2434: } else {
1.44 raeburn 2435: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2436: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2437: 'permanentemail','id');
1.33 raeburn 2438: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2439: my $numrows = 0;
1.26 raeburn 2440: if (ref($types) eq 'ARRAY') {
2441: if (@{$types} > 0) {
2442: $datatable =
2443: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2444: \@fields,$types,\$numrows);
1.30 raeburn 2445: $$rowtotal += @{$types};
1.26 raeburn 2446: }
1.3 raeburn 2447: }
2448: $datatable .=
2449: &usertype_update_row($settings,{'default' => $othertitle},
2450: \%fieldtitles,\@fields,['default'],
2451: \$numrows);
1.30 raeburn 2452: $$rowtotal ++;
1.3 raeburn 2453: }
2454: return $datatable;
2455: }
2456:
1.125 raeburn 2457: sub print_autocreate {
2458: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2459: my (%createon,%createoff,%currhash);
1.125 raeburn 2460: my @types = ('xml','req');
2461: if (ref($settings) eq 'HASH') {
2462: foreach my $item (@types) {
2463: $createoff{$item} = ' checked="checked" ';
2464: $createon{$item} = ' ';
2465: if (exists($settings->{$item})) {
2466: if ($settings->{$item}) {
2467: $createon{$item} = ' checked="checked" ';
2468: $createoff{$item} = ' ';
2469: }
2470: }
2471: }
1.160.6.16 raeburn 2472: if ($settings->{'xmldc'} ne '') {
2473: $currhash{$settings->{'xmldc'}} = 1;
2474: }
1.125 raeburn 2475: } else {
2476: foreach my $item (@types) {
2477: $createoff{$item} = ' checked="checked" ';
2478: $createon{$item} = ' ';
2479: }
2480: }
2481: $$rowtotal += 2;
1.160.6.16 raeburn 2482: my $numinrow = 2;
1.125 raeburn 2483: my $datatable='<tr class="LC_odd_row">'.
2484: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2485: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2486: '<input type="radio" name="autocreate_xml"'.
2487: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2488: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2489: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2490: '</td></tr><tr>'.
2491: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2493: '<input type="radio" name="autocreate_req"'.
2494: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2495: '<label><input type="radio" name="autocreate_req"'.
2496: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2497: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2498: 'autocreate_xmldc',%currhash);
1.125 raeburn 2499: if ($numdc > 1) {
1.143 raeburn 2500: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2501: &mt('Course creation processed as: (choose Dom. Coord.)').
2502: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2503: } else {
1.143 raeburn 2504: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2505: }
1.160.6.16 raeburn 2506: $$rowtotal += $rows;
1.125 raeburn 2507: return $datatable;
2508: }
2509:
1.23 raeburn 2510: sub print_directorysrch {
1.30 raeburn 2511: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2512: my $srchon = ' ';
2513: my $srchoff = ' checked="checked" ';
1.25 raeburn 2514: my ($exacton,$containson,$beginson);
1.24 raeburn 2515: my $localon = ' ';
2516: my $localoff = ' checked="checked" ';
1.23 raeburn 2517: if (ref($settings) eq 'HASH') {
2518: if ($settings->{'available'} eq '1') {
2519: $srchon = $srchoff;
2520: $srchoff = ' ';
2521: }
1.24 raeburn 2522: if ($settings->{'localonly'} eq '1') {
2523: $localon = $localoff;
2524: $localoff = ' ';
2525: }
1.25 raeburn 2526: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2527: foreach my $type (@{$settings->{'searchtypes'}}) {
2528: if ($type eq 'exact') {
2529: $exacton = ' checked="checked" ';
2530: } elsif ($type eq 'contains') {
2531: $containson = ' checked="checked" ';
2532: } elsif ($type eq 'begins') {
2533: $beginson = ' checked="checked" ';
2534: }
2535: }
2536: } else {
2537: if ($settings->{'searchtypes'} eq 'exact') {
2538: $exacton = ' checked="checked" ';
2539: } elsif ($settings->{'searchtypes'} eq 'contains') {
2540: $containson = ' checked="checked" ';
2541: } elsif ($settings->{'searchtypes'} eq 'specify') {
2542: $exacton = ' checked="checked" ';
2543: $containson = ' checked="checked" ';
2544: }
1.23 raeburn 2545: }
2546: }
2547: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2548: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2549:
2550: my $numinrow = 4;
1.26 raeburn 2551: my $cansrchrow = 0;
1.23 raeburn 2552: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2553: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2554: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2555: '<input type="radio" name="dirsrch_available"'.
2556: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2557: '<label><input type="radio" name="dirsrch_available"'.
2558: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2559: '</tr><tr>'.
1.30 raeburn 2560: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2561: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2562: '<input type="radio" name="dirsrch_localonly"'.
2563: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2564: '<label><input type="radio" name="dirsrch_localonly"'.
2565: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2566: '</tr>';
1.30 raeburn 2567: $$rowtotal += 2;
1.26 raeburn 2568: if (ref($usertypes) eq 'HASH') {
2569: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2570: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2571: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2572: $cansrchrow = 1;
2573: }
2574: }
2575: if ($cansrchrow) {
1.30 raeburn 2576: $$rowtotal ++;
1.26 raeburn 2577: $datatable .= '<tr>';
2578: } else {
2579: $datatable .= '<tr class="LC_odd_row">';
2580: }
1.30 raeburn 2581: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2582: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2583: foreach my $title (@{$titleorder}) {
2584: if (defined($searchtitles->{$title})) {
2585: my $check = ' ';
1.93 raeburn 2586: if (ref($settings) eq 'HASH') {
1.39 raeburn 2587: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2588: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2589: $check = ' checked="checked" ';
2590: }
1.25 raeburn 2591: }
2592: }
2593: $datatable .= '<td class="LC_left_item">'.
2594: '<span class="LC_nobreak"><label>'.
2595: '<input type="checkbox" name="searchby" '.
2596: 'value="'.$title.'"'.$check.'/>'.
2597: $searchtitles->{$title}.'</label></span></td>';
2598: }
2599: }
1.26 raeburn 2600: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2601: $$rowtotal ++;
1.26 raeburn 2602: if ($cansrchrow) {
2603: $datatable .= '<tr class="LC_odd_row">';
2604: } else {
2605: $datatable .= '<tr>';
2606: }
1.30 raeburn 2607: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2608: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2609: '<span class="LC_nobreak"><label>'.
2610: '<input type="checkbox" name="searchtypes" '.
2611: $exacton.' value="exact" />'.&mt('Exact match').
2612: '</label> '.
2613: '<label><input type="checkbox" name="searchtypes" '.
2614: $beginson.' value="begins" />'.&mt('Begins with').
2615: '</label> '.
2616: '<label><input type="checkbox" name="searchtypes" '.
2617: $containson.' value="contains" />'.&mt('Contains').
2618: '</label></span></td></tr>';
1.30 raeburn 2619: $$rowtotal ++;
1.25 raeburn 2620: return $datatable;
2621: }
2622:
1.28 raeburn 2623: sub print_contacts {
1.30 raeburn 2624: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2625: my $datatable;
2626: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2627: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2628: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2629: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2630: foreach my $type (@mailings) {
2631: $otheremails{$type} = '';
2632: }
1.134 raeburn 2633: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2634: if (ref($settings) eq 'HASH') {
2635: foreach my $item (@contacts) {
2636: if (exists($settings->{$item})) {
2637: $to{$item} = $settings->{$item};
2638: }
2639: }
2640: foreach my $type (@mailings) {
2641: if (exists($settings->{$type})) {
2642: if (ref($settings->{$type}) eq 'HASH') {
2643: foreach my $item (@contacts) {
2644: if ($settings->{$type}{$item}) {
2645: $checked{$type}{$item} = ' checked="checked" ';
2646: }
2647: }
2648: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2649: if ($type eq 'helpdeskmail') {
2650: $bccemails{$type} = $settings->{$type}{'bcc'};
2651: }
1.28 raeburn 2652: }
1.89 raeburn 2653: } elsif ($type eq 'lonstatusmail') {
2654: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2655: }
2656: }
2657: } else {
2658: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2659: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2660: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2661: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2662: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2663: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2664: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2665: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2666: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2667: }
2668: my ($titles,$short_titles) = &contact_titles();
2669: my $rownum = 0;
2670: my $css_class;
2671: foreach my $item (@contacts) {
1.69 raeburn 2672: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2673: $datatable .= '<tr'.$css_class.'>'.
2674: '<td><span class="LC_nobreak">'.$titles->{$item}.
2675: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2676: '<input type="text" name="'.$item.'" value="'.
2677: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2678: $rownum ++;
1.28 raeburn 2679: }
2680: foreach my $type (@mailings) {
1.69 raeburn 2681: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2682: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2683: '<td><span class="LC_nobreak">'.
2684: $titles->{$type}.': </span></td>'.
1.28 raeburn 2685: '<td class="LC_left_item">'.
2686: '<span class="LC_nobreak">';
2687: foreach my $item (@contacts) {
2688: $datatable .= '<label>'.
2689: '<input type="checkbox" name="'.$type.'"'.
2690: $checked{$type}{$item}.
2691: ' value="'.$item.'" />'.$short_titles->{$item}.
2692: '</label> ';
2693: }
2694: $datatable .= '</span><br />'.&mt('Others').': '.
2695: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2696: 'value="'.$otheremails{$type}.'" />';
2697: if ($type eq 'helpdeskmail') {
1.136 raeburn 2698: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2699: '<input type="text" name="'.$type.'_bcc" '.
2700: 'value="'.$bccemails{$type}.'" />';
2701: }
2702: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2703: $rownum ++;
1.28 raeburn 2704: }
1.160.6.23 raeburn 2705: my %choices;
2706: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2707: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2708: &mt('LON-CAPA core group - MSU'),600,500));
2709: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2710: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2711: &mt('LON-CAPA core group - MSU'),600,500));
2712: my @toggles = ('reporterrors','reportupdates');
2713: my %defaultchecked = ('reporterrors' => 'on',
2714: 'reportupdates' => 'on');
2715: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2716: \%choices,$rownum);
2717: $datatable .= $reports;
1.30 raeburn 2718: $$rowtotal += $rownum;
1.28 raeburn 2719: return $datatable;
2720: }
2721:
1.118 jms 2722: sub print_helpsettings {
1.160.6.5 raeburn 2723: my ($dom,$confname,$settings,$rowtotal) = @_;
2724: my ($datatable,$itemcount);
2725: $itemcount = 1;
2726: my (%choices,%defaultchecked,@toggles);
2727: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2728: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2729: &mt('LON-CAPA bug tracker'),600,500));
2730: %defaultchecked = ('submitbugs' => 'on');
2731: @toggles = ('submitbugs',);
1.122 jms 2732:
1.160.6.5 raeburn 2733: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2734: \%choices,$itemcount);
2735: return $datatable;
1.121 raeburn 2736: }
2737:
2738: sub radiobutton_prefs {
1.160.6.16 raeburn 2739: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2740: $additional) = @_;
1.121 raeburn 2741: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2742: (ref($choices) eq 'HASH'));
2743:
2744: my (%checkedon,%checkedoff,$datatable,$css_class);
2745:
2746: foreach my $item (@{$toggles}) {
2747: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2748: $checkedon{$item} = ' checked="checked" ';
2749: $checkedoff{$item} = ' ';
1.121 raeburn 2750: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2751: $checkedoff{$item} = ' checked="checked" ';
2752: $checkedon{$item} = ' ';
2753: }
2754: }
2755: if (ref($settings) eq 'HASH') {
1.121 raeburn 2756: foreach my $item (@{$toggles}) {
1.118 jms 2757: if ($settings->{$item} eq '1') {
2758: $checkedon{$item} = ' checked="checked" ';
2759: $checkedoff{$item} = ' ';
2760: } elsif ($settings->{$item} eq '0') {
2761: $checkedoff{$item} = ' checked="checked" ';
2762: $checkedon{$item} = ' ';
2763: }
2764: }
1.121 raeburn 2765: }
1.160.6.16 raeburn 2766: if ($onclick) {
2767: $onclick = ' onclick="'.$onclick.'"';
2768: }
1.121 raeburn 2769: foreach my $item (@{$toggles}) {
1.118 jms 2770: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2771: $datatable .=
1.160.6.16 raeburn 2772: '<tr'.$css_class.'><td valign="top">'.
2773: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2774: '</span></td>'.
2775: '<td class="LC_right_item"><span class="LC_nobreak">'.
2776: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2777: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2778: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2779: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2780: '</span>'.$additional.
2781: '</td>'.
1.118 jms 2782: '</tr>';
2783: $itemcount ++;
1.121 raeburn 2784: }
2785: return ($datatable,$itemcount);
2786: }
2787:
2788: sub print_coursedefaults {
1.139 raeburn 2789: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2790: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2791: my $itemcount = 1;
1.160.6.16 raeburn 2792: my %choices = &Apache::lonlocal::texthash (
2793: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2794: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2795: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2796: coursecredits => 'Credits can be specified for courses',
2797: );
1.160.6.21 raeburn 2798: my %staticdefaults = (
2799: anonsurvey_threshold => 10,
2800: uploadquota => 500,
2801: );
1.139 raeburn 2802: if ($position eq 'top') {
2803: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2804: @toggles = ('canuse_pdfforms');
1.139 raeburn 2805: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2806: \%choices,$itemcount);
1.139 raeburn 2807: } else {
2808: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2809: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2810: %curruploadquota);
1.160.6.16 raeburn 2811: my $currusecredits = 0;
1.160.6.30 raeburn 2812: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2813: if (ref($settings) eq 'HASH') {
2814: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2815: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2816: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2817: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2818: }
2819: }
1.160.6.16 raeburn 2820: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2821: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2822: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2823: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2824: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2825: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2826: $currusecredits = 1;
2827: }
2828: }
1.139 raeburn 2829: }
2830: if (!$currdefresponder) {
1.160.6.21 raeburn 2831: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2832: } elsif ($currdefresponder < 1) {
2833: $currdefresponder = 1;
2834: }
1.160.6.21 raeburn 2835: foreach my $type (@types) {
2836: if ($curruploadquota{$type} eq '') {
2837: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2838: }
2839: }
1.139 raeburn 2840: $datatable .=
1.160.6.16 raeburn 2841: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2842: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2843: '</span></td>'.
2844: '<td class="LC_right_item"><span class="LC_nobreak">'.
2845: '<input type="text" name="anonsurvey_threshold"'.
2846: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2847: '</td></tr>'."\n";
2848: $itemcount ++;
2849: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2850: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2851: $choices{'uploadquota'}.
2852: '</span></td>'.
2853: '<td align="right" class="LC_right_item">'.
2854: '<table><tr>';
1.160.6.21 raeburn 2855: foreach my $type (@types) {
2856: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2857: '<input type="text" name="uploadquota_'.$type.'"'.
2858: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2859: }
2860: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2861: $itemcount ++;
1.160.6.40 raeburn 2862: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2863: my $display = 'none';
2864: if ($currusecredits) {
2865: $display = 'block';
2866: }
2867: my $additional = '<div id="credits" style="display: '.$display.'">'.
2868: '<span class="LC_nobreak">'.
2869: &mt('Default credits for official courses [_1]',
2870: '<input type="text" name="official_credits" value="'.
2871: $def_official_credits.'" size="3" />').
2872: '</span><br />'.
2873: '<span class="LC_nobreak">'.
2874: &mt('Default credits for unofficial courses [_1]',
2875: '<input type="text" name="unofficial_credits" value="'.
2876: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2877: '</span><br />'.
2878: '<span class="LC_nobreak">'.
2879: &mt('Default credits for textbook courses [_1]',
2880: '<input type="text" name="textbook_credits" value="'.
2881: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2882: '</span></div>'."\n";
2883: %defaultchecked = ('coursecredits' => 'off');
2884: @toggles = ('coursecredits');
2885: my $current = {
2886: 'coursecredits' => $currusecredits,
2887: };
2888: (my $table,$itemcount) =
2889: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2890: \%choices,$itemcount,$onclick,$additional);
2891: $datatable .= $table;
1.160.6.37 raeburn 2892: $itemcount ++;
2893: }
2894: $$rowtotal += $itemcount;
2895: return $datatable;
2896: }
2897:
2898: sub print_selfenrollment {
2899: my ($position,$dom,$settings,$rowtotal) = @_;
2900: my ($css_class,$datatable);
2901: my $itemcount = 1;
2902: my @types = ('official','unofficial','community','textbook');
2903: if (($position eq 'top') || ($position eq 'middle')) {
2904: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2905: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2906: my @rows;
2907: my $key;
2908: if ($position eq 'top') {
2909: $key = 'admin';
2910: if (ref($rowsref) eq 'ARRAY') {
2911: @rows = @{$rowsref};
2912: }
2913: } elsif ($position eq 'middle') {
2914: $key = 'default';
2915: @rows = ('types','registered','approval','limit');
2916: }
2917: foreach my $row (@rows) {
2918: if (defined($titlesref->{$row})) {
2919: $itemcount ++;
2920: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2921: $datatable .= '<tr'.$css_class.'>'.
2922: '<td>'.$titlesref->{$row}.'</td>'.
2923: '<td class="LC_left_item">'.
2924: '<table><tr>';
2925: my (%current,%currentcap);
2926: if (ref($settings) eq 'HASH') {
2927: if (ref($settings->{$key}) eq 'HASH') {
2928: foreach my $type (@types) {
2929: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2930: $current{$type} = $settings->{$key}->{$type}->{$row};
2931: }
2932: if (($row eq 'limit') && ($key eq 'default')) {
2933: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2934: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2935: }
2936: }
2937: }
2938: }
2939: }
2940: my %roles = (
2941: '0' => &Apache::lonnet::plaintext('dc'),
2942: );
2943:
2944: foreach my $type (@types) {
2945: unless (($row eq 'registered') && ($key eq 'default')) {
2946: $datatable .= '<th>'.&mt($type).'</th>';
2947: }
2948: }
2949: unless (($row eq 'registered') && ($key eq 'default')) {
2950: $datatable .= '</tr><tr>';
2951: }
2952: foreach my $type (@types) {
2953: if ($type eq 'community') {
2954: $roles{'1'} = &mt('Community personnel');
2955: } else {
2956: $roles{'1'} = &mt('Course personnel');
2957: }
2958: $datatable .= '<td style="vertical-align: top">';
2959: if ($position eq 'top') {
2960: my %checked;
2961: if ($current{$type} eq '0') {
2962: $checked{'0'} = ' checked="checked"';
2963: } else {
2964: $checked{'1'} = ' checked="checked"';
2965: }
2966: foreach my $role ('1','0') {
2967: $datatable .= '<span class="LC_nobreak"><label>'.
2968: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2969: 'value="'.$role.'"'.$checked{$role}.' />'.
2970: $roles{$role}.'</label></span> ';
2971: }
2972: } else {
2973: if ($row eq 'types') {
2974: my %checked;
2975: if ($current{$type} =~ /^(all|dom)$/) {
2976: $checked{$1} = ' checked="checked"';
2977: } else {
2978: $checked{''} = ' checked="checked"';
2979: }
2980: foreach my $val ('','dom','all') {
2981: $datatable .= '<span class="LC_nobreak"><label>'.
2982: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2983: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2984: }
2985: } elsif ($row eq 'registered') {
2986: my %checked;
2987: if ($current{$type} eq '1') {
2988: $checked{'1'} = ' checked="checked"';
2989: } else {
2990: $checked{'0'} = ' checked="checked"';
2991: }
2992: foreach my $val ('0','1') {
2993: $datatable .= '<span class="LC_nobreak"><label>'.
2994: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2995: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2996: }
2997: } elsif ($row eq 'approval') {
2998: my %checked;
2999: if ($current{$type} =~ /^([12])$/) {
3000: $checked{$1} = ' checked="checked"';
3001: } else {
3002: $checked{'0'} = ' checked="checked"';
3003: }
3004: for my $val (0..2) {
3005: $datatable .= '<span class="LC_nobreak"><label>'.
3006: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3007: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3008: }
3009: } elsif ($row eq 'limit') {
3010: my %checked;
3011: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3012: $checked{$1} = ' checked="checked"';
3013: } else {
3014: $checked{'none'} = ' checked="checked"';
3015: }
3016: my $cap;
3017: if ($currentcap{$type} =~ /^\d+$/) {
3018: $cap = $currentcap{$type};
3019: }
3020: foreach my $val ('none','allstudents','selfenrolled') {
3021: $datatable .= '<span class="LC_nobreak"><label>'.
3022: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3023: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3024: }
3025: $datatable .= '<br />'.
3026: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3027: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3028: '</span>';
3029: }
3030: }
3031: $datatable .= '</td>';
3032: }
3033: $datatable .= '</tr>';
3034: }
3035: $datatable .= '</table></td></tr>';
3036: }
3037: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3038: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3039: }
3040: $$rowtotal += $itemcount;
3041: return $datatable;
3042: }
3043:
3044: sub print_validation_rows {
3045: my ($caller,$dom,$settings,$rowtotal) = @_;
3046: my ($itemsref,$namesref,$fieldsref);
3047: if ($caller eq 'selfenroll') {
3048: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3049: } elsif ($caller eq 'requestcourses') {
3050: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3051: }
3052: my %currvalidation;
3053: if (ref($settings) eq 'HASH') {
3054: if (ref($settings->{'validation'}) eq 'HASH') {
3055: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3056: }
1.160.6.39 raeburn 3057: }
3058: my $datatable;
3059: my $itemcount = 0;
3060: foreach my $item (@{$itemsref}) {
3061: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3062: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3063: $namesref->{$item}.
3064: '</span></td>'.
3065: '<td class="LC_left_item">';
3066: if (($item eq 'url') || ($item eq 'button')) {
3067: $datatable .= '<span class="LC_nobreak">'.
3068: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3069: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3070: } elsif ($item eq 'fields') {
3071: my @currfields;
3072: if (ref($currvalidation{$item}) eq 'ARRAY') {
3073: @currfields = @{$currvalidation{$item}};
3074: }
3075: foreach my $field (@{$fieldsref}) {
3076: my $check = '';
3077: if (grep(/^\Q$field\E$/,@currfields)) {
3078: $check = ' checked="checked"';
3079: }
3080: $datatable .= '<span class="LC_nobreak"><label>'.
3081: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3082: ' value="'.$field.'"'.$check.' />'.$field.
3083: '</label></span> ';
3084: }
3085: } elsif ($item eq 'markup') {
3086: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3087: $currvalidation{$item}.
1.160.6.37 raeburn 3088: '</textarea>';
1.160.6.39 raeburn 3089: }
3090: $datatable .= '</td></tr>'."\n";
3091: if (ref($rowtotal)) {
1.160.6.37 raeburn 3092: $itemcount ++;
3093: }
1.139 raeburn 3094: }
1.160.6.39 raeburn 3095: if ($caller eq 'requestcourses') {
3096: my %currhash;
3097: if (ref($settings->{'validation'}) eq 'HASH') {
3098: if ($settings->{'validation'}{'dc'} ne '') {
3099: $currhash{$settings->{'validation'}{'dc'}} = 1;
3100: }
3101: }
3102: my $numinrow = 2;
3103: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3104: 'validationdc',%currhash);
3105: if ($numdc > 1) {
3106: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3107: &mt('Course creation processed as: (choose Dom. Coord.)').
3108: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3109: } else {
3110: $datatable .= $dctable.'</td></tr>';
3111: }
3112: $itemcount ++;
3113: }
3114: if (ref($rowtotal)) {
3115: $$rowtotal += $itemcount;
3116: }
1.121 raeburn 3117: return $datatable;
1.118 jms 3118: }
3119:
1.137 raeburn 3120: sub print_usersessions {
3121: my ($position,$dom,$settings,$rowtotal) = @_;
3122: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3123: my (%by_ip,%by_location,@intdoms);
3124: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3125:
3126: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3127: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3128: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3129: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3130: my $itemcount = 1;
3131: if ($position eq 'top') {
1.152 raeburn 3132: if (keys(%serverhomes) > 1) {
1.145 raeburn 3133: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3134: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3135: } else {
1.140 raeburn 3136: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3137: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3138: }
1.137 raeburn 3139: } else {
1.145 raeburn 3140: if (keys(%by_location) == 0) {
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 institution.');
1.145 raeburn 3143: } else {
3144: my %lt = &usersession_titles();
3145: my $numinrow = 5;
3146: my $prefix;
3147: my @types;
3148: if ($position eq 'bottom') {
3149: $prefix = 'remote';
3150: @types = ('version','excludedomain','includedomain');
3151: } else {
3152: $prefix = 'hosted';
3153: @types = ('excludedomain','includedomain');
3154: }
3155: my (%current,%checkedon,%checkedoff);
3156: my @lcversions = &Apache::lonnet::all_loncaparevs();
3157: my @locations = sort(keys(%by_location));
3158: foreach my $type (@types) {
3159: $checkedon{$type} = '';
3160: $checkedoff{$type} = ' checked="checked"';
3161: }
3162: if (ref($settings) eq 'HASH') {
3163: if (ref($settings->{$prefix}) eq 'HASH') {
3164: foreach my $key (keys(%{$settings->{$prefix}})) {
3165: $current{$key} = $settings->{$prefix}{$key};
3166: if ($key eq 'version') {
3167: if ($current{$key} ne '') {
3168: $checkedon{$key} = ' checked="checked"';
3169: $checkedoff{$key} = '';
3170: }
3171: } elsif (ref($current{$key}) eq 'ARRAY') {
3172: $checkedon{$key} = ' checked="checked"';
3173: $checkedoff{$key} = '';
3174: }
1.137 raeburn 3175: }
3176: }
3177: }
1.145 raeburn 3178: foreach my $type (@types) {
3179: next if ($type ne 'version' && !@locations);
3180: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3181: $datatable .= '<tr'.$css_class.'>
3182: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3183: <span class="LC_nobreak">
3184: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3185: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3186: if ($type eq 'version') {
3187: my $selector = '<select name="'.$prefix.'_version">';
3188: foreach my $version (@lcversions) {
3189: my $selected = '';
3190: if ($current{'version'} eq $version) {
3191: $selected = ' selected="selected"';
3192: }
3193: $selector .= ' <option value="'.$version.'"'.
3194: $selected.'>'.$version.'</option>';
3195: }
3196: $selector .= '</select> ';
3197: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3198: } else {
3199: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3200: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3201: ' />'.(' 'x2).
3202: '<input type="button" value="'.&mt('uncheck all').'" '.
3203: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3204: "\n".
3205: '</div><div><table>';
3206: my $rem;
3207: for (my $i=0; $i<@locations; $i++) {
3208: my ($showloc,$value,$checkedtype);
3209: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3210: my $ip = $by_location{$locations[$i]}->[0];
3211: if (ref($by_ip{$ip}) eq 'ARRAY') {
3212: $value = join(':',@{$by_ip{$ip}});
3213: $showloc = join(', ',@{$by_ip{$ip}});
3214: if (ref($current{$type}) eq 'ARRAY') {
3215: foreach my $loc (@{$by_ip{$ip}}) {
3216: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3217: $checkedtype = ' checked="checked"';
3218: last;
3219: }
3220: }
1.138 raeburn 3221: }
3222: }
3223: }
1.145 raeburn 3224: $rem = $i%($numinrow);
3225: if ($rem == 0) {
3226: if ($i > 0) {
3227: $datatable .= '</tr>';
3228: }
3229: $datatable .= '<tr>';
3230: }
3231: $datatable .= '<td class="LC_left_item">'.
3232: '<span class="LC_nobreak"><label>'.
3233: '<input type="checkbox" name="'.$prefix.'_'.$type.
3234: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3235: '</label></span></td>';
1.137 raeburn 3236: }
1.145 raeburn 3237: $rem = @locations%($numinrow);
3238: my $colsleft = $numinrow - $rem;
3239: if ($colsleft > 1 ) {
3240: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3241: ' </td>';
3242: } elsif ($colsleft == 1) {
3243: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3244: }
1.145 raeburn 3245: $datatable .= '</tr></table>';
1.137 raeburn 3246: }
1.145 raeburn 3247: $datatable .= '</td></tr>';
3248: $itemcount ++;
1.137 raeburn 3249: }
3250: }
3251: }
3252: $$rowtotal += $itemcount;
3253: return $datatable;
3254: }
3255:
1.138 raeburn 3256: sub build_location_hashes {
3257: my ($intdoms,$by_ip,$by_location) = @_;
3258: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3259: (ref($by_location) eq 'HASH'));
3260: my %iphost = &Apache::lonnet::get_iphost();
3261: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3262: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3263: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3264: foreach my $id (@{$iphost{$primary_ip}}) {
3265: my $intdom = &Apache::lonnet::internet_dom($id);
3266: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3267: push(@{$intdoms},$intdom);
3268: }
3269: }
3270: }
3271: foreach my $ip (keys(%iphost)) {
3272: if (ref($iphost{$ip}) eq 'ARRAY') {
3273: foreach my $id (@{$iphost{$ip}}) {
3274: my $location = &Apache::lonnet::internet_dom($id);
3275: if ($location) {
3276: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3277: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3278: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3279: push(@{$by_ip->{$ip}},$location);
3280: }
3281: } else {
3282: $by_ip->{$ip} = [$location];
3283: }
3284: }
3285: }
3286: }
3287: }
3288: foreach my $ip (sort(keys(%{$by_ip}))) {
3289: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3290: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3291: my $first = $by_ip->{$ip}->[0];
3292: if (ref($by_location->{$first}) eq 'ARRAY') {
3293: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3294: push(@{$by_location->{$first}},$ip);
3295: }
3296: } else {
3297: $by_location->{$first} = [$ip];
3298: }
3299: }
3300: }
3301: return;
3302: }
3303:
1.145 raeburn 3304: sub current_offloads_to {
3305: my ($dom,$settings,$servers) = @_;
3306: my (%spareid,%otherdomconfigs);
1.152 raeburn 3307: if (ref($servers) eq 'HASH') {
1.145 raeburn 3308: foreach my $lonhost (sort(keys(%{$servers}))) {
3309: my $gotspares;
1.152 raeburn 3310: if (ref($settings) eq 'HASH') {
3311: if (ref($settings->{'spares'}) eq 'HASH') {
3312: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3313: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3314: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3315: $gotspares = 1;
3316: }
1.145 raeburn 3317: }
3318: }
3319: unless ($gotspares) {
3320: my $gotspares;
3321: my $serverhomeID =
3322: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3323: my $serverhomedom =
3324: &Apache::lonnet::host_domain($serverhomeID);
3325: if ($serverhomedom ne $dom) {
3326: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3327: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3328: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3329: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3330: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3331: $gotspares = 1;
3332: }
3333: }
3334: } else {
3335: $otherdomconfigs{$serverhomedom} =
3336: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3337: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3338: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3339: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3340: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3341: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3342: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3343: $gotspares = 1;
3344: }
3345: }
3346: }
3347: }
3348: }
3349: }
3350: }
3351: unless ($gotspares) {
3352: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3353: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3354: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3355: } else {
3356: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3357: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3358: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3359: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3360: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3361: } else {
1.150 raeburn 3362: my %what = (
3363: spareid => 1,
3364: );
3365: my ($result,$returnhash) =
3366: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3367: if ($result eq 'ok') {
3368: if (ref($returnhash) eq 'HASH') {
3369: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3370: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3371: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3372: }
3373: }
1.145 raeburn 3374: }
3375: }
3376: }
3377: }
3378: }
3379: }
3380: return %spareid;
3381: }
3382:
3383: sub spares_row {
1.152 raeburn 3384: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3385: my $css_class;
3386: my $numinrow = 4;
3387: my $itemcount = 1;
3388: my $datatable;
1.152 raeburn 3389: my %typetitles = &sparestype_titles();
3390: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3391: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3392: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3393: my ($othercontrol,$serverdom);
3394: if ($serverhome ne $server) {
3395: $serverdom = &Apache::lonnet::host_domain($serverhome);
3396: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3397: } else {
3398: $serverdom = &Apache::lonnet::host_domain($server);
3399: if ($serverdom ne $dom) {
3400: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3401: }
3402: }
3403: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3404: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3405: $datatable .= '<tr'.$css_class.'>
3406: <td rowspan="2">
1.160.6.13 raeburn 3407: <span class="LC_nobreak">'.
3408: &mt('[_1] when busy, offloads to:'
3409: ,'<b>'.$server.'</b>').
3410: "\n";
1.145 raeburn 3411: my (%current,%canselect);
1.152 raeburn 3412: my @choices =
3413: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3414: foreach my $type ('primary','default') {
3415: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3416: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3417: my @spares = @{$spareid->{$server}{$type}};
3418: if (@spares > 0) {
1.152 raeburn 3419: if ($othercontrol) {
3420: $current{$type} = join(', ',@spares);
3421: } else {
3422: $current{$type} .= '<table>';
3423: my $numspares = scalar(@spares);
3424: for (my $i=0; $i<@spares; $i++) {
3425: my $rem = $i%($numinrow);
3426: if ($rem == 0) {
3427: if ($i > 0) {
3428: $current{$type} .= '</tr>';
3429: }
3430: $current{$type} .= '<tr>';
1.145 raeburn 3431: }
1.152 raeburn 3432: $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'".');" /> '.
3433: $spareid->{$server}{$type}[$i].
3434: '</label></td>'."\n";
3435: }
3436: my $rem = @spares%($numinrow);
3437: my $colsleft = $numinrow - $rem;
3438: if ($colsleft > 1 ) {
3439: $current{$type} .= '<td colspan="'.$colsleft.
3440: '" class="LC_left_item">'.
3441: ' </td>';
3442: } elsif ($colsleft == 1) {
3443: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3444: }
1.152 raeburn 3445: $current{$type} .= '</tr></table>';
1.150 raeburn 3446: }
1.145 raeburn 3447: }
3448: }
3449: if ($current{$type} eq '') {
3450: $current{$type} = &mt('None specified');
3451: }
1.152 raeburn 3452: if ($othercontrol) {
3453: if ($type eq 'primary') {
3454: $canselect{$type} = $othercontrol;
3455: }
3456: } else {
3457: $canselect{$type} =
3458: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3459: '<select name="newspare_'.$type.'_'.$server.'" '.
3460: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3461: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3462: if (@choices > 0) {
3463: foreach my $lonhost (@choices) {
3464: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3465: }
3466: }
3467: $canselect{$type} .= '</select>'."\n";
3468: }
3469: } else {
3470: $current{$type} = &mt('Could not be determined');
3471: if ($type eq 'primary') {
3472: $canselect{$type} = $othercontrol;
3473: }
1.145 raeburn 3474: }
1.152 raeburn 3475: if ($type eq 'default') {
3476: $datatable .= '<tr'.$css_class.'>';
3477: }
3478: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3479: '<td>'.$current{$type}.'</td>'."\n".
3480: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3481: }
3482: $itemcount ++;
3483: }
3484: }
3485: $$rowtotal += $itemcount;
3486: return $datatable;
3487: }
3488:
1.152 raeburn 3489: sub possible_newspares {
3490: my ($server,$currspares,$serverhomes,$altids) = @_;
3491: my $serverhostname = &Apache::lonnet::hostname($server);
3492: my %excluded;
3493: if ($serverhostname ne '') {
3494: %excluded = (
3495: $serverhostname => 1,
3496: );
3497: }
3498: if (ref($currspares) eq 'HASH') {
3499: foreach my $type (keys(%{$currspares})) {
3500: if (ref($currspares->{$type}) eq 'ARRAY') {
3501: if (@{$currspares->{$type}} > 0) {
3502: foreach my $curr (@{$currspares->{$type}}) {
3503: my $hostname = &Apache::lonnet::hostname($curr);
3504: $excluded{$hostname} = 1;
3505: }
3506: }
3507: }
3508: }
3509: }
3510: my @choices;
3511: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3512: if (keys(%{$serverhomes}) > 1) {
3513: foreach my $name (sort(keys(%{$serverhomes}))) {
3514: unless ($excluded{$name}) {
3515: if (exists($altids->{$serverhomes->{$name}})) {
3516: push(@choices,$altids->{$serverhomes->{$name}});
3517: } else {
3518: push(@choices,$serverhomes->{$name});
1.145 raeburn 3519: }
3520: }
3521: }
3522: }
3523: }
1.152 raeburn 3524: return sort(@choices);
1.145 raeburn 3525: }
3526:
1.150 raeburn 3527: sub print_loadbalancing {
3528: my ($dom,$settings,$rowtotal) = @_;
3529: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3530: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3531: my $numinrow = 1;
3532: my $datatable;
3533: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3534: my (%currbalancer,%currtargets,%currrules,%existing);
3535: if (ref($settings) eq 'HASH') {
3536: %existing = %{$settings};
3537: }
3538: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3539: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3540: \%currtargets,\%currrules);
1.150 raeburn 3541: } else {
3542: return;
3543: }
3544: my ($othertitle,$usertypes,$types) =
3545: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3546: my $rownum = 8;
1.150 raeburn 3547: if (ref($types) eq 'ARRAY') {
3548: $rownum += scalar(@{$types});
3549: }
1.160.6.7 raeburn 3550: my @css_class = ('LC_odd_row','LC_even_row');
3551: my $balnum = 0;
3552: my $islast;
3553: my (@toshow,$disabledtext);
3554: if (keys(%currbalancer) > 0) {
3555: @toshow = sort(keys(%currbalancer));
3556: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3557: push(@toshow,'');
3558: }
3559: } else {
3560: @toshow = ('');
3561: $disabledtext = &mt('No existing load balancer');
3562: }
3563: foreach my $lonhost (@toshow) {
3564: if ($balnum == scalar(@toshow)-1) {
3565: $islast = 1;
3566: } else {
3567: $islast = 0;
3568: }
3569: my $cssidx = $balnum%2;
3570: my $targets_div_style = 'display: none';
3571: my $disabled_div_style = 'display: block';
3572: my $homedom_div_style = 'display: none';
3573: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3574: '<td rowspan="'.$rownum.'" valign="top">'.
3575: '<p>';
3576: if ($lonhost eq '') {
3577: $datatable .= '<span class="LC_nobreak">';
3578: if (keys(%currbalancer) > 0) {
3579: $datatable .= &mt('Add balancer:');
3580: } else {
3581: $datatable .= &mt('Enable balancer:');
3582: }
3583: $datatable .= ' '.
3584: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3585: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3586: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3587: '<option value="" selected="selected">'.&mt('None').
3588: '</option>'."\n";
3589: foreach my $server (sort(keys(%servers))) {
3590: next if ($currbalancer{$server});
3591: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3592: }
3593: $datatable .=
3594: '</select>'."\n".
3595: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3596: } else {
3597: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3598: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3599: &mt('Stop balancing').'</label>'.
3600: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3601: $targets_div_style = 'display: block';
3602: $disabled_div_style = 'display: none';
3603: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3604: $homedom_div_style = 'display: block';
3605: }
3606: }
3607: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3608: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3609: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3610: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3611: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3612: my @sparestypes = ('primary','default');
3613: my %typetitles = &sparestype_titles();
3614: foreach my $sparetype (@sparestypes) {
3615: my $targettable;
3616: for (my $i=0; $i<$numspares; $i++) {
3617: my $checked;
3618: if (ref($currtargets{$lonhost}) eq 'HASH') {
3619: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3620: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3621: $checked = ' checked="checked"';
3622: }
3623: }
3624: }
3625: my ($chkboxval,$disabled);
3626: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3627: $chkboxval = $spares[$i];
3628: }
3629: if (exists($currbalancer{$spares[$i]})) {
3630: $disabled = ' disabled="disabled"';
3631: }
3632: $targettable .=
3633: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3634: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3635: '</span></label></td>';
3636: my $rem = $i%($numinrow);
3637: if ($rem == 0) {
3638: if (($i > 0) && ($i < $numspares-1)) {
3639: $targettable .= '</tr>';
3640: }
3641: if ($i < $numspares-1) {
3642: $targettable .= '<tr>';
1.150 raeburn 3643: }
3644: }
3645: }
1.160.6.7 raeburn 3646: if ($targettable ne '') {
3647: my $rem = $numspares%($numinrow);
3648: my $colsleft = $numinrow - $rem;
3649: if ($colsleft > 1 ) {
3650: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3651: ' </td>';
3652: } elsif ($colsleft == 1) {
3653: $targettable .= '<td class="LC_left_item"> </td>';
3654: }
3655: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3656: '<table><tr>'.$targettable.'</tr></table><br />';
3657: }
3658: }
3659: $datatable .= '</div></td></tr>'.
3660: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3661: $othertitle,$usertypes,$types,\%servers,
3662: \%currbalancer,$lonhost,
3663: $targets_div_style,$homedom_div_style,
3664: $css_class[$cssidx],$balnum,$islast);
3665: $$rowtotal += $rownum;
3666: $balnum ++;
3667: }
3668: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3669: return $datatable;
3670: }
3671:
3672: sub get_loadbalancers_config {
3673: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3674: return unless ((ref($servers) eq 'HASH') &&
3675: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3676: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3677: if (keys(%{$existing}) > 0) {
3678: my $oldlonhost;
3679: foreach my $key (sort(keys(%{$existing}))) {
3680: if ($key eq 'lonhost') {
3681: $oldlonhost = $existing->{'lonhost'};
3682: $currbalancer->{$oldlonhost} = 1;
3683: } elsif ($key eq 'targets') {
3684: if ($oldlonhost) {
3685: $currtargets->{$oldlonhost} = $existing->{'targets'};
3686: }
3687: } elsif ($key eq 'rules') {
3688: if ($oldlonhost) {
3689: $currrules->{$oldlonhost} = $existing->{'rules'};
3690: }
3691: } elsif (ref($existing->{$key}) eq 'HASH') {
3692: $currbalancer->{$key} = 1;
3693: $currtargets->{$key} = $existing->{$key}{'targets'};
3694: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3695: }
3696: }
1.160.6.7 raeburn 3697: } else {
3698: my ($balancerref,$targetsref) =
3699: &Apache::lonnet::get_lonbalancer_config($servers);
3700: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3701: foreach my $server (sort(keys(%{$balancerref}))) {
3702: $currbalancer->{$server} = 1;
3703: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3704: }
3705: }
3706: }
1.160.6.7 raeburn 3707: return;
1.150 raeburn 3708: }
3709:
3710: sub loadbalancing_rules {
3711: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3712: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3713: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3714: my $output;
1.160.6.7 raeburn 3715: my $num = 0;
3716: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3717: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3718: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3719: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3720: $num ++;
1.150 raeburn 3721: my $current;
3722: if (ref($currrules) eq 'HASH') {
3723: $current = $currrules->{$type};
3724: }
1.160.6.26 raeburn 3725: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3726: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3727: $current = '';
3728: }
3729: }
3730: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3731: $servers,$currbalancer,$lonhost,$dom,
3732: $targets_div_style,$homedom_div_style,
3733: $css_class,$balnum,$num,$islast);
1.150 raeburn 3734: }
3735: }
3736: return $output;
3737: }
3738:
3739: sub loadbalancing_titles {
3740: my ($dom,$intdom,$usertypes,$types) = @_;
3741: my %othertypes = (
3742: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3743: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3744: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3745: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3746: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3747: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3748: );
1.160.6.26 raeburn 3749: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3750: if (ref($types) eq 'ARRAY') {
3751: unshift(@alltypes,@{$types},'default');
3752: }
3753: my %titles;
3754: foreach my $type (@alltypes) {
3755: if ($type =~ /^_LC_/) {
3756: $titles{$type} = $othertypes{$type};
3757: } elsif ($type eq 'default') {
3758: $titles{$type} = &mt('All users from [_1]',$dom);
3759: if (ref($types) eq 'ARRAY') {
3760: if (@{$types} > 0) {
3761: $titles{$type} = &mt('Other users from [_1]',$dom);
3762: }
3763: }
3764: } elsif (ref($usertypes) eq 'HASH') {
3765: $titles{$type} = $usertypes->{$type};
3766: }
3767: }
3768: return (\@alltypes,\%othertypes,\%titles);
3769: }
3770:
3771: sub loadbalance_rule_row {
1.160.6.7 raeburn 3772: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3773: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3774: my @rulenames;
1.150 raeburn 3775: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3776: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3777: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3778: } else {
1.160.6.26 raeburn 3779: @rulenames = ('default','homeserver');
3780: if ($type eq '_LC_external') {
3781: push(@rulenames,'externalbalancer');
3782: } else {
3783: push(@rulenames,'specific');
3784: }
3785: push(@rulenames,'none');
1.150 raeburn 3786: }
3787: my $style = $targets_div_style;
1.160.6.26 raeburn 3788: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3789: $style = $homedom_div_style;
3790: }
1.160.6.7 raeburn 3791: my $space;
3792: if ($islast && $num == 1) {
3793: $space = '<div display="inline-block"> </div>';
3794: }
3795: my $output =
3796: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3797: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3798: '<td valaign="top">'.$space.
3799: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3800: for (my $i=0; $i<@rulenames; $i++) {
3801: my $rule = $rulenames[$i];
3802: my ($checked,$extra);
3803: if ($rulenames[$i] eq 'default') {
3804: $rule = '';
3805: }
3806: if ($rulenames[$i] eq 'specific') {
3807: if (ref($servers) eq 'HASH') {
3808: my $default;
3809: if (($current ne '') && (exists($servers->{$current}))) {
3810: $checked = ' checked="checked"';
3811: }
3812: unless ($checked) {
3813: $default = ' selected="selected"';
3814: }
1.160.6.7 raeburn 3815: $extra =
3816: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3817: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3818: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3819: '<option value=""'.$default.'></option>'."\n";
3820: foreach my $server (sort(keys(%{$servers}))) {
3821: if (ref($currbalancer) eq 'HASH') {
3822: next if (exists($currbalancer->{$server}));
3823: }
1.150 raeburn 3824: my $selected;
1.160.6.7 raeburn 3825: if ($server eq $current) {
1.150 raeburn 3826: $selected = ' selected="selected"';
3827: }
1.160.6.7 raeburn 3828: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3829: }
3830: $extra .= '</select>';
3831: }
3832: } elsif ($rule eq $current) {
3833: $checked = ' checked="checked"';
3834: }
3835: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3836: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3837: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3838: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3839: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3840: '</label>'.$extra.'</span><br />'."\n";
3841: }
3842: $output .= '</div></td></tr>'."\n";
3843: return $output;
3844: }
3845:
3846: sub offloadtype_text {
3847: my %ruletitles = &Apache::lonlocal::texthash (
3848: 'default' => 'Offloads to default destinations',
3849: 'homeserver' => "Offloads to user's home server",
3850: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3851: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3852: 'none' => 'No offload',
1.160.6.26 raeburn 3853: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3854: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3855: );
3856: return %ruletitles;
3857: }
3858:
3859: sub sparestype_titles {
3860: my %typestitles = &Apache::lonlocal::texthash (
3861: 'primary' => 'primary',
3862: 'default' => 'default',
3863: );
3864: return %typestitles;
3865: }
3866:
1.28 raeburn 3867: sub contact_titles {
3868: my %titles = &Apache::lonlocal::texthash (
3869: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3870: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3871: 'errormail' => 'Error reports to be e-mailed to',
3872: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3873: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3874: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3875: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3876: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3877: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3878: );
3879: my %short_titles = &Apache::lonlocal::texthash (
3880: adminemail => 'Admin E-mail address',
3881: supportemail => 'Support E-mail',
3882: );
3883: return (\%titles,\%short_titles);
3884: }
3885:
1.72 raeburn 3886: sub tool_titles {
3887: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3888: aboutme => 'Personal web page',
1.86 raeburn 3889: blog => 'Blog',
1.160.6.4 raeburn 3890: webdav => 'WebDAV',
1.86 raeburn 3891: portfolio => 'Portfolio',
1.88 bisitz 3892: official => 'Official courses (with institutional codes)',
3893: unofficial => 'Unofficial courses',
1.98 raeburn 3894: community => 'Communities',
1.160.6.30 raeburn 3895: textbook => 'Textbook courses',
1.86 raeburn 3896: );
1.72 raeburn 3897: return %titles;
3898: }
3899:
1.101 raeburn 3900: sub courserequest_titles {
3901: my %titles = &Apache::lonlocal::texthash (
3902: official => 'Official',
3903: unofficial => 'Unofficial',
3904: community => 'Communities',
1.160.6.30 raeburn 3905: textbook => 'Textbook',
1.101 raeburn 3906: norequest => 'Not allowed',
1.104 raeburn 3907: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3908: validate => 'With validation',
3909: autolimit => 'Numerical limit',
1.103 raeburn 3910: unlimited => '(blank for unlimited)',
1.101 raeburn 3911: );
3912: return %titles;
3913: }
3914:
1.160.6.5 raeburn 3915: sub authorrequest_titles {
3916: my %titles = &Apache::lonlocal::texthash (
3917: norequest => 'Not allowed',
3918: approval => 'Approval by Dom. Coord.',
3919: automatic => 'Automatic approval',
3920: );
3921: return %titles;
3922: }
3923:
1.101 raeburn 3924: sub courserequest_conditions {
3925: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3926: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3927: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3928: );
3929: return %conditions;
3930: }
3931:
3932:
1.27 raeburn 3933: sub print_usercreation {
1.30 raeburn 3934: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3935: my $numinrow = 4;
1.28 raeburn 3936: my $datatable;
3937: if ($position eq 'top') {
1.30 raeburn 3938: $$rowtotal ++;
1.34 raeburn 3939: my $rowcount = 0;
1.32 raeburn 3940: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3941: if (ref($rules) eq 'HASH') {
3942: if (keys(%{$rules}) > 0) {
1.32 raeburn 3943: $datatable .= &user_formats_row('username',$settings,$rules,
3944: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3945: $$rowtotal ++;
1.32 raeburn 3946: $rowcount ++;
3947: }
3948: }
3949: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3950: if (ref($idrules) eq 'HASH') {
3951: if (keys(%{$idrules}) > 0) {
3952: $datatable .= &user_formats_row('id',$settings,$idrules,
3953: $idruleorder,$numinrow,$rowcount);
3954: $$rowtotal ++;
3955: $rowcount ++;
1.28 raeburn 3956: }
3957: }
1.39 raeburn 3958: if ($rowcount == 0) {
3959: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3960: $$rowtotal ++;
3961: $rowcount ++;
3962: }
1.34 raeburn 3963: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3964: my @creators = ('author','course','requestcrs');
1.37 raeburn 3965: my ($rules,$ruleorder) =
3966: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3967: my %lt = &usercreation_types();
3968: my %checked;
3969: if (ref($settings) eq 'HASH') {
3970: if (ref($settings->{'cancreate'}) eq 'HASH') {
3971: foreach my $item (@creators) {
3972: $checked{$item} = $settings->{'cancreate'}{$item};
3973: }
3974: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3975: foreach my $item (@creators) {
3976: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3977: $checked{$item} = 'none';
3978: }
3979: }
3980: }
3981: }
3982: my $rownum = 0;
3983: foreach my $item (@creators) {
3984: $rownum ++;
1.160.6.34 raeburn 3985: if ($checked{$item} eq '') {
3986: $checked{$item} = 'any';
1.34 raeburn 3987: }
3988: my $css_class;
3989: if ($rownum%2) {
3990: $css_class = '';
3991: } else {
3992: $css_class = ' class="LC_odd_row" ';
3993: }
3994: $datatable .= '<tr'.$css_class.'>'.
3995: '<td><span class="LC_nobreak">'.$lt{$item}.
3996: '</span></td><td align="right">';
1.160.6.34 raeburn 3997: my @options = ('any');
3998: if (ref($rules) eq 'HASH') {
3999: if (keys(%{$rules}) > 0) {
4000: push(@options,('official','unofficial'));
1.37 raeburn 4001: }
4002: }
1.160.6.34 raeburn 4003: push(@options,'none');
1.37 raeburn 4004: foreach my $option (@options) {
1.50 raeburn 4005: my $type = 'radio';
1.34 raeburn 4006: my $check = ' ';
1.160.6.34 raeburn 4007: if ($checked{$item} eq $option) {
4008: $check = ' checked="checked" ';
1.34 raeburn 4009: }
4010: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4011: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4012: $item.'" value="'.$option.'"'.$check.'/> '.
4013: $lt{$option}.'</label> </span>';
4014: }
4015: $datatable .= '</td></tr>';
4016: }
1.28 raeburn 4017: } else {
4018: my @contexts = ('author','course','domain');
4019: my @authtypes = ('int','krb4','krb5','loc');
4020: my %checked;
4021: if (ref($settings) eq 'HASH') {
4022: if (ref($settings->{'authtypes'}) eq 'HASH') {
4023: foreach my $item (@contexts) {
4024: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4025: foreach my $auth (@authtypes) {
4026: if ($settings->{'authtypes'}{$item}{$auth}) {
4027: $checked{$item}{$auth} = ' checked="checked" ';
4028: }
4029: }
4030: }
4031: }
1.27 raeburn 4032: }
1.35 raeburn 4033: } else {
4034: foreach my $item (@contexts) {
1.36 raeburn 4035: foreach my $auth (@authtypes) {
1.35 raeburn 4036: $checked{$item}{$auth} = ' checked="checked" ';
4037: }
4038: }
1.27 raeburn 4039: }
1.28 raeburn 4040: my %title = &context_names();
4041: my %authname = &authtype_names();
4042: my $rownum = 0;
4043: my $css_class;
4044: foreach my $item (@contexts) {
4045: if ($rownum%2) {
4046: $css_class = '';
4047: } else {
4048: $css_class = ' class="LC_odd_row" ';
4049: }
1.30 raeburn 4050: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4051: '<td>'.$title{$item}.
4052: '</td><td class="LC_left_item">'.
4053: '<span class="LC_nobreak">';
4054: foreach my $auth (@authtypes) {
4055: $datatable .= '<label>'.
4056: '<input type="checkbox" name="'.$item.'_auth" '.
4057: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4058: $authname{$auth}.'</label> ';
4059: }
4060: $datatable .= '</span></td></tr>';
4061: $rownum ++;
1.27 raeburn 4062: }
1.30 raeburn 4063: $$rowtotal += $rownum;
1.27 raeburn 4064: }
4065: return $datatable;
4066: }
4067:
1.160.6.34 raeburn 4068: sub print_selfcreation {
4069: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4070: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4071: if (ref($settings) eq 'HASH') {
4072: if (ref($settings->{'cancreate'}) eq 'HASH') {
4073: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4074: if (ref($createsettings) eq 'HASH') {
4075: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4076: @selfcreate = @{$createsettings->{'selfcreate'}};
4077: } elsif ($createsettings->{'selfcreate'} ne '') {
4078: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4079: @selfcreate = ('email','login','sso');
4080: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4081: @selfcreate = ($createsettings->{'selfcreate'});
4082: }
4083: }
4084: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4085: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4086: }
4087: }
4088: }
4089: }
4090: my %radiohash;
4091: my $numinrow = 4;
4092: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4093: if ($position eq 'top') {
4094: my %choices = &Apache::lonlocal::texthash (
4095: cancreate_login => 'Institutional Login',
4096: cancreate_sso => 'Institutional Single Sign On',
4097: );
4098: my @toggles = sort(keys(%choices));
4099: my %defaultchecked = (
4100: 'cancreate_login' => 'off',
4101: 'cancreate_sso' => 'off',
4102: );
1.160.6.35 raeburn 4103: my ($onclick,$itemcount);
1.160.6.34 raeburn 4104: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4105: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4106: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4107:
1.160.6.34 raeburn 4108: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4109:
4110: if (ref($usertypes) eq 'HASH') {
4111: if (keys(%{$usertypes}) > 0) {
4112: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4113: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4114: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4115: $$rowtotal ++;
4116: }
4117: }
1.160.6.44 raeburn 4118: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4119: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4120: $fieldtitles{'inststatus'} = &mt('Institutional status');
4121: my $rem;
4122: my $numperrow = 2;
4123: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4124: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4125: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4126: '<td class="LC_left_item">'."\n".
4127: '<table><tr><td>'."\n";
4128: for (my $i=0; $i<@fields; $i++) {
4129: $rem = $i%($numperrow);
4130: if ($rem == 0) {
4131: if ($i > 0) {
4132: $datatable .= '</tr>';
4133: }
4134: $datatable .= '<tr>';
4135: }
4136: my $currval;
4137: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4138: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4139: }
4140: $datatable .= '<td class="LC_left_item">'.
4141: '<span class="LC_nobreak">'.
4142: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4143: 'value="'.$currval.'" size="10" /> '.
4144: $fieldtitles{$fields[$i]}.'</span></td>';
4145: }
4146: my $colsleft = $numperrow - $rem;
4147: if ($colsleft > 1 ) {
4148: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4149: ' </td>';
4150: } elsif ($colsleft == 1) {
4151: $datatable .= '<td class="LC_left_item"> </td>';
4152: }
4153: $datatable .= '</tr></table></td></tr>';
4154: $$rowtotal ++;
1.160.6.34 raeburn 4155: } elsif ($position eq 'middle') {
4156: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4157: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4158: $usertypes->{'default'} = $othertitle;
4159: if (ref($types) eq 'ARRAY') {
4160: push(@{$types},'default');
4161: $usertypes->{'default'} = $othertitle;
4162: foreach my $status (@{$types}) {
4163: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4164: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4165: $$rowtotal ++;
1.160.6.34 raeburn 4166: }
4167: }
4168: } else {
1.160.6.40 raeburn 4169: my %choices = &Apache::lonlocal::texthash (
4170: cancreate_email => 'E-mail address as username',
4171: );
4172: my @toggles = sort(keys(%choices));
4173: my %defaultchecked = (
4174: 'cancreate_email' => 'off',
4175: );
4176: my $itemcount = 0;
4177: my $display = 'none';
4178: if (grep(/^\Qemail\E$/,@selfcreate)) {
4179: $display = 'block';
4180: }
4181: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4182: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4183: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4184: my $usertypes = {};
4185: my $order = [];
4186: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4187: $usertypes = $domdefaults{'inststatustypes'};
4188: $order = $domdefaults{'inststatusguest'};
4189: }
4190: if (ref($order) eq 'ARRAY') {
4191: push(@{$order},'default');
4192: if (@{$order} > 1) {
4193: $usertypes->{'default'} = &mt('Other users');
4194: $additional .= '<table><tr>';
4195: foreach my $status (@{$order}) {
4196: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4197: }
4198: $additional .= '</tr><tr>';
4199: foreach my $status (@{$order}) {
4200: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4201: }
1.160.6.40 raeburn 4202: $additional .= '</tr></table>';
1.160.6.34 raeburn 4203: } else {
1.160.6.40 raeburn 4204: $usertypes->{'default'} = &mt('All users');
4205: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4206: }
4207: }
1.160.6.40 raeburn 4208: $additional .= '</div>'."\n";
4209:
4210: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4211: \%choices,$$rowtotal,$onclick,$additional);
4212: $$rowtotal ++;
1.160.6.40 raeburn 4213: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4214: $$rowtotal ++;
1.160.6.35 raeburn 4215: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4216: $numinrow = 1;
1.160.6.40 raeburn 4217: if (ref($order) eq 'ARRAY') {
4218: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4219: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4220: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4221: $$rowtotal ++;
4222: }
4223: }
1.160.6.34 raeburn 4224: my ($emailrules,$emailruleorder) =
4225: &Apache::lonnet::inst_userrules($dom,'email');
4226: if (ref($emailrules) eq 'HASH') {
4227: if (keys(%{$emailrules}) > 0) {
4228: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4229: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4230: $$rowtotal ++;
4231: }
4232: }
1.160.6.35 raeburn 4233: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4234: }
4235: return $datatable;
4236: }
4237:
1.160.6.40 raeburn 4238: sub email_as_username {
4239: my ($rowtotal,$processing,$type) = @_;
4240: my %choices =
4241: &Apache::lonlocal::texthash (
4242: automatic => 'Automatic approval',
4243: approval => 'Queued for approval',
4244: );
4245: my $output;
4246: foreach my $option ('automatic','approval') {
4247: my $checked;
4248: if (ref($processing) eq 'HASH') {
4249: if ($type eq '') {
4250: if (!exists($processing->{'default'})) {
4251: if ($option eq 'automatic') {
4252: $checked = ' checked="checked"';
4253: }
4254: } else {
4255: if ($processing->{'default'} eq $option) {
4256: $checked = ' checked="checked"';
4257: }
4258: }
4259: } else {
4260: if (!exists($processing->{$type})) {
4261: if ($option eq 'automatic') {
4262: $checked = ' checked="checked"';
4263: }
4264: } else {
4265: if ($processing->{$type} eq $option) {
4266: $checked = ' checked="checked"';
4267: }
4268: }
4269: }
4270: } elsif ($option eq 'automatic') {
4271: $checked = ' checked="checked"';
4272: }
4273: my $name = 'cancreate_emailprocess';
4274: if (($type ne '') && ($type ne 'default')) {
4275: $name .= '_'.$type;
4276: }
4277: $output .= '<span class="LC_nobreak"><label>'.
4278: '<input type="radio" name="'.$name.'"'.
4279: $checked.' value="'.$option.'" />'.
4280: $choices{$option}.'</label></span>';
4281: if ($type eq '') {
4282: $output .= ' ';
4283: } else {
4284: $output .= '<br />';
4285: }
4286: }
4287: $$rowtotal ++;
4288: return $output;
4289: }
4290:
1.160.6.5 raeburn 4291: sub captcha_choice {
4292: my ($context,$settings,$itemcount) = @_;
4293: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4294: my %lt = &captcha_phrases();
4295: $keyentry = 'hidden';
4296: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4297: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4298: } elsif ($context eq 'login') {
4299: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4300: }
4301: if (ref($settings) eq 'HASH') {
4302: if ($settings->{'captcha'}) {
4303: $checked{$settings->{'captcha'}} = ' checked="checked"';
4304: } else {
4305: $checked{'original'} = ' checked="checked"';
4306: }
4307: if ($settings->{'captcha'} eq 'recaptcha') {
4308: $pubtext = $lt{'pub'};
4309: $privtext = $lt{'priv'};
4310: $keyentry = 'text';
4311: }
4312: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4313: $currpub = $settings->{'recaptchakeys'}{'public'};
4314: $currpriv = $settings->{'recaptchakeys'}{'private'};
4315: }
4316: } else {
4317: $checked{'original'} = ' checked="checked"';
4318: }
4319: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4320: my $output = '<tr'.$css_class.'>'.
4321: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4322: '<table><tr><td>'."\n";
4323: foreach my $option ('original','recaptcha','notused') {
4324: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4325: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4326: $lt{$option}.'</label></span>';
4327: unless ($option eq 'notused') {
4328: $output .= (' 'x2)."\n";
4329: }
4330: }
4331: #
4332: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4333: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4334: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4335: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4336: #
4337: $output .= '</td></tr>'."\n".
4338: '<tr><td>'."\n".
4339: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4340: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4341: $currpub.'" size="40" /></span><br />'."\n".
4342: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4343: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4344: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4345: '</td></tr>';
4346: return $output;
4347: }
4348:
1.32 raeburn 4349: sub user_formats_row {
4350: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4351: my $output;
4352: my %text = (
4353: 'username' => 'new usernames',
4354: 'id' => 'IDs',
1.45 raeburn 4355: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4356: );
4357: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4358: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4359: '<td><span class="LC_nobreak">';
4360: if ($type eq 'email') {
4361: $output .= &mt("Formats disallowed for $text{$type}: ");
4362: } else {
4363: $output .= &mt("Format rules to check for $text{$type}: ");
4364: }
4365: $output .= '</span></td>'.
4366: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4367: my $rem;
4368: if (ref($ruleorder) eq 'ARRAY') {
4369: for (my $i=0; $i<@{$ruleorder}; $i++) {
4370: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4371: my $rem = $i%($numinrow);
4372: if ($rem == 0) {
4373: if ($i > 0) {
4374: $output .= '</tr>';
4375: }
4376: $output .= '<tr>';
4377: }
4378: my $check = ' ';
1.39 raeburn 4379: if (ref($settings) eq 'HASH') {
4380: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4381: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4382: $check = ' checked="checked" ';
4383: }
1.27 raeburn 4384: }
4385: }
4386: $output .= '<td class="LC_left_item">'.
4387: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4388: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4389: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4390: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4391: }
4392: }
4393: $rem = @{$ruleorder}%($numinrow);
4394: }
4395: my $colsleft = $numinrow - $rem;
4396: if ($colsleft > 1 ) {
4397: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4398: ' </td>';
4399: } elsif ($colsleft == 1) {
4400: $output .= '<td class="LC_left_item"> </td>';
4401: }
4402: $output .= '</tr></table></td></tr>';
4403: return $output;
4404: }
4405:
1.34 raeburn 4406: sub usercreation_types {
4407: my %lt = &Apache::lonlocal::texthash (
4408: author => 'When adding a co-author',
4409: course => 'When adding a user to a course',
1.100 raeburn 4410: requestcrs => 'When requesting a course',
1.34 raeburn 4411: any => 'Any',
4412: official => 'Institutional only ',
4413: unofficial => 'Non-institutional only',
4414: none => 'None',
4415: );
4416: return %lt;
1.48 raeburn 4417: }
1.34 raeburn 4418:
1.160.6.34 raeburn 4419: sub selfcreation_types {
4420: my %lt = &Apache::lonlocal::texthash (
4421: selfcreate => 'User creates own account',
4422: any => 'Any',
4423: official => 'Institutional only ',
4424: unofficial => 'Non-institutional only',
4425: email => 'E-mail address',
4426: login => 'Institutional Login',
4427: sso => 'SSO',
4428: );
4429: }
4430:
1.28 raeburn 4431: sub authtype_names {
4432: my %lt = &Apache::lonlocal::texthash(
4433: int => 'Internal',
4434: krb4 => 'Kerberos 4',
4435: krb5 => 'Kerberos 5',
4436: loc => 'Local',
4437: );
4438: return %lt;
4439: }
4440:
4441: sub context_names {
4442: my %context_title = &Apache::lonlocal::texthash(
4443: author => 'Creating users when an Author',
4444: course => 'Creating users when in a course',
4445: domain => 'Creating users when a Domain Coordinator',
4446: );
4447: return %context_title;
4448: }
4449:
1.33 raeburn 4450: sub print_usermodification {
4451: my ($position,$dom,$settings,$rowtotal) = @_;
4452: my $numinrow = 4;
4453: my ($context,$datatable,$rowcount);
4454: if ($position eq 'top') {
4455: $rowcount = 0;
4456: $context = 'author';
4457: foreach my $role ('ca','aa') {
4458: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4459: $numinrow,$rowcount);
4460: $$rowtotal ++;
4461: $rowcount ++;
4462: }
1.160.6.37 raeburn 4463: } elsif ($position eq 'bottom') {
1.33 raeburn 4464: $context = 'course';
4465: $rowcount = 0;
4466: foreach my $role ('st','ep','ta','in','cr') {
4467: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4468: $numinrow,$rowcount);
4469: $$rowtotal ++;
4470: $rowcount ++;
4471: }
4472: }
4473: return $datatable;
4474: }
4475:
1.43 raeburn 4476: sub print_defaults {
1.160.6.40 raeburn 4477: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4478: my $rownum = 0;
4479: my ($datatable,$css_class);
1.160.6.40 raeburn 4480: if ($position eq 'top') {
4481: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4482: 'datelocale_def','portal_def');
4483: my %defaults;
4484: if (ref($settings) eq 'HASH') {
4485: %defaults = %{$settings};
1.43 raeburn 4486: } else {
1.160.6.40 raeburn 4487: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4488: foreach my $item (@items) {
4489: $defaults{$item} = $domdefaults{$item};
4490: }
1.43 raeburn 4491: }
1.160.6.40 raeburn 4492: my $titles = &defaults_titles($dom);
4493: foreach my $item (@items) {
4494: if ($rownum%2) {
4495: $css_class = '';
4496: } else {
4497: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4498: }
1.160.6.40 raeburn 4499: $datatable .= '<tr'.$css_class.'>'.
4500: '<td><span class="LC_nobreak">'.$titles->{$item}.
4501: '</span></td><td class="LC_right_item" colspan="3">';
4502: if ($item eq 'auth_def') {
4503: my @authtypes = ('internal','krb4','krb5','localauth');
4504: my %shortauth = (
4505: internal => 'int',
4506: krb4 => 'krb4',
4507: krb5 => 'krb5',
4508: localauth => 'loc'
4509: );
4510: my %authnames = &authtype_names();
4511: foreach my $auth (@authtypes) {
4512: my $checked = ' ';
4513: if ($defaults{$item} eq $auth) {
4514: $checked = ' checked="checked" ';
4515: }
4516: $datatable .= '<label><input type="radio" name="'.$item.
4517: '" value="'.$auth.'"'.$checked.'/>'.
4518: $authnames{$shortauth{$auth}}.'</label> ';
4519: }
4520: } elsif ($item eq 'timezone_def') {
4521: my $includeempty = 1;
4522: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4523: } elsif ($item eq 'datelocale_def') {
4524: my $includeempty = 1;
4525: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4526: } elsif ($item eq 'lang_def') {
4527: my %langchoices = &get_languages_hash();
4528: $langchoices{''} = 'No language preference';
4529: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4530: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4531: \%langchoices);
4532: } else {
4533: my $size;
4534: if ($item eq 'portal_def') {
4535: $size = ' size="25"';
4536: }
4537: $datatable .= '<input type="text" name="'.$item.'" value="'.
4538: $defaults{$item}.'"'.$size.' />';
4539: }
4540: $datatable .= '</td></tr>';
4541: $rownum ++;
4542: }
4543: } else {
4544: my (%defaults);
4545: if (ref($settings) eq 'HASH') {
4546: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4547: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4548: my $maxnum = @{$settings->{'inststatusorder'}};
4549: for (my $i=0; $i<$maxnum; $i++) {
4550: $css_class = $rownum%2?' class="LC_odd_row"':'';
4551: my $item = $settings->{'inststatusorder'}->[$i];
4552: my $title = $settings->{'inststatustypes'}->{$item};
4553: my $guestok;
4554: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4555: $guestok = 1;
4556: }
4557: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4558: $datatable .= '<tr'.$css_class.'>'.
4559: '<td><span class="LC_nobreak">'.
4560: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4561: for (my $k=0; $k<=$maxnum; $k++) {
4562: my $vpos = $k+1;
4563: my $selstr;
4564: if ($k == $i) {
4565: $selstr = ' selected="selected" ';
4566: }
4567: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4568: }
4569: my ($checkedon,$checkedoff);
4570: $checkedoff = ' checked="checked"';
4571: if ($guestok) {
4572: $checkedon = $checkedoff;
4573: $checkedoff = '';
4574: }
4575: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4576: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4577: &mt('delete').'</span></td>'.
4578: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4579: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4580: '</span></td>'.
4581: '<td class="LC_right_item"><span class="LC_nobreak">'.
4582: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4583: &mt('Yes').'</label>'.(' 'x2).
4584: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4585: &mt('No').'</label></span></td></tr>';
4586: }
4587: $css_class = $rownum%2?' class="LC_odd_row"':'';
4588: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4589: $datatable .= '<tr '.$css_class.'>'.
4590: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4591: for (my $k=0; $k<=$maxnum; $k++) {
4592: my $vpos = $k+1;
4593: my $selstr;
4594: if ($k == $maxnum) {
4595: $selstr = ' selected="selected" ';
4596: }
4597: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4598: }
4599: $datatable .= '</select> '.&mt('Internal ID:').
4600: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4601: ' '.&mt('(new)').
4602: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4603: &mt('Name displayed:').
4604: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4605: '<td class="LC_right_item"><span class="LC_nobreak">'.
4606: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4607: &mt('Yes').'</label>'.(' 'x2).
4608: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4609: &mt('No').'</label></span></td></tr>';
4610: '</tr>'."\n";
4611: $rownum ++;
1.141 raeburn 4612: }
1.43 raeburn 4613: }
4614: }
4615: $$rowtotal += $rownum;
4616: return $datatable;
4617: }
4618:
1.160.6.5 raeburn 4619: sub get_languages_hash {
4620: my %langchoices;
4621: foreach my $id (&Apache::loncommon::languageids()) {
4622: my $code = &Apache::loncommon::supportedlanguagecode($id);
4623: if ($code ne '') {
4624: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4625: }
4626: }
4627: return %langchoices;
4628: }
4629:
1.43 raeburn 4630: sub defaults_titles {
1.141 raeburn 4631: my ($dom) = @_;
1.43 raeburn 4632: my %titles = &Apache::lonlocal::texthash (
4633: 'auth_def' => 'Default authentication type',
4634: 'auth_arg_def' => 'Default authentication argument',
4635: 'lang_def' => 'Default language',
1.54 raeburn 4636: 'timezone_def' => 'Default timezone',
1.68 raeburn 4637: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4638: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4639: );
1.141 raeburn 4640: if ($dom) {
4641: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4642: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4643: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4644: $protocol = 'http' if ($protocol ne 'https');
4645: if ($uint_dom) {
4646: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4647: $uint_dom);
4648: }
4649: }
1.43 raeburn 4650: return (\%titles);
4651: }
4652:
1.46 raeburn 4653: sub print_scantronformat {
4654: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4655: my $itemcount = 1;
1.60 raeburn 4656: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4657: %confhash);
1.46 raeburn 4658: my $switchserver = &check_switchserver($dom,$confname);
4659: my %lt = &Apache::lonlocal::texthash (
1.95 www 4660: default => 'Default bubblesheet format file error',
4661: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4662: );
4663: my %scantronfiles = (
4664: default => 'default.tab',
4665: custom => 'custom.tab',
4666: );
4667: foreach my $key (keys(%scantronfiles)) {
4668: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4669: .$scantronfiles{$key};
4670: }
4671: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4672: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4673: if (!$switchserver) {
4674: my $servadm = $r->dir_config('lonAdmEMail');
4675: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4676: if ($configuserok eq 'ok') {
4677: if ($author_ok eq 'ok') {
4678: my %legacyfile = (
4679: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4680: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4681: );
4682: my %md5chk;
4683: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4684: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4685: chomp($md5chk{$type});
1.46 raeburn 4686: }
4687: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4688: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4689: ($scantronurls{$type},my $error) =
1.46 raeburn 4690: &legacy_scantronformat($r,$dom,$confname,
4691: $type,$legacyfile{$type},
4692: $scantronurls{$type},
4693: $scantronfiles{$type});
1.60 raeburn 4694: if ($error ne '') {
4695: $error{$type} = $error;
4696: }
4697: }
4698: if (keys(%error) == 0) {
4699: $is_custom = 1;
4700: $confhash{'scantron'}{'scantronformat'} =
4701: $scantronurls{'custom'};
4702: my $putresult =
4703: &Apache::lonnet::put_dom('configuration',
4704: \%confhash,$dom);
4705: if ($putresult ne 'ok') {
4706: $error{'custom'} =
4707: '<span class="LC_error">'.
4708: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4709: }
1.46 raeburn 4710: }
4711: } else {
1.60 raeburn 4712: ($scantronurls{'default'},my $error) =
1.46 raeburn 4713: &legacy_scantronformat($r,$dom,$confname,
4714: 'default',$legacyfile{'default'},
4715: $scantronurls{'default'},
4716: $scantronfiles{'default'});
1.60 raeburn 4717: if ($error eq '') {
4718: $confhash{'scantron'}{'scantronformat'} = '';
4719: my $putresult =
4720: &Apache::lonnet::put_dom('configuration',
4721: \%confhash,$dom);
4722: if ($putresult ne 'ok') {
4723: $error{'default'} =
4724: '<span class="LC_error">'.
4725: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4726: }
4727: } else {
4728: $error{'default'} = $error;
4729: }
1.46 raeburn 4730: }
4731: }
4732: }
4733: } else {
1.95 www 4734: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4735: }
4736: }
4737: if (ref($settings) eq 'HASH') {
4738: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4739: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4740: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4741: $scantronurl = '';
4742: } else {
4743: $scantronurl = $settings->{'scantronformat'};
4744: }
4745: $is_custom = 1;
4746: } else {
4747: $scantronurl = $scantronurls{'default'};
4748: }
4749: } else {
1.60 raeburn 4750: if ($is_custom) {
4751: $scantronurl = $scantronurls{'custom'};
4752: } else {
4753: $scantronurl = $scantronurls{'default'};
4754: }
1.46 raeburn 4755: }
4756: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4757: $datatable .= '<tr'.$css_class.'>';
4758: if (!$is_custom) {
1.65 raeburn 4759: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4760: '<span class="LC_nobreak">';
1.46 raeburn 4761: if ($scantronurl) {
1.160.6.21 raeburn 4762: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4763: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4764: } else {
4765: $datatable = &mt('File unavailable for display');
4766: }
1.65 raeburn 4767: $datatable .= '</span></td>';
1.60 raeburn 4768: if (keys(%error) == 0) {
4769: $datatable .= '<td valign="bottom">';
4770: if (!$switchserver) {
4771: $datatable .= &mt('Upload:').'<br />';
4772: }
4773: } else {
4774: my $errorstr;
4775: foreach my $key (sort(keys(%error))) {
4776: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4777: }
4778: $datatable .= '<td>'.$errorstr;
4779: }
1.46 raeburn 4780: } else {
4781: if (keys(%error) > 0) {
4782: my $errorstr;
4783: foreach my $key (sort(keys(%error))) {
4784: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4785: }
1.60 raeburn 4786: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4787: } elsif ($scantronurl) {
1.160.6.26 raeburn 4788: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4789: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4790: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4791: $link.
4792: '<label><input type="checkbox" name="scantronformat_del"'.
4793: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4794: '<td><span class="LC_nobreak"> '.
4795: &mt('Replace:').'</span><br />';
1.46 raeburn 4796: }
4797: }
4798: if (keys(%error) == 0) {
4799: if ($switchserver) {
4800: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4801: } else {
1.65 raeburn 4802: $datatable .='<span class="LC_nobreak"> '.
4803: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4804: }
4805: }
4806: $datatable .= '</td></tr>';
4807: $$rowtotal ++;
4808: return $datatable;
4809: }
4810:
4811: sub legacy_scantronformat {
4812: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4813: my ($url,$error);
4814: my @statinfo = &Apache::lonnet::stat_file($newurl);
4815: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4816: (my $result,$url) =
4817: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4818: '','',$newfile);
4819: if ($result ne 'ok') {
1.130 raeburn 4820: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4821: }
4822: }
4823: return ($url,$error);
4824: }
1.43 raeburn 4825:
1.49 raeburn 4826: sub print_coursecategories {
1.57 raeburn 4827: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4828: my $datatable;
4829: if ($position eq 'top') {
1.160.6.42 raeburn 4830: my (%checked);
4831: my @catitems = ('unauth','auth');
4832: my @cattypes = ('std','domonly','codesrch','none');
4833: $checked{'unauth'} = 'std';
4834: $checked{'auth'} = 'std';
4835: if (ref($settings) eq 'HASH') {
4836: foreach my $type (@cattypes) {
4837: if ($type eq $settings->{'unauth'}) {
4838: $checked{'unauth'} = $type;
4839: }
4840: if ($type eq $settings->{'auth'}) {
4841: $checked{'auth'} = $type;
4842: }
4843: }
4844: }
4845: my %lt = &Apache::lonlocal::texthash (
4846: unauth => 'Catalog type for unauthenticated users',
4847: auth => 'Catalog type for authenticated users',
4848: none => 'No catalog',
4849: std => 'Standard catalog',
4850: domonly => 'Domain-only catalog',
4851: codesrch => "Code search form",
4852: );
4853: my $itemcount = 0;
4854: foreach my $item (@catitems) {
4855: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4856: $datatable .= '<tr '.$css_class.'>'.
4857: '<td>'.$lt{$item}.'</td>'.
4858: '<td class="LC_right_item"><span class="LC_nobreak">';
4859: foreach my $type (@cattypes) {
4860: my $ischecked;
4861: if ($checked{$item} eq $type) {
4862: $ischecked=' checked="checked"';
4863: }
4864: $datatable .= '<label>'.
4865: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4866: ' />'.$lt{$type}.'</label> ';
4867: }
4868: $datatable .= '</td></tr>';
4869: $itemcount ++;
4870: }
4871: $$rowtotal += $itemcount;
4872: } elsif ($position eq 'middle') {
1.57 raeburn 4873: my $toggle_cats_crs = ' ';
4874: my $toggle_cats_dom = ' checked="checked" ';
4875: my $can_cat_crs = ' ';
4876: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4877: my $toggle_catscomm_comm = ' ';
4878: my $toggle_catscomm_dom = ' checked="checked" ';
4879: my $can_catcomm_comm = ' ';
4880: my $can_catcomm_dom = ' checked="checked" ';
4881:
1.57 raeburn 4882: if (ref($settings) eq 'HASH') {
4883: if ($settings->{'togglecats'} eq 'crs') {
4884: $toggle_cats_crs = $toggle_cats_dom;
4885: $toggle_cats_dom = ' ';
4886: }
4887: if ($settings->{'categorize'} eq 'crs') {
4888: $can_cat_crs = $can_cat_dom;
4889: $can_cat_dom = ' ';
4890: }
1.120 raeburn 4891: if ($settings->{'togglecatscomm'} eq 'comm') {
4892: $toggle_catscomm_comm = $toggle_catscomm_dom;
4893: $toggle_catscomm_dom = ' ';
4894: }
4895: if ($settings->{'categorizecomm'} eq 'comm') {
4896: $can_catcomm_comm = $can_catcomm_dom;
4897: $can_catcomm_dom = ' ';
4898: }
1.57 raeburn 4899: }
4900: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4901: togglecats => 'Show/Hide a course in catalog',
4902: togglecatscomm => 'Show/Hide a community in catalog',
4903: categorize => 'Assign a category to a course',
4904: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4905: );
4906: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4907: dom => 'Set in Domain',
4908: crs => 'Set in Course',
4909: comm => 'Set in Community',
1.57 raeburn 4910: );
4911: $datatable = '<tr class="LC_odd_row">'.
4912: '<td>'.$title{'togglecats'}.'</td>'.
4913: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4914: '<input type="radio" name="togglecats"'.
4915: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4916: '<label><input type="radio" name="togglecats"'.
4917: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4918: '</tr><tr>'.
4919: '<td>'.$title{'categorize'}.'</td>'.
4920: '<td class="LC_right_item"><span class="LC_nobreak">'.
4921: '<label><input type="radio" name="categorize"'.
4922: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4923: '<label><input type="radio" name="categorize"'.
4924: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4925: '</tr><tr class="LC_odd_row">'.
4926: '<td>'.$title{'togglecatscomm'}.'</td>'.
4927: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4928: '<input type="radio" name="togglecatscomm"'.
4929: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4930: '<label><input type="radio" name="togglecatscomm"'.
4931: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4932: '</tr><tr>'.
4933: '<td>'.$title{'categorizecomm'}.'</td>'.
4934: '<td class="LC_right_item"><span class="LC_nobreak">'.
4935: '<label><input type="radio" name="categorizecomm"'.
4936: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4937: '<label><input type="radio" name="categorizecomm"'.
4938: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4939: '</tr>';
1.120 raeburn 4940: $$rowtotal += 4;
1.57 raeburn 4941: } else {
4942: my $css_class;
4943: my $itemcount = 1;
4944: my $cathash;
4945: if (ref($settings) eq 'HASH') {
4946: $cathash = $settings->{'cats'};
4947: }
4948: if (ref($cathash) eq 'HASH') {
4949: my (@cats,@trails,%allitems,%idx,@jsarray);
4950: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4951: \%allitems,\%idx,\@jsarray);
4952: my $maxdepth = scalar(@cats);
4953: my $colattrib = '';
4954: if ($maxdepth > 2) {
4955: $colattrib = ' colspan="2" ';
4956: }
4957: my @path;
4958: if (@cats > 0) {
4959: if (ref($cats[0]) eq 'ARRAY') {
4960: my $numtop = @{$cats[0]};
4961: my $maxnum = $numtop;
1.120 raeburn 4962: my %default_names = (
4963: instcode => &mt('Official courses'),
4964: communities => &mt('Communities'),
4965: );
4966:
4967: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4968: ($cathash->{'instcode::0'} eq '') ||
4969: (!grep(/^communities$/,@{$cats[0]})) ||
4970: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4971: $maxnum ++;
4972: }
4973: my $lastidx;
4974: for (my $i=0; $i<$numtop; $i++) {
4975: my $parent = $cats[0][$i];
4976: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4977: my $item = &escape($parent).'::0';
4978: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4979: $lastidx = $idx{$item};
4980: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4981: .'<select name="'.$item.'"'.$chgstr.'>';
4982: for (my $k=0; $k<=$maxnum; $k++) {
4983: my $vpos = $k+1;
4984: my $selstr;
4985: if ($k == $i) {
4986: $selstr = ' selected="selected" ';
4987: }
4988: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4989: }
1.160.6.29 raeburn 4990: $datatable .= '</select></span></td><td>';
1.120 raeburn 4991: if ($parent eq 'instcode' || $parent eq 'communities') {
4992: $datatable .= '<span class="LC_nobreak">'
4993: .$default_names{$parent}.'</span>';
4994: if ($parent eq 'instcode') {
4995: $datatable .= '<br /><span class="LC_nobreak">('
4996: .&mt('with institutional codes')
4997: .')</span></td><td'.$colattrib.'>';
4998: } else {
4999: $datatable .= '<table><tr><td>';
5000: }
5001: $datatable .= '<span class="LC_nobreak">'
5002: .'<label><input type="radio" name="'
5003: .$parent.'" value="1" checked="checked" />'
5004: .&mt('Display').'</label>';
5005: if ($parent eq 'instcode') {
5006: $datatable .= ' ';
5007: } else {
5008: $datatable .= '</span></td></tr><tr><td>'
5009: .'<span class="LC_nobreak">';
5010: }
5011: $datatable .= '<label><input type="radio" name="'
5012: .$parent.'" value="0" />'
5013: .&mt('Do not display').'</label></span>';
5014: if ($parent eq 'communities') {
5015: $datatable .= '</td></tr></table>';
5016: }
5017: $datatable .= '</td>';
1.57 raeburn 5018: } else {
5019: $datatable .= $parent
1.160.6.29 raeburn 5020: .' <span class="LC_nobreak"><label>'
5021: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5022: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5023: }
5024: my $depth = 1;
5025: push(@path,$parent);
5026: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5027: pop(@path);
5028: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5029: $itemcount ++;
5030: }
1.48 raeburn 5031: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5032: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5033: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5034: for (my $k=0; $k<=$maxnum; $k++) {
5035: my $vpos = $k+1;
5036: my $selstr;
1.57 raeburn 5037: if ($k == $numtop) {
1.48 raeburn 5038: $selstr = ' selected="selected" ';
5039: }
5040: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5041: }
1.59 bisitz 5042: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5043: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5044: .'</tr>'."\n";
1.48 raeburn 5045: $itemcount ++;
1.120 raeburn 5046: foreach my $default ('instcode','communities') {
5047: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5049: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5050: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5051: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5052: for (my $k=0; $k<=$maxnum; $k++) {
5053: my $vpos = $k+1;
5054: my $selstr;
5055: if ($k == $maxnum) {
5056: $selstr = ' selected="selected" ';
5057: }
5058: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5059: }
1.120 raeburn 5060: $datatable .= '</select></span></td>'.
5061: '<td><span class="LC_nobreak">'.
5062: $default_names{$default}.'</span>';
5063: if ($default eq 'instcode') {
5064: $datatable .= '<br /><span class="LC_nobreak">('
5065: .&mt('with institutional codes').')</span>';
5066: }
5067: $datatable .= '</td>'
5068: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5069: .&mt('Display').'</label> '
5070: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5071: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5072: }
5073: }
5074: }
1.57 raeburn 5075: } else {
5076: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5077: }
5078: } else {
1.160.6.42 raeburn 5079: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5080: .&initialize_categories($itemcount);
1.48 raeburn 5081: }
1.57 raeburn 5082: $$rowtotal += $itemcount;
1.48 raeburn 5083: }
5084: return $datatable;
5085: }
5086:
1.69 raeburn 5087: sub print_serverstatuses {
5088: my ($dom,$settings,$rowtotal) = @_;
5089: my $datatable;
5090: my @pages = &serverstatus_pages();
5091: my (%namedaccess,%machineaccess);
5092: foreach my $type (@pages) {
5093: $namedaccess{$type} = '';
5094: $machineaccess{$type}= '';
5095: }
5096: if (ref($settings) eq 'HASH') {
5097: foreach my $type (@pages) {
5098: if (exists($settings->{$type})) {
5099: if (ref($settings->{$type}) eq 'HASH') {
5100: foreach my $key (keys(%{$settings->{$type}})) {
5101: if ($key eq 'namedusers') {
5102: $namedaccess{$type} = $settings->{$type}->{$key};
5103: } elsif ($key eq 'machines') {
5104: $machineaccess{$type} = $settings->{$type}->{$key};
5105: }
5106: }
5107: }
5108: }
5109: }
5110: }
1.81 raeburn 5111: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5112: my $rownum = 0;
5113: my $css_class;
5114: foreach my $type (@pages) {
5115: $rownum ++;
5116: $css_class = $rownum%2?' class="LC_odd_row"':'';
5117: $datatable .= '<tr'.$css_class.'>'.
5118: '<td><span class="LC_nobreak">'.
5119: $titles->{$type}.'</span></td>'.
5120: '<td class="LC_left_item">'.
5121: '<input type="text" name="'.$type.'_namedusers" '.
5122: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5123: '<td class="LC_right_item">'.
5124: '<span class="LC_nobreak">'.
5125: '<input type="text" name="'.$type.'_machines" '.
5126: 'value="'.$machineaccess{$type}.'" size="10" />'.
5127: '</td></tr>'."\n";
5128: }
5129: $$rowtotal += $rownum;
5130: return $datatable;
5131: }
5132:
5133: sub serverstatus_pages {
5134: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5135: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5136: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5137: 'uniquecodes','diskusage');
1.69 raeburn 5138: }
5139:
1.160.6.40 raeburn 5140: sub defaults_javascript {
5141: my ($settings) = @_;
5142: my ($output,$jstext);
5143: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5144: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5145: if ($maxnum eq '') {
5146: $maxnum = 0;
5147: }
5148: $maxnum ++;
5149: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5150: return <<"ENDSCRIPT";
5151: <script type="text/javascript">
5152: // <![CDATA[
5153: function reorderTypes(form,caller) {
5154: var changedVal;
5155: $jstext
5156: var newpos = 'addinststatus_pos';
5157: var current = new Array;
5158: var maxh = $maxnum;
5159: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5160: var oldVal;
5161: if (caller == newpos) {
5162: changedVal = newitemVal;
5163: } else {
5164: var curritem = 'inststatus_pos_'+caller;
5165: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5166: current[newitemVal] = newpos;
5167: }
5168: for (var i=0; i<inststatuses.length; i++) {
5169: if (inststatuses[i] != caller) {
5170: var elementName = 'inststatus_pos_'+inststatuses[i];
5171: if (form.elements[elementName]) {
5172: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5173: current[currVal] = elementName;
5174: }
5175: }
5176: }
5177: for (var j=0; j<maxh; j++) {
5178: if (current[j] == undefined) {
5179: oldVal = j;
5180: }
5181: }
5182: if (oldVal < changedVal) {
5183: for (var k=oldVal+1; k<=changedVal ; k++) {
5184: var elementName = current[k];
5185: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5186: }
5187: } else {
5188: for (var k=changedVal; k<oldVal; k++) {
5189: var elementName = current[k];
5190: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5191: }
5192: }
5193: return;
5194: }
5195:
5196: // ]]>
5197: </script>
5198:
5199: ENDSCRIPT
5200: }
5201: }
5202:
1.49 raeburn 5203: sub coursecategories_javascript {
5204: my ($settings) = @_;
1.57 raeburn 5205: my ($output,$jstext,$cathash);
1.49 raeburn 5206: if (ref($settings) eq 'HASH') {
1.57 raeburn 5207: $cathash = $settings->{'cats'};
5208: }
5209: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5210: my (@cats,@jsarray,%idx);
1.57 raeburn 5211: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5212: if (@jsarray > 0) {
5213: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5214: for (my $i=0; $i<@jsarray; $i++) {
5215: if (ref($jsarray[$i]) eq 'ARRAY') {
5216: my $catstr = join('","',@{$jsarray[$i]});
5217: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5218: }
5219: }
5220: }
5221: } else {
5222: $jstext = ' var categories = Array(1);'."\n".
5223: ' categories[0] = Array("instcode_pos");'."\n";
5224: }
1.160.6.42 raeburn 5225: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5226: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5227: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5228: $output = <<"ENDSCRIPT";
5229: <script type="text/javascript">
1.109 raeburn 5230: // <![CDATA[
1.49 raeburn 5231: function reorderCats(form,parent,item,idx) {
5232: var changedVal;
5233: $jstext
5234: var newpos = 'addcategory_pos';
5235: if (parent == '') {
5236: var has_instcode = 0;
5237: var maxtop = categories[idx].length;
5238: for (var j=0; j<maxtop; j++) {
5239: if (categories[idx][j] == 'instcode::0') {
5240: has_instcode == 1;
5241: }
5242: }
5243: if (has_instcode == 0) {
5244: categories[idx][maxtop] = 'instcode_pos';
5245: }
5246: } else {
5247: newpos += '_'+parent;
5248: }
5249: var maxh = 1 + categories[idx].length;
5250: var current = new Array;
5251: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5252: if (item == newpos) {
5253: changedVal = newitemVal;
5254: } else {
5255: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5256: current[newitemVal] = newpos;
5257: }
5258: for (var i=0; i<categories[idx].length; i++) {
5259: var elementName = categories[idx][i];
5260: if (elementName != item) {
5261: if (form.elements[elementName]) {
5262: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5263: current[currVal] = elementName;
5264: }
5265: }
5266: }
5267: var oldVal;
5268: for (var j=0; j<maxh; j++) {
5269: if (current[j] == undefined) {
5270: oldVal = j;
5271: }
5272: }
5273: if (oldVal < changedVal) {
5274: for (var k=oldVal+1; k<=changedVal ; k++) {
5275: var elementName = current[k];
5276: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5277: }
5278: } else {
5279: for (var k=changedVal; k<oldVal; k++) {
5280: var elementName = current[k];
5281: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5282: }
5283: }
5284: return;
5285: }
1.120 raeburn 5286:
5287: function categoryCheck(form) {
5288: if (form.elements['addcategory_name'].value == 'instcode') {
5289: alert('$instcode_reserved\\n$choose_again');
5290: return false;
5291: }
5292: if (form.elements['addcategory_name'].value == 'communities') {
5293: alert('$communities_reserved\\n$choose_again');
5294: return false;
5295: }
5296: return true;
5297: }
5298:
1.109 raeburn 5299: // ]]>
1.49 raeburn 5300: </script>
5301:
5302: ENDSCRIPT
5303: return $output;
5304: }
5305:
1.48 raeburn 5306: sub initialize_categories {
5307: my ($itemcount) = @_;
1.120 raeburn 5308: my ($datatable,$css_class,$chgstr);
5309: my %default_names = (
5310: instcode => 'Official courses (with institutional codes)',
5311: communities => 'Communities',
5312: );
5313: my $select0 = ' selected="selected"';
5314: my $select1 = '';
5315: foreach my $default ('instcode','communities') {
5316: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5317: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5318: if ($default eq 'communities') {
5319: $select1 = $select0;
5320: $select0 = '';
5321: }
5322: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5323: .'<select name="'.$default.'_pos">'
5324: .'<option value="0"'.$select0.'>1</option>'
5325: .'<option value="1"'.$select1.'>2</option>'
5326: .'<option value="2">3</option></select> '
5327: .$default_names{$default}
5328: .'</span></td><td><span class="LC_nobreak">'
5329: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5330: .&mt('Display').'</label> <label>'
5331: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5332: .'</label></span></td></tr>';
1.120 raeburn 5333: $itemcount ++;
5334: }
1.48 raeburn 5335: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5336: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5337: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5338: .'<select name="addcategory_pos"'.$chgstr.'>'
5339: .'<option value="0">1</option>'
5340: .'<option value="1">2</option>'
5341: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5342: .&mt('Add category').'</td><td>'.&mt('Name:')
5343: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5344: return $datatable;
5345: }
5346:
5347: sub build_category_rows {
1.49 raeburn 5348: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5349: my ($text,$name,$item,$chgstr);
1.48 raeburn 5350: if (ref($cats) eq 'ARRAY') {
5351: my $maxdepth = scalar(@{$cats});
5352: if (ref($cats->[$depth]) eq 'HASH') {
5353: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5354: my $numchildren = @{$cats->[$depth]{$parent}};
5355: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5356: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5357: my ($idxnum,$parent_name,$parent_item);
5358: my $higher = $depth - 1;
5359: if ($higher == 0) {
5360: $parent_name = &escape($parent).'::'.$higher;
5361: } else {
5362: if (ref($path) eq 'ARRAY') {
5363: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5364: }
5365: }
5366: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5367: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5368: if ($j < $numchildren) {
1.48 raeburn 5369: $name = $cats->[$depth]{$parent}[$j];
5370: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5371: $idxnum = $idx->{$item};
5372: } else {
5373: $name = $parent_name;
5374: $item = $parent_item;
1.48 raeburn 5375: }
1.49 raeburn 5376: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5377: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5378: for (my $i=0; $i<=$numchildren; $i++) {
5379: my $vpos = $i+1;
5380: my $selstr;
5381: if ($j == $i) {
5382: $selstr = ' selected="selected" ';
5383: }
5384: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5385: }
5386: $text .= '</select> ';
5387: if ($j < $numchildren) {
5388: my $deeper = $depth+1;
5389: $text .= $name.' '
5390: .'<label><input type="checkbox" name="deletecategory" value="'
5391: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5392: if(ref($path) eq 'ARRAY') {
5393: push(@{$path},$name);
1.49 raeburn 5394: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5395: pop(@{$path});
5396: }
5397: } else {
1.59 bisitz 5398: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5399: if ($j == $numchildren) {
5400: $text .= $name;
5401: } else {
5402: $text .= $item;
5403: }
5404: $text .= '" value="" />';
5405: }
5406: $text .= '</td></tr>';
5407: }
5408: $text .= '</table></td>';
5409: } else {
5410: my $higher = $depth-1;
5411: if ($higher == 0) {
5412: $name = &escape($parent).'::'.$higher;
5413: } else {
5414: if (ref($path) eq 'ARRAY') {
5415: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5416: }
5417: }
5418: my $colspan;
5419: if ($parent ne 'instcode') {
5420: $colspan = $maxdepth - $depth - 1;
5421: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5422: }
5423: }
5424: }
5425: }
5426: return $text;
5427: }
5428:
1.33 raeburn 5429: sub modifiable_userdata_row {
1.160.6.35 raeburn 5430: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5431: my ($role,$rolename,$statustype);
5432: $role = $item;
1.160.6.34 raeburn 5433: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5434: if ($item =~ /^emailusername_(.+)$/) {
5435: $statustype = $1;
5436: $role = 'emailusername';
5437: if (ref($usertypes) eq 'HASH') {
5438: if ($usertypes->{$statustype}) {
5439: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5440: } else {
5441: $rolename = &mt('Data provided by user');
5442: }
5443: }
1.160.6.34 raeburn 5444: }
5445: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5446: if (ref($usertypes) eq 'HASH') {
5447: $rolename = $usertypes->{$role};
5448: } else {
5449: $rolename = $role;
5450: }
1.33 raeburn 5451: } else {
1.63 raeburn 5452: if ($role eq 'cr') {
5453: $rolename = &mt('Custom role');
5454: } else {
5455: $rolename = &Apache::lonnet::plaintext($role);
5456: }
1.33 raeburn 5457: }
1.160.6.34 raeburn 5458: my (@fields,%fieldtitles);
5459: if (ref($fieldsref) eq 'ARRAY') {
5460: @fields = @{$fieldsref};
5461: } else {
5462: @fields = ('lastname','firstname','middlename','generation',
5463: 'permanentemail','id');
5464: }
5465: if ((ref($titlesref) eq 'HASH')) {
5466: %fieldtitles = %{$titlesref};
5467: } else {
5468: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5469: }
1.33 raeburn 5470: my $output;
5471: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5472: $output = '<tr '.$css_class.'>'.
5473: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5474: '<td class="LC_left_item" colspan="2"><table>';
5475: my $rem;
5476: my %checks;
5477: if (ref($settings) eq 'HASH') {
5478: if (ref($settings->{$context}) eq 'HASH') {
5479: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5480: my $hashref = $settings->{$context}->{$role};
5481: if ($role eq 'emailusername') {
5482: if ($statustype) {
5483: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5484: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5485: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5486: foreach my $field (@fields) {
5487: if ($hashref->{$field}) {
5488: $checks{$field} = $hashref->{$field};
5489: }
5490: }
5491: }
5492: }
5493: }
5494: } else {
5495: if (ref($hashref) eq 'HASH') {
5496: foreach my $field (@fields) {
5497: if ($hashref->{$field}) {
5498: $checks{$field} = ' checked="checked" ';
5499: }
5500: }
1.33 raeburn 5501: }
5502: }
5503: }
5504: }
5505: }
1.160.6.39 raeburn 5506:
1.33 raeburn 5507: for (my $i=0; $i<@fields; $i++) {
5508: my $rem = $i%($numinrow);
5509: if ($rem == 0) {
5510: if ($i > 0) {
5511: $output .= '</tr>';
5512: }
5513: $output .= '<tr>';
5514: }
5515: my $check = ' ';
1.160.6.35 raeburn 5516: unless ($role eq 'emailusername') {
5517: if (exists($checks{$fields[$i]})) {
5518: $check = $checks{$fields[$i]}
5519: } else {
5520: if ($role eq 'st') {
5521: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5522: $check = ' checked="checked" ';
1.160.6.35 raeburn 5523: }
1.33 raeburn 5524: }
5525: }
5526: }
5527: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5528: '<span class="LC_nobreak">';
5529: if ($role eq 'emailusername') {
5530: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5531: $checks{$fields[$i]} = 'omit';
5532: }
5533: foreach my $option ('required','optional','omit') {
5534: my $checked='';
5535: if ($checks{$fields[$i]} eq $option) {
5536: $checked='checked="checked" ';
5537: }
5538: $output .= '<label>'.
5539: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5540: &mt($option).'</label>'.(' ' x2);
5541: }
5542: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5543: } else {
5544: $output .= '<label>'.
5545: '<input type="checkbox" name="canmodify_'.$role.'" '.
5546: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5547: '</label>';
5548: }
5549: $output .= '</span></td>';
1.33 raeburn 5550: $rem = @fields%($numinrow);
5551: }
5552: my $colsleft = $numinrow - $rem;
5553: if ($colsleft > 1 ) {
5554: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5555: ' </td>';
5556: } elsif ($colsleft == 1) {
5557: $output .= '<td class="LC_left_item"> </td>';
5558: }
5559: $output .= '</tr></table></td></tr>';
5560: return $output;
5561: }
1.28 raeburn 5562:
1.93 raeburn 5563: sub insttypes_row {
1.160.6.34 raeburn 5564: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5565: my %lt = &Apache::lonlocal::texthash (
5566: cansearch => 'Users allowed to search',
5567: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5568: lockablenames => 'User preference to lock name',
1.93 raeburn 5569: );
5570: my $showdom;
5571: if ($context eq 'cansearch') {
5572: $showdom = ' ('.$dom.')';
5573: }
1.160.6.5 raeburn 5574: my $class = 'LC_left_item';
5575: if ($context eq 'statustocreate') {
5576: $class = 'LC_right_item';
5577: }
1.160.6.34 raeburn 5578: my $css_class = ' class="LC_odd_row"';
5579: if ($rownum ne '') {
5580: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5581: }
5582: my $output = '<tr'.$css_class.'>'.
5583: '<td>'.$lt{$context}.$showdom.
5584: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5585: my $rem;
5586: if (ref($types) eq 'ARRAY') {
5587: for (my $i=0; $i<@{$types}; $i++) {
5588: if (defined($usertypes->{$types->[$i]})) {
5589: my $rem = $i%($numinrow);
5590: if ($rem == 0) {
5591: if ($i > 0) {
5592: $output .= '</tr>';
5593: }
5594: $output .= '<tr>';
1.23 raeburn 5595: }
1.26 raeburn 5596: my $check = ' ';
1.99 raeburn 5597: if (ref($settings) eq 'HASH') {
5598: if (ref($settings->{$context}) eq 'ARRAY') {
5599: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5600: $check = ' checked="checked" ';
5601: }
5602: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5603: $check = ' checked="checked" ';
5604: }
1.23 raeburn 5605: }
1.26 raeburn 5606: $output .= '<td class="LC_left_item">'.
5607: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5608: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5609: 'value="'.$types->[$i].'"'.$check.'/>'.
5610: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5611: }
5612: }
1.26 raeburn 5613: $rem = @{$types}%($numinrow);
1.23 raeburn 5614: }
5615: my $colsleft = $numinrow - $rem;
1.131 raeburn 5616: if (($rem == 0) && (@{$types} > 0)) {
5617: $output .= '<tr>';
5618: }
1.23 raeburn 5619: if ($colsleft > 1) {
1.25 raeburn 5620: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5621: } else {
1.25 raeburn 5622: $output .= '<td class="LC_left_item">';
1.23 raeburn 5623: }
5624: my $defcheck = ' ';
1.99 raeburn 5625: if (ref($settings) eq 'HASH') {
5626: if (ref($settings->{$context}) eq 'ARRAY') {
5627: if (grep(/^default$/,@{$settings->{$context}})) {
5628: $defcheck = ' checked="checked" ';
5629: }
5630: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5631: $defcheck = ' checked="checked" ';
5632: }
1.23 raeburn 5633: }
1.25 raeburn 5634: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5635: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5636: 'value="default"'.$defcheck.'/>'.
5637: $othertitle.'</label></span></td>'.
5638: '</tr></table></td></tr>';
5639: return $output;
1.23 raeburn 5640: }
5641:
5642: sub sorted_searchtitles {
5643: my %searchtitles = &Apache::lonlocal::texthash(
5644: 'uname' => 'username',
5645: 'lastname' => 'last name',
5646: 'lastfirst' => 'last name, first name',
5647: );
5648: my @titleorder = ('uname','lastname','lastfirst');
5649: return (\%searchtitles,\@titleorder);
5650: }
5651:
1.25 raeburn 5652: sub sorted_searchtypes {
5653: my %srchtypes_desc = (
5654: exact => 'is exact match',
5655: contains => 'contains ..',
5656: begins => 'begins with ..',
5657: );
5658: my @srchtypeorder = ('exact','begins','contains');
5659: return (\%srchtypes_desc,\@srchtypeorder);
5660: }
5661:
1.3 raeburn 5662: sub usertype_update_row {
5663: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5664: my $datatable;
5665: my $numinrow = 4;
5666: foreach my $type (@{$types}) {
5667: if (defined($usertypes->{$type})) {
5668: $$rownums ++;
5669: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5670: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5671: '</td><td class="LC_left_item"><table>';
5672: for (my $i=0; $i<@{$fields}; $i++) {
5673: my $rem = $i%($numinrow);
5674: if ($rem == 0) {
5675: if ($i > 0) {
5676: $datatable .= '</tr>';
5677: }
5678: $datatable .= '<tr>';
5679: }
5680: my $check = ' ';
1.39 raeburn 5681: if (ref($settings) eq 'HASH') {
5682: if (ref($settings->{'fields'}) eq 'HASH') {
5683: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5684: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5685: $check = ' checked="checked" ';
5686: }
1.3 raeburn 5687: }
5688: }
5689: }
5690:
5691: if ($i == @{$fields}-1) {
5692: my $colsleft = $numinrow - $rem;
5693: if ($colsleft > 1) {
5694: $datatable .= '<td colspan="'.$colsleft.'">';
5695: } else {
5696: $datatable .= '<td>';
5697: }
5698: } else {
5699: $datatable .= '<td>';
5700: }
1.8 raeburn 5701: $datatable .= '<span class="LC_nobreak"><label>'.
5702: '<input type="checkbox" name="updateable_'.$type.
5703: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5704: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5705: }
5706: $datatable .= '</tr></table></td></tr>';
5707: }
5708: }
5709: return $datatable;
1.1 raeburn 5710: }
5711:
5712: sub modify_login {
1.160.6.24 raeburn 5713: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5714: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5715: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5716: %title = ( coursecatalog => 'Display course catalog',
5717: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5718: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5719: newuser => 'Link for visitors to create a user account',
5720: loginheader => 'Log-in box header');
5721: @offon = ('off','on');
1.112 raeburn 5722: if (ref($domconfig{login}) eq 'HASH') {
5723: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5724: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5725: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5726: }
5727: }
5728: }
1.9 raeburn 5729: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5730: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5731: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5732: foreach my $item (@toggles) {
5733: $loginhash{login}{$item} = $env{'form.'.$item};
5734: }
1.41 raeburn 5735: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5736: if (ref($colchanges{'login'}) eq 'HASH') {
5737: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5738: \%loginhash);
5739: }
1.110 raeburn 5740:
1.149 raeburn 5741: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5742: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5743: if (keys(%servers) > 1) {
5744: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5745: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5746: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5747: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5748: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5749: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5750: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5751: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5752: $changes{'loginvia'}{$lonhost} = 1;
5753: } else {
5754: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5755: $changes{'loginvia'}{$lonhost} = 1;
5756: }
5757: } else {
5758: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5759: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5760: $changes{'loginvia'}{$lonhost} = 1;
5761: }
5762: }
5763: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5764: foreach my $item (@loginvia_attribs) {
5765: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5766: }
5767: } else {
5768: foreach my $item (@loginvia_attribs) {
5769: my $new = $env{'form.'.$lonhost.'_'.$item};
5770: if (($item eq 'serverpath') && ($new eq 'custom')) {
5771: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5772: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5773: $new = '/';
5774: }
5775: }
5776: if (($item eq 'custompath') &&
5777: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5778: $new = '';
5779: }
5780: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5781: $changes{'loginvia'}{$lonhost} = 1;
5782: }
5783: if ($item eq 'exempt') {
5784: $new =~ s/^\s+//;
5785: $new =~ s/\s+$//;
5786: my @poss_ips = split(/\s*[,:]\s*/,$new);
5787: my @okips;
5788: foreach my $ip (@poss_ips) {
5789: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5790: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5791: push(@okips,$ip);
5792: }
5793: }
5794: }
5795: if (@okips > 0) {
5796: $new = join(',',@okips);
5797: } else {
5798: $new = '';
5799: }
5800: }
5801: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5802: }
5803: }
1.112 raeburn 5804: } else {
1.128 raeburn 5805: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5806: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5807: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5808: foreach my $item (@loginvia_attribs) {
5809: my $new = $env{'form.'.$lonhost.'_'.$item};
5810: if (($item eq 'serverpath') && ($new eq 'custom')) {
5811: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5812: $new = '/';
5813: }
5814: }
5815: if (($item eq 'custompath') &&
5816: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5817: $new = '';
5818: }
5819: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5820: }
1.110 raeburn 5821: }
5822: }
5823: }
5824: }
1.119 raeburn 5825:
1.160.6.5 raeburn 5826: my $servadm = $r->dir_config('lonAdmEMail');
5827: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5828: if (ref($domconfig{'login'}) eq 'HASH') {
5829: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5830: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5831: if ($lang eq 'nolang') {
5832: push(@currlangs,$lang);
5833: } elsif (defined($langchoices{$lang})) {
5834: push(@currlangs,$lang);
5835: } else {
5836: next;
5837: }
5838: }
5839: }
5840: }
5841: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5842: if (@currlangs > 0) {
5843: foreach my $lang (@currlangs) {
5844: if (grep(/^\Q$lang\E$/,@delurls)) {
5845: $changes{'helpurl'}{$lang} = 1;
5846: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5847: $changes{'helpurl'}{$lang} = 1;
5848: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5849: push(@newlangs,$lang);
5850: } else {
5851: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5852: }
5853: }
5854: }
5855: unless (grep(/^nolang$/,@currlangs)) {
5856: if ($env{'form.loginhelpurl_nolang.filename'}) {
5857: $changes{'helpurl'}{'nolang'} = 1;
5858: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5859: push(@newlangs,'nolang');
5860: }
5861: }
5862: if ($env{'form.loginhelpurl_add_lang'}) {
5863: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5864: ($env{'form.loginhelpurl_add_file.filename'})) {
5865: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5866: $addedfile = $env{'form.loginhelpurl_add_lang'};
5867: }
5868: }
5869: if ((@newlangs > 0) || ($addedfile)) {
5870: my $error;
5871: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5872: if ($configuserok eq 'ok') {
5873: if ($switchserver) {
5874: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5875: } elsif ($author_ok eq 'ok') {
5876: my @allnew = @newlangs;
5877: if ($addedfile ne '') {
5878: push(@allnew,$addedfile);
5879: }
5880: foreach my $lang (@allnew) {
5881: my $formelem = 'loginhelpurl_'.$lang;
5882: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5883: $formelem = 'loginhelpurl_add_file';
5884: }
5885: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5886: "help/$lang",'','',$newfile{$lang});
5887: if ($result eq 'ok') {
5888: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5889: $changes{'helpurl'}{$lang} = 1;
5890: } else {
5891: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5892: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5893: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5894: (!grep(/^\Q$lang\E$/,@delurls))) {
5895:
5896: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5897: }
5898: }
5899: }
5900: } else {
5901: $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);
5902: }
5903: } else {
5904: $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);
5905: }
5906: if ($error) {
5907: &Apache::lonnet::logthis($error);
5908: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5909: }
5910: }
5911: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5912:
5913: my $defaulthelpfile = '/adm/loginproblems.html';
5914: my $defaulttext = &mt('Default in use');
5915:
1.1 raeburn 5916: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5917: $dom);
5918: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5919: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5920: my %defaultchecked = (
5921: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5922: 'helpdesk' => 'on',
1.42 raeburn 5923: 'adminmail' => 'off',
1.43 raeburn 5924: 'newuser' => 'off',
1.42 raeburn 5925: );
1.55 raeburn 5926: if (ref($domconfig{'login'}) eq 'HASH') {
5927: foreach my $item (@toggles) {
5928: if ($defaultchecked{$item} eq 'on') {
5929: if (($domconfig{'login'}{$item} eq '0') &&
5930: ($env{'form.'.$item} eq '1')) {
5931: $changes{$item} = 1;
5932: } elsif (($domconfig{'login'}{$item} eq '' ||
5933: $domconfig{'login'}{$item} eq '1') &&
5934: ($env{'form.'.$item} eq '0')) {
5935: $changes{$item} = 1;
5936: }
5937: } elsif ($defaultchecked{$item} eq 'off') {
5938: if (($domconfig{'login'}{$item} eq '1') &&
5939: ($env{'form.'.$item} eq '0')) {
5940: $changes{$item} = 1;
5941: } elsif (($domconfig{'login'}{$item} eq '' ||
5942: $domconfig{'login'}{$item} eq '0') &&
5943: ($env{'form.'.$item} eq '1')) {
5944: $changes{$item} = 1;
5945: }
1.42 raeburn 5946: }
5947: }
1.41 raeburn 5948: }
1.6 raeburn 5949: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5950: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5951: if (ref($lastactref) eq 'HASH') {
5952: $lastactref->{'domainconfig'} = 1;
5953: }
1.1 raeburn 5954: $resulttext = &mt('Changes made:').'<ul>';
5955: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5956: if ($item eq 'loginvia') {
1.112 raeburn 5957: if (ref($changes{$item}) eq 'HASH') {
5958: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5959: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5960: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5961: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5962: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5963: $protocol = 'http' if ($protocol ne 'https');
5964: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5965:
5966: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5967: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5968: } else {
5969: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5970: }
5971: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5972: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5973: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5974: }
5975: $resulttext .= '</li>';
5976: } else {
5977: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5978: }
1.112 raeburn 5979: } else {
1.128 raeburn 5980: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5981: }
5982: }
1.128 raeburn 5983: $resulttext .= '</ul></li>';
1.112 raeburn 5984: }
1.160.6.5 raeburn 5985: } elsif ($item eq 'helpurl') {
5986: if (ref($changes{$item}) eq 'HASH') {
5987: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5988: if (grep(/^\Q$lang\E$/,@delurls)) {
5989: my ($chg,$link);
5990: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5991: if ($lang eq 'nolang') {
5992: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5993: } else {
5994: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5995: }
5996: $resulttext .= '<li>'.$chg.'</li>';
5997: } else {
5998: my $chg;
5999: if ($lang eq 'nolang') {
6000: $chg = &mt('custom log-in help file for no preferred language');
6001: } else {
6002: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6003: }
6004: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6005: $loginhash{'login'}{'helpurl'}{$lang}.
6006: '?inhibitmenu=yes',$chg,600,500).
6007: '</li>';
6008: }
6009: }
6010: }
6011: } elsif ($item eq 'captcha') {
6012: if (ref($loginhash{'login'}) eq 'HASH') {
6013: my $chgtxt;
6014: if ($loginhash{'login'}{$item} eq 'notused') {
6015: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6016: } else {
6017: my %captchas = &captcha_phrases();
6018: if ($captchas{$loginhash{'login'}{$item}}) {
6019: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6020: } else {
6021: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6022: }
6023: }
6024: $resulttext .= '<li>'.$chgtxt.'</li>';
6025: }
6026: } elsif ($item eq 'recaptchakeys') {
6027: if (ref($loginhash{'login'}) eq 'HASH') {
6028: my ($privkey,$pubkey);
6029: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6030: $pubkey = $loginhash{'login'}{$item}{'public'};
6031: $privkey = $loginhash{'login'}{$item}{'private'};
6032: }
6033: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6034: if (!$pubkey) {
6035: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6036: } else {
6037: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6038: }
6039: if (!$privkey) {
6040: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6041: } else {
6042: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6043: }
6044: $chgtxt .= '</ul>';
6045: $resulttext .= '<li>'.$chgtxt.'</li>';
6046: }
1.41 raeburn 6047: } else {
6048: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6049: }
1.1 raeburn 6050: }
1.6 raeburn 6051: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6052: } else {
6053: $resulttext = &mt('No changes made to log-in page settings');
6054: }
6055: } else {
1.11 albertel 6056: $resulttext = '<span class="LC_error">'.
6057: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6058: }
1.6 raeburn 6059: if ($errors) {
1.9 raeburn 6060: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6061: $errors.'</ul>';
6062: }
6063: return $resulttext;
6064: }
6065:
6066: sub color_font_choices {
6067: my %choices =
6068: &Apache::lonlocal::texthash (
6069: img => "Header",
6070: bgs => "Background colors",
6071: links => "Link colors",
1.55 raeburn 6072: images => "Images",
1.6 raeburn 6073: font => "Font color",
1.160.6.22 raeburn 6074: fontmenu => "Font menu",
1.76 raeburn 6075: pgbg => "Page",
1.6 raeburn 6076: tabbg => "Header",
6077: sidebg => "Border",
6078: link => "Link",
6079: alink => "Active link",
6080: vlink => "Visited link",
6081: );
6082: return %choices;
6083: }
6084:
6085: sub modify_rolecolors {
1.160.6.24 raeburn 6086: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6087: my ($resulttext,%rolehash);
6088: $rolehash{'rolecolors'} = {};
1.55 raeburn 6089: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6090: if ($domconfig{'rolecolors'} eq '') {
6091: $domconfig{'rolecolors'} = {};
6092: }
6093: }
1.9 raeburn 6094: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6095: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6096: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6097: $dom);
6098: if ($putresult eq 'ok') {
6099: if (keys(%changes) > 0) {
1.41 raeburn 6100: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6101: if (ref($lastactref) eq 'HASH') {
6102: $lastactref->{'domainconfig'} = 1;
6103: }
1.6 raeburn 6104: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6105: $rolehash{'rolecolors'});
6106: } else {
6107: $resulttext = &mt('No changes made to default color schemes');
6108: }
6109: } else {
1.11 albertel 6110: $resulttext = '<span class="LC_error">'.
6111: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6112: }
6113: if ($errors) {
6114: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6115: $errors.'</ul>';
6116: }
6117: return $resulttext;
6118: }
6119:
6120: sub modify_colors {
1.9 raeburn 6121: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6122: my (%changes,%choices);
1.51 raeburn 6123: my @bgs;
1.6 raeburn 6124: my @links = ('link','alink','vlink');
1.41 raeburn 6125: my @logintext;
1.6 raeburn 6126: my @images;
6127: my $servadm = $r->dir_config('lonAdmEMail');
6128: my $errors;
1.160.6.22 raeburn 6129: my %defaults;
1.6 raeburn 6130: foreach my $role (@{$roles}) {
6131: if ($role eq 'login') {
1.12 raeburn 6132: %choices = &login_choices();
1.41 raeburn 6133: @logintext = ('textcol','bgcol');
1.12 raeburn 6134: } else {
6135: %choices = &color_font_choices();
6136: }
6137: if ($role eq 'login') {
1.41 raeburn 6138: @images = ('img','logo','domlogo','login');
1.51 raeburn 6139: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6140: } else {
6141: @images = ('img');
1.160.6.22 raeburn 6142: @bgs = ('pgbg','tabbg','sidebg');
6143: }
6144: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6145: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6146: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6147: }
6148: if ($role eq 'login') {
6149: foreach my $item (@logintext) {
1.160.6.39 raeburn 6150: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6151: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6152: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6153: }
6154: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6155: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6156: }
6157: }
6158: } else {
1.160.6.39 raeburn 6159: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6160: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6161: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6162: }
6163: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6164: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6165: }
1.6 raeburn 6166: }
1.160.6.22 raeburn 6167: foreach my $item (@bgs) {
1.160.6.39 raeburn 6168: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6169: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6170: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6171: }
6172: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6173: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6174: }
6175: }
6176: foreach my $item (@links) {
1.160.6.39 raeburn 6177: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6178: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6179: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6180: }
6181: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6182: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6183: }
1.6 raeburn 6184: }
1.46 raeburn 6185: my ($configuserok,$author_ok,$switchserver) =
6186: &config_check($dom,$confname,$servadm);
1.9 raeburn 6187: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6188: if (ref($domconfig->{$role}) ne 'HASH') {
6189: $domconfig->{$role} = {};
6190: }
1.8 raeburn 6191: foreach my $img (@images) {
1.70 raeburn 6192: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6193: if (defined($env{'form.login_showlogo_'.$img})) {
6194: $confhash->{$role}{'showlogo'}{$img} = 1;
6195: } else {
6196: $confhash->{$role}{'showlogo'}{$img} = 0;
6197: }
6198: }
1.18 albertel 6199: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6200: && !defined($domconfig->{$role}{$img})
6201: && !$env{'form.'.$role.'_del_'.$img}
6202: && $env{'form.'.$role.'_import_'.$img}) {
6203: # import the old configured image from the .tab setting
6204: # if they haven't provided a new one
6205: $domconfig->{$role}{$img} =
6206: $env{'form.'.$role.'_import_'.$img};
6207: }
1.6 raeburn 6208: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6209: my $error;
1.6 raeburn 6210: if ($configuserok eq 'ok') {
1.9 raeburn 6211: if ($switchserver) {
1.12 raeburn 6212: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6213: } else {
6214: if ($author_ok eq 'ok') {
6215: my ($result,$logourl) =
6216: &publishlogo($r,'upload',$role.'_'.$img,
6217: $dom,$confname,$img,$width,$height);
6218: if ($result eq 'ok') {
6219: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6220: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6221: } else {
1.12 raeburn 6222: $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 6223: }
6224: } else {
1.46 raeburn 6225: $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 6226: }
6227: }
6228: } else {
1.46 raeburn 6229: $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 6230: }
6231: if ($error) {
1.8 raeburn 6232: &Apache::lonnet::logthis($error);
1.11 albertel 6233: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6234: }
6235: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6236: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6237: my $error;
6238: if ($configuserok eq 'ok') {
6239: # is confname an author?
6240: if ($switchserver eq '') {
6241: if ($author_ok eq 'ok') {
6242: my ($result,$logourl) =
6243: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6244: $dom,$confname,$img,$width,$height);
6245: if ($result eq 'ok') {
6246: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6247: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6248: }
6249: }
6250: }
6251: }
1.6 raeburn 6252: }
6253: }
6254: }
6255: if (ref($domconfig) eq 'HASH') {
6256: if (ref($domconfig->{$role}) eq 'HASH') {
6257: foreach my $img (@images) {
6258: if ($domconfig->{$role}{$img} ne '') {
6259: if ($env{'form.'.$role.'_del_'.$img}) {
6260: $confhash->{$role}{$img} = '';
1.12 raeburn 6261: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6262: } else {
1.9 raeburn 6263: if ($confhash->{$role}{$img} eq '') {
6264: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6265: }
1.6 raeburn 6266: }
6267: } else {
6268: if ($env{'form.'.$role.'_del_'.$img}) {
6269: $confhash->{$role}{$img} = '';
1.12 raeburn 6270: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6271: }
6272: }
1.70 raeburn 6273: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6274: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6275: if ($confhash->{$role}{'showlogo'}{$img} ne
6276: $domconfig->{$role}{'showlogo'}{$img}) {
6277: $changes{$role}{'showlogo'}{$img} = 1;
6278: }
6279: } else {
6280: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6281: $changes{$role}{'showlogo'}{$img} = 1;
6282: }
6283: }
6284: }
6285: }
1.6 raeburn 6286: if ($domconfig->{$role}{'font'} ne '') {
6287: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6288: $changes{$role}{'font'} = 1;
6289: }
6290: } else {
6291: if ($confhash->{$role}{'font'}) {
6292: $changes{$role}{'font'} = 1;
6293: }
6294: }
1.107 raeburn 6295: if ($role ne 'login') {
6296: if ($domconfig->{$role}{'fontmenu'} ne '') {
6297: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6298: $changes{$role}{'fontmenu'} = 1;
6299: }
6300: } else {
6301: if ($confhash->{$role}{'fontmenu'}) {
6302: $changes{$role}{'fontmenu'} = 1;
6303: }
1.97 tempelho 6304: }
6305: }
1.6 raeburn 6306: foreach my $item (@bgs) {
6307: if ($domconfig->{$role}{$item} ne '') {
6308: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6309: $changes{$role}{'bgs'}{$item} = 1;
6310: }
6311: } else {
6312: if ($confhash->{$role}{$item}) {
6313: $changes{$role}{'bgs'}{$item} = 1;
6314: }
6315: }
6316: }
6317: foreach my $item (@links) {
6318: if ($domconfig->{$role}{$item} ne '') {
6319: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6320: $changes{$role}{'links'}{$item} = 1;
6321: }
6322: } else {
6323: if ($confhash->{$role}{$item}) {
6324: $changes{$role}{'links'}{$item} = 1;
6325: }
6326: }
6327: }
1.41 raeburn 6328: foreach my $item (@logintext) {
6329: if ($domconfig->{$role}{$item} ne '') {
6330: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6331: $changes{$role}{'logintext'}{$item} = 1;
6332: }
6333: } else {
6334: if ($confhash->{$role}{$item}) {
6335: $changes{$role}{'logintext'}{$item} = 1;
6336: }
6337: }
6338: }
1.6 raeburn 6339: } else {
6340: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6341: \@logintext,$confhash,\%changes);
1.6 raeburn 6342: }
6343: } else {
6344: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6345: \@logintext,$confhash,\%changes);
1.6 raeburn 6346: }
6347: }
6348: return ($errors,%changes);
6349: }
6350:
1.46 raeburn 6351: sub config_check {
6352: my ($dom,$confname,$servadm) = @_;
6353: my ($configuserok,$author_ok,$switchserver,%currroles);
6354: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6355: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6356: $confname,$servadm);
6357: if ($configuserok eq 'ok') {
6358: $switchserver = &check_switchserver($dom,$confname);
6359: if ($switchserver eq '') {
6360: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6361: }
6362: }
6363: return ($configuserok,$author_ok,$switchserver);
6364: }
6365:
1.6 raeburn 6366: sub default_change_checker {
1.41 raeburn 6367: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6368: foreach my $item (@{$links}) {
6369: if ($confhash->{$role}{$item}) {
6370: $changes->{$role}{'links'}{$item} = 1;
6371: }
6372: }
6373: foreach my $item (@{$bgs}) {
6374: if ($confhash->{$role}{$item}) {
6375: $changes->{$role}{'bgs'}{$item} = 1;
6376: }
6377: }
1.41 raeburn 6378: foreach my $item (@{$logintext}) {
6379: if ($confhash->{$role}{$item}) {
6380: $changes->{$role}{'logintext'}{$item} = 1;
6381: }
6382: }
1.6 raeburn 6383: foreach my $img (@{$images}) {
6384: if ($env{'form.'.$role.'_del_'.$img}) {
6385: $confhash->{$role}{$img} = '';
1.12 raeburn 6386: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6387: }
1.70 raeburn 6388: if ($role eq 'login') {
6389: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6390: $changes->{$role}{'showlogo'}{$img} = 1;
6391: }
6392: }
1.6 raeburn 6393: }
6394: if ($confhash->{$role}{'font'}) {
6395: $changes->{$role}{'font'} = 1;
6396: }
1.48 raeburn 6397: }
1.6 raeburn 6398:
6399: sub display_colorchgs {
6400: my ($dom,$changes,$roles,$confhash) = @_;
6401: my (%choices,$resulttext);
6402: if (!grep(/^login$/,@{$roles})) {
6403: $resulttext = &mt('Changes made:').'<br />';
6404: }
6405: foreach my $role (@{$roles}) {
6406: if ($role eq 'login') {
6407: %choices = &login_choices();
6408: } else {
6409: %choices = &color_font_choices();
6410: }
6411: if (ref($changes->{$role}) eq 'HASH') {
6412: if ($role ne 'login') {
6413: $resulttext .= '<h4>'.&mt($role).'</h4>';
6414: }
6415: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6416: if ($role ne 'login') {
6417: $resulttext .= '<ul>';
6418: }
6419: if (ref($changes->{$role}{$key}) eq 'HASH') {
6420: if ($role ne 'login') {
6421: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6422: }
6423: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6424: if (($role eq 'login') && ($key eq 'showlogo')) {
6425: if ($confhash->{$role}{$key}{$item}) {
6426: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6427: } else {
6428: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6429: }
6430: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6431: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6432: } else {
1.12 raeburn 6433: my $newitem = $confhash->{$role}{$item};
6434: if ($key eq 'images') {
6435: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6436: }
6437: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6438: }
6439: }
6440: if ($role ne 'login') {
6441: $resulttext .= '</ul></li>';
6442: }
6443: } else {
6444: if ($confhash->{$role}{$key} eq '') {
6445: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6446: } else {
6447: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6448: }
6449: }
6450: if ($role ne 'login') {
6451: $resulttext .= '</ul>';
6452: }
6453: }
6454: }
6455: }
1.3 raeburn 6456: return $resulttext;
1.1 raeburn 6457: }
6458:
1.9 raeburn 6459: sub thumb_dimensions {
6460: return ('200','50');
6461: }
6462:
1.16 raeburn 6463: sub check_dimensions {
6464: my ($inputfile) = @_;
6465: my ($fullwidth,$fullheight);
6466: if ($inputfile =~ m|^[/\w.\-]+$|) {
6467: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6468: my $imageinfo = <PIPE>;
6469: if (!close(PIPE)) {
6470: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6471: }
6472: chomp($imageinfo);
6473: my ($fullsize) =
1.21 raeburn 6474: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6475: if ($fullsize) {
6476: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6477: }
6478: }
6479: }
6480: return ($fullwidth,$fullheight);
6481: }
6482:
1.9 raeburn 6483: sub check_configuser {
6484: my ($uhome,$dom,$confname,$servadm) = @_;
6485: my ($configuserok,%currroles);
6486: if ($uhome eq 'no_host') {
6487: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6488: my $configpass = &LONCAPA::Enrollment::create_password();
6489: $configuserok =
6490: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6491: $configpass,'','','','','',undef,$servadm);
6492: } else {
6493: $configuserok = 'ok';
6494: %currroles =
6495: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6496: }
6497: return ($configuserok,%currroles);
6498: }
6499:
6500: sub check_authorstatus {
6501: my ($dom,$confname,%currroles) = @_;
6502: my $author_ok;
1.40 raeburn 6503: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6504: my $start = time;
6505: my $end = 0;
6506: $author_ok =
6507: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6508: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6509: } else {
6510: $author_ok = 'ok';
6511: }
6512: return $author_ok;
6513: }
6514:
6515: sub publishlogo {
1.46 raeburn 6516: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6517: my ($output,$fname,$logourl);
6518: if ($action eq 'upload') {
6519: $fname=$env{'form.'.$formname.'.filename'};
6520: chop($env{'form.'.$formname});
6521: } else {
6522: ($fname) = ($formname =~ /([^\/]+)$/);
6523: }
1.46 raeburn 6524: if ($savefileas ne '') {
6525: $fname = $savefileas;
6526: }
1.9 raeburn 6527: $fname=&Apache::lonnet::clean_filename($fname);
6528: # See if there is anything left
6529: unless ($fname) { return ('error: no uploaded file'); }
6530: $fname="$subdir/$fname";
1.160.6.5 raeburn 6531: my $docroot=$r->dir_config('lonDocRoot');
6532: my $filepath="$docroot/priv";
6533: my $relpath = "$dom/$confname";
1.9 raeburn 6534: my ($fnamepath,$file,$fetchthumb);
6535: $file=$fname;
6536: if ($fname=~m|/|) {
6537: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6538: }
1.160.6.26 raeburn 6539: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6540: my $count;
1.160.6.5 raeburn 6541: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6542: $filepath.="/$parts[$count]";
6543: if ((-e $filepath)!=1) {
6544: mkdir($filepath,02770);
6545: }
6546: }
6547: # Check for bad extension and disallow upload
6548: if ($file=~/\.(\w+)$/ &&
6549: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6550: $output =
1.160.6.25 raeburn 6551: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6552: } elsif ($file=~/\.(\w+)$/ &&
6553: !defined(&Apache::loncommon::fileembstyle($1))) {
6554: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6555: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6556: $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 6557: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6558: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6559: } else {
6560: my $source = $filepath.'/'.$file;
6561: my $logfile;
6562: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6563: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6564: }
6565: print $logfile
6566: "\n================= Publish ".localtime()." ================\n".
6567: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6568: # Save the file
6569: if (!open(FH,'>'.$source)) {
6570: &Apache::lonnet::logthis('Failed to create '.$source);
6571: return (&mt('Failed to create file'));
6572: }
6573: if ($action eq 'upload') {
6574: if (!print FH ($env{'form.'.$formname})) {
6575: &Apache::lonnet::logthis('Failed to write to '.$source);
6576: return (&mt('Failed to write file'));
6577: }
6578: } else {
6579: my $original = &Apache::lonnet::filelocation('',$formname);
6580: if(!copy($original,$source)) {
6581: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6582: return (&mt('Failed to write file'));
6583: }
6584: }
6585: close(FH);
6586: chmod(0660, $source); # Permissions to rw-rw---.
6587:
6588: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6589: my $copyfile=$targetdir.'/'.$file;
6590:
6591: my @parts=split(/\//,$targetdir);
6592: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6593: for (my $count=5;$count<=$#parts;$count++) {
6594: $path.="/$parts[$count]";
6595: if (!-e $path) {
6596: print $logfile "\nCreating directory ".$path;
6597: mkdir($path,02770);
6598: }
6599: }
6600: my $versionresult;
6601: if (-e $copyfile) {
6602: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6603: } else {
6604: $versionresult = 'ok';
6605: }
6606: if ($versionresult eq 'ok') {
6607: if (copy($source,$copyfile)) {
6608: print $logfile "\nCopied original source to ".$copyfile."\n";
6609: $output = 'ok';
6610: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6611: push(@{$modified_urls},[$copyfile,$source]);
6612: my $metaoutput =
6613: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6614: unless ($registered_cleanup) {
6615: my $handlers = $r->get_handlers('PerlCleanupHandler');
6616: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6617: $registered_cleanup=1;
6618: }
1.9 raeburn 6619: } else {
6620: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6621: $output = &mt('Failed to copy file to RES space').", $!";
6622: }
6623: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6624: my $inputfile = $filepath.'/'.$file;
6625: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6626: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6627: if ($fullwidth ne '' && $fullheight ne '') {
6628: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6629: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6630: system("convert -sample $thumbsize $inputfile $outfile");
6631: chmod(0660, $filepath.'/tn-'.$file);
6632: if (-e $outfile) {
6633: my $copyfile=$targetdir.'/tn-'.$file;
6634: if (copy($outfile,$copyfile)) {
6635: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6636: my $thumb_metaoutput =
6637: &write_metadata($dom,$confname,$formname,
6638: $targetdir,'tn-'.$file,$logfile);
6639: push(@{$modified_urls},[$copyfile,$outfile]);
6640: unless ($registered_cleanup) {
6641: my $handlers = $r->get_handlers('PerlCleanupHandler');
6642: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6643: $registered_cleanup=1;
6644: }
1.16 raeburn 6645: } else {
6646: print $logfile "\nUnable to write ".$copyfile.
6647: ':'.$!."\n";
6648: }
6649: }
1.9 raeburn 6650: }
6651: }
6652: }
6653: } else {
6654: $output = $versionresult;
6655: }
6656: }
6657: return ($output,$logourl);
6658: }
6659:
6660: sub logo_versioning {
6661: my ($targetdir,$file,$logfile) = @_;
6662: my $target = $targetdir.'/'.$file;
6663: my ($maxversion,$fn,$extn,$output);
6664: $maxversion = 0;
6665: if ($file =~ /^(.+)\.(\w+)$/) {
6666: $fn=$1;
6667: $extn=$2;
6668: }
6669: opendir(DIR,$targetdir);
6670: while (my $filename=readdir(DIR)) {
6671: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6672: $maxversion=($1>$maxversion)?$1:$maxversion;
6673: }
6674: }
6675: $maxversion++;
6676: print $logfile "\nCreating old version ".$maxversion."\n";
6677: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6678: if (copy($target,$copyfile)) {
6679: print $logfile "Copied old target to ".$copyfile."\n";
6680: $copyfile=$copyfile.'.meta';
6681: if (copy($target.'.meta',$copyfile)) {
6682: print $logfile "Copied old target metadata to ".$copyfile."\n";
6683: $output = 'ok';
6684: } else {
6685: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6686: $output = &mt('Failed to copy old meta').", $!, ";
6687: }
6688: } else {
6689: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6690: $output = &mt('Failed to copy old target').", $!, ";
6691: }
6692: return $output;
6693: }
6694:
6695: sub write_metadata {
6696: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6697: my (%metadatafields,%metadatakeys,$output);
6698: $metadatafields{'title'}=$formname;
6699: $metadatafields{'creationdate'}=time;
6700: $metadatafields{'lastrevisiondate'}=time;
6701: $metadatafields{'copyright'}='public';
6702: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6703: $env{'user.domain'};
6704: $metadatafields{'authorspace'}=$confname.':'.$dom;
6705: $metadatafields{'domain'}=$dom;
6706: {
6707: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6708: my $mfh;
1.155 raeburn 6709: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6710: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6711: unless ($_=~/\./) {
6712: my $unikey=$_;
6713: $unikey=~/^([A-Za-z]+)/;
6714: my $tag=$1;
6715: $tag=~tr/A-Z/a-z/;
6716: print $mfh "\n\<$tag";
6717: foreach (split(/\,/,$metadatakeys{$unikey})) {
6718: my $value=$metadatafields{$unikey.'.'.$_};
6719: $value=~s/\"/\'\'/g;
6720: print $mfh ' '.$_.'="'.$value.'"';
6721: }
6722: print $mfh '>'.
6723: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6724: .'</'.$tag.'>';
6725: }
6726: }
6727: $output = 'ok';
6728: print $logfile "\nWrote metadata";
6729: close($mfh);
6730: } else {
6731: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6732: $output = &mt('Could not write metadata');
6733: }
6734: }
1.155 raeburn 6735: return $output;
6736: }
6737:
6738: sub notifysubscribed {
6739: foreach my $targetsource (@{$modified_urls}){
6740: next unless (ref($targetsource) eq 'ARRAY');
6741: my ($target,$source)=@{$targetsource};
6742: if ($source ne '') {
6743: if (open(my $logfh,'>>'.$source.'.log')) {
6744: print $logfh "\nCleanup phase: Notifications\n";
6745: my @subscribed=&subscribed_hosts($target);
6746: foreach my $subhost (@subscribed) {
6747: print $logfh "\nNotifying host ".$subhost.':';
6748: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6749: print $logfh $reply;
6750: }
6751: my @subscribedmeta=&subscribed_hosts("$target.meta");
6752: foreach my $subhost (@subscribedmeta) {
6753: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6754: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6755: $subhost);
6756: print $logfh $reply;
6757: }
6758: print $logfh "\n============ Done ============\n";
1.160 raeburn 6759: close($logfh);
1.155 raeburn 6760: }
6761: }
6762: }
6763: return OK;
6764: }
6765:
6766: sub subscribed_hosts {
6767: my ($target) = @_;
6768: my @subscribed;
6769: if (open(my $fh,"<$target.subscription")) {
6770: while (my $subline=<$fh>) {
6771: if ($subline =~ /^($match_lonid):/) {
6772: my $host = $1;
6773: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6774: unless (grep(/^\Q$host\E$/,@subscribed)) {
6775: push(@subscribed,$host);
6776: }
6777: }
6778: }
6779: }
6780: }
6781: return @subscribed;
1.9 raeburn 6782: }
6783:
6784: sub check_switchserver {
6785: my ($dom,$confname) = @_;
6786: my ($allowed,$switchserver);
6787: my $home = &Apache::lonnet::homeserver($confname,$dom);
6788: if ($home eq 'no_host') {
6789: $home = &Apache::lonnet::domain($dom,'primary');
6790: }
6791: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6792: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6793: if (!$allowed) {
1.160.6.11 raeburn 6794: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6795: }
6796: return $switchserver;
6797: }
6798:
1.1 raeburn 6799: sub modify_quotas {
1.160.6.30 raeburn 6800: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6801: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6802: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6803: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6804: $validationfieldsref);
1.86 raeburn 6805: if ($action eq 'quotas') {
6806: $context = 'tools';
1.160.6.26 raeburn 6807: } else {
1.86 raeburn 6808: $context = $action;
6809: }
6810: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6811: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6812: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6813: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6814: %titles = &courserequest_titles();
6815: $toolregexp = join('|',@usertools);
6816: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6817: $confname = $dom.'-domainconfig';
6818: my $servadm = $r->dir_config('lonAdmEMail');
6819: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6820: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6821: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6822: } elsif ($context eq 'requestauthor') {
6823: @usertools = ('author');
6824: %titles = &authorrequest_titles();
1.86 raeburn 6825: } else {
1.160.6.4 raeburn 6826: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6827: %titles = &tool_titles();
1.86 raeburn 6828: }
1.160.6.27 raeburn 6829: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6830: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6831: foreach my $key (keys(%env)) {
1.101 raeburn 6832: if ($context eq 'requestcourses') {
6833: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6834: my $item = $1;
6835: my $type = $2;
6836: if ($type =~ /^limit_(.+)/) {
6837: $limithash{$item}{$1} = $env{$key};
6838: } else {
6839: $confhash{$item}{$type} = $env{$key};
6840: }
6841: }
1.160.6.5 raeburn 6842: } elsif ($context eq 'requestauthor') {
6843: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6844: $confhash{$1} = $env{$key};
6845: }
1.101 raeburn 6846: } else {
1.86 raeburn 6847: if ($key =~ /^form\.quota_(.+)$/) {
6848: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6849: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6850: $confhash{'authorquota'}{$1} = $env{$key};
6851: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6852: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6853: }
1.72 raeburn 6854: }
6855: }
1.160.6.5 raeburn 6856: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6857: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6858: @approvalnotify = sort(@approvalnotify);
6859: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6860: my @crstypes = ('official','unofficial','community','textbook');
6861: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6862: foreach my $type (@hasuniquecode) {
6863: if (grep(/^\Q$type\E$/,@crstypes)) {
6864: $confhash{'uniquecode'}{$type} = 1;
6865: }
6866: }
1.160.6.46! raeburn 6867: my (%newbook,%allpos);
1.160.6.30 raeburn 6868: if ($context eq 'requestcourses') {
1.160.6.46! raeburn 6869: foreach my $type ('textbooks','templates') {
! 6870: @{$allpos{$type}} = ();
! 6871: my $invalid;
! 6872: if ($type eq 'textbooks') {
! 6873: $invalid = &mt('Invalid LON-CAPA course for textbook');
! 6874: } else {
! 6875: $invalid = &mt('Invalid LON-CAPA course for template');
! 6876: }
! 6877: if ($env{'form.'.$type.'_addbook'}) {
! 6878: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
! 6879: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
! 6880: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
! 6881: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
! 6882: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
! 6883: } else {
! 6884: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
! 6885: my $position = $env{'form.'.$type.'_addbook_pos'};
! 6886: $position =~ s/\D+//g;
! 6887: if ($position ne '') {
! 6888: $allpos{$type}[$position] = $newbook{$type};
! 6889: }
1.160.6.30 raeburn 6890: }
1.160.6.46! raeburn 6891: } else {
! 6892: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 6893: }
6894: }
1.160.6.46! raeburn 6895: }
1.160.6.30 raeburn 6896: }
1.102 raeburn 6897: if (ref($domconfig{$action}) eq 'HASH') {
6898: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6899: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6900: $changes{'notify'}{'approval'} = 1;
6901: }
6902: } else {
1.144 raeburn 6903: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6904: $changes{'notify'}{'approval'} = 1;
6905: }
6906: }
1.160.6.30 raeburn 6907: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6908: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6909: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6910: unless ($confhash{'uniquecode'}{$crstype}) {
6911: $changes{'uniquecode'} = 1;
6912: }
6913: }
6914: unless ($changes{'uniquecode'}) {
6915: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6916: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6917: $changes{'uniquecode'} = 1;
6918: }
6919: }
6920: }
6921: } else {
6922: $changes{'uniquecode'} = 1;
6923: }
6924: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6925: $changes{'uniquecode'} = 1;
6926: }
6927: if ($context eq 'requestcourses') {
1.160.6.46! raeburn 6928: foreach my $type ('textbooks','templates') {
! 6929: if (ref($domconfig{$action}{$type}) eq 'HASH') {
! 6930: my %deletions;
! 6931: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
! 6932: if (@todelete) {
! 6933: map { $deletions{$_} = 1; } @todelete;
! 6934: }
! 6935: my %imgdeletions;
! 6936: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
! 6937: if (@todeleteimages) {
! 6938: map { $imgdeletions{$_} = 1; } @todeleteimages;
! 6939: }
! 6940: my $maxnum = $env{'form.'.$type.'_maxnum'};
! 6941: for (my $i=0; $i<=$maxnum; $i++) {
! 6942: my $itemid = $env{'form.'.$type.'_id_'.$i};
! 6943: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
! 6944: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
! 6945: if ($deletions{$key}) {
! 6946: if ($domconfig{$action}{$type}{$key}{'image'}) {
! 6947: #FIXME need to obsolete item in RES space
! 6948: }
! 6949: next;
! 6950: } else {
! 6951: my $newpos = $env{'form.'.$itemid};
! 6952: $newpos =~ s/\D+//g;
! 6953: foreach my $item ('subject','title','author') {
! 6954: next if (($item eq 'author') && ($type eq 'templates'));
! 6955: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
! 6956: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
! 6957: $changes{$type}{$key} = 1;
! 6958: }
! 6959: }
! 6960: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 6961: }
1.160.6.46! raeburn 6962: if ($imgdeletions{$key}) {
! 6963: $changes{$type}{$key} = 1;
! 6964: #FIXME need to obsolete item in RES space
! 6965: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
! 6966: my ($cdom,$cnum) = split(/_/,$key);
! 6967: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
! 6968: $cdom,$cnum,$type,$configuserok,
! 6969: $switchserver,$author_ok);
! 6970: if ($imgurl) {
! 6971: $confhash{$type}{$key}{'image'} = $imgurl;
! 6972: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 6973: }
1.160.6.46! raeburn 6974: if ($error) {
! 6975: &Apache::lonnet::logthis($error);
! 6976: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6977: }
! 6978: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
! 6979: $confhash{$type}{$key}{'image'} =
! 6980: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 6981: }
6982: }
6983: }
6984: }
6985: }
6986: }
1.102 raeburn 6987: } else {
1.144 raeburn 6988: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6989: $changes{'notify'}{'approval'} = 1;
6990: }
1.160.6.30 raeburn 6991: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6992: $changes{'uniquecode'} = 1;
6993: }
6994: }
6995: if ($context eq 'requestcourses') {
1.160.6.46! raeburn 6996: foreach my $type ('textbooks','templates') {
! 6997: if ($newbook{$type}) {
! 6998: $changes{$type}{$newbook{$type}} = 1;
! 6999: foreach my $item ('subject','title','author') {
! 7000: next if (($item eq 'author') && ($type eq 'template'));
! 7001: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
! 7002: if ($env{'form.'.$type.'_addbook_'.$item}) {
! 7003: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
! 7004: }
! 7005: }
! 7006: if ($type eq 'textbooks') {
! 7007: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
! 7008: my ($cdom,$cnum) = split(/_/,$newbook{$type});
! 7009: my ($imageurl,$error) =
! 7010: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
! 7011: $configuserok,$switchserver,$author_ok);
! 7012: if ($imageurl) {
! 7013: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
! 7014: }
! 7015: if ($error) {
! 7016: &Apache::lonnet::logthis($error);
! 7017: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 7018: }
! 7019: }
1.160.6.30 raeburn 7020: }
7021: }
1.160.6.46! raeburn 7022: if (@{$allpos{$type}} > 0) {
! 7023: my $idx = 0;
! 7024: foreach my $item (@{$allpos{$type}}) {
! 7025: if ($item ne '') {
! 7026: $confhash{$type}{$item}{'order'} = $idx;
! 7027: if (ref($domconfig{$action}) eq 'HASH') {
! 7028: if (ref($domconfig{$action}{$type}) eq 'HASH') {
! 7029: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
! 7030: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
! 7031: $changes{$type}{$item} = 1;
! 7032: }
1.160.6.30 raeburn 7033: }
7034: }
7035: }
1.160.6.46! raeburn 7036: $idx ++;
1.160.6.30 raeburn 7037: }
7038: }
7039: }
7040: }
1.160.6.39 raeburn 7041: if (ref($validationitemsref) eq 'ARRAY') {
7042: foreach my $item (@{$validationitemsref}) {
7043: if ($item eq 'fields') {
7044: my @changed;
7045: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7046: if (@{$confhash{'validation'}{$item}} > 0) {
7047: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7048: }
7049: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7050: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7051: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7052: $domconfig{'requestcourses'}{'validation'}{$item});
7053: } else {
7054: @changed = @{$confhash{'validation'}{$item}};
7055: }
7056: } else {
7057: @changed = @{$confhash{'validation'}{$item}};
7058: }
7059: if (@changed) {
7060: if ($confhash{'validation'}{$item}) {
7061: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7062: } else {
7063: $changes{'validation'}{$item} = &mt('None');
7064: }
7065: }
7066: } else {
7067: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7068: if ($item eq 'markup') {
7069: if ($env{'form.requestcourses_validation_'.$item}) {
7070: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7071: }
7072: }
7073: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7074: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7075: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7076: }
7077: } else {
7078: if ($confhash{'validation'}{$item} ne '') {
7079: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7080: }
7081: }
7082: }
7083: }
7084: }
7085: if ($env{'form.validationdc'}) {
7086: my $newval = $env{'form.validationdc'};
7087: my %domcoords = &get_active_dcs($dom);
7088: if (exists($domcoords{$newval})) {
7089: $confhash{'validation'}{'dc'} = $newval;
7090: }
7091: }
7092: if (ref($confhash{'validation'}) eq 'HASH') {
7093: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7094: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7095: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7096: if ($confhash{'validation'}{'dc'} eq '') {
7097: $changes{'validation'}{'dc'} = &mt('None');
7098: } else {
7099: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7100: }
7101: }
7102: } elsif ($confhash{'validation'}{'dc'} ne '') {
7103: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7104: }
7105: } elsif ($confhash{'validation'}{'dc'} ne '') {
7106: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7107: }
7108: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7109: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7110: $changes{'validation'}{'dc'} = &mt('None');
7111: }
7112: }
1.102 raeburn 7113: }
7114: } else {
1.86 raeburn 7115: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7116: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7117: }
1.72 raeburn 7118: foreach my $item (@usertools) {
7119: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7120: my $unset;
1.101 raeburn 7121: if ($context eq 'requestcourses') {
1.104 raeburn 7122: $unset = '0';
7123: if ($type eq '_LC_adv') {
7124: $unset = '';
7125: }
1.101 raeburn 7126: if ($confhash{$item}{$type} eq 'autolimit') {
7127: $confhash{$item}{$type} .= '=';
7128: unless ($limithash{$item}{$type} =~ /\D/) {
7129: $confhash{$item}{$type} .= $limithash{$item}{$type};
7130: }
7131: }
1.160.6.5 raeburn 7132: } elsif ($context eq 'requestauthor') {
7133: $unset = '0';
7134: if ($type eq '_LC_adv') {
7135: $unset = '';
7136: }
1.72 raeburn 7137: } else {
1.101 raeburn 7138: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7139: $confhash{$item}{$type} = 1;
7140: } else {
7141: $confhash{$item}{$type} = 0;
7142: }
1.72 raeburn 7143: }
1.86 raeburn 7144: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7145: if ($action eq 'requestauthor') {
7146: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7147: $changes{$type} = 1;
7148: }
7149: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7150: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7151: $changes{$item}{$type} = 1;
7152: }
7153: } else {
7154: if ($context eq 'requestcourses') {
1.104 raeburn 7155: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7156: $changes{$item}{$type} = 1;
7157: }
7158: } else {
7159: if (!$confhash{$item}{$type}) {
7160: $changes{$item}{$type} = 1;
7161: }
7162: }
7163: }
7164: } else {
7165: if ($context eq 'requestcourses') {
1.104 raeburn 7166: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7167: $changes{$item}{$type} = 1;
7168: }
1.160.6.5 raeburn 7169: } elsif ($context eq 'requestauthor') {
7170: if ($confhash{$type} ne $unset) {
7171: $changes{$type} = 1;
7172: }
1.72 raeburn 7173: } else {
7174: if (!$confhash{$item}{$type}) {
7175: $changes{$item}{$type} = 1;
7176: }
7177: }
7178: }
1.1 raeburn 7179: }
7180: }
1.160.6.5 raeburn 7181: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7182: if (ref($domconfig{'quotas'}) eq 'HASH') {
7183: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7184: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7185: if (exists($confhash{'defaultquota'}{$key})) {
7186: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7187: $changes{'defaultquota'}{$key} = 1;
7188: }
7189: } else {
7190: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7191: }
7192: }
1.86 raeburn 7193: } else {
7194: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7195: if (exists($confhash{'defaultquota'}{$key})) {
7196: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7197: $changes{'defaultquota'}{$key} = 1;
7198: }
7199: } else {
7200: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7201: }
1.1 raeburn 7202: }
7203: }
1.160.6.20 raeburn 7204: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7205: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7206: if (exists($confhash{'authorquota'}{$key})) {
7207: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7208: $changes{'authorquota'}{$key} = 1;
7209: }
7210: } else {
7211: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7212: }
7213: }
7214: }
1.1 raeburn 7215: }
1.86 raeburn 7216: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7217: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7218: if (ref($domconfig{'quotas'}) eq 'HASH') {
7219: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7220: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7221: $changes{'defaultquota'}{$key} = 1;
7222: }
7223: } else {
7224: if (!exists($domconfig{'quotas'}{$key})) {
7225: $changes{'defaultquota'}{$key} = 1;
7226: }
1.72 raeburn 7227: }
7228: } else {
1.86 raeburn 7229: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7230: }
1.1 raeburn 7231: }
7232: }
1.160.6.20 raeburn 7233: if (ref($confhash{'authorquota'}) eq 'HASH') {
7234: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7235: if (ref($domconfig{'quotas'}) eq 'HASH') {
7236: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7237: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7238: $changes{'authorquota'}{$key} = 1;
7239: }
7240: } else {
7241: $changes{'authorquota'}{$key} = 1;
7242: }
7243: } else {
7244: $changes{'authorquota'}{$key} = 1;
7245: }
7246: }
7247: }
1.1 raeburn 7248: }
1.72 raeburn 7249:
1.160.6.5 raeburn 7250: if ($context eq 'requestauthor') {
7251: $domdefaults{'requestauthor'} = \%confhash;
7252: } else {
7253: foreach my $key (keys(%confhash)) {
1.160.6.46! raeburn 7254: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7255: $domdefaults{$key} = $confhash{$key};
7256: }
1.160.6.5 raeburn 7257: }
1.72 raeburn 7258: }
1.160.6.5 raeburn 7259:
1.1 raeburn 7260: my %quotahash = (
1.86 raeburn 7261: $action => { %confhash }
1.1 raeburn 7262: );
7263: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7264: $dom);
7265: if ($putresult eq 'ok') {
7266: if (keys(%changes) > 0) {
1.72 raeburn 7267: my $cachetime = 24*60*60;
7268: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7269: if (ref($lastactref) eq 'HASH') {
7270: $lastactref->{'domdefaults'} = 1;
7271: }
1.1 raeburn 7272: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7273: unless (($context eq 'requestcourses') ||
7274: ($context eq 'requestauthor')) {
1.86 raeburn 7275: if (ref($changes{'defaultquota'}) eq 'HASH') {
7276: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7277: foreach my $type (@{$types},'default') {
7278: if (defined($changes{'defaultquota'}{$type})) {
7279: my $typetitle = $usertypes->{$type};
7280: if ($type eq 'default') {
7281: $typetitle = $othertitle;
7282: }
1.160.6.28 raeburn 7283: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7284: }
7285: }
1.86 raeburn 7286: $resulttext .= '</ul></li>';
1.72 raeburn 7287: }
1.160.6.20 raeburn 7288: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7289: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7290: foreach my $type (@{$types},'default') {
7291: if (defined($changes{'authorquota'}{$type})) {
7292: my $typetitle = $usertypes->{$type};
7293: if ($type eq 'default') {
7294: $typetitle = $othertitle;
7295: }
1.160.6.28 raeburn 7296: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7297: }
7298: }
7299: $resulttext .= '</ul></li>';
7300: }
1.72 raeburn 7301: }
1.80 raeburn 7302: my %newenv;
1.72 raeburn 7303: foreach my $item (@usertools) {
1.160.6.5 raeburn 7304: my (%haschgs,%inconf);
7305: if ($context eq 'requestauthor') {
7306: %haschgs = %changes;
7307: %inconf = %confhash;
7308: } else {
7309: if (ref($changes{$item}) eq 'HASH') {
7310: %haschgs = %{$changes{$item}};
7311: }
7312: if (ref($confhash{$item}) eq 'HASH') {
7313: %inconf = %{$confhash{$item}};
7314: }
7315: }
7316: if (keys(%haschgs) > 0) {
1.80 raeburn 7317: my $newacc =
7318: &Apache::lonnet::usertools_access($env{'user.name'},
7319: $env{'user.domain'},
1.86 raeburn 7320: $item,'reload',$context);
1.160.6.5 raeburn 7321: if (($context eq 'requestcourses') ||
7322: ($context eq 'requestauthor')) {
1.108 raeburn 7323: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7324: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7325: }
7326: } else {
7327: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7328: $newenv{'environment.availabletools.'.$item} = $newacc;
7329: }
1.80 raeburn 7330: }
1.160.6.5 raeburn 7331: unless ($context eq 'requestauthor') {
7332: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7333: }
1.72 raeburn 7334: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7335: if ($haschgs{$type}) {
1.72 raeburn 7336: my $typetitle = $usertypes->{$type};
7337: if ($type eq 'default') {
7338: $typetitle = $othertitle;
7339: } elsif ($type eq '_LC_adv') {
7340: $typetitle = 'LON-CAPA Advanced Users';
7341: }
1.160.6.5 raeburn 7342: if ($inconf{$type}) {
1.101 raeburn 7343: if ($context eq 'requestcourses') {
7344: my $cond;
1.160.6.5 raeburn 7345: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7346: if ($1 eq '') {
7347: $cond = &mt('(Automatic processing of any request).');
7348: } else {
7349: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7350: }
7351: } else {
1.160.6.5 raeburn 7352: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7353: }
7354: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7355: } elsif ($context eq 'requestauthor') {
7356: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7357: $titles{$inconf{$type}},$typetitle);
7358:
1.101 raeburn 7359: } else {
7360: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7361: }
1.72 raeburn 7362: } else {
1.104 raeburn 7363: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7364: if ($inconf{$type} eq '0') {
1.104 raeburn 7365: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7366: } else {
7367: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7368: }
7369: } else {
7370: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7371: }
1.72 raeburn 7372: }
7373: }
1.26 raeburn 7374: }
1.160.6.5 raeburn 7375: unless ($context eq 'requestauthor') {
7376: $resulttext .= '</ul></li>';
7377: }
1.26 raeburn 7378: }
1.1 raeburn 7379: }
1.160.6.5 raeburn 7380: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7381: if (ref($changes{'notify'}) eq 'HASH') {
7382: if ($changes{'notify'}{'approval'}) {
7383: if (ref($confhash{'notify'}) eq 'HASH') {
7384: if ($confhash{'notify'}{'approval'}) {
7385: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7386: } else {
1.160.6.5 raeburn 7387: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7388: }
7389: }
7390: }
7391: }
7392: }
1.160.6.30 raeburn 7393: if ($action eq 'requestcourses') {
7394: my @offon = ('off','on');
7395: if ($changes{'uniquecode'}) {
7396: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7397: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7398: $resulttext .= '<li>'.
7399: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7400: '</li>';
7401: } else {
7402: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7403: '</li>';
7404: }
7405: }
1.160.6.46! raeburn 7406: foreach my $type ('textbooks','templates') {
! 7407: if (ref($changes{$type}) eq 'HASH') {
! 7408: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
! 7409: foreach my $key (sort(keys(%{$changes{$type}}))) {
! 7410: my %coursehash = &Apache::lonnet::coursedescription($key);
! 7411: my $coursetitle = $coursehash{'description'};
! 7412: my $position = $confhash{$type}{$key}{'order'} + 1;
! 7413: $resulttext .= '<li>';
! 7414: foreach my $item ('subject','title','author') {
! 7415: next if (($item eq 'author') && ($type eq 'templates'));
! 7416: my $name = $item.':';
! 7417: $name =~ s/^(\w)/\U$1/;
! 7418: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
! 7419: }
! 7420: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
! 7421: if ($type eq 'textbooks') {
! 7422: if ($confhash{$type}{$key}{'image'}) {
! 7423: $resulttext .= ' '.&mt('Image: [_1]',
! 7424: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
! 7425: ' alt="Textbook cover" />').'<br />';
! 7426: }
! 7427: }
! 7428: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7429: }
1.160.6.46! raeburn 7430: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7431: }
7432: }
1.160.6.39 raeburn 7433: if (ref($changes{'validation'}) eq 'HASH') {
7434: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7435: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7436: foreach my $item (@{$validationitemsref}) {
7437: if (exists($changes{'validation'}{$item})) {
7438: if ($item eq 'markup') {
7439: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7440: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7441: } else {
7442: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7443: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7444: }
7445: }
7446: }
7447: if (exists($changes{'validation'}{'dc'})) {
7448: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7449: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7450: }
7451: }
7452: }
1.160.6.30 raeburn 7453: }
1.1 raeburn 7454: $resulttext .= '</ul>';
1.80 raeburn 7455: if (keys(%newenv)) {
7456: &Apache::lonnet::appenv(\%newenv);
7457: }
1.1 raeburn 7458: } else {
1.86 raeburn 7459: if ($context eq 'requestcourses') {
7460: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7461: } elsif ($context eq 'requestauthor') {
7462: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7463: } else {
1.90 weissno 7464: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7465: }
1.1 raeburn 7466: }
7467: } else {
1.11 albertel 7468: $resulttext = '<span class="LC_error">'.
7469: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7470: }
1.160.6.30 raeburn 7471: if ($errors) {
7472: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7473: '<ul>'.$errors.'</ul></p>';
7474: }
1.3 raeburn 7475: return $resulttext;
1.1 raeburn 7476: }
7477:
1.160.6.30 raeburn 7478: sub process_textbook_image {
1.160.6.46! raeburn 7479: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7480: my $filename = $env{'form.'.$caller.'.filename'};
7481: my ($error,$url);
7482: my ($width,$height) = (50,50);
7483: if ($configuserok eq 'ok') {
7484: if ($switchserver) {
7485: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7486: $switchserver);
7487: } elsif ($author_ok eq 'ok') {
7488: my ($result,$imageurl) =
7489: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46! raeburn 7490: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7491: if ($result eq 'ok') {
7492: $url = $imageurl;
7493: } else {
7494: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7495: }
7496: } else {
7497: $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);
7498: }
7499: } else {
7500: $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);
7501: }
7502: return ($url,$error);
7503: }
7504:
1.3 raeburn 7505: sub modify_autoenroll {
1.160.6.24 raeburn 7506: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7507: my ($resulttext,%changes);
7508: my %currautoenroll;
7509: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7510: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7511: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7512: }
7513: }
7514: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7515: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7516: sender => 'Sender for notification messages',
7517: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7518: my @offon = ('off','on');
1.17 raeburn 7519: my $sender_uname = $env{'form.sender_uname'};
7520: my $sender_domain = $env{'form.sender_domain'};
7521: if ($sender_domain eq '') {
7522: $sender_uname = '';
7523: } elsif ($sender_uname eq '') {
7524: $sender_domain = '';
7525: }
1.129 raeburn 7526: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7527: my %autoenrollhash = (
1.129 raeburn 7528: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7529: 'sender_uname' => $sender_uname,
7530: 'sender_domain' => $sender_domain,
7531: 'co-owners' => $coowners,
1.1 raeburn 7532: }
7533: );
1.4 raeburn 7534: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7535: $dom);
1.1 raeburn 7536: if ($putresult eq 'ok') {
7537: if (exists($currautoenroll{'run'})) {
7538: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7539: $changes{'run'} = 1;
7540: }
7541: } elsif ($autorun) {
7542: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7543: $changes{'run'} = 1;
1.1 raeburn 7544: }
7545: }
1.17 raeburn 7546: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7547: $changes{'sender'} = 1;
7548: }
1.17 raeburn 7549: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7550: $changes{'sender'} = 1;
7551: }
1.129 raeburn 7552: if ($currautoenroll{'co-owners'} ne '') {
7553: if ($currautoenroll{'co-owners'} ne $coowners) {
7554: $changes{'coowners'} = 1;
7555: }
7556: } elsif ($coowners) {
7557: $changes{'coowners'} = 1;
7558: }
1.1 raeburn 7559: if (keys(%changes) > 0) {
7560: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7561: if ($changes{'run'}) {
1.1 raeburn 7562: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7563: }
7564: if ($changes{'sender'}) {
1.17 raeburn 7565: if ($sender_uname eq '' || $sender_domain eq '') {
7566: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7567: } else {
7568: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7569: }
1.1 raeburn 7570: }
1.129 raeburn 7571: if ($changes{'coowners'}) {
7572: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7573: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7574: if (ref($lastactref) eq 'HASH') {
7575: $lastactref->{'domainconfig'} = 1;
7576: }
1.129 raeburn 7577: }
1.1 raeburn 7578: $resulttext .= '</ul>';
7579: } else {
7580: $resulttext = &mt('No changes made to auto-enrollment settings');
7581: }
7582: } else {
1.11 albertel 7583: $resulttext = '<span class="LC_error">'.
7584: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7585: }
1.3 raeburn 7586: return $resulttext;
1.1 raeburn 7587: }
7588:
7589: sub modify_autoupdate {
1.3 raeburn 7590: my ($dom,%domconfig) = @_;
1.1 raeburn 7591: my ($resulttext,%currautoupdate,%fields,%changes);
7592: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7593: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7594: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7595: }
7596: }
7597: my @offon = ('off','on');
7598: my %title = &Apache::lonlocal::texthash (
7599: run => 'Auto-update:',
7600: classlists => 'Updates to user information in classlists?'
7601: );
1.44 raeburn 7602: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7603: my %fieldtitles = &Apache::lonlocal::texthash (
7604: id => 'Student/Employee ID',
1.20 raeburn 7605: permanentemail => 'E-mail address',
1.1 raeburn 7606: lastname => 'Last Name',
7607: firstname => 'First Name',
7608: middlename => 'Middle Name',
1.132 raeburn 7609: generation => 'Generation',
1.1 raeburn 7610: );
1.142 raeburn 7611: $othertitle = &mt('All users');
1.1 raeburn 7612: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7613: $othertitle = &mt('Other users');
1.1 raeburn 7614: }
7615: foreach my $key (keys(%env)) {
7616: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7617: my ($usertype,$item) = ($1,$2);
7618: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7619: if ($usertype eq 'default') {
7620: push(@{$fields{$1}},$2);
7621: } elsif (ref($types) eq 'ARRAY') {
7622: if (grep(/^\Q$usertype\E$/,@{$types})) {
7623: push(@{$fields{$1}},$2);
7624: }
7625: }
7626: }
1.1 raeburn 7627: }
7628: }
1.131 raeburn 7629: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7630: @lockablenames = sort(@lockablenames);
7631: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7632: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7633: if (@changed) {
7634: $changes{'lockablenames'} = 1;
7635: }
7636: } else {
7637: if (@lockablenames) {
7638: $changes{'lockablenames'} = 1;
7639: }
7640: }
1.1 raeburn 7641: my %updatehash = (
7642: autoupdate => { run => $env{'form.autoupdate_run'},
7643: classlists => $env{'form.classlists'},
7644: fields => {%fields},
1.131 raeburn 7645: lockablenames => \@lockablenames,
1.1 raeburn 7646: }
7647: );
7648: foreach my $key (keys(%currautoupdate)) {
7649: if (($key eq 'run') || ($key eq 'classlists')) {
7650: if (exists($updatehash{autoupdate}{$key})) {
7651: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7652: $changes{$key} = 1;
7653: }
7654: }
7655: } elsif ($key eq 'fields') {
7656: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7657: foreach my $item (@{$types},'default') {
1.1 raeburn 7658: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7659: my $change = 0;
7660: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7661: if (!exists($fields{$item})) {
7662: $change = 1;
1.132 raeburn 7663: last;
1.1 raeburn 7664: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7665: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7666: $change = 1;
1.132 raeburn 7667: last;
1.1 raeburn 7668: }
7669: }
7670: }
7671: if ($change) {
7672: push(@{$changes{$key}},$item);
7673: }
1.26 raeburn 7674: }
1.1 raeburn 7675: }
7676: }
1.131 raeburn 7677: } elsif ($key eq 'lockablenames') {
7678: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7679: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7680: if (@changed) {
7681: $changes{'lockablenames'} = 1;
7682: }
7683: } else {
7684: if (@lockablenames) {
7685: $changes{'lockablenames'} = 1;
7686: }
7687: }
7688: }
7689: }
7690: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7691: if (@lockablenames) {
7692: $changes{'lockablenames'} = 1;
1.1 raeburn 7693: }
7694: }
1.26 raeburn 7695: foreach my $item (@{$types},'default') {
7696: if (defined($fields{$item})) {
7697: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7698: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7699: my $change = 0;
7700: if (ref($fields{$item}) eq 'ARRAY') {
7701: foreach my $type (@{$fields{$item}}) {
7702: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7703: $change = 1;
7704: last;
7705: }
7706: }
7707: }
7708: if ($change) {
7709: push(@{$changes{'fields'}},$item);
7710: }
7711: } else {
1.26 raeburn 7712: push(@{$changes{'fields'}},$item);
7713: }
7714: } else {
7715: push(@{$changes{'fields'}},$item);
1.1 raeburn 7716: }
7717: }
7718: }
7719: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7720: $dom);
7721: if ($putresult eq 'ok') {
7722: if (keys(%changes) > 0) {
7723: $resulttext = &mt('Changes made:').'<ul>';
7724: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7725: if ($key eq 'lockablenames') {
7726: $resulttext .= '<li>';
7727: if (@lockablenames) {
7728: $usertypes->{'default'} = $othertitle;
7729: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7730: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7731: } else {
7732: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7733: }
7734: $resulttext .= '</li>';
7735: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7736: foreach my $item (@{$changes{$key}}) {
7737: my @newvalues;
7738: foreach my $type (@{$fields{$item}}) {
7739: push(@newvalues,$fieldtitles{$type});
7740: }
1.3 raeburn 7741: my $newvaluestr;
7742: if (@newvalues > 0) {
7743: $newvaluestr = join(', ',@newvalues);
7744: } else {
7745: $newvaluestr = &mt('none');
1.6 raeburn 7746: }
1.1 raeburn 7747: if ($item eq 'default') {
1.26 raeburn 7748: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7749: } else {
1.26 raeburn 7750: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7751: }
7752: }
7753: } else {
7754: my $newvalue;
7755: if ($key eq 'run') {
7756: $newvalue = $offon[$env{'form.autoupdate_run'}];
7757: } else {
7758: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7759: }
1.1 raeburn 7760: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7761: }
7762: }
7763: $resulttext .= '</ul>';
7764: } else {
1.3 raeburn 7765: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7766: }
7767: } else {
1.11 albertel 7768: $resulttext = '<span class="LC_error">'.
7769: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7770: }
1.3 raeburn 7771: return $resulttext;
1.1 raeburn 7772: }
7773:
1.125 raeburn 7774: sub modify_autocreate {
7775: my ($dom,%domconfig) = @_;
7776: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7777: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7778: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7779: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7780: }
7781: }
7782: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7783: req => 'Auto-creation of validated requests for official courses',
7784: xmldc => 'Identity of course creator of courses from XML files',
7785: );
7786: my @types = ('xml','req');
7787: foreach my $item (@types) {
7788: $newvals{$item} = $env{'form.autocreate_'.$item};
7789: $newvals{$item} =~ s/\D//g;
7790: $newvals{$item} = 0 if ($newvals{$item} eq '');
7791: }
7792: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7793: my %domcoords = &get_active_dcs($dom);
7794: unless (exists($domcoords{$newvals{'xmldc'}})) {
7795: $newvals{'xmldc'} = '';
7796: }
7797: %autocreatehash = (
7798: autocreate => { xml => $newvals{'xml'},
7799: req => $newvals{'req'},
7800: }
7801: );
7802: if ($newvals{'xmldc'} ne '') {
7803: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7804: }
7805: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7806: $dom);
7807: if ($putresult eq 'ok') {
7808: my @items = @types;
7809: if ($newvals{'xml'}) {
7810: push(@items,'xmldc');
7811: }
7812: foreach my $item (@items) {
7813: if (exists($currautocreate{$item})) {
7814: if ($currautocreate{$item} ne $newvals{$item}) {
7815: $changes{$item} = 1;
7816: }
7817: } elsif ($newvals{$item}) {
7818: $changes{$item} = 1;
7819: }
7820: }
7821: if (keys(%changes) > 0) {
7822: my @offon = ('off','on');
7823: $resulttext = &mt('Changes made:').'<ul>';
7824: foreach my $item (@types) {
7825: if ($changes{$item}) {
7826: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7827: $resulttext .= '<li>'.
7828: &mt("$title{$item} set to [_1]$newtxt [_2]",
7829: '<b>','</b>').
7830: '</li>';
1.125 raeburn 7831: }
7832: }
7833: if ($changes{'xmldc'}) {
7834: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7835: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7836: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7837: }
7838: $resulttext .= '</ul>';
7839: } else {
7840: $resulttext = &mt('No changes made to auto-creation settings');
7841: }
7842: } else {
7843: $resulttext = '<span class="LC_error">'.
7844: &mt('An error occurred: [_1]',$putresult).'</span>';
7845: }
7846: return $resulttext;
7847: }
7848:
1.23 raeburn 7849: sub modify_directorysrch {
7850: my ($dom,%domconfig) = @_;
7851: my ($resulttext,%changes);
7852: my %currdirsrch;
7853: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7854: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7855: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7856: }
7857: }
7858: my %title = ( available => 'Directory search available',
1.24 raeburn 7859: localonly => 'Other domains can search',
1.23 raeburn 7860: searchby => 'Search types',
7861: searchtypes => 'Search latitude');
7862: my @offon = ('off','on');
1.24 raeburn 7863: my @otherdoms = ('Yes','No');
1.23 raeburn 7864:
1.25 raeburn 7865: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7866: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7867: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7868:
1.44 raeburn 7869: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7870: if (keys(%{$usertypes}) == 0) {
7871: @cansearch = ('default');
7872: } else {
7873: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7874: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7875: if (!grep(/^\Q$type\E$/,@cansearch)) {
7876: push(@{$changes{'cansearch'}},$type);
7877: }
1.23 raeburn 7878: }
1.26 raeburn 7879: foreach my $type (@cansearch) {
7880: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7881: push(@{$changes{'cansearch'}},$type);
7882: }
1.23 raeburn 7883: }
1.26 raeburn 7884: } else {
7885: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7886: }
7887: }
7888:
7889: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7890: foreach my $by (@{$currdirsrch{'searchby'}}) {
7891: if (!grep(/^\Q$by\E$/,@searchby)) {
7892: push(@{$changes{'searchby'}},$by);
7893: }
7894: }
7895: foreach my $by (@searchby) {
7896: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7897: push(@{$changes{'searchby'}},$by);
7898: }
7899: }
7900: } else {
7901: push(@{$changes{'searchby'}},@searchby);
7902: }
1.25 raeburn 7903:
7904: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7905: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7906: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7907: push(@{$changes{'searchtypes'}},$type);
7908: }
7909: }
7910: foreach my $type (@searchtypes) {
7911: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7912: push(@{$changes{'searchtypes'}},$type);
7913: }
7914: }
7915: } else {
7916: if (exists($currdirsrch{'searchtypes'})) {
7917: foreach my $type (@searchtypes) {
7918: if ($type ne $currdirsrch{'searchtypes'}) {
7919: push(@{$changes{'searchtypes'}},$type);
7920: }
7921: }
7922: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7923: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7924: }
7925: } else {
7926: push(@{$changes{'searchtypes'}},@searchtypes);
7927: }
7928: }
7929:
1.23 raeburn 7930: my %dirsrch_hash = (
7931: directorysrch => { available => $env{'form.dirsrch_available'},
7932: cansearch => \@cansearch,
1.24 raeburn 7933: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7934: searchby => \@searchby,
1.25 raeburn 7935: searchtypes => \@searchtypes,
1.23 raeburn 7936: }
7937: );
7938: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7939: $dom);
7940: if ($putresult eq 'ok') {
7941: if (exists($currdirsrch{'available'})) {
7942: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7943: $changes{'available'} = 1;
7944: }
7945: } else {
7946: if ($env{'form.dirsrch_available'} eq '1') {
7947: $changes{'available'} = 1;
7948: }
7949: }
1.24 raeburn 7950: if (exists($currdirsrch{'localonly'})) {
7951: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7952: $changes{'localonly'} = 1;
7953: }
7954: } else {
7955: if ($env{'form.dirsrch_localonly'} eq '1') {
7956: $changes{'localonly'} = 1;
7957: }
7958: }
1.23 raeburn 7959: if (keys(%changes) > 0) {
7960: $resulttext = &mt('Changes made:').'<ul>';
7961: if ($changes{'available'}) {
7962: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7963: }
1.24 raeburn 7964: if ($changes{'localonly'}) {
7965: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7966: }
7967:
1.23 raeburn 7968: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7969: my $chgtext;
1.26 raeburn 7970: if (ref($usertypes) eq 'HASH') {
7971: if (keys(%{$usertypes}) > 0) {
7972: foreach my $type (@{$types}) {
7973: if (grep(/^\Q$type\E$/,@cansearch)) {
7974: $chgtext .= $usertypes->{$type}.'; ';
7975: }
7976: }
7977: if (grep(/^default$/,@cansearch)) {
7978: $chgtext .= $othertitle;
7979: } else {
7980: $chgtext =~ s/\; $//;
7981: }
1.160.6.13 raeburn 7982: $resulttext .=
7983: '<li>'.
7984: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7985: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7986: '</li>';
1.23 raeburn 7987: }
7988: }
7989: }
7990: if (ref($changes{'searchby'}) eq 'ARRAY') {
7991: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7992: my $chgtext;
7993: foreach my $type (@{$titleorder}) {
7994: if (grep(/^\Q$type\E$/,@searchby)) {
7995: if (defined($searchtitles->{$type})) {
7996: $chgtext .= $searchtitles->{$type}.'; ';
7997: }
7998: }
7999: }
8000: $chgtext =~ s/\; $//;
8001: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8002: }
1.25 raeburn 8003: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8004: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8005: my $chgtext;
8006: foreach my $type (@{$srchtypeorder}) {
8007: if (grep(/^\Q$type\E$/,@searchtypes)) {
8008: if (defined($srchtypes_desc->{$type})) {
8009: $chgtext .= $srchtypes_desc->{$type}.'; ';
8010: }
8011: }
8012: }
8013: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8014: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8015: }
8016: $resulttext .= '</ul>';
8017: } else {
8018: $resulttext = &mt('No changes made to institution directory search settings');
8019: }
8020: } else {
8021: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8022: &mt('An error occurred: [_1]',$putresult).'</span>';
8023: }
8024: return $resulttext;
8025: }
8026:
1.28 raeburn 8027: sub modify_contacts {
1.160.6.24 raeburn 8028: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8029: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8030: if (ref($domconfig{'contacts'}) eq 'HASH') {
8031: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8032: $currsetting{$key} = $domconfig{'contacts'}{$key};
8033: }
8034: }
1.134 raeburn 8035: my (%others,%to,%bcc);
1.28 raeburn 8036: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8037: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8038: 'requestsmail','updatesmail','idconflictsmail');
8039: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8040: foreach my $type (@mailings) {
8041: @{$newsetting{$type}} =
8042: &Apache::loncommon::get_env_multiple('form.'.$type);
8043: foreach my $item (@contacts) {
8044: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8045: $contacts_hash{contacts}{$type}{$item} = 1;
8046: } else {
8047: $contacts_hash{contacts}{$type}{$item} = 0;
8048: }
8049: }
8050: $others{$type} = $env{'form.'.$type.'_others'};
8051: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8052: if ($type eq 'helpdeskmail') {
8053: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8054: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8055: }
1.28 raeburn 8056: }
8057: foreach my $item (@contacts) {
8058: $to{$item} = $env{'form.'.$item};
8059: $contacts_hash{'contacts'}{$item} = $to{$item};
8060: }
1.160.6.23 raeburn 8061: foreach my $item (@toggles) {
8062: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8063: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8064: }
8065: }
1.28 raeburn 8066: if (keys(%currsetting) > 0) {
8067: foreach my $item (@contacts) {
8068: if ($to{$item} ne $currsetting{$item}) {
8069: $changes{$item} = 1;
8070: }
8071: }
8072: foreach my $type (@mailings) {
8073: foreach my $item (@contacts) {
8074: if (ref($currsetting{$type}) eq 'HASH') {
8075: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8076: push(@{$changes{$type}},$item);
8077: }
8078: } else {
8079: push(@{$changes{$type}},@{$newsetting{$type}});
8080: }
8081: }
8082: if ($others{$type} ne $currsetting{$type}{'others'}) {
8083: push(@{$changes{$type}},'others');
8084: }
1.134 raeburn 8085: if ($type eq 'helpdeskmail') {
8086: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8087: push(@{$changes{$type}},'bcc');
8088: }
8089: }
1.28 raeburn 8090: }
8091: } else {
8092: my %default;
8093: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8094: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8095: $default{'errormail'} = 'adminemail';
8096: $default{'packagesmail'} = 'adminemail';
8097: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8098: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8099: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8100: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8101: foreach my $item (@contacts) {
8102: if ($to{$item} ne $default{$item}) {
8103: $changes{$item} = 1;
1.160.6.23 raeburn 8104: }
1.28 raeburn 8105: }
8106: foreach my $type (@mailings) {
8107: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8108:
8109: push(@{$changes{$type}},@{$newsetting{$type}});
8110: }
8111: if ($others{$type} ne '') {
8112: push(@{$changes{$type}},'others');
1.134 raeburn 8113: }
8114: if ($type eq 'helpdeskmail') {
8115: if ($bcc{$type} ne '') {
8116: push(@{$changes{$type}},'bcc');
8117: }
8118: }
1.28 raeburn 8119: }
8120: }
1.160.6.23 raeburn 8121: foreach my $item (@toggles) {
8122: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8123: $changes{$item} = 1;
8124: } elsif ((!$env{'form.'.$item}) &&
8125: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8126: $changes{$item} = 1;
8127: }
8128: }
1.28 raeburn 8129: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8130: $dom);
8131: if ($putresult eq 'ok') {
8132: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8133: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8134: if (ref($lastactref) eq 'HASH') {
8135: $lastactref->{'domainconfig'} = 1;
8136: }
1.28 raeburn 8137: my ($titles,$short_titles) = &contact_titles();
8138: $resulttext = &mt('Changes made:').'<ul>';
8139: foreach my $item (@contacts) {
8140: if ($changes{$item}) {
8141: $resulttext .= '<li>'.$titles->{$item}.
8142: &mt(' set to: ').
8143: '<span class="LC_cusr_emph">'.
8144: $to{$item}.'</span></li>';
8145: }
8146: }
8147: foreach my $type (@mailings) {
8148: if (ref($changes{$type}) eq 'ARRAY') {
8149: $resulttext .= '<li>'.$titles->{$type}.': ';
8150: my @text;
8151: foreach my $item (@{$newsetting{$type}}) {
8152: push(@text,$short_titles->{$item});
8153: }
8154: if ($others{$type} ne '') {
8155: push(@text,$others{$type});
8156: }
8157: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8158: join(', ',@text).'</span>';
8159: if ($type eq 'helpdeskmail') {
8160: if ($bcc{$type} ne '') {
8161: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8162: }
8163: }
8164: $resulttext .= '</li>';
1.28 raeburn 8165: }
8166: }
1.160.6.23 raeburn 8167: my @offon = ('off','on');
8168: if ($changes{'reporterrors'}) {
8169: $resulttext .= '<li>'.
8170: &mt('E-mail error reports to [_1] set to "'.
8171: $offon[$env{'form.reporterrors'}].'".',
8172: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8173: &mt('LON-CAPA core group - MSU'),600,500)).
8174: '</li>';
8175: }
8176: if ($changes{'reportupdates'}) {
8177: $resulttext .= '<li>'.
8178: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8179: $offon[$env{'form.reportupdates'}].'".',
8180: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8181: &mt('LON-CAPA core group - MSU'),600,500)).
8182: '</li>';
8183: }
1.28 raeburn 8184: $resulttext .= '</ul>';
8185: } else {
1.34 raeburn 8186: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8187: }
8188: } else {
8189: $resulttext = '<span class="LC_error">'.
8190: &mt('An error occurred: [_1].',$putresult).'</span>';
8191: }
8192: return $resulttext;
8193: }
8194:
8195: sub modify_usercreation {
1.27 raeburn 8196: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8197: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8198: my $warningmsg;
1.27 raeburn 8199: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8200: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8201: if ($key eq 'cancreate') {
8202: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8203: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8204: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8205: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8206: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8207: } else {
8208: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8209: }
1.50 raeburn 8210: }
1.43 raeburn 8211: }
1.160.6.34 raeburn 8212: } elsif ($key eq 'email_rule') {
8213: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8214: } else {
8215: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8216: }
8217: }
1.34 raeburn 8218: }
1.160.6.34 raeburn 8219: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8220: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8221: my @contexts = ('author','course','requestcrs');
8222: foreach my $item(@contexts) {
8223: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8224: }
1.34 raeburn 8225: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8226: foreach my $item (@contexts) {
1.160.6.34 raeburn 8227: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8228: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8229: }
1.27 raeburn 8230: }
1.34 raeburn 8231: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8232: foreach my $item (@contexts) {
1.43 raeburn 8233: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8234: if ($cancreate{$item} ne 'any') {
8235: push(@{$changes{'cancreate'}},$item);
8236: }
8237: } else {
8238: if ($cancreate{$item} ne 'none') {
8239: push(@{$changes{'cancreate'}},$item);
8240: }
1.27 raeburn 8241: }
8242: }
8243: } else {
1.43 raeburn 8244: foreach my $item (@contexts) {
1.34 raeburn 8245: push(@{$changes{'cancreate'}},$item);
8246: }
1.27 raeburn 8247: }
1.34 raeburn 8248:
1.27 raeburn 8249: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8250: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8251: if (!grep(/^\Q$type\E$/,@username_rule)) {
8252: push(@{$changes{'username_rule'}},$type);
8253: }
8254: }
8255: foreach my $type (@username_rule) {
8256: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8257: push(@{$changes{'username_rule'}},$type);
8258: }
8259: }
8260: } else {
8261: push(@{$changes{'username_rule'}},@username_rule);
8262: }
8263:
1.32 raeburn 8264: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8265: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8266: if (!grep(/^\Q$type\E$/,@id_rule)) {
8267: push(@{$changes{'id_rule'}},$type);
8268: }
8269: }
8270: foreach my $type (@id_rule) {
8271: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8272: push(@{$changes{'id_rule'}},$type);
8273: }
8274: }
8275: } else {
8276: push(@{$changes{'id_rule'}},@id_rule);
8277: }
8278:
1.43 raeburn 8279: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8280: my @authtypes = ('int','krb4','krb5','loc');
8281: my %authhash;
1.43 raeburn 8282: foreach my $item (@authen_contexts) {
1.28 raeburn 8283: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8284: foreach my $auth (@authtypes) {
8285: if (grep(/^\Q$auth\E$/,@authallowed)) {
8286: $authhash{$item}{$auth} = 1;
8287: } else {
8288: $authhash{$item}{$auth} = 0;
8289: }
8290: }
8291: }
8292: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8293: foreach my $item (@authen_contexts) {
1.28 raeburn 8294: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8295: foreach my $auth (@authtypes) {
8296: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8297: push(@{$changes{'authtypes'}},$item);
8298: last;
8299: }
8300: }
8301: }
8302: }
8303: } else {
1.43 raeburn 8304: foreach my $item (@authen_contexts) {
1.28 raeburn 8305: push(@{$changes{'authtypes'}},$item);
8306: }
8307: }
8308:
1.160.6.34 raeburn 8309: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8310: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8311: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8312: $save_usercreate{'id_rule'} = \@id_rule;
8313: $save_usercreate{'username_rule'} = \@username_rule,
8314: $save_usercreate{'authtypes'} = \%authhash;
8315:
1.27 raeburn 8316: my %usercreation_hash = (
1.160.6.34 raeburn 8317: usercreation => \%save_usercreate,
8318: );
1.27 raeburn 8319:
8320: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8321: $dom);
1.50 raeburn 8322:
1.160.6.34 raeburn 8323: if ($putresult eq 'ok') {
8324: if (keys(%changes) > 0) {
8325: $resulttext = &mt('Changes made:').'<ul>';
8326: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8327: my %lt = &usercreation_types();
8328: foreach my $type (@{$changes{'cancreate'}}) {
8329: my $chgtext = $lt{$type}.', ';
8330: if ($cancreate{$type} eq 'none') {
8331: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8332: } elsif ($cancreate{$type} eq 'any') {
8333: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8334: } elsif ($cancreate{$type} eq 'official') {
8335: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8336: } elsif ($cancreate{$type} eq 'unofficial') {
8337: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8338: }
8339: $resulttext .= '<li>'.$chgtext.'</li>';
8340: }
8341: }
8342: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8343: my ($rules,$ruleorder) =
8344: &Apache::lonnet::inst_userrules($dom,'username');
8345: my $chgtext = '<ul>';
8346: foreach my $type (@username_rule) {
8347: if (ref($rules->{$type}) eq 'HASH') {
8348: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8349: }
8350: }
8351: $chgtext .= '</ul>';
8352: if (@username_rule > 0) {
8353: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8354: } else {
8355: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8356: }
8357: }
8358: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8359: my ($idrules,$idruleorder) =
8360: &Apache::lonnet::inst_userrules($dom,'id');
8361: my $chgtext = '<ul>';
8362: foreach my $type (@id_rule) {
8363: if (ref($idrules->{$type}) eq 'HASH') {
8364: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8365: }
8366: }
8367: $chgtext .= '</ul>';
8368: if (@id_rule > 0) {
8369: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8370: } else {
8371: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8372: }
8373: }
8374: my %authname = &authtype_names();
8375: my %context_title = &context_names();
8376: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8377: my $chgtext = '<ul>';
8378: foreach my $type (@{$changes{'authtypes'}}) {
8379: my @allowed;
8380: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8381: foreach my $auth (@authtypes) {
8382: if ($authhash{$type}{$auth}) {
8383: push(@allowed,$authname{$auth});
8384: }
8385: }
8386: if (@allowed > 0) {
8387: $chgtext .= join(', ',@allowed).'</li>';
8388: } else {
8389: $chgtext .= &mt('none').'</li>';
8390: }
8391: }
8392: $chgtext .= '</ul>';
8393: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8394: $resulttext .= '</li>';
8395: }
8396: $resulttext .= '</ul>';
8397: } else {
8398: $resulttext = &mt('No changes made to user creation settings');
8399: }
8400: } else {
8401: $resulttext = '<span class="LC_error">'.
8402: &mt('An error occurred: [_1]',$putresult).'</span>';
8403: }
8404: if ($warningmsg ne '') {
8405: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8406: }
8407: return $resulttext;
8408: }
8409:
8410: sub modify_selfcreation {
8411: my ($dom,%domconfig) = @_;
8412: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8413: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8414: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8415: if (ref($types) eq 'ARRAY') {
8416: $usertypes->{'default'} = $othertitle;
8417: push(@{$types},'default');
8418: }
1.160.6.34 raeburn 8419: #
8420: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8421: #
8422: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8423: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8424: if ($key eq 'cancreate') {
8425: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8426: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8427: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8428: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8429: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8430: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8431: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8432: } else {
8433: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8434: }
8435: }
8436: }
8437: } elsif ($key eq 'email_rule') {
8438: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8439: } else {
8440: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8441: }
8442: }
8443: }
8444: #
8445: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8446: #
8447: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8448: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8449: if ($key eq 'selfcreate') {
8450: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8451: } else {
8452: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8453: }
8454: }
8455: }
8456:
8457: my @contexts = ('selfcreate');
8458: @{$cancreate{'selfcreate'}} = ();
8459: %{$cancreate{'emailusername'}} = ();
8460: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8461: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8462: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8463: my %selfcreatetypes = (
8464: sso => 'users authenticated by institutional single sign on',
8465: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8466: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8467: );
1.160.6.34 raeburn 8468: #
8469: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8470: # is permitted.
8471: #
1.160.6.40 raeburn 8472:
8473: my @statuses;
8474: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8475: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8476: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8477: }
8478: }
8479: push(@statuses,'default');
8480:
1.160.6.35 raeburn 8481: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8482: if ($item eq 'email') {
1.160.6.40 raeburn 8483: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8484: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8485: push(@contexts,'selfcreateprocessing');
8486: foreach my $type (@statuses) {
8487: if ($type eq 'default') {
8488: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8489: } else {
8490: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8491: }
8492: }
1.160.6.34 raeburn 8493: }
8494: } else {
8495: if ($env{'form.cancreate_'.$item}) {
8496: push(@{$cancreate{'selfcreate'}},$item);
8497: }
8498: }
8499: }
8500: my (@email_rule,%userinfo,%savecaptcha);
8501: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8502: #
1.160.6.35 raeburn 8503: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8504: # 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 8505: #
1.160.6.40 raeburn 8506:
8507: if ($env{'form.cancreate_email'} eq 'email') {
1.160.6.37 raeburn 8508: push(@contexts,'emailusername');
1.160.6.35 raeburn 8509: if (ref($types) eq 'ARRAY') {
8510: foreach my $type (@{$types}) {
8511: if (ref($infofields) eq 'ARRAY') {
8512: foreach my $field (@{$infofields}) {
8513: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8514: $cancreate{'emailusername'}{$type}{$field} = $1;
8515: }
8516: }
1.160.6.34 raeburn 8517: }
8518: }
8519: }
8520: #
8521: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8522: # queued requests for self-creation of account using e-mail address as username
8523: #
8524:
8525: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8526: @approvalnotify = sort(@approvalnotify);
8527: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8528: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8529: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8530: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8531: push(@{$changes{'cancreate'}},'notify');
8532: }
8533: } else {
8534: if ($cancreate{'notify'}{'approval'}) {
8535: push(@{$changes{'cancreate'}},'notify');
8536: }
8537: }
8538: } elsif ($cancreate{'notify'}{'approval'}) {
8539: push(@{$changes{'cancreate'}},'notify');
8540: }
8541:
8542: #
8543: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8544: #
8545: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8546: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8547: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8548: if (@{$curr_usercreation{'email_rule'}} > 0) {
8549: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8550: if (!grep(/^\Q$type\E$/,@email_rule)) {
8551: push(@{$changes{'email_rule'}},$type);
8552: }
8553: }
8554: }
8555: if (@email_rule > 0) {
8556: foreach my $type (@email_rule) {
8557: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8558: push(@{$changes{'email_rule'}},$type);
8559: }
8560: }
8561: }
8562: } elsif (@email_rule > 0) {
8563: push(@{$changes{'email_rule'}},@email_rule);
8564: }
8565: }
8566: #
1.160.6.40 raeburn 8567: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8568: # institutional log-in.
8569: #
8570: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8571: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8572: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8573: ($domdefaults{'auth_def'} eq 'localauth'))) {
8574: $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.').' '.
8575: &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.');
8576: }
8577: }
8578: my @fields = ('lastname','firstname','middlename','generation',
8579: 'permanentemail','id');
1.160.6.44 raeburn 8580: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 8581: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8582: #
8583: # Where usernames may created for institutional log-in and/or institutional single sign on:
8584: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8585: # may self-create accounts
8586: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8587: # which the user may supply, if institutional data is unavailable.
8588: #
8589: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8590: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8591: if (@{$types} > 1) {
1.160.6.34 raeburn 8592: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8593: push(@contexts,'statustocreate');
8594: } else {
8595: undef($cancreate{'statustocreate'});
8596: }
8597: foreach my $type (@{$types}) {
8598: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8599: foreach my $field (@fields) {
8600: if (grep(/^\Q$field\E$/,@modifiable)) {
8601: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8602: } else {
8603: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8604: }
8605: }
8606: }
8607: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8608: foreach my $type (@{$types}) {
8609: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8610: foreach my $field (@fields) {
8611: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8612: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8613: push(@{$changes{'selfcreate'}},$type);
8614: last;
8615: }
8616: }
8617: }
8618: }
8619: } else {
8620: foreach my $type (@{$types}) {
8621: push(@{$changes{'selfcreate'}},$type);
8622: }
8623: }
8624: }
1.160.6.44 raeburn 8625: foreach my $field (@shibfields) {
8626: if ($env{'form.shibenv_'.$field} ne '') {
8627: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8628: }
8629: }
8630: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8631: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8632: foreach my $field (@shibfields) {
8633: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8634: push(@{$changes{'cancreate'}},'shibenv');
8635: }
8636: }
8637: } else {
8638: foreach my $field (@shibfields) {
8639: if ($env{'form.shibenv_'.$field}) {
8640: push(@{$changes{'cancreate'}},'shibenv');
8641: last;
8642: }
8643: }
8644: }
8645: }
1.160.6.34 raeburn 8646: }
8647: foreach my $item (@contexts) {
8648: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8649: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8650: if (ref($cancreate{$item}) eq 'ARRAY') {
8651: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8652: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8653: push(@{$changes{'cancreate'}},$item);
8654: }
8655: }
8656: }
8657: }
8658: if (ref($cancreate{$item}) eq 'ARRAY') {
8659: foreach my $type (@{$cancreate{$item}}) {
8660: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8661: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8662: push(@{$changes{'cancreate'}},$item);
8663: }
8664: }
8665: }
8666: }
8667: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8668: if (ref($cancreate{$item}) eq 'HASH') {
8669: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8670: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8671: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8672: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8673: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8674: push(@{$changes{'cancreate'}},$item);
8675: }
8676: }
8677: }
1.160.6.40 raeburn 8678: } elsif ($item eq 'selfcreateprocessing') {
8679: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8680: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8681: push(@{$changes{'cancreate'}},$item);
8682: }
8683: }
1.160.6.35 raeburn 8684: } else {
8685: if (!$cancreate{$item}{$curr}) {
8686: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8687: push(@{$changes{'cancreate'}},$item);
8688: }
1.160.6.34 raeburn 8689: }
8690: }
8691: }
8692: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8693: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8694: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8695: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8696: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8697: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8698: push(@{$changes{'cancreate'}},$item);
8699: }
8700: }
8701: } else {
8702: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8703: push(@{$changes{'cancreate'}},$item);
8704: }
8705: }
8706: }
1.160.6.40 raeburn 8707: } elsif ($item eq 'selfcreateprocessing') {
8708: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8709: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8710: push(@{$changes{'cancreate'}},$item);
8711: }
8712: }
1.160.6.35 raeburn 8713: } else {
8714: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8715: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8716: push(@{$changes{'cancreate'}},$item);
8717: }
1.160.6.34 raeburn 8718: }
8719: }
8720: }
8721: }
8722: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8723: if (ref($cancreate{$item}) eq 'ARRAY') {
8724: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8725: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8726: push(@{$changes{'cancreate'}},$item);
8727: }
8728: }
8729: } elsif (ref($cancreate{$item}) eq 'HASH') {
8730: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8731: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8732: push(@{$changes{'cancreate'}},$item);
8733: }
8734: }
8735: }
8736: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8737: if (ref($cancreate{$item}) eq 'HASH') {
8738: foreach my $type (keys(%{$cancreate{$item}})) {
8739: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8740: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8741: if ($cancreate{$item}{$type}{$field}) {
8742: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8743: push(@{$changes{'cancreate'}},$item);
8744: }
8745: last;
8746: }
8747: }
8748: }
8749: }
1.160.6.34 raeburn 8750: }
8751: }
8752: }
8753: #
8754: # Populate %save_usercreate hash with updates to self-creation configuration.
8755: #
8756: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8757: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8758: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8759: if (ref($cancreate{'notify'}) eq 'HASH') {
8760: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8761: }
1.160.6.40 raeburn 8762: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8763: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8764: }
1.160.6.34 raeburn 8765: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8766: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8767: }
1.160.6.44 raeburn 8768: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8769: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8770: }
1.160.6.34 raeburn 8771: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8772: $save_usercreate{'emailrule'} = \@email_rule;
8773:
8774: my %userconfig_hash = (
8775: usercreation => \%save_usercreate,
8776: usermodification => \%save_usermodify,
8777: );
8778: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8779: $dom);
8780: #
8781: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8782: #
1.27 raeburn 8783: if ($putresult eq 'ok') {
8784: if (keys(%changes) > 0) {
8785: $resulttext = &mt('Changes made:').'<ul>';
8786: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8787: my %lt = &selfcreation_types();
1.34 raeburn 8788: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8789: my $chgtext;
1.45 raeburn 8790: if ($type eq 'selfcreate') {
1.50 raeburn 8791: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8792: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8793: } else {
1.160.6.34 raeburn 8794: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8795: '<ul>';
1.50 raeburn 8796: foreach my $case (@{$cancreate{$type}}) {
8797: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8798: }
8799: $chgtext .= '</ul>';
1.100 raeburn 8800: if (ref($cancreate{$type}) eq 'ARRAY') {
8801: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8802: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8803: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8804: $chgtext .= '<br />'.
8805: '<span class="LC_warning">'.
8806: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8807: '</span>';
1.100 raeburn 8808: }
8809: }
8810: }
8811: }
1.43 raeburn 8812: }
1.160.6.44 raeburn 8813: } elsif ($type eq 'shibenv') {
8814: if (keys(%{$cancreate{$type}}) == 0) {
8815: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
8816: } else {
8817: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
8818: '<ul>';
8819: foreach my $field (@shibfields) {
8820: next if ($cancreate{$type}{$field} eq '');
8821: if ($field eq 'inststatus') {
8822: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
8823: } else {
8824: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
8825: }
8826: }
8827: $chgtext .= '</ul>';
8828: }
1.93 raeburn 8829: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8830: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8831: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8832: if (@{$cancreate{'selfcreate'}} > 0) {
8833: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8834: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8835: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8836: $chgtext .= '<br />'.
8837: '<span class="LC_warning">'.
8838: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8839: '</span>';
8840: }
1.96 raeburn 8841: } elsif (ref($usertypes) eq 'HASH') {
8842: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8843: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8844: } else {
8845: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8846: }
8847: $chgtext .= '<ul>';
8848: foreach my $case (@{$cancreate{$type}}) {
8849: if ($case eq 'default') {
8850: $chgtext .= '<li>'.$othertitle.'</li>';
8851: } else {
8852: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8853: }
8854: }
1.100 raeburn 8855: $chgtext .= '</ul>';
8856: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8857: $chgtext .= '<br /><span class="LC_warning">'.
8858: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8859: '</span>';
1.100 raeburn 8860: }
8861: }
8862: } else {
8863: if (@{$cancreate{$type}} == 0) {
8864: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8865: } else {
8866: $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 8867: }
8868: }
8869: }
1.160.6.40 raeburn 8870: } elsif ($type eq 'selfcreateprocessing') {
8871: my %choices = &Apache::lonlocal::texthash (
8872: automatic => 'Automatic approval',
8873: approval => 'Queued for approval',
8874: );
8875: if (@statuses > 1) {
8876: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8877: '<ul>';
8878: foreach my $type (@statuses) {
8879: if ($type eq 'default') {
8880: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8881: } else {
8882: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8883: }
8884: }
8885: $chgtext .= '</ul>';
8886: } else {
8887: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8888: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8889: }
1.160.6.5 raeburn 8890: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8891: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8892: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8893: } else {
8894: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8895: if ($captchas{$savecaptcha{$type}}) {
8896: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8897: } else {
8898: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8899: }
8900: }
8901: } elsif ($type eq 'recaptchakeys') {
8902: my ($privkey,$pubkey);
1.160.6.34 raeburn 8903: if (ref($savecaptcha{$type}) eq 'HASH') {
8904: $pubkey = $savecaptcha{$type}{'public'};
8905: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8906: }
8907: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8908: if (!$pubkey) {
8909: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8910: } else {
8911: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8912: }
8913: if (!$privkey) {
8914: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8915: } else {
8916: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8917: }
8918: $chgtext .= '</ul>';
1.160.6.34 raeburn 8919: } elsif ($type eq 'emailusername') {
8920: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8921: if (ref($types) eq 'ARRAY') {
8922: foreach my $type (@{$types}) {
8923: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8924: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8925: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8926: '<ul>';
8927: foreach my $field (@{$infofields}) {
8928: if ($cancreate{'emailusername'}{$type}{$field}) {
8929: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8930: }
8931: }
8932: }
8933: $chgtext .= '</ul>';
8934: } else {
8935: $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 8936: }
8937: }
8938: }
8939: }
8940: } elsif ($type eq 'notify') {
8941: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8942: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8943: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8944: if ($cancreate{'notify'}{'approval'}) {
8945: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8946: }
8947: }
1.43 raeburn 8948: }
1.34 raeburn 8949: }
1.160.6.34 raeburn 8950: if ($chgtext) {
8951: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8952: }
8953: }
8954: }
1.43 raeburn 8955: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8956: my ($emailrules,$emailruleorder) =
8957: &Apache::lonnet::inst_userrules($dom,'email');
8958: my $chgtext = '<ul>';
8959: foreach my $type (@email_rule) {
8960: if (ref($emailrules->{$type}) eq 'HASH') {
8961: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8962: }
8963: }
8964: $chgtext .= '</ul>';
8965: if (@email_rule > 0) {
1.160.6.34 raeburn 8966: $resulttext .= '<li>'.
8967: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8968: $chgtext.
8969: '</li>';
1.43 raeburn 8970: } else {
1.160.6.34 raeburn 8971: $resulttext .= '<li>'.
8972: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8973: '</li>';
1.43 raeburn 8974: }
8975: }
1.160.6.34 raeburn 8976: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8977: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8978: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8979: foreach my $type (@{$changes{'selfcreate'}}) {
8980: my $typename = $type;
8981: if (ref($usertypes) eq 'HASH') {
8982: if ($usertypes->{$type} ne '') {
8983: $typename = $usertypes->{$type};
1.28 raeburn 8984: }
8985: }
1.160.6.34 raeburn 8986: my @modifiable;
8987: $resulttext .= '<li>'.
8988: &mt('Self-creation of account by users with status: [_1]',
8989: '<span class="LC_cusr_emph">'.$typename.'</span>').
8990: ' - '.&mt('modifiable fields (if institutional data blank): ');
8991: foreach my $field (@fields) {
8992: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8993: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
8994: }
8995: }
8996: if (@modifiable > 0) {
8997: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8998: } else {
1.160.6.34 raeburn 8999: $resulttext .= &mt('none');
1.43 raeburn 9000: }
1.160.6.34 raeburn 9001: $resulttext .= '</li>';
1.28 raeburn 9002: }
1.160.6.34 raeburn 9003: $resulttext .= '</ul></li>';
1.28 raeburn 9004: }
1.27 raeburn 9005: $resulttext .= '</ul>';
9006: } else {
1.160.6.34 raeburn 9007: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9008: }
9009: } else {
9010: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9011: &mt('An error occurred: [_1]',$putresult).'</span>';
9012: }
1.43 raeburn 9013: if ($warningmsg ne '') {
9014: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9015: }
1.23 raeburn 9016: return $resulttext;
9017: }
9018:
1.160.6.5 raeburn 9019: sub process_captcha {
9020: my ($container,$changes,$newsettings,$current) = @_;
9021: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9022: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9023: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9024: $newsettings->{'captcha'} = 'original';
9025: }
9026: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9027: if ($container eq 'cancreate') {
9028: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9029: push(@{$changes->{'cancreate'}},'captcha');
9030: } elsif (!defined($changes->{'cancreate'})) {
9031: $changes->{'cancreate'} = ['captcha'];
9032: }
9033: } else {
9034: $changes->{'captcha'} = 1;
9035: }
9036: }
9037: my ($newpub,$newpriv,$currpub,$currpriv);
9038: if ($newsettings->{'captcha'} eq 'recaptcha') {
9039: $newpub = $env{'form.'.$container.'_recaptchapub'};
9040: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
9041: $newpub =~ s/\W//g;
9042: $newpriv =~ s/\W//g;
9043: $newsettings->{'recaptchakeys'} = {
9044: public => $newpub,
9045: private => $newpriv,
9046: };
9047: }
9048: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9049: $currpub = $current->{'recaptchakeys'}{'public'};
9050: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9051: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9052: $newsettings->{'recaptchakeys'} = {
9053: public => '',
9054: private => '',
9055: }
9056: }
1.160.6.5 raeburn 9057: }
9058: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9059: if ($container eq 'cancreate') {
9060: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9061: push(@{$changes->{'cancreate'}},'recaptchakeys');
9062: } elsif (!defined($changes->{'cancreate'})) {
9063: $changes->{'cancreate'} = ['recaptchakeys'];
9064: }
9065: } else {
9066: $changes->{'recaptchakeys'} = 1;
9067: }
9068: }
9069: return;
9070: }
9071:
1.33 raeburn 9072: sub modify_usermodification {
9073: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9074: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9075: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9076: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9077: if ($key eq 'selfcreate') {
9078: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9079: } else {
9080: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9081: }
1.33 raeburn 9082: }
9083: }
1.160.6.34 raeburn 9084: my @contexts = ('author','course');
1.33 raeburn 9085: my %context_title = (
9086: author => 'In author context',
9087: course => 'In course context',
9088: );
9089: my @fields = ('lastname','firstname','middlename','generation',
9090: 'permanentemail','id');
9091: my %roles = (
9092: author => ['ca','aa'],
9093: course => ['st','ep','ta','in','cr'],
9094: );
9095: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9096: foreach my $context (@contexts) {
9097: foreach my $role (@{$roles{$context}}) {
9098: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9099: foreach my $item (@fields) {
9100: if (grep(/^\Q$item\E$/,@modifiable)) {
9101: $modifyhash{$context}{$role}{$item} = 1;
9102: } else {
9103: $modifyhash{$context}{$role}{$item} = 0;
9104: }
9105: }
9106: }
9107: if (ref($curr_usermodification{$context}) eq 'HASH') {
9108: foreach my $role (@{$roles{$context}}) {
9109: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9110: foreach my $field (@fields) {
9111: if ($modifyhash{$context}{$role}{$field} ne
9112: $curr_usermodification{$context}{$role}{$field}) {
9113: push(@{$changes{$context}},$role);
9114: last;
9115: }
9116: }
9117: }
9118: }
9119: } else {
9120: foreach my $context (@contexts) {
9121: foreach my $role (@{$roles{$context}}) {
9122: push(@{$changes{$context}},$role);
9123: }
9124: }
9125: }
9126: }
9127: my %usermodification_hash = (
9128: usermodification => \%modifyhash,
9129: );
9130: my $putresult = &Apache::lonnet::put_dom('configuration',
9131: \%usermodification_hash,$dom);
9132: if ($putresult eq 'ok') {
9133: if (keys(%changes) > 0) {
9134: $resulttext = &mt('Changes made: ').'<ul>';
9135: foreach my $context (@contexts) {
9136: if (ref($changes{$context}) eq 'ARRAY') {
9137: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9138: if (ref($changes{$context}) eq 'ARRAY') {
9139: foreach my $role (@{$changes{$context}}) {
9140: my $rolename;
1.160.6.34 raeburn 9141: if ($role eq 'cr') {
9142: $rolename = &mt('Custom');
1.33 raeburn 9143: } else {
1.160.6.34 raeburn 9144: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9145: }
9146: my @modifiable;
1.160.6.34 raeburn 9147: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9148: foreach my $field (@fields) {
9149: if ($modifyhash{$context}{$role}{$field}) {
9150: push(@modifiable,$fieldtitles{$field});
9151: }
9152: }
9153: if (@modifiable > 0) {
9154: $resulttext .= join(', ',@modifiable);
9155: } else {
9156: $resulttext .= &mt('none');
9157: }
9158: $resulttext .= '</li>';
9159: }
9160: $resulttext .= '</ul></li>';
9161: }
9162: }
9163: }
9164: $resulttext .= '</ul>';
9165: } else {
9166: $resulttext = &mt('No changes made to user modification settings');
9167: }
9168: } else {
9169: $resulttext = '<span class="LC_error">'.
9170: &mt('An error occurred: [_1]',$putresult).'</span>';
9171: }
9172: return $resulttext;
9173: }
9174:
1.43 raeburn 9175: sub modify_defaults {
1.160.6.27 raeburn 9176: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9177: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9178: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9179: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9180: my @authtypes = ('internal','krb4','krb5','localauth');
9181: foreach my $item (@items) {
9182: $newvalues{$item} = $env{'form.'.$item};
9183: if ($item eq 'auth_def') {
9184: if ($newvalues{$item} ne '') {
9185: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9186: push(@errors,$item);
9187: }
9188: }
9189: } elsif ($item eq 'lang_def') {
9190: if ($newvalues{$item} ne '') {
9191: if ($newvalues{$item} =~ /^(\w+)/) {
9192: my $langcode = $1;
1.103 raeburn 9193: if ($langcode ne 'x_chef') {
9194: if (code2language($langcode) eq '') {
9195: push(@errors,$item);
9196: }
1.43 raeburn 9197: }
9198: } else {
9199: push(@errors,$item);
9200: }
9201: }
1.54 raeburn 9202: } elsif ($item eq 'timezone_def') {
9203: if ($newvalues{$item} ne '') {
1.62 raeburn 9204: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9205: push(@errors,$item);
9206: }
9207: }
1.68 raeburn 9208: } elsif ($item eq 'datelocale_def') {
9209: if ($newvalues{$item} ne '') {
9210: my @datelocale_ids = DateTime::Locale->ids();
9211: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9212: push(@errors,$item);
9213: }
9214: }
1.141 raeburn 9215: } elsif ($item eq 'portal_def') {
9216: if ($newvalues{$item} ne '') {
9217: 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])\/?$/) {
9218: push(@errors,$item);
9219: }
9220: }
1.43 raeburn 9221: }
9222: if (grep(/^\Q$item\E$/,@errors)) {
9223: $newvalues{$item} = $domdefaults{$item};
9224: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9225: $changes{$item} = 1;
9226: }
1.72 raeburn 9227: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9228: }
9229: my %defaults_hash = (
1.72 raeburn 9230: defaults => \%newvalues,
9231: );
1.43 raeburn 9232: my $title = &defaults_titles();
1.160.6.40 raeburn 9233:
9234: my $currinststatus;
9235: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9236: $currinststatus = $domconfig{'inststatus'};
9237: } else {
9238: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9239: $currinststatus = {
9240: inststatustypes => $usertypes,
9241: inststatusorder => $types,
9242: inststatusguest => [],
9243: };
9244: }
9245: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9246: my @allpos;
9247: my %guests;
9248: my %alltypes;
9249: my ($currtitles,$currguests,$currorder);
9250: if (ref($currinststatus) eq 'HASH') {
9251: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9252: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9253: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9254: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9255: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9256: }
9257: }
9258: unless (grep(/^\Q$type\E$/,@todelete)) {
9259: my $position = $env{'form.inststatus_pos_'.$type};
9260: $position =~ s/\D+//g;
9261: $allpos[$position] = $type;
9262: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9263: $alltypes{$type} =~ s/`//g;
9264: if ($env{'form.inststatus_guest_'.$type}) {
9265: $guests{$type} = 1;
9266: }
9267: }
9268: }
9269: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9270: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9271: }
9272: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9273: $currtitles =~ s/,$//;
9274: }
9275: }
9276: if ($env{'form.addinststatus'}) {
9277: my $newtype = $env{'form.addinststatus'};
9278: $newtype =~ s/\W//g;
9279: unless (exists($alltypes{$newtype})) {
9280: if ($env{'form.addinststatus_guest'}) {
9281: $guests{$newtype} = 1;
9282: }
9283: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9284: $alltypes{$newtype} =~ s/`//g;
9285: my $position = $env{'form.addinststatus_pos'};
9286: $position =~ s/\D+//g;
9287: if ($position ne '') {
9288: $allpos[$position] = $newtype;
9289: }
9290: }
9291: }
9292: my (@orderedstatus,@orderedguests);
9293: foreach my $type (@allpos) {
9294: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9295: push(@orderedstatus,$type);
9296: if ($guests{$type}) {
9297: push(@orderedguests,$type);
9298: }
9299: }
9300: }
9301: foreach my $type (keys(%alltypes)) {
9302: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9303: delete($alltypes{$type});
9304: }
9305: }
9306: $defaults_hash{'inststatus'} = {
9307: inststatustypes => \%alltypes,
9308: inststatusorder => \@orderedstatus,
9309: inststatusguest => \@orderedguests,
9310: };
9311: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9312: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9313: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9314: }
9315: }
9316: if ($currorder ne join(',',@orderedstatus)) {
9317: $changes{'inststatus'}{'inststatusorder'} = 1;
9318: }
9319: if ($currguests ne join(',',@orderedguests)) {
9320: $changes{'inststatus'}{'inststatusguest'} = 1;
9321: }
9322: my $newtitles;
9323: foreach my $item (@orderedstatus) {
9324: $newtitles .= $alltypes{$item}.',';
9325: }
9326: $newtitles =~ s/,$//;
9327: if ($currtitles ne $newtitles) {
9328: $changes{'inststatus'}{'inststatustypes'} = 1;
9329: }
1.43 raeburn 9330: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9331: $dom);
9332: if ($putresult eq 'ok') {
9333: if (keys(%changes) > 0) {
9334: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9335: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9336: 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";
9337: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9338: if ($item eq 'inststatus') {
9339: if (ref($changes{'inststatus'}) eq 'HASH') {
9340: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9341: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9342: foreach my $type (@orderedstatus) {
9343: $resulttext .= $alltypes{$type}.', ';
9344: }
9345: $resulttext =~ s/, $//;
9346: $resulttext .= '</li>';
9347: }
9348: if ($changes{'inststatus'}{'inststatusguest'}) {
9349: $resulttext .= '<li>';
9350: if (@orderedguests) {
9351: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9352: foreach my $type (@orderedguests) {
9353: $resulttext .= $alltypes{$type}.', ';
9354: }
9355: $resulttext =~ s/, $//;
9356: } else {
9357: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9358: }
9359: $resulttext .= '</li>';
9360: }
9361: }
9362: } else {
9363: my $value = $env{'form.'.$item};
9364: if ($value eq '') {
9365: $value = &mt('none');
9366: } elsif ($item eq 'auth_def') {
9367: my %authnames = &authtype_names();
9368: my %shortauth = (
9369: internal => 'int',
9370: krb4 => 'krb4',
9371: krb5 => 'krb5',
9372: localauth => 'loc',
9373: );
9374: $value = $authnames{$shortauth{$value}};
9375: }
9376: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9377: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9378: }
9379: }
9380: $resulttext .= '</ul>';
9381: $mailmsgtext .= "\n";
9382: my $cachetime = 24*60*60;
1.72 raeburn 9383: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9384: if (ref($lastactref) eq 'HASH') {
9385: $lastactref->{'domdefaults'} = 1;
9386: }
1.68 raeburn 9387: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9388: my $notify = 1;
9389: if (ref($domconfig{'contacts'}) eq 'HASH') {
9390: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9391: $notify = 0;
9392: }
9393: }
9394: if ($notify) {
9395: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9396: "LON-CAPA Domain Settings Change - $dom",
9397: $mailmsgtext);
9398: }
1.54 raeburn 9399: }
1.43 raeburn 9400: } else {
1.54 raeburn 9401: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9402: }
9403: } else {
9404: $resulttext = '<span class="LC_error">'.
9405: &mt('An error occurred: [_1]',$putresult).'</span>';
9406: }
9407: if (@errors > 0) {
9408: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9409: foreach my $item (@errors) {
9410: $resulttext .= ' "'.$title->{$item}.'",';
9411: }
9412: $resulttext =~ s/,$//;
9413: }
9414: return $resulttext;
9415: }
9416:
1.46 raeburn 9417: sub modify_scantron {
1.160.6.24 raeburn 9418: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9419: my ($resulttext,%confhash,%changes,$errors);
9420: my $custom = 'custom.tab';
9421: my $default = 'default.tab';
9422: my $servadm = $r->dir_config('lonAdmEMail');
9423: my ($configuserok,$author_ok,$switchserver) =
9424: &config_check($dom,$confname,$servadm);
9425: if ($env{'form.scantronformat.filename'} ne '') {
9426: my $error;
9427: if ($configuserok eq 'ok') {
9428: if ($switchserver) {
1.130 raeburn 9429: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9430: } else {
9431: if ($author_ok eq 'ok') {
9432: my ($result,$scantronurl) =
9433: &publishlogo($r,'upload','scantronformat',$dom,
9434: $confname,'scantron','','',$custom);
9435: if ($result eq 'ok') {
9436: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9437: $changes{'scantronformat'} = 1;
1.46 raeburn 9438: } else {
9439: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9440: }
9441: } else {
9442: $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);
9443: }
9444: }
9445: } else {
9446: $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);
9447: }
9448: if ($error) {
9449: &Apache::lonnet::logthis($error);
9450: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9451: }
9452: }
1.48 raeburn 9453: if (ref($domconfig{'scantron'}) eq 'HASH') {
9454: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9455: if ($env{'form.scantronformat_del'}) {
9456: $confhash{'scantron'}{'scantronformat'} = '';
9457: $changes{'scantronformat'} = 1;
1.46 raeburn 9458: }
9459: }
9460: }
9461: if (keys(%confhash) > 0) {
9462: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9463: $dom);
9464: if ($putresult eq 'ok') {
9465: if (keys(%changes) > 0) {
1.48 raeburn 9466: if (ref($confhash{'scantron'}) eq 'HASH') {
9467: $resulttext = &mt('Changes made:').'<ul>';
9468: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9469: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9470: } else {
1.130 raeburn 9471: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9472: }
1.48 raeburn 9473: $resulttext .= '</ul>';
9474: } else {
1.130 raeburn 9475: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9476: }
9477: $resulttext .= '</ul>';
9478: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9479: if (ref($lastactref) eq 'HASH') {
9480: $lastactref->{'domainconfig'} = 1;
9481: }
1.46 raeburn 9482: } else {
1.130 raeburn 9483: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9484: }
9485: } else {
9486: $resulttext = '<span class="LC_error">'.
9487: &mt('An error occurred: [_1]',$putresult).'</span>';
9488: }
9489: } else {
1.130 raeburn 9490: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9491: }
9492: if ($errors) {
9493: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9494: $errors.'</ul>';
9495: }
9496: return $resulttext;
9497: }
9498:
1.48 raeburn 9499: sub modify_coursecategories {
1.160.6.43 raeburn 9500: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9501: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9502: $cathash);
1.48 raeburn 9503: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9504: my @catitems = ('unauth','auth');
9505: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9506: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9507: $cathash = $domconfig{'coursecategories'}{'cats'};
9508: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9509: $changes{'togglecats'} = 1;
9510: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9511: }
9512: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9513: $changes{'categorize'} = 1;
9514: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9515: }
1.120 raeburn 9516: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9517: $changes{'togglecatscomm'} = 1;
9518: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9519: }
9520: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9521: $changes{'categorizecomm'} = 1;
9522: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9523: }
1.160.6.42 raeburn 9524: foreach my $item (@catitems) {
9525: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9526: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9527: $changes{$item} = 1;
9528: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9529: }
9530: }
9531: }
1.57 raeburn 9532: } else {
9533: $changes{'togglecats'} = 1;
9534: $changes{'categorize'} = 1;
1.124 raeburn 9535: $changes{'togglecatscomm'} = 1;
9536: $changes{'categorizecomm'} = 1;
1.87 raeburn 9537: $domconfig{'coursecategories'} = {
9538: togglecats => $env{'form.togglecats'},
9539: categorize => $env{'form.categorize'},
1.124 raeburn 9540: togglecatscomm => $env{'form.togglecatscomm'},
9541: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9542: };
1.160.6.42 raeburn 9543: foreach my $item (@catitems) {
9544: if ($env{'form.coursecat_'.$item} ne 'std') {
9545: $changes{$item} = 1;
9546: }
9547: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9548: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9549: }
9550: }
1.57 raeburn 9551: }
9552: if (ref($cathash) eq 'HASH') {
9553: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9554: push (@deletecategory,'instcode::0');
9555: }
1.120 raeburn 9556: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9557: push(@deletecategory,'communities::0');
9558: }
1.48 raeburn 9559: }
1.57 raeburn 9560: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9561: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9562: if (@deletecategory > 0) {
9563: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9564: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9565: foreach my $item (@deletecategory) {
1.57 raeburn 9566: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9567: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9568: $deletions{$item} = 1;
1.57 raeburn 9569: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9570: }
9571: }
9572: }
1.57 raeburn 9573: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9574: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9575: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9576: $reorderings{$item} = 1;
1.57 raeburn 9577: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9578: }
9579: if ($env{'form.addcategory_name_'.$item} ne '') {
9580: my $newcat = $env{'form.addcategory_name_'.$item};
9581: my $newdepth = $depth+1;
9582: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9583: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9584: $adds{$newitem} = 1;
9585: }
9586: if ($env{'form.subcat_'.$item} ne '') {
9587: my $newcat = $env{'form.subcat_'.$item};
9588: my $newdepth = $depth+1;
9589: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9590: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9591: $adds{$newitem} = 1;
9592: }
9593: }
9594: }
9595: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9596: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9597: my $newitem = 'instcode::0';
1.57 raeburn 9598: if ($cathash->{$newitem} eq '') {
9599: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9600: $adds{$newitem} = 1;
9601: }
9602: } else {
9603: my $newitem = 'instcode::0';
1.57 raeburn 9604: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9605: $adds{$newitem} = 1;
9606: }
9607: }
1.120 raeburn 9608: if ($env{'form.communities'} eq '1') {
9609: if (ref($cathash) eq 'HASH') {
9610: my $newitem = 'communities::0';
9611: if ($cathash->{$newitem} eq '') {
9612: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9613: $adds{$newitem} = 1;
9614: }
9615: } else {
9616: my $newitem = 'communities::0';
9617: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9618: $adds{$newitem} = 1;
9619: }
9620: }
1.48 raeburn 9621: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9622: if (($env{'form.addcategory_name'} ne 'instcode') &&
9623: ($env{'form.addcategory_name'} ne 'communities')) {
9624: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9625: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9626: $adds{$newitem} = 1;
9627: }
1.48 raeburn 9628: }
1.57 raeburn 9629: my $putresult;
1.48 raeburn 9630: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9631: if (keys(%deletions) > 0) {
9632: foreach my $key (keys(%deletions)) {
9633: if ($predelallitems{$key} ne '') {
9634: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9635: }
9636: }
9637: }
9638: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9639: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9640: if (ref($chkcats[0]) eq 'ARRAY') {
9641: my $depth = 0;
9642: my $chg = 0;
9643: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9644: my $name = $chkcats[0][$i];
9645: my $item;
9646: if ($name eq '') {
9647: $chg ++;
9648: } else {
9649: $item = &escape($name).'::0';
9650: if ($chg) {
1.57 raeburn 9651: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9652: }
9653: $depth ++;
1.57 raeburn 9654: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9655: $depth --;
9656: }
9657: }
9658: }
1.57 raeburn 9659: }
9660: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9661: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9662: if ($putresult eq 'ok') {
1.57 raeburn 9663: my %title = (
1.120 raeburn 9664: togglecats => 'Show/Hide a course in catalog',
9665: categorize => 'Assign a category to a course',
9666: togglecatscomm => 'Show/Hide a community in catalog',
9667: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9668: );
9669: my %level = (
1.120 raeburn 9670: dom => 'set in Domain ("Modify Course/Community")',
9671: crs => 'set in Course ("Course Configuration")',
9672: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9673: none => 'No catalog',
9674: std => 'Standard catalog',
9675: domonly => 'Domain-only catalog',
9676: codesrch => 'Code search form',
1.57 raeburn 9677: );
1.48 raeburn 9678: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9679: if ($changes{'togglecats'}) {
9680: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9681: }
9682: if ($changes{'categorize'}) {
9683: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9684: }
1.120 raeburn 9685: if ($changes{'togglecatscomm'}) {
9686: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9687: }
9688: if ($changes{'categorizecomm'}) {
9689: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9690: }
1.160.6.42 raeburn 9691: if ($changes{'unauth'}) {
9692: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9693: }
9694: if ($changes{'auth'}) {
9695: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9696: }
1.57 raeburn 9697: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9698: my $cathash;
9699: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9700: $cathash = $domconfig{'coursecategories'}{'cats'};
9701: } else {
9702: $cathash = {};
9703: }
9704: my (@cats,@trails,%allitems);
9705: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9706: if (keys(%deletions) > 0) {
9707: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9708: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9709: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9710: }
9711: $resulttext .= '</ul></li>';
9712: }
9713: if (keys(%reorderings) > 0) {
9714: my %sort_by_trail;
9715: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9716: foreach my $key (keys(%reorderings)) {
9717: if ($allitems{$key} ne '') {
9718: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9719: }
1.48 raeburn 9720: }
1.57 raeburn 9721: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9722: $resulttext .= '<li>'.$trails[$trail].'</li>';
9723: }
9724: $resulttext .= '</ul></li>';
1.48 raeburn 9725: }
1.57 raeburn 9726: if (keys(%adds) > 0) {
9727: my %sort_by_trail;
9728: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9729: foreach my $key (keys(%adds)) {
9730: if ($allitems{$key} ne '') {
9731: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9732: }
9733: }
9734: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9735: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9736: }
1.57 raeburn 9737: $resulttext .= '</ul></li>';
1.48 raeburn 9738: }
9739: }
9740: $resulttext .= '</ul>';
1.160.6.43 raeburn 9741: if ($changes{'unauth'} || $changes{'auth'}) {
9742: &Apache::loncommon::devalidate_domconfig_cache($dom);
9743: if (ref($lastactref) eq 'HASH') {
9744: $lastactref->{'domainconfig'} = 1;
9745: }
9746: }
1.48 raeburn 9747: } else {
9748: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9749: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9750: }
9751: } else {
1.120 raeburn 9752: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9753: }
9754: return $resulttext;
9755: }
9756:
1.69 raeburn 9757: sub modify_serverstatuses {
9758: my ($dom,%domconfig) = @_;
9759: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9760: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9761: %currserverstatus = %{$domconfig{'serverstatuses'}};
9762: }
9763: my @pages = &serverstatus_pages();
9764: foreach my $type (@pages) {
9765: $newserverstatus{$type}{'namedusers'} = '';
9766: $newserverstatus{$type}{'machines'} = '';
9767: if (defined($env{'form.'.$type.'_namedusers'})) {
9768: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9769: my @okusers;
9770: foreach my $user (@users) {
9771: my ($uname,$udom) = split(/:/,$user);
9772: if (($udom =~ /^$match_domain$/) &&
9773: (&Apache::lonnet::domain($udom)) &&
9774: ($uname =~ /^$match_username$/)) {
9775: if (!grep(/^\Q$user\E/,@okusers)) {
9776: push(@okusers,$user);
9777: }
9778: }
9779: }
9780: if (@okusers > 0) {
9781: @okusers = sort(@okusers);
9782: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9783: }
9784: }
9785: if (defined($env{'form.'.$type.'_machines'})) {
9786: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9787: my @okmachines;
9788: foreach my $ip (@machines) {
9789: my @parts = split(/\./,$ip);
9790: next if (@parts < 4);
9791: my $badip = 0;
9792: for (my $i=0; $i<4; $i++) {
9793: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9794: $badip = 1;
9795: last;
9796: }
9797: }
9798: if (!$badip) {
9799: push(@okmachines,$ip);
9800: }
9801: }
9802: @okmachines = sort(@okmachines);
9803: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9804: }
9805: }
9806: my %serverstatushash = (
9807: serverstatuses => \%newserverstatus,
9808: );
9809: foreach my $type (@pages) {
1.83 raeburn 9810: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9811: my (@current,@new);
1.83 raeburn 9812: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9813: if ($currserverstatus{$type}{$setting} ne '') {
9814: @current = split(/,/,$currserverstatus{$type}{$setting});
9815: }
9816: }
9817: if ($newserverstatus{$type}{$setting} ne '') {
9818: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9819: }
9820: if (@current > 0) {
9821: if (@new > 0) {
9822: foreach my $item (@current) {
9823: if (!grep(/^\Q$item\E$/,@new)) {
9824: $changes{$type}{$setting} = 1;
1.82 raeburn 9825: last;
9826: }
9827: }
1.84 raeburn 9828: foreach my $item (@new) {
9829: if (!grep(/^\Q$item\E$/,@current)) {
9830: $changes{$type}{$setting} = 1;
9831: last;
1.82 raeburn 9832: }
9833: }
9834: } else {
1.83 raeburn 9835: $changes{$type}{$setting} = 1;
1.69 raeburn 9836: }
1.83 raeburn 9837: } elsif (@new > 0) {
9838: $changes{$type}{$setting} = 1;
1.69 raeburn 9839: }
9840: }
9841: }
9842: if (keys(%changes) > 0) {
1.81 raeburn 9843: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9844: my $putresult = &Apache::lonnet::put_dom('configuration',
9845: \%serverstatushash,$dom);
9846: if ($putresult eq 'ok') {
9847: $resulttext .= &mt('Changes made:').'<ul>';
9848: foreach my $type (@pages) {
1.84 raeburn 9849: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9850: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9851: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9852: if ($newserverstatus{$type}{'namedusers'} eq '') {
9853: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9854: } else {
9855: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9856: }
1.84 raeburn 9857: }
9858: if ($changes{$type}{'machines'}) {
1.69 raeburn 9859: if ($newserverstatus{$type}{'machines'} eq '') {
9860: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9861: } else {
9862: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9863: }
9864:
9865: }
9866: $resulttext .= '</ul></li>';
9867: }
9868: }
9869: $resulttext .= '</ul>';
9870: } else {
9871: $resulttext = '<span class="LC_error">'.
9872: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9873:
9874: }
9875: } else {
9876: $resulttext = &mt('No changes made to access to server status pages');
9877: }
9878: return $resulttext;
9879: }
9880:
1.118 jms 9881: sub modify_helpsettings {
1.122 jms 9882: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9883: my ($resulttext,$errors,%changes,%helphash);
9884: my %defaultchecked = ('submitbugs' => 'on');
9885: my @offon = ('off','on');
1.118 jms 9886: my @toggles = ('submitbugs');
9887: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9888: foreach my $item (@toggles) {
1.160.6.5 raeburn 9889: if ($defaultchecked{$item} eq 'on') {
9890: if ($domconfig{'helpsettings'}{$item} eq '') {
9891: if ($env{'form.'.$item} eq '0') {
9892: $changes{$item} = 1;
9893: }
9894: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9895: $changes{$item} = 1;
9896: }
9897: } elsif ($defaultchecked{$item} eq 'off') {
9898: if ($domconfig{'helpsettings'}{$item} eq '') {
9899: if ($env{'form.'.$item} eq '1') {
9900: $changes{$item} = 1;
9901: }
9902: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9903: $changes{$item} = 1;
9904: }
1.160.6.26 raeburn 9905: }
1.160.6.5 raeburn 9906: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9907: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9908: }
9909: }
1.118 jms 9910: }
1.123 jms 9911: my $putresult;
9912: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9913: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9914: if ($putresult eq 'ok') {
9915: $resulttext = &mt('Changes made:').'<ul>';
9916: foreach my $item (sort(keys(%changes))) {
9917: if ($item eq 'submitbugs') {
9918: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9919: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9920: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9921: }
9922: }
9923: $resulttext .= '</ul>';
9924: } else {
9925: $resulttext = &mt('No changes made to help settings');
9926: $errors .= '<li><span class="LC_error">'.
9927: &mt('An error occurred storing the settings: [_1]',
9928: $putresult).'</span></li>';
9929: }
1.118 jms 9930: }
9931: if ($errors) {
1.160.6.5 raeburn 9932: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9933: $errors.'</ul>';
9934: }
9935: return $resulttext;
9936: }
9937:
1.121 raeburn 9938: sub modify_coursedefaults {
1.160.6.27 raeburn 9939: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9940: my ($resulttext,$errors,%changes,%defaultshash);
9941: my %defaultchecked = ('canuse_pdfforms' => 'off');
9942: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9943: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9944: 'uploadquota_community','uploadquota_textbook');
9945: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9946: my %staticdefaults = (
9947: anonsurvey_threshold => 10,
9948: uploadquota => 500,
9949: );
1.121 raeburn 9950:
9951: $defaultshash{'coursedefaults'} = {};
9952:
9953: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9954: if ($domconfig{'coursedefaults'} eq '') {
9955: $domconfig{'coursedefaults'} = {};
9956: }
9957: }
9958:
9959: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9960: foreach my $item (@toggles) {
9961: if ($defaultchecked{$item} eq 'on') {
9962: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9963: ($env{'form.'.$item} eq '0')) {
9964: $changes{$item} = 1;
1.160.6.16 raeburn 9965: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9966: $changes{$item} = 1;
9967: }
9968: } elsif ($defaultchecked{$item} eq 'off') {
9969: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9970: ($env{'form.'.$item} eq '1')) {
9971: $changes{$item} = 1;
9972: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9973: $changes{$item} = 1;
9974: }
9975: }
9976: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9977: }
1.160.6.21 raeburn 9978: foreach my $item (@numbers) {
9979: my ($currdef,$newdef);
1.160.6.26 raeburn 9980: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 9981: if ($item eq 'anonsurvey_threshold') {
9982: $currdef = $domconfig{'coursedefaults'}{$item};
9983: $newdef =~ s/\D//g;
9984: if ($newdef eq '' || $newdef < 1) {
9985: $newdef = 1;
9986: }
9987: $defaultshash{'coursedefaults'}{$item} = $newdef;
9988: } else {
9989: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9990: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9991: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9992: }
9993: $newdef =~ s/[^\w.\-]//g;
9994: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9995: }
9996: if ($currdef ne $newdef) {
9997: my $staticdef;
9998: if ($item eq 'anonsurvey_threshold') {
9999: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10000: $changes{$item} = 1;
10001: }
10002: } else {
10003: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10004: $changes{'uploadquota'} = 1;
10005: }
10006: }
1.139 raeburn 10007: }
10008: }
1.160.6.37 raeburn 10009:
1.160.6.16 raeburn 10010: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 10011: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10012: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 10013: $unofficialcreds =~ s/[^\d.]+//g;
10014: my $textbookcreds = $env{'form.textbook_credits'};
10015: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 10016: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10017: ($env{'form.coursecredits'} eq '1')) {
10018: $changes{'coursecredits'} = 1;
10019: } else {
10020: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 10021: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10022: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 10023: $changes{'coursecredits'} = 1;
10024: }
10025: }
10026: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10027: official => $officialcreds,
10028: unofficial => $unofficialcreds,
1.160.6.30 raeburn 10029: textbook => $textbookcreds,
1.160.6.16 raeburn 10030: }
1.121 raeburn 10031: }
10032: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10033: $dom);
10034: if ($putresult eq 'ok') {
10035: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10036: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 10037: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
10038: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 10039: if ($changes{'canuse_pdfforms'}) {
10040: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10041: }
10042: if ($changes{'coursecredits'}) {
10043: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10044: $domdefaults{'officialcredits'} =
10045: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10046: $domdefaults{'unofficialcredits'} =
10047: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 10048: $domdefaults{'textbookcredits'} =
10049: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 10050: }
10051: }
1.160.6.21 raeburn 10052: if ($changes{'uploadquota'}) {
10053: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10054: foreach my $type (@types) {
10055: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10056: }
10057: }
10058: }
1.121 raeburn 10059: my $cachetime = 24*60*60;
10060: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10061: if (ref($lastactref) eq 'HASH') {
10062: $lastactref->{'domdefaults'} = 1;
10063: }
1.121 raeburn 10064: }
10065: $resulttext = &mt('Changes made:').'<ul>';
10066: foreach my $item (sort(keys(%changes))) {
10067: if ($item eq 'canuse_pdfforms') {
10068: if ($env{'form.'.$item} eq '1') {
10069: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10070: } else {
10071: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10072: }
1.139 raeburn 10073: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10074: $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 10075: } elsif ($item eq 'uploadquota') {
10076: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10077: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10078: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10079: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10080: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10081:
1.160.6.21 raeburn 10082: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10083: '</ul>'.
10084: '</li>';
10085: } else {
10086: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10087: }
1.160.6.16 raeburn 10088: } elsif ($item eq 'coursecredits') {
10089: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10090: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10091: ($domdefaults{'unofficialcredits'} eq '') &&
10092: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10093: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10094: } else {
10095: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10096: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10097: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10098: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10099: '</ul>'.
10100: '</li>';
10101: }
10102: } else {
10103: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10104: }
1.140 raeburn 10105: }
1.121 raeburn 10106: }
10107: $resulttext .= '</ul>';
10108: } else {
10109: $resulttext = &mt('No changes made to course defaults');
10110: }
10111: } else {
10112: $resulttext = '<span class="LC_error">'.
10113: &mt('An error occurred: [_1]',$putresult).'</span>';
10114: }
10115: return $resulttext;
10116: }
10117:
1.160.6.37 raeburn 10118: sub modify_selfenrollment {
10119: my ($dom,$lastactref,%domconfig) = @_;
10120: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10121: my @types = ('official','unofficial','community','textbook');
10122: my %titles = &tool_titles();
10123: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10124: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10125: $ordered{'default'} = ['types','registered','approval','limit'];
10126:
10127: my (%roles,%shown,%toplevel);
10128: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10129:
10130: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10131: if ($domconfig{'selfenrollment'} eq '') {
10132: $domconfig{'selfenrollment'} = {};
10133: }
10134: }
10135: %toplevel = (
10136: admin => 'Configuration Rights',
10137: default => 'Default settings',
10138: validation => 'Validation of self-enrollment requests',
10139: );
10140: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10141:
10142: if (ref($ordered{'admin'}) eq 'ARRAY') {
10143: foreach my $item (@{$ordered{'admin'}}) {
10144: foreach my $type (@types) {
10145: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10146: $selfenrollhash{'admin'}{$type}{$item} = 1;
10147: } else {
10148: $selfenrollhash{'admin'}{$type}{$item} = 0;
10149: }
10150: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10151: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10152: if ($selfenrollhash{'admin'}{$type}{$item} ne
10153: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10154: push(@{$changes{'admin'}{$type}},$item);
10155: }
10156: } else {
10157: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10158: push(@{$changes{'admin'}{$type}},$item);
10159: }
10160: }
10161: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10162: push(@{$changes{'admin'}{$type}},$item);
10163: }
10164: }
10165: }
10166: }
10167:
10168: foreach my $item (@{$ordered{'default'}}) {
10169: foreach my $type (@types) {
10170: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10171: if ($item eq 'types') {
10172: unless (($value eq 'all') || ($value eq 'dom')) {
10173: $value = '';
10174: }
10175: } elsif ($item eq 'registered') {
10176: unless ($value eq '1') {
10177: $value = 0;
10178: }
10179: } elsif ($item eq 'approval') {
10180: unless ($value =~ /^[012]$/) {
10181: $value = 0;
10182: }
10183: } else {
10184: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10185: $value = 'none';
10186: }
10187: }
10188: $selfenrollhash{'default'}{$type}{$item} = $value;
10189: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10190: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10191: if ($selfenrollhash{'default'}{$type}{$item} ne
10192: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10193: push(@{$changes{'default'}{$type}},$item);
10194: }
10195: } else {
10196: push(@{$changes{'default'}{$type}},$item);
10197: }
10198: } else {
10199: push(@{$changes{'default'}{$type}},$item);
10200: }
10201: if ($item eq 'limit') {
10202: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10203: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10204: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10205: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10206: }
10207: } else {
10208: $selfenrollhash{'default'}{$type}{'cap'} = '';
10209: }
10210: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10211: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10212: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10213: push(@{$changes{'default'}{$type}},'cap');
10214: }
10215: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10216: push(@{$changes{'default'}{$type}},'cap');
10217: }
10218: }
10219: }
10220: }
10221:
10222: foreach my $item (@{$itemsref}) {
10223: if ($item eq 'fields') {
10224: my @changed;
10225: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10226: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10227: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10228: }
10229: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10230: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10231: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10232: $domconfig{'selfenrollment'}{'validation'}{$item});
10233: } else {
10234: @changed = @{$selfenrollhash{'validation'}{$item}};
10235: }
10236: } else {
10237: @changed = @{$selfenrollhash{'validation'}{$item}};
10238: }
10239: if (@changed) {
10240: if ($selfenrollhash{'validation'}{$item}) {
10241: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10242: } else {
10243: $changes{'validation'}{$item} = &mt('None');
10244: }
10245: }
10246: } else {
10247: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10248: if ($item eq 'markup') {
10249: if ($env{'form.selfenroll_validation_'.$item}) {
10250: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10251: }
10252: }
10253: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10254: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10255: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10256: }
10257: }
10258: }
10259: }
10260:
10261: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10262: $dom);
10263: if ($putresult eq 'ok') {
10264: if (keys(%changes) > 0) {
10265: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10266: $resulttext = &mt('Changes made:').'<ul>';
10267: foreach my $key ('admin','default','validation') {
10268: if (ref($changes{$key}) eq 'HASH') {
10269: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10270: if ($key eq 'validation') {
10271: foreach my $item (@{$itemsref}) {
10272: if (exists($changes{$key}{$item})) {
10273: if ($item eq 'markup') {
10274: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10275: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10276: } else {
10277: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10278: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10279: }
10280: }
10281: }
10282: } else {
10283: foreach my $type (@types) {
10284: if ($type eq 'community') {
10285: $roles{'1'} = &mt('Community personnel');
10286: } else {
10287: $roles{'1'} = &mt('Course personnel');
10288: }
10289: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10290: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10291: if ($key eq 'admin') {
10292: my @mgrdc = ();
10293: if (ref($ordered{$key}) eq 'ARRAY') {
10294: foreach my $item (@{$ordered{'admin'}}) {
10295: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10296: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10297: push(@mgrdc,$item);
10298: }
10299: }
10300: }
10301: if (@mgrdc) {
10302: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10303: } else {
10304: delete($domdefaults{$type.'selfenrolladmdc'});
10305: }
10306: }
10307: } else {
10308: if (ref($ordered{$key}) eq 'ARRAY') {
10309: foreach my $item (@{$ordered{$key}}) {
10310: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10311: $domdefaults{$type.'selfenroll'.$item} =
10312: $selfenrollhash{$key}{$type}{$item};
10313: }
10314: }
10315: }
10316: }
10317: }
10318: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10319: foreach my $item (@{$ordered{$key}}) {
10320: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10321: $resulttext .= '<li>';
10322: if ($key eq 'admin') {
10323: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10324: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10325: } else {
10326: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10327: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10328: }
10329: $resulttext .= '</li>';
10330: }
10331: }
10332: $resulttext .= '</ul></li>';
10333: }
10334: }
10335: $resulttext .= '</ul></li>';
10336: }
10337: }
10338: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10339: my $cachetime = 24*60*60;
10340: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10341: if (ref($lastactref) eq 'HASH') {
10342: $lastactref->{'domdefaults'} = 1;
10343: }
10344: }
10345: }
10346: $resulttext .= '</ul>';
10347: } else {
10348: $resulttext = &mt('No changes made to self-enrollment settings');
10349: }
10350: } else {
10351: $resulttext = '<span class="LC_error">'.
10352: &mt('An error occurred: [_1]',$putresult).'</span>';
10353: }
10354: return $resulttext;
10355: }
10356:
1.137 raeburn 10357: sub modify_usersessions {
1.160.6.27 raeburn 10358: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10359: my @hostingtypes = ('version','excludedomain','includedomain');
10360: my @offloadtypes = ('primary','default');
10361: my %types = (
10362: remote => \@hostingtypes,
10363: hosted => \@hostingtypes,
10364: spares => \@offloadtypes,
10365: );
10366: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10367: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10368: my (%by_ip,%by_location,@intdoms);
10369: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10370: my @locations = sort(keys(%by_location));
1.137 raeburn 10371: my (%defaultshash,%changes);
10372: foreach my $prefix (@prefixes) {
10373: $defaultshash{'usersessions'}{$prefix} = {};
10374: }
1.160.6.27 raeburn 10375: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10376: my $resulttext;
1.138 raeburn 10377: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10378: foreach my $prefix (@prefixes) {
1.145 raeburn 10379: next if ($prefix eq 'spares');
10380: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10381: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10382: if ($type eq 'version') {
10383: my $value = $env{'form.'.$prefix.'_'.$type};
10384: my $okvalue;
10385: if ($value ne '') {
10386: if (grep(/^\Q$value\E$/,@lcversions)) {
10387: $okvalue = $value;
10388: }
10389: }
10390: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10391: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10392: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10393: if ($inuse == 0) {
10394: $changes{$prefix}{$type} = 1;
10395: } else {
10396: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10397: $changes{$prefix}{$type} = 1;
10398: }
10399: if ($okvalue ne '') {
10400: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10401: }
10402: }
10403: } else {
10404: if (($inuse == 1) && ($okvalue ne '')) {
10405: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10406: $changes{$prefix}{$type} = 1;
10407: }
10408: }
10409: } else {
10410: if (($inuse == 1) && ($okvalue ne '')) {
10411: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10412: $changes{$prefix}{$type} = 1;
10413: }
10414: }
10415: } else {
10416: if (($inuse == 1) && ($okvalue ne '')) {
10417: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10418: $changes{$prefix}{$type} = 1;
10419: }
10420: }
10421: } else {
10422: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10423: my @okvals;
10424: foreach my $val (@vals) {
1.138 raeburn 10425: if ($val =~ /:/) {
10426: my @items = split(/:/,$val);
10427: foreach my $item (@items) {
10428: if (ref($by_location{$item}) eq 'ARRAY') {
10429: push(@okvals,$item);
10430: }
10431: }
10432: } else {
10433: if (ref($by_location{$val}) eq 'ARRAY') {
10434: push(@okvals,$val);
10435: }
1.137 raeburn 10436: }
10437: }
10438: @okvals = sort(@okvals);
10439: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10440: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10441: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10442: if ($inuse == 0) {
10443: $changes{$prefix}{$type} = 1;
10444: } else {
10445: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10446: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10447: if (@changed > 0) {
10448: $changes{$prefix}{$type} = 1;
10449: }
10450: }
10451: } else {
10452: if ($inuse == 1) {
10453: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10454: $changes{$prefix}{$type} = 1;
10455: }
10456: }
10457: } else {
10458: if ($inuse == 1) {
10459: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10460: $changes{$prefix}{$type} = 1;
10461: }
10462: }
10463: } else {
10464: if ($inuse == 1) {
10465: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10466: $changes{$prefix}{$type} = 1;
10467: }
10468: }
10469: }
10470: }
10471: }
1.145 raeburn 10472:
10473: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10474: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10475: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10476: my $savespares;
10477:
10478: foreach my $lonhost (sort(keys(%servers))) {
10479: my $serverhomeID =
10480: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10481: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10482: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10483: my %spareschg;
10484: foreach my $type (@{$types{'spares'}}) {
10485: my @okspares;
10486: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10487: foreach my $server (@checked) {
1.152 raeburn 10488: if (&Apache::lonnet::hostname($server) ne '') {
10489: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10490: unless (grep(/^\Q$server\E$/,@okspares)) {
10491: push(@okspares,$server);
10492: }
1.145 raeburn 10493: }
10494: }
10495: }
10496: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10497: my $newspare;
1.152 raeburn 10498: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10499: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10500: $newspare = $new;
10501: }
10502: }
1.152 raeburn 10503: my @spares;
10504: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10505: @spares = sort(@okspares,$newspare);
10506: } else {
10507: @spares = sort(@okspares);
10508: }
10509: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10510: if (ref($spareid{$lonhost}) eq 'HASH') {
10511: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10512: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10513: if (@diffs > 0) {
10514: $spareschg{$type} = 1;
10515: }
10516: }
10517: }
10518: }
10519: if (keys(%spareschg) > 0) {
10520: $changes{'spares'}{$lonhost} = \%spareschg;
10521: }
10522: }
10523:
10524: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10525: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10526: if (ref($changes{'spares'}) eq 'HASH') {
10527: if (keys(%{$changes{'spares'}}) > 0) {
10528: $savespares = 1;
10529: }
10530: }
10531: } else {
10532: $savespares = 1;
10533: }
10534: }
10535:
1.147 raeburn 10536: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10537: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10538: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10539: $dom);
10540: if ($putresult eq 'ok') {
10541: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10542: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10543: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10544: }
10545: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10546: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10547: }
10548: }
10549: my $cachetime = 24*60*60;
10550: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10551: if (ref($lastactref) eq 'HASH') {
10552: $lastactref->{'domdefaults'} = 1;
10553: }
1.147 raeburn 10554: if (keys(%changes) > 0) {
10555: my %lt = &usersession_titles();
10556: $resulttext = &mt('Changes made:').'<ul>';
10557: foreach my $prefix (@prefixes) {
10558: if (ref($changes{$prefix}) eq 'HASH') {
10559: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10560: if ($prefix eq 'spares') {
10561: if (ref($changes{$prefix}) eq 'HASH') {
10562: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10563: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10564: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10565: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10566: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10567: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10568: foreach my $type (@{$types{$prefix}}) {
10569: if ($changes{$prefix}{$lonhost}{$type}) {
10570: my $offloadto = &mt('None');
10571: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10572: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10573: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10574: }
1.145 raeburn 10575: }
1.147 raeburn 10576: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10577: }
1.137 raeburn 10578: }
10579: }
1.147 raeburn 10580: $resulttext .= '</li>';
1.137 raeburn 10581: }
10582: }
1.147 raeburn 10583: } else {
10584: foreach my $type (@{$types{$prefix}}) {
10585: if (defined($changes{$prefix}{$type})) {
10586: my $newvalue;
10587: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10588: if (ref($defaultshash{'usersessions'}{$prefix})) {
10589: if ($type eq 'version') {
10590: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10591: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10592: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10593: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10594: }
1.145 raeburn 10595: }
10596: }
10597: }
1.147 raeburn 10598: if ($newvalue eq '') {
10599: if ($type eq 'version') {
10600: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10601: } else {
10602: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10603: }
1.145 raeburn 10604: } else {
1.147 raeburn 10605: if ($type eq 'version') {
10606: $newvalue .= ' '.&mt('(or later)');
10607: }
10608: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10609: }
1.137 raeburn 10610: }
10611: }
10612: }
1.147 raeburn 10613: $resulttext .= '</ul>';
1.137 raeburn 10614: }
10615: }
1.147 raeburn 10616: $resulttext .= '</ul>';
10617: } else {
10618: $resulttext = $nochgmsg;
1.137 raeburn 10619: }
10620: } else {
10621: $resulttext = '<span class="LC_error">'.
10622: &mt('An error occurred: [_1]',$putresult).'</span>';
10623: }
10624: } else {
1.147 raeburn 10625: $resulttext = $nochgmsg;
1.137 raeburn 10626: }
10627: return $resulttext;
10628: }
10629:
1.150 raeburn 10630: sub modify_loadbalancing {
10631: my ($dom,%domconfig) = @_;
10632: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10633: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10634: my ($othertitle,$usertypes,$types) =
10635: &Apache::loncommon::sorted_inst_types($dom);
10636: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10637: my @sparestypes = ('primary','default');
10638: my %typetitles = &sparestype_titles();
10639: my $resulttext;
1.160.6.7 raeburn 10640: my (%currbalancer,%currtargets,%currrules,%existing);
10641: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10642: %existing = %{$domconfig{'loadbalancing'}};
10643: }
10644: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10645: \%currtargets,\%currrules);
10646: my ($saveloadbalancing,%defaultshash,%changes);
10647: my ($alltypes,$othertypes,$titles) =
10648: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10649: my %ruletitles = &offloadtype_text();
10650: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10651: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10652: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10653: if ($balancer eq '') {
10654: next;
10655: }
10656: if (!exists($servers{$balancer})) {
10657: if (exists($currbalancer{$balancer})) {
10658: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10659: }
1.160.6.7 raeburn 10660: next;
10661: }
10662: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10663: push(@{$changes{'delete'}},$balancer);
10664: next;
10665: }
10666: if (!exists($currbalancer{$balancer})) {
10667: push(@{$changes{'add'}},$balancer);
10668: }
10669: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10670: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10671: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10672: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10673: $saveloadbalancing = 1;
10674: }
10675: foreach my $sparetype (@sparestypes) {
10676: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10677: my @offloadto;
10678: foreach my $target (@targets) {
10679: if (($servers{$target}) && ($target ne $balancer)) {
10680: if ($sparetype eq 'default') {
10681: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10682: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10683: }
10684: }
1.160.6.7 raeburn 10685: unless(grep(/^\Q$target\E$/,@offloadto)) {
10686: push(@offloadto,$target);
10687: }
1.150 raeburn 10688: }
1.160.6.7 raeburn 10689: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10690: }
10691: }
1.160.6.7 raeburn 10692: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10693: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10694: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10695: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10696: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10697: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10698: }
1.160.6.7 raeburn 10699: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10700: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10701: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10702: }
10703: }
10704: }
10705: } else {
1.160.6.7 raeburn 10706: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10707: foreach my $sparetype (@sparestypes) {
10708: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10709: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10710: $changes{'curr'}{$balancer}{'targets'} = 1;
10711: }
1.150 raeburn 10712: }
10713: }
1.160.6.7 raeburn 10714: }
1.150 raeburn 10715: }
10716: my $ishomedom;
1.160.6.7 raeburn 10717: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10718: $ishomedom = 1;
1.150 raeburn 10719: }
10720: if (ref($alltypes) eq 'ARRAY') {
10721: foreach my $type (@{$alltypes}) {
10722: my $rule;
1.160.6.7 raeburn 10723: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10724: (!$ishomedom)) {
1.160.6.7 raeburn 10725: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10726: }
10727: if ($rule eq 'specific') {
10728: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10729: }
1.160.6.7 raeburn 10730: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10731: if (ref($currrules{$balancer}) eq 'HASH') {
10732: if ($rule ne $currrules{$balancer}{$type}) {
10733: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10734: }
10735: } elsif ($rule ne '') {
1.160.6.7 raeburn 10736: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10737: }
10738: }
10739: }
1.160.6.7 raeburn 10740: }
10741: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10742: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10743: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10744: $defaultshash{'loadbalancing'} = {};
10745: }
10746: my $putresult = &Apache::lonnet::put_dom('configuration',
10747: \%defaultshash,$dom);
10748: if ($putresult eq 'ok') {
10749: if (keys(%changes) > 0) {
10750: if (ref($changes{'delete'}) eq 'ARRAY') {
10751: foreach my $balancer (sort(@{$changes{'delete'}})) {
10752: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10753: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10754: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10755: }
1.160.6.7 raeburn 10756: }
10757: if (ref($changes{'add'}) eq 'ARRAY') {
10758: foreach my $balancer (sort(@{$changes{'add'}})) {
10759: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10760: }
10761: }
10762: if (ref($changes{'curr'}) eq 'HASH') {
10763: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10764: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10765: if ($changes{'curr'}{$balancer}{'targets'}) {
10766: my %offloadstr;
10767: foreach my $sparetype (@sparestypes) {
10768: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10769: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10770: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10771: }
10772: }
1.150 raeburn 10773: }
1.160.6.7 raeburn 10774: if (keys(%offloadstr) == 0) {
10775: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10776: } else {
1.160.6.7 raeburn 10777: my $showoffload;
10778: foreach my $sparetype (@sparestypes) {
10779: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10780: if (defined($offloadstr{$sparetype})) {
10781: $showoffload .= $offloadstr{$sparetype};
10782: } else {
10783: $showoffload .= &mt('None');
10784: }
10785: $showoffload .= (' 'x3);
10786: }
10787: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10788: }
10789: }
10790: }
1.160.6.7 raeburn 10791: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10792: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10793: foreach my $type (@{$alltypes}) {
10794: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10795: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10796: my $balancetext;
10797: if ($rule eq '') {
10798: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10799: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10800: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10801: $balancetext = $ruletitles{$rule};
10802: } else {
10803: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10804: }
1.160.6.26 raeburn 10805: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10806: }
10807: }
10808: }
10809: }
1.160.6.29 raeburn 10810: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10811: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10812: }
1.160.6.7 raeburn 10813: }
10814: if ($resulttext ne '') {
10815: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10816: } else {
10817: $resulttext = $nochgmsg;
10818: }
10819: } else {
1.160.6.7 raeburn 10820: $resulttext = $nochgmsg;
1.150 raeburn 10821: }
10822: } else {
1.160.6.7 raeburn 10823: $resulttext = '<span class="LC_error">'.
10824: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10825: }
10826: } else {
1.160.6.7 raeburn 10827: $resulttext = $nochgmsg;
1.150 raeburn 10828: }
10829: return $resulttext;
10830: }
10831:
1.48 raeburn 10832: sub recurse_check {
10833: my ($chkcats,$categories,$depth,$name) = @_;
10834: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10835: my $chg = 0;
10836: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10837: my $category = $chkcats->[$depth]{$name}[$j];
10838: my $item;
10839: if ($category eq '') {
10840: $chg ++;
10841: } else {
10842: my $deeper = $depth + 1;
10843: $item = &escape($category).':'.&escape($name).':'.$depth;
10844: if ($chg) {
10845: $categories->{$item} -= $chg;
10846: }
10847: &recurse_check($chkcats,$categories,$deeper,$category);
10848: $deeper --;
10849: }
10850: }
10851: }
10852: return;
10853: }
10854:
10855: sub recurse_cat_deletes {
10856: my ($item,$coursecategories,$deletions) = @_;
10857: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10858: my $subdepth = $depth + 1;
10859: if (ref($coursecategories) eq 'HASH') {
10860: foreach my $subitem (keys(%{$coursecategories})) {
10861: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10862: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10863: delete($coursecategories->{$subitem});
10864: $deletions->{$subitem} = 1;
10865: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10866: }
1.48 raeburn 10867: }
10868: }
10869: return;
10870: }
10871:
1.125 raeburn 10872: sub get_active_dcs {
10873: my ($dom) = @_;
1.160.6.16 raeburn 10874: my $now = time;
10875: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10876: my %domcoords;
10877: my $numdcs = 0;
10878: foreach my $server (keys(%dompersonnel)) {
10879: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10880: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10881: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10882: }
10883: }
10884: return %domcoords;
10885: }
10886:
10887: sub active_dc_picker {
1.160.6.16 raeburn 10888: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10889: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10890: my @domcoord = keys(%domcoords);
10891: if (keys(%currhash)) {
10892: foreach my $dc (keys(%currhash)) {
10893: unless (exists($domcoords{$dc})) {
10894: push(@domcoord,$dc);
10895: }
10896: }
10897: }
10898: @domcoord = sort(@domcoord);
10899: my $numdcs = scalar(@domcoord);
10900: my $rows = 0;
10901: my $table;
1.125 raeburn 10902: if ($numdcs > 1) {
1.160.6.16 raeburn 10903: $table = '<table>';
10904: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10905: my $rem = $i%($numinrow);
10906: if ($rem == 0) {
10907: if ($i > 0) {
1.160.6.16 raeburn 10908: $table .= '</tr>';
1.125 raeburn 10909: }
1.160.6.16 raeburn 10910: $table .= '<tr>';
10911: $rows ++;
1.125 raeburn 10912: }
1.160.6.16 raeburn 10913: my $check = '';
10914: if ($inputtype eq 'radio') {
10915: if (keys(%currhash) == 0) {
10916: if (!$i) {
10917: $check = ' checked="checked"';
10918: }
10919: } elsif (exists($currhash{$domcoord[$i]})) {
10920: $check = ' checked="checked"';
10921: }
10922: } else {
10923: if (exists($currhash{$domcoord[$i]})) {
10924: $check = ' checked="checked"';
1.125 raeburn 10925: }
10926: }
1.160.6.16 raeburn 10927: if ($i == @domcoord - 1) {
1.125 raeburn 10928: my $colsleft = $numinrow - $rem;
10929: if ($colsleft > 1) {
1.160.6.16 raeburn 10930: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10931: } else {
1.160.6.16 raeburn 10932: $table .= '<td class="LC_left_item">';
1.125 raeburn 10933: }
10934: } else {
1.160.6.16 raeburn 10935: $table .= '<td class="LC_left_item">';
10936: }
10937: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10938: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10939: $table .= '<span class="LC_nobreak"><label>'.
10940: '<input type="'.$inputtype.'" name="'.$name.'"'.
10941: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10942: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10943: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10944: }
1.160.6.33 raeburn 10945: $table .= '</label></span></td>';
1.125 raeburn 10946: }
1.160.6.16 raeburn 10947: $table .= '</tr></table>';
10948: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10949: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10950: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10951: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 10952: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10953: if ($user ne $dcname.':'.$dcdom) {
10954: $table .= ' ('.$dcname.':'.$dcdom.')';
10955: }
1.160.6.16 raeburn 10956: } else {
10957: my $check;
10958: if (exists($currhash{$domcoord[0]})) {
10959: $check = ' checked="checked"';
10960: }
1.160.6.31 raeburn 10961: $table .= '<span class="LC_nobreak"><label>'.
10962: '<input type="checkbox" name="'.$name.'" '.
10963: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10964: if ($user ne $dcname.':'.$dcdom) {
10965: $table .= ' ('.$dcname.':'.$dcdom.')';
10966: }
10967: $table .= '</label></span>';
1.160.6.16 raeburn 10968: $rows ++;
10969: }
1.125 raeburn 10970: }
1.160.6.16 raeburn 10971: return ($numdcs,$table,$rows);
1.125 raeburn 10972: }
10973:
1.137 raeburn 10974: sub usersession_titles {
10975: return &Apache::lonlocal::texthash(
10976: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10977: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10978: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10979: version => 'LON-CAPA version requirement',
1.138 raeburn 10980: excludedomain => 'Allow all, but exclude specific domains',
10981: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10982: primary => 'Primary (checked first)',
1.154 raeburn 10983: default => 'Default',
1.137 raeburn 10984: );
10985: }
10986:
1.152 raeburn 10987: sub id_for_thisdom {
10988: my (%servers) = @_;
10989: my %altids;
10990: foreach my $server (keys(%servers)) {
10991: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10992: if ($serverhome ne $server) {
10993: $altids{$serverhome} = $server;
10994: }
10995: }
10996: return %altids;
10997: }
10998:
1.150 raeburn 10999: sub count_servers {
11000: my ($currbalancer,%servers) = @_;
11001: my (@spares,$numspares);
11002: foreach my $lonhost (sort(keys(%servers))) {
11003: next if ($currbalancer eq $lonhost);
11004: push(@spares,$lonhost);
11005: }
11006: if ($currbalancer) {
11007: $numspares = scalar(@spares);
11008: } else {
11009: $numspares = scalar(@spares) - 1;
11010: }
11011: return ($numspares,@spares);
11012: }
11013:
11014: sub lonbalance_targets_js {
1.160.6.7 raeburn 11015: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11016: my $select = &mt('Select');
11017: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11018: if (ref($servers) eq 'HASH') {
11019: $alltargets = join("','",sort(keys(%{$servers})));
11020: my @homedoms;
11021: foreach my $server (sort(keys(%{$servers}))) {
11022: if (&Apache::lonnet::host_domain($server) eq $dom) {
11023: push(@homedoms,'1');
11024: } else {
11025: push(@homedoms,'0');
11026: }
11027: }
11028: $allishome = join("','",@homedoms);
11029: }
11030: if (ref($types) eq 'ARRAY') {
11031: if (@{$types} > 0) {
11032: @alltypes = @{$types};
11033: }
11034: }
11035: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11036: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11037: my (%currbalancer,%currtargets,%currrules,%existing);
11038: if (ref($settings) eq 'HASH') {
11039: %existing = %{$settings};
11040: }
11041: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11042: \%currtargets,\%currrules);
11043: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11044: return <<"END";
11045:
11046: <script type="text/javascript">
11047: // <![CDATA[
11048:
1.160.6.7 raeburn 11049: currBalancers = new Array('$balancers');
11050:
11051: function toggleTargets(balnum) {
11052: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11053: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11054: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11055: var prevbalancer = prevhostitem.value;
11056: var baltotal = document.getElementById('loadbalancing_total').value;
11057: prevhostitem.value = balancer;
11058: if (prevbalancer != '') {
11059: var prevIdx = currBalancers.indexOf(prevbalancer);
11060: if (prevIdx != -1) {
11061: currBalancers.splice(prevIdx,1);
11062: }
11063: }
1.150 raeburn 11064: if (balancer == '') {
1.160.6.7 raeburn 11065: hideSpares(balnum);
1.150 raeburn 11066: } else {
1.160.6.7 raeburn 11067: var currIdx = currBalancers.indexOf(balancer);
11068: if (currIdx == -1) {
11069: currBalancers.push(balancer);
11070: }
1.150 raeburn 11071: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11072: var ishomedom = homedoms[lonhostitem.selectedIndex];
11073: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11074: }
1.160.6.7 raeburn 11075: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11076: return;
11077: }
11078:
1.160.6.7 raeburn 11079: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11080: var alltargets = new Array('$alltargets');
11081: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11082: var offloadtypes = new Array('primary','default');
11083:
1.160.6.7 raeburn 11084: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11085: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11086:
1.151 raeburn 11087: for (var i=0; i<offloadtypes.length; i++) {
11088: var count = 0;
11089: for (var j=0; j<alltargets.length; j++) {
11090: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11091: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11092: item.value = alltargets[j];
11093: item.style.textAlign='left';
11094: item.style.textFace='normal';
11095: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11096: if (currBalancers.indexOf(alltargets[j]) == -1) {
11097: item.disabled = '';
11098: } else {
11099: item.disabled = 'disabled';
11100: item.checked = false;
11101: }
1.151 raeburn 11102: count ++;
11103: }
1.150 raeburn 11104: }
11105: }
1.151 raeburn 11106: for (var k=0; k<insttypes.length; k++) {
11107: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11108: if (ishomedom == 1) {
1.160.6.7 raeburn 11109: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11110: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11111: } else {
1.160.6.7 raeburn 11112: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11113: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11114: }
11115: } else {
1.160.6.7 raeburn 11116: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11117: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11118: }
1.151 raeburn 11119: if ((insttypes[k] != '_LC_external') &&
11120: ((insttypes[k] != '_LC_internetdom') ||
11121: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11122: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11123: item.options.length = 0;
11124: item.options[0] = new Option("","",true,true);
11125: var idx = 0;
1.151 raeburn 11126: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11127: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11128: idx ++;
11129: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11130: }
11131: }
11132: }
11133: }
11134: return;
11135: }
11136:
1.160.6.7 raeburn 11137: function hideSpares(balnum) {
1.150 raeburn 11138: var alltargets = new Array('$alltargets');
11139: var insttypes = new Array('$allinsttypes');
11140: var offloadtypes = new Array('primary','default');
11141:
1.160.6.7 raeburn 11142: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11143: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11144:
11145: var total = alltargets.length - 1;
11146: for (var i=0; i<offloadtypes; i++) {
11147: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11148: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11149: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11150: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11151: }
1.150 raeburn 11152: }
11153: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11154: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11155: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11156: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11157: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11158: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11159: }
11160: }
11161: return;
11162: }
11163:
1.160.6.7 raeburn 11164: function checkOffloads(item,balnum,type) {
1.150 raeburn 11165: var alltargets = new Array('$alltargets');
11166: var offloadtypes = new Array('primary','default');
11167: if (item.checked) {
11168: var total = alltargets.length - 1;
11169: var other;
11170: if (type == offloadtypes[0]) {
1.151 raeburn 11171: other = offloadtypes[1];
1.150 raeburn 11172: } else {
1.151 raeburn 11173: other = offloadtypes[0];
1.150 raeburn 11174: }
11175: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11176: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11177: if (server == item.value) {
1.160.6.7 raeburn 11178: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11179: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11180: }
11181: }
11182: }
11183: }
11184: return;
11185: }
11186:
1.160.6.7 raeburn 11187: function singleServerToggle(balnum,type) {
11188: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11189: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11190: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11191: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11192:
11193: } else {
1.160.6.7 raeburn 11194: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11195: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11196: }
11197: return;
11198: }
11199:
1.160.6.7 raeburn 11200: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11201: if (type == '_LC_external') {
1.160.6.26 raeburn 11202: return;
1.150 raeburn 11203: }
1.160.6.7 raeburn 11204: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11205: for (var i=0; i<typesRules.length; i++) {
11206: if (formname.elements[typesRules[i]].checked) {
11207: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11208: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11209: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11210: } else {
1.160.6.7 raeburn 11211: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11212: }
11213: }
11214: }
11215: return;
11216: }
11217:
11218: function balancerDeleteChange(balnum) {
11219: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11220: var baltotal = document.getElementById('loadbalancing_total').value;
11221: var addtarget;
11222: var removetarget;
11223: var action = 'delete';
11224: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11225: var lonhost = hostitem.value;
11226: var currIdx = currBalancers.indexOf(lonhost);
11227: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11228: if (currIdx != -1) {
11229: currBalancers.splice(currIdx,1);
11230: }
11231: addtarget = lonhost;
11232: } else {
11233: if (currIdx == -1) {
11234: currBalancers.push(lonhost);
11235: }
11236: removetarget = lonhost;
11237: action = 'undelete';
11238: }
11239: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11240: }
11241: return;
11242: }
11243:
11244: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11245: if (baltotal > 1) {
11246: var offloadtypes = new Array('primary','default');
11247: var alltargets = new Array('$alltargets');
11248: var insttypes = new Array('$allinsttypes');
11249: for (var i=0; i<baltotal; i++) {
11250: if (i != balnum) {
11251: for (var j=0; j<offloadtypes.length; j++) {
11252: var total = alltargets.length - 1;
11253: for (var k=0; k<total; k++) {
11254: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11255: var server = serveritem.value;
11256: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11257: if (server == addtarget) {
11258: serveritem.disabled = '';
11259: }
11260: }
11261: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11262: if (server == removetarget) {
11263: serveritem.disabled = 'disabled';
11264: serveritem.checked = false;
11265: }
11266: }
11267: }
11268: }
11269: for (var j=0; j<insttypes.length; j++) {
11270: if (insttypes[j] != '_LC_external') {
11271: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11272: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11273: var currSel = singleserver.selectedIndex;
11274: var currVal = singleserver.options[currSel].value;
11275: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11276: var numoptions = singleserver.options.length;
11277: var needsnew = 1;
11278: for (var k=0; k<numoptions; k++) {
11279: if (singleserver.options[k] == addtarget) {
11280: needsnew = 0;
11281: break;
11282: }
11283: }
11284: if (needsnew == 1) {
11285: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11286: }
11287: }
11288: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11289: singleserver.options.length = 0;
11290: if ((currVal) && (currVal != removetarget)) {
11291: singleserver.options[0] = new Option("","",false,false);
11292: } else {
11293: singleserver.options[0] = new Option("","",true,true);
11294: }
11295: var idx = 0;
11296: for (var m=0; m<alltargets.length; m++) {
11297: if (currBalancers.indexOf(alltargets[m]) == -1) {
11298: idx ++;
11299: if (currVal == alltargets[m]) {
11300: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11301: } else {
11302: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11303: }
11304: }
11305: }
11306: }
11307: }
11308: }
11309: }
1.150 raeburn 11310: }
11311: }
11312: }
11313: return;
11314: }
11315:
1.152 raeburn 11316: // ]]>
11317: </script>
11318:
11319: END
11320: }
11321:
11322: sub new_spares_js {
11323: my @sparestypes = ('primary','default');
11324: my $types = join("','",@sparestypes);
11325: my $select = &mt('Select');
11326: return <<"END";
11327:
11328: <script type="text/javascript">
11329: // <![CDATA[
11330:
11331: function updateNewSpares(formname,lonhost) {
11332: var types = new Array('$types');
11333: var include = new Array();
11334: var exclude = new Array();
11335: for (var i=0; i<types.length; i++) {
11336: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11337: for (var j=0; j<spareboxes.length; j++) {
11338: if (formname.elements[spareboxes[j]].checked) {
11339: exclude.push(formname.elements[spareboxes[j]].value);
11340: } else {
11341: include.push(formname.elements[spareboxes[j]].value);
11342: }
11343: }
11344: }
11345: for (var i=0; i<types.length; i++) {
11346: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11347: var selIdx = newSpare.selectedIndex;
11348: var currnew = newSpare.options[selIdx].value;
11349: var okSpares = new Array();
11350: for (var j=0; j<newSpare.options.length; j++) {
11351: var possible = newSpare.options[j].value;
11352: if (possible != '') {
11353: if (exclude.indexOf(possible) == -1) {
11354: okSpares.push(possible);
11355: } else {
11356: if (currnew == possible) {
11357: selIdx = 0;
11358: }
11359: }
11360: }
11361: }
11362: for (var k=0; k<include.length; k++) {
11363: if (okSpares.indexOf(include[k]) == -1) {
11364: okSpares.push(include[k]);
11365: }
11366: }
11367: okSpares.sort();
11368: newSpare.options.length = 0;
11369: if (selIdx == 0) {
11370: newSpare.options[0] = new Option("$select","",true,true);
11371: } else {
11372: newSpare.options[0] = new Option("$select","",false,false);
11373: }
11374: for (var m=0; m<okSpares.length; m++) {
11375: var idx = m+1;
11376: var selThis = 0;
11377: if (selIdx != 0) {
11378: if (okSpares[m] == currnew) {
11379: selThis = 1;
11380: }
11381: }
11382: if (selThis == 1) {
11383: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11384: } else {
11385: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11386: }
11387: }
11388: }
11389: return;
11390: }
11391:
11392: function checkNewSpares(lonhost,type) {
11393: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11394: var chosen = newSpare.options[newSpare.selectedIndex].value;
11395: if (chosen != '') {
11396: var othertype;
11397: var othernewSpare;
11398: if (type == 'primary') {
11399: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11400: }
11401: if (type == 'default') {
11402: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11403: }
11404: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11405: othernewSpare.selectedIndex = 0;
11406: }
11407: }
11408: return;
11409: }
11410:
11411: // ]]>
11412: </script>
11413:
11414: END
11415:
11416: }
11417:
11418: sub common_domprefs_js {
11419: return <<"END";
11420:
11421: <script type="text/javascript">
11422: // <![CDATA[
11423:
1.150 raeburn 11424: function getIndicesByName(formname,item) {
1.152 raeburn 11425: var group = new Array();
1.150 raeburn 11426: for (var i=0;i<formname.elements.length;i++) {
11427: if (formname.elements[i].name == item) {
1.152 raeburn 11428: group.push(formname.elements[i].id);
1.150 raeburn 11429: }
11430: }
1.152 raeburn 11431: return group;
1.150 raeburn 11432: }
11433:
11434: // ]]>
11435: </script>
11436:
11437: END
1.152 raeburn 11438:
1.150 raeburn 11439: }
11440:
1.160.6.5 raeburn 11441: sub recaptcha_js {
11442: my %lt = &captcha_phrases();
11443: return <<"END";
11444:
11445: <script type="text/javascript">
11446: // <![CDATA[
11447:
11448: function updateCaptcha(caller,context) {
11449: var privitem;
11450: var pubitem;
11451: var privtext;
11452: var pubtext;
11453: if (document.getElementById(context+'_recaptchapub')) {
11454: pubitem = document.getElementById(context+'_recaptchapub');
11455: } else {
11456: return;
11457: }
11458: if (document.getElementById(context+'_recaptchapriv')) {
11459: privitem = document.getElementById(context+'_recaptchapriv');
11460: } else {
11461: return;
11462: }
11463: if (document.getElementById(context+'_recaptchapubtxt')) {
11464: pubtext = document.getElementById(context+'_recaptchapubtxt');
11465: } else {
11466: return;
11467: }
11468: if (document.getElementById(context+'_recaptchaprivtxt')) {
11469: privtext = document.getElementById(context+'_recaptchaprivtxt');
11470: } else {
11471: return;
11472: }
11473: if (caller.checked) {
11474: if (caller.value == 'recaptcha') {
11475: pubitem.type = 'text';
11476: privitem.type = 'text';
11477: pubitem.size = '40';
11478: privitem.size = '40';
11479: pubtext.innerHTML = "$lt{'pub'}";
11480: privtext.innerHTML = "$lt{'priv'}";
11481: } else {
11482: pubitem.type = 'hidden';
11483: privitem.type = 'hidden';
11484: pubtext.innerHTML = '';
11485: privtext.innerHTML = '';
11486: }
11487: }
11488: return;
11489: }
11490:
11491: // ]]>
11492: </script>
11493:
11494: END
11495:
11496: }
11497:
1.160.6.40 raeburn 11498: sub toggle_display_js {
1.160.6.16 raeburn 11499: return <<"END";
11500:
11501: <script type="text/javascript">
11502: // <![CDATA[
11503:
1.160.6.40 raeburn 11504: function toggleDisplay(domForm,caller) {
11505: if (document.getElementById(caller)) {
11506: var divitem = document.getElementById(caller);
11507: var optionsElement = domForm.coursecredits;
11508: if (caller == 'emailoptions') {
11509: optionsElement = domForm.cancreate_email;
11510: }
11511: if (optionsElement.length) {
1.160.6.16 raeburn 11512: var currval;
1.160.6.40 raeburn 11513: for (var i=0; i<optionsElement.length; i++) {
11514: if (optionsElement[i].checked) {
11515: currval = optionsElement[i].value;
1.160.6.16 raeburn 11516: }
11517: }
11518: if (currval == 1) {
1.160.6.40 raeburn 11519: divitem.style.display = 'block';
1.160.6.16 raeburn 11520: } else {
1.160.6.40 raeburn 11521: divitem.style.display = 'none';
1.160.6.16 raeburn 11522: }
11523: }
11524: }
11525: return;
11526: }
11527:
11528: // ]]>
11529: </script>
11530:
11531: END
11532:
11533: }
11534:
1.160.6.5 raeburn 11535: sub captcha_phrases {
11536: return &Apache::lonlocal::texthash (
11537: priv => 'Private key',
11538: pub => 'Public key',
11539: original => 'original (CAPTCHA)',
11540: recaptcha => 'successor (ReCAPTCHA)',
11541: notused => 'unused',
11542: );
11543: }
11544:
1.160.6.24 raeburn 11545: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11546: my ($dom,$cachekeys) = @_;
11547: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11548: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11549: my %thismachine;
11550: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11551: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11552: if (keys(%servers) > 1) {
11553: foreach my $server (keys(%servers)) {
11554: next if ($thismachine{$server});
1.160.6.27 raeburn 11555: my @cached;
11556: foreach my $name (@posscached) {
11557: if ($cachekeys->{$name}) {
11558: push(@cached,&escape($name).':'.&escape($dom));
11559: }
11560: }
11561: if (@cached) {
11562: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11563: }
1.160.6.24 raeburn 11564: }
11565: }
11566: return;
11567: }
11568:
1.3 raeburn 11569: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>