Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.72
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.72! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.71 2016/09/18 19:22:48 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.41 raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: 'usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.160.6.56 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 255: col2 => 'Value'}],
1.160.6.37 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.160.6.40 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.160.6.40 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.160.6.20 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.160.6.28 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.160.6.37 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.160.6.35 raeburn 294: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.160.6.37 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
1.160.6.72! raeburn 307: { text => 'Directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72! raeburn 309: header => [{col1 => 'Institutional Directory Setting',
! 310: col2 => 'Value',},
! 311: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 312: col2 => 'Value',}],
1.160.6.37 raeburn 313: print => \&print_directorysrch,
314: modify => \&modify_directorysrch,
1.30 raeburn 315: },
316: 'contacts' =>
317: { text => 'Contact Information',
1.67 raeburn 318: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 319: header => [{col1 => 'Setting',
320: col2 => 'Value',}],
1.160.6.37 raeburn 321: print => \&print_contacts,
322: modify => \&modify_contacts,
1.30 raeburn 323: },
324: 'usercreation' =>
325: { text => 'User creation',
1.67 raeburn 326: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 327: header => [{col1 => 'Format rule type',
328: col2 => 'Format rules in force'},
1.34 raeburn 329: {col1 => 'User account creation',
330: col2 => 'Usernames which may be created',},
1.30 raeburn 331: {col1 => 'Context',
1.43 raeburn 332: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 333: print => \&print_usercreation,
334: modify => \&modify_usercreation,
1.30 raeburn 335: },
1.160.6.34 raeburn 336: 'selfcreation' =>
337: { text => 'Users self-creating accounts',
338: help => 'Domain_Configuration_Self_Creation',
339: header => [{col1 => 'Self-creation with institutional username',
340: col2 => 'Enabled?'},
341: {col1 => 'Institutional user type (login/SSO self-creation)',
342: col2 => 'Information user can enter'},
343: {col1 => 'Self-creation with e-mail as username',
344: col2 => 'Settings'}],
1.160.6.37 raeburn 345: print => \&print_selfcreation,
346: modify => \&modify_selfcreation,
1.160.6.34 raeburn 347: },
1.69 raeburn 348: 'usermodification' =>
1.33 raeburn 349: { text => 'User modification',
1.67 raeburn 350: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 351: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 352: col2 => 'User information updatable in author context'},
1.33 raeburn 353: {col1 => 'Target user has role',
1.160.6.35 raeburn 354: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 355: print => \&print_usermodification,
356: modify => \&modify_usermodification,
1.33 raeburn 357: },
1.69 raeburn 358: 'scantron' =>
1.95 www 359: { text => 'Bubblesheet format file',
1.67 raeburn 360: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 361: header => [ {col1 => 'Item',
362: col2 => '',
363: }],
1.160.6.37 raeburn 364: print => \&print_scantron,
365: modify => \&modify_scantron,
1.46 raeburn 366: },
1.86 raeburn 367: 'requestcourses' =>
368: {text => 'Request creation of courses',
369: help => 'Domain_Configuration_Request_Courses',
370: header => [{col1 => 'User affiliation',
1.102 raeburn 371: col2 => 'Availability/Processing of requests',},
372: {col1 => 'Setting',
1.160.6.30 raeburn 373: col2 => 'Value'},
374: {col1 => 'Available textbooks',
1.160.6.39 raeburn 375: col2 => ''},
1.160.6.46 raeburn 376: {col1 => 'Available templates',
377: col2 => ''},
1.160.6.39 raeburn 378: {col1 => 'Validation (not official courses)',
379: col2 => 'Value'},],
1.160.6.37 raeburn 380: print => \&print_quotas,
381: modify => \&modify_quotas,
1.86 raeburn 382: },
1.160.6.5 raeburn 383: 'requestauthor' =>
1.160.6.34 raeburn 384: {text => 'Request Authoring Space',
1.160.6.5 raeburn 385: help => 'Domain_Configuration_Request_Author',
386: header => [{col1 => 'User affiliation',
387: col2 => 'Availability/Processing of requests',},
388: {col1 => 'Setting',
389: col2 => 'Value'}],
1.160.6.37 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.160.6.5 raeburn 392: },
1.69 raeburn 393: 'coursecategories' =>
1.120 raeburn 394: { text => 'Cataloging of courses/communities',
1.67 raeburn 395: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 396: header => [{col1 => 'Catalog type/availability',
397: col2 => '',},
398: {col1 => 'Category settings for standard catalog',
1.57 raeburn 399: col2 => '',},
400: {col1 => 'Categories',
401: col2 => '',
402: }],
1.160.6.37 raeburn 403: print => \&print_coursecategories,
404: modify => \&modify_coursecategories,
1.69 raeburn 405: },
406: 'serverstatuses' =>
1.77 raeburn 407: {text => 'Access to server status pages',
1.69 raeburn 408: help => 'Domain_Configuration_Server_Status',
409: header => [{col1 => 'Status Page',
410: col2 => 'Other named users',
411: col3 => 'Specific IPs',
412: }],
1.160.6.37 raeburn 413: print => \&print_serverstatuses,
414: modify => \&modify_serverstatuses,
1.69 raeburn 415: },
1.160.6.39 raeburn 416: 'coursedefaults' =>
1.160.6.16 raeburn 417: {text => 'Course/Community defaults',
418: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 419: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
420: col2 => 'Value',},
421: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 422: col2 => 'Value',},],
1.160.6.37 raeburn 423: print => \&print_coursedefaults,
424: modify => \&modify_coursedefaults,
425: },
1.160.6.39 raeburn 426: 'selfenrollment' =>
1.160.6.37 raeburn 427: {text => 'Self-enrollment in Course/Community',
428: help => 'Domain_Configuration_Selfenrollment',
429: header => [{col1 => 'Configuration Rights',
430: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
431: {col1 => 'Defaults',
432: col2 => 'Value'},
433: {col1 => 'Self-enrollment validation (optional)',
434: col2 => 'Value'},],
435: print => \&print_selfenrollment,
436: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 437: },
1.141 raeburn 438: 'usersessions' =>
1.145 raeburn 439: {text => 'User session hosting/offloading',
1.137 raeburn 440: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 441: header => [{col1 => 'Domain server',
442: col2 => 'Servers to offload sessions to when busy'},
443: {col1 => 'Hosting of users from other domains',
1.137 raeburn 444: col2 => 'Rules'},
445: {col1 => "Hosting domain's own users elsewhere",
446: col2 => 'Rules'}],
1.160.6.37 raeburn 447: print => \&print_usersessions,
448: modify => \&modify_usersessions,
1.137 raeburn 449: },
1.150 raeburn 450: 'loadbalancing' =>
1.160.6.7 raeburn 451: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 452: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 453: header => [{col1 => 'Balancers',
1.150 raeburn 454: col2 => 'Default destinations',
1.160.6.13 raeburn 455: col3 => 'User affiliation',
1.150 raeburn 456: col4 => 'Overrides'},
457: ],
1.160.6.37 raeburn 458: print => \&print_loadbalancing,
459: modify => \&modify_loadbalancing,
1.150 raeburn 460: },
1.3 raeburn 461: );
1.110 raeburn 462: if (keys(%servers) > 1) {
463: $prefs{'login'} = { text => 'Log-in page options',
464: help => 'Domain_Configuration_Login_Page',
465: header => [{col1 => 'Log-in Service',
466: col2 => 'Server Setting',},
467: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 468: col2 => ''},
469: {col1 => 'Log-in Help',
1.160.6.56 raeburn 470: col2 => 'Value'},
471: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 472: col2 => 'Value'}],
1.160.6.37 raeburn 473: print => \&print_login,
474: modify => \&modify_login,
1.110 raeburn 475: };
476: }
1.160.6.13 raeburn 477:
1.6 raeburn 478: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 479: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 480: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 481: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 482: text=>"Settings to display/modify"});
1.9 raeburn 483: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 484:
1.3 raeburn 485: if ($phase eq 'process') {
1.160.6.27 raeburn 486: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
487: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 488: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 489: $r->rflush();
1.160.6.27 raeburn 490: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 491: }
1.30 raeburn 492: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 493: my $js = &recaptcha_js().
1.160.6.40 raeburn 494: &toggle_display_js();
1.160.6.7 raeburn 495: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 496: my ($othertitle,$usertypes,$types) =
497: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 498: $js .= &lonbalance_targets_js($dom,$types,\%servers,
499: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 500: &new_spares_js().
501: &common_domprefs_js().
502: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 503: }
1.160.6.30 raeburn 504: if (grep(/^requestcourses$/,@actions)) {
505: my $javascript_validations;
506: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
507: $js .= <<END;
508: <script type="text/javascript">
509: $javascript_validations
510: </script>
511: $coursebrowserjs
512: END
513: }
1.150 raeburn 514: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 515: } else {
1.160.6.11 raeburn 516: # check if domconfig user exists for the domain.
517: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 518: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 519: &config_check($dom,$confname,$servadm);
520: unless ($configuserok eq 'ok') {
521: &Apache::lonconfigsettings::print_header($r,$phase,$context);
522: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
523: $confname).
524: '<br />'
525: );
526: if ($switchserver) {
527: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
528: '<br />'.
529: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
530: '<br />'.
531: &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).
532: '<br />'.
533: &mt('To do that now, use the following link: [_1]',$switchserver)
534: );
535: } else {
536: $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.').
537: '<br />'.
538: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
539: );
540: }
541: $r->print(&Apache::loncommon::end_page());
542: return OK;
543: }
1.21 raeburn 544: if (keys(%domconfig) == 0) {
545: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 546: my @ids=&Apache::lonnet::current_machine_ids();
547: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 548: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 549: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 550: my $custom_img_count = 0;
551: foreach my $img (@loginimages) {
552: if ($designhash{$dom.'.login.'.$img} ne '') {
553: $custom_img_count ++;
554: }
555: }
556: foreach my $role (@roles) {
557: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
558: $custom_img_count ++;
559: }
560: }
561: if ($custom_img_count > 0) {
1.94 raeburn 562: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 563: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 564: $r->print(
565: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
566: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
567: &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 />'.
568: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
569: if ($switch_server) {
1.30 raeburn 570: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 571: }
1.91 raeburn 572: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 573: return OK;
574: }
575: }
576: }
1.91 raeburn 577: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 578: }
579: return OK;
580: }
581:
582: sub process_changes {
1.160.6.24 raeburn 583: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 584: my %domconfig;
585: if (ref($values) eq 'HASH') {
586: %domconfig = %{$values};
587: }
1.3 raeburn 588: my $output;
589: if ($action eq 'login') {
1.160.6.24 raeburn 590: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 591: } elsif ($action eq 'rolecolors') {
1.9 raeburn 592: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 593: $lastactref,%domconfig);
1.3 raeburn 594: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 595: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 596: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 597: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 598: } elsif ($action eq 'autoupdate') {
599: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 600: } elsif ($action eq 'autocreate') {
601: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 602: } elsif ($action eq 'directorysrch') {
603: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 604: } elsif ($action eq 'usercreation') {
1.28 raeburn 605: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 606: } elsif ($action eq 'selfcreation') {
607: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 608: } elsif ($action eq 'usermodification') {
609: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 610: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 611: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 612: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 613: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 614: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 615: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 616: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 617: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 618: } elsif ($action eq 'serverstatuses') {
619: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 620: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 621: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 622: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 623: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 624: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 625: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 626: } elsif ($action eq 'selfenrollment') {
627: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 628: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 629: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 630: } elsif ($action eq 'loadbalancing') {
631: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 632: }
633: return $output;
634: }
635:
636: sub print_config_box {
1.9 raeburn 637: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 638: my $rowtotal = 0;
1.49 raeburn 639: my $output;
640: if ($action eq 'coursecategories') {
641: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 642: } elsif ($action eq 'defaults') {
643: $output = &defaults_javascript($settings);
1.91 raeburn 644: }
1.160.6.40 raeburn 645: $output .=
1.30 raeburn 646: '<table class="LC_nested_outer">
1.3 raeburn 647: <tr>
1.66 raeburn 648: <th align="left" valign="middle"><span class="LC_nobreak">'.
649: &mt($item->{text}).' '.
650: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
651: '</tr>';
1.30 raeburn 652: $rowtotal ++;
1.110 raeburn 653: my $numheaders = 1;
654: if (ref($item->{'header'}) eq 'ARRAY') {
655: $numheaders = scalar(@{$item->{'header'}});
656: }
657: if ($numheaders > 1) {
1.64 raeburn 658: my $colspan = '';
1.145 raeburn 659: my $rightcolspan = '';
1.160.6.42 raeburn 660: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72! raeburn 661: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 662: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 663: $colspan = ' colspan="2"';
664: }
1.145 raeburn 665: if ($action eq 'usersessions') {
666: $rightcolspan = ' colspan="3"';
667: }
1.30 raeburn 668: $output .= '
1.3 raeburn 669: <tr>
670: <td>
671: <table class="LC_nested">
672: <tr class="LC_info_row">
1.59 bisitz 673: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 674: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 675: </tr>';
1.69 raeburn 676: $rowtotal ++;
1.160.6.37 raeburn 677: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 678: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.72! raeburn 679: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch')) {
1.160.6.37 raeburn 680: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 681: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 682: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 683: } elsif ($action eq 'login') {
1.160.6.56 raeburn 684: if ($numheaders == 4) {
1.160.6.5 raeburn 685: $colspan = ' colspan="2"';
686: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
687: } else {
688: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
689: }
1.160.6.37 raeburn 690: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 691: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 692: } elsif ($action eq 'rolecolors') {
1.30 raeburn 693: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 694: }
1.30 raeburn 695: $output .= '
1.6 raeburn 696: </table>
697: </td>
698: </tr>
699: <tr>
700: <td>
701: <table class="LC_nested">
702: <tr class="LC_info_row">
1.160.6.37 raeburn 703: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 704: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 705: </tr>';
706: $rowtotal ++;
1.160.6.37 raeburn 707: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
708: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 709: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
710: if ($action eq 'coursecategories') {
711: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
712: $colspan = ' colspan="2"';
713: } else {
714: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
715: }
716: $output .= '
1.63 raeburn 717: </table>
718: </td>
719: </tr>
720: <tr>
721: <td>
722: <table class="LC_nested">
723: <tr class="LC_info_row">
724: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 725: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 726: </tr>'."\n";
727: if ($action eq 'coursecategories') {
728: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
729: } else {
730: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
731: }
1.63 raeburn 732: $rowtotal ++;
1.160.6.57 raeburn 733: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.72! raeburn 734: ($action eq 'defaults') || ($action eq 'directorysrch')) {
1.160.6.37 raeburn 735: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 736: } elsif ($action eq 'login') {
1.160.6.56 raeburn 737: if ($numheaders == 4) {
1.160.6.5 raeburn 738: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
739: </table>
740: </td>
741: </tr>
742: <tr>
743: <td>
744: <table class="LC_nested">
745: <tr class="LC_info_row">
746: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 747: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 748: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
749: $rowtotal ++;
750: } else {
751: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
752: }
1.160.6.56 raeburn 753: $output .= '
754: </table>
755: </td>
756: </tr>
757: <tr>
758: <td>
759: <table class="LC_nested">
760: <tr class="LC_info_row">';
761: if ($numheaders == 4) {
762: $output .= '
763: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
764: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
765: </tr>';
766: } else {
767: $output .= '
768: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
769: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
770: </tr>';
771: }
772: $rowtotal ++;
773: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 774: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 775: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
776: $rowtotal ++;
777: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 778: </table>
779: </td>
780: </tr>
781: <tr>
782: <td>
783: <table class="LC_nested">
784: <tr class="LC_info_row">
785: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
786: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 787: &textbookcourses_javascript($settings).
788: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
789: </table>
790: </td>
791: </tr>
792: <tr>
793: <td>
794: <table class="LC_nested">
795: <tr class="LC_info_row">
796: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
797: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
798: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 799: </table>
800: </td>
801: </tr>
802: <tr>
803: <td>
804: <table class="LC_nested">
805: <tr class="LC_info_row">
1.160.6.46 raeburn 806: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
807: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 808: </tr>'.
809: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 810: } elsif ($action eq 'requestauthor') {
811: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 812: $rowtotal ++;
1.122 jms 813: } elsif ($action eq 'rolecolors') {
1.30 raeburn 814: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 815: </table>
816: </td>
817: </tr>
818: <tr>
819: <td>
820: <table class="LC_nested">
821: <tr class="LC_info_row">
1.69 raeburn 822: <td class="LC_left_item"'.$colspan.' valign="top">'.
823: &mt($item->{'header'}->[2]->{'col1'}).'</td>
824: <td class="LC_right_item" valign="top">'.
825: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 826: </tr>'.
1.30 raeburn 827: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 828: </table>
829: </td>
830: </tr>
831: <tr>
832: <td>
833: <table class="LC_nested">
834: <tr class="LC_info_row">
1.59 bisitz 835: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
836: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 837: </tr>'.
1.30 raeburn 838: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
839: $rowtotal += 2;
1.6 raeburn 840: }
1.3 raeburn 841: } else {
1.30 raeburn 842: $output .= '
1.3 raeburn 843: <tr>
844: <td>
845: <table class="LC_nested">
1.30 raeburn 846: <tr class="LC_info_row">';
1.160.6.72! raeburn 847: if ($action eq 'login') {
1.30 raeburn 848: $output .= '
1.59 bisitz 849: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 850: } elsif ($action eq 'serverstatuses') {
851: $output .= '
852: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
853: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
854:
1.6 raeburn 855: } else {
1.30 raeburn 856: $output .= '
1.69 raeburn 857: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
858: }
1.72 raeburn 859: if (defined($item->{'header'}->[0]->{'col3'})) {
860: $output .= '<td class="LC_left_item" valign="top">'.
861: &mt($item->{'header'}->[0]->{'col2'});
862: if ($action eq 'serverstatuses') {
863: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
864: }
1.69 raeburn 865: } else {
866: $output .= '<td class="LC_right_item" valign="top">'.
867: &mt($item->{'header'}->[0]->{'col2'});
868: }
869: $output .= '</td>';
870: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 871: if (defined($item->{'header'}->[0]->{'col4'})) {
872: $output .= '<td class="LC_left_item" valign="top">'.
873: &mt($item->{'header'}->[0]->{'col3'});
874: } else {
875: $output .= '<td class="LC_right_item" valign="top">'.
876: &mt($item->{'header'}->[0]->{'col3'});
877: }
1.69 raeburn 878: if ($action eq 'serverstatuses') {
879: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
880: }
881: $output .= '</td>';
1.6 raeburn 882: }
1.150 raeburn 883: if ($item->{'header'}->[0]->{'col4'}) {
884: $output .= '<td class="LC_right_item" valign="top">'.
885: &mt($item->{'header'}->[0]->{'col4'});
886: }
1.69 raeburn 887: $output .= '</tr>';
1.48 raeburn 888: $rowtotal ++;
1.160.6.5 raeburn 889: if ($action eq 'quotas') {
1.86 raeburn 890: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72! raeburn 891: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
! 892: ($action eq 'contacts') || ($action eq 'serverstatuses') ||
! 893: ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 894: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 895: } elsif ($action eq 'scantron') {
896: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 897: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 898: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 899: }
1.3 raeburn 900: }
1.30 raeburn 901: $output .= '
1.3 raeburn 902: </table>
903: </td>
904: </tr>
1.30 raeburn 905: </table><br />';
906: return ($output,$rowtotal);
1.1 raeburn 907: }
908:
1.3 raeburn 909: sub print_login {
1.160.6.5 raeburn 910: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 911: my ($css_class,$datatable);
1.6 raeburn 912: my %choices = &login_choices();
1.110 raeburn 913:
1.160.6.5 raeburn 914: if ($caller eq 'service') {
1.149 raeburn 915: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 916: my $choice = $choices{'disallowlogin'};
917: $css_class = ' class="LC_odd_row"';
1.128 raeburn 918: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 919: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 920: '<th>'.$choices{'server'}.'</th>'.
921: '<th>'.$choices{'serverpath'}.'</th>'.
922: '<th>'.$choices{'custompath'}.'</th>'.
923: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 924: my %disallowed;
925: if (ref($settings) eq 'HASH') {
926: if (ref($settings->{'loginvia'}) eq 'HASH') {
927: %disallowed = %{$settings->{'loginvia'}};
928: }
929: }
930: foreach my $lonhost (sort(keys(%servers))) {
931: my $direct = 'selected="selected"';
1.128 raeburn 932: if (ref($disallowed{$lonhost}) eq 'HASH') {
933: if ($disallowed{$lonhost}{'server'} ne '') {
934: $direct = '';
935: }
1.110 raeburn 936: }
1.115 raeburn 937: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 938: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 939: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
940: '</option>';
1.160.6.13 raeburn 941: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 942: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 943: my $selected = '';
1.128 raeburn 944: if (ref($disallowed{$lonhost}) eq 'HASH') {
945: if ($hostid eq $disallowed{$lonhost}{'server'}) {
946: $selected = 'selected="selected"';
947: }
1.110 raeburn 948: }
949: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
950: $servers{$hostid}.'</option>';
951: }
1.128 raeburn 952: $datatable .= '</select></td>'.
953: '<td><select name="'.$lonhost.'_serverpath">';
954: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
955: my $pathname = $path;
956: if ($path eq 'custom') {
957: $pathname = &mt('Custom Path').' ->';
958: }
959: my $selected = '';
960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
962: $selected = 'selected="selected"';
963: }
964: } elsif ($path eq '') {
965: $selected = 'selected="selected"';
966: }
967: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
968: }
969: $datatable .= '</select></td>';
970: my ($custom,$exempt);
971: if (ref($disallowed{$lonhost}) eq 'HASH') {
972: $custom = $disallowed{$lonhost}{'custompath'};
973: $exempt = $disallowed{$lonhost}{'exempt'};
974: }
975: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
976: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
977: '</tr>';
1.110 raeburn 978: }
979: $datatable .= '</table></td></tr>';
980: return $datatable;
1.160.6.5 raeburn 981: } elsif ($caller eq 'page') {
982: my %defaultchecked = (
983: 'coursecatalog' => 'on',
1.160.6.14 raeburn 984: 'helpdesk' => 'on',
1.160.6.5 raeburn 985: 'adminmail' => 'off',
986: 'newuser' => 'off',
987: );
1.160.6.14 raeburn 988: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 989: my (%checkedon,%checkedoff);
1.42 raeburn 990: foreach my $item (@toggles) {
1.160.6.5 raeburn 991: if ($defaultchecked{$item} eq 'on') {
992: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 993: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 994: } elsif ($defaultchecked{$item} eq 'off') {
995: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 996: $checkedon{$item} = ' ';
997: }
1.1 raeburn 998: }
1.160.6.5 raeburn 999: my @images = ('img','logo','domlogo','login');
1000: my @logintext = ('textcol','bgcol');
1001: my @bgs = ('pgbg','mainbg','sidebg');
1002: my @links = ('link','alink','vlink');
1003: my %designhash = &Apache::loncommon::get_domainconf($dom);
1004: my %defaultdesign = %Apache::loncommon::defaultdesign;
1005: my (%is_custom,%designs);
1006: my %defaults = (
1007: font => $defaultdesign{'login.font'},
1008: );
1.6 raeburn 1009: foreach my $item (@images) {
1.160.6.5 raeburn 1010: $defaults{$item} = $defaultdesign{'login.'.$item};
1011: $defaults{'showlogo'}{$item} = 1;
1012: }
1013: foreach my $item (@bgs) {
1014: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1015: }
1.41 raeburn 1016: foreach my $item (@logintext) {
1.160.6.5 raeburn 1017: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1018: }
1.160.6.5 raeburn 1019: foreach my $item (@links) {
1020: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1021: }
1.160.6.5 raeburn 1022: if (ref($settings) eq 'HASH') {
1023: foreach my $item (@toggles) {
1024: if ($settings->{$item} eq '1') {
1025: $checkedon{$item} = ' checked="checked" ';
1026: $checkedoff{$item} = ' ';
1027: } elsif ($settings->{$item} eq '0') {
1028: $checkedoff{$item} = ' checked="checked" ';
1029: $checkedon{$item} = ' ';
1030: }
1.6 raeburn 1031: }
1.160.6.5 raeburn 1032: foreach my $item (@images) {
1033: if (defined($settings->{$item})) {
1034: $designs{$item} = $settings->{$item};
1035: $is_custom{$item} = 1;
1036: }
1037: if (defined($settings->{'showlogo'}{$item})) {
1038: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1039: }
1040: }
1041: foreach my $item (@logintext) {
1042: if ($settings->{$item} ne '') {
1043: $designs{'logintext'}{$item} = $settings->{$item};
1044: $is_custom{$item} = 1;
1045: }
1046: }
1047: if ($settings->{'font'} ne '') {
1048: $designs{'font'} = $settings->{'font'};
1049: $is_custom{'font'} = 1;
1050: }
1051: foreach my $item (@bgs) {
1052: if ($settings->{$item} ne '') {
1053: $designs{'bgs'}{$item} = $settings->{$item};
1054: $is_custom{$item} = 1;
1055: }
1056: }
1057: foreach my $item (@links) {
1058: if ($settings->{$item} ne '') {
1059: $designs{'links'}{$item} = $settings->{$item};
1060: $is_custom{$item} = 1;
1061: }
1062: }
1063: } else {
1064: if ($designhash{$dom.'.login.font'} ne '') {
1065: $designs{'font'} = $designhash{$dom.'.login.font'};
1066: $is_custom{'font'} = 1;
1067: }
1068: foreach my $item (@images) {
1069: if ($designhash{$dom.'.login.'.$item} ne '') {
1070: $designs{$item} = $designhash{$dom.'.login.'.$item};
1071: $is_custom{$item} = 1;
1072: }
1073: }
1074: foreach my $item (@bgs) {
1075: if ($designhash{$dom.'.login.'.$item} ne '') {
1076: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1077: $is_custom{$item} = 1;
1078: }
1079: }
1080: foreach my $item (@links) {
1081: if ($designhash{$dom.'.login.'.$item} ne '') {
1082: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1083: $is_custom{$item} = 1;
1084: }
1.6 raeburn 1085: }
1086: }
1.160.6.5 raeburn 1087: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1088: logo => 'Institution Logo',
1089: domlogo => 'Domain Logo',
1090: login => 'Login box');
1091: my $itemcount = 1;
1092: foreach my $item (@toggles) {
1093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1094: $datatable .=
1095: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1096: '</td><td>'.
1097: '<span class="LC_nobreak"><label><input type="radio" name="'.
1098: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1099: '</label> <label><input type="radio" name="'.$item.'"'.
1100: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1101: '</tr>';
1102: $itemcount ++;
1.6 raeburn 1103: }
1.160.6.5 raeburn 1104: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1105: $datatable .= '</tr></table></td></tr>';
1106: } elsif ($caller eq 'help') {
1107: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1108: my $switchserver = &check_switchserver($dom,$confname);
1109: my $itemcount = 1;
1110: $defaulturl = '/adm/loginproblems.html';
1111: $defaulttype = 'default';
1112: %lt = &Apache::lonlocal::texthash (
1113: del => 'Delete?',
1114: rep => 'Replace:',
1115: upl => 'Upload:',
1116: default => 'Default',
1117: custom => 'Custom',
1118: );
1119: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1120: my @currlangs;
1121: if (ref($settings) eq 'HASH') {
1122: if (ref($settings->{'helpurl'}) eq 'HASH') {
1123: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1124: next if ($settings->{'helpurl'}{$key} eq '');
1125: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1126: $type{$key} = 'custom';
1127: unless ($key eq 'nolang') {
1128: push(@currlangs,$key);
1129: }
1130: }
1131: } elsif ($settings->{'helpurl'} ne '') {
1132: $type{'nolang'} = 'custom';
1133: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1134: }
1135: }
1.160.6.5 raeburn 1136: foreach my $lang ('nolang',sort(@currlangs)) {
1137: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1138: $datatable .= '<tr'.$css_class.'>';
1139: if ($url{$lang} eq '') {
1140: $url{$lang} = $defaulturl;
1141: }
1142: if ($type{$lang} eq '') {
1143: $type{$lang} = $defaulttype;
1144: }
1145: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1146: if ($lang eq 'nolang') {
1147: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1148: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1149: } else {
1150: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1151: $langchoices{$lang},
1152: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1153: }
1154: $datatable .= '</span></td>'."\n".
1155: '<td class="LC_left_item">';
1156: if ($type{$lang} eq 'custom') {
1157: $datatable .= '<span class="LC_nobreak"><label>'.
1158: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1159: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1160: } else {
1161: $datatable .= $lt{'upl'};
1162: }
1163: $datatable .='<br />';
1164: if ($switchserver) {
1165: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1166: } else {
1167: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1168: }
1.160.6.5 raeburn 1169: $datatable .= '</td></tr>';
1170: $itemcount ++;
1.6 raeburn 1171: }
1.160.6.5 raeburn 1172: my @addlangs;
1173: foreach my $lang (sort(keys(%langchoices))) {
1174: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1175: push(@addlangs,$lang);
1176: }
1177: if (@addlangs > 0) {
1178: my %toadd;
1179: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1180: $toadd{''} = &mt('Select');
1181: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1182: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1183: &mt('Add log-in help page for a specific language:').' '.
1184: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1185: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1186: if ($switchserver) {
1187: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1188: } else {
1189: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1190: }
1.160.6.5 raeburn 1191: $datatable .= '</td></tr>';
1192: $itemcount ++;
1.6 raeburn 1193: }
1.160.6.5 raeburn 1194: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1195: } elsif ($caller eq 'headtag') {
1196: my %domservers = &Apache::lonnet::get_servers($dom);
1197: my $choice = $choices{'headtag'};
1198: $css_class = ' class="LC_odd_row"';
1199: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1200: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1201: '<th>'.$choices{'current'}.'</th>'.
1202: '<th>'.$choices{'action'}.'</th>'.
1203: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1204: my (%currurls,%currexempt);
1205: if (ref($settings) eq 'HASH') {
1206: if (ref($settings->{'headtag'}) eq 'HASH') {
1207: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1208: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1209: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1210: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1211: }
1212: }
1213: }
1214: }
1215: my %lt = &Apache::lonlocal::texthash(
1216: del => 'Delete?',
1217: rep => 'Replace:',
1218: upl => 'Upload:',
1219: curr => 'View contents',
1220: none => 'None',
1221: );
1222: my $switchserver = &check_switchserver($dom,$confname);
1223: foreach my $lonhost (sort(keys(%domservers))) {
1224: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1225: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1226: if ($currurls{$lonhost}) {
1227: $datatable .= '<td class="LC_right_item"><a href="'.
1228: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1229: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1230: '">'.$lt{'curr'}.'</a></td>'.
1231: '<td><span class="LC_nobreak"><label>'.
1232: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1233: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1234: } else {
1235: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1236: }
1237: $datatable .='<br />';
1238: if ($switchserver) {
1239: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1240: } else {
1241: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1242: }
1243: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1244: }
1245: $datatable .= '</table></td></tr>';
1.1 raeburn 1246: }
1.6 raeburn 1247: return $datatable;
1248: }
1249:
1250: sub login_choices {
1251: my %choices =
1252: &Apache::lonlocal::texthash (
1.116 bisitz 1253: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1254: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1255: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1256: disallowlogin => "Login page requests redirected",
1257: hostid => "Server",
1.128 raeburn 1258: server => "Redirect to:",
1259: serverpath => "Path",
1260: custompath => "Custom",
1261: exempt => "Exempt IP(s)",
1.110 raeburn 1262: directlogin => "No redirect",
1263: newuser => "Link to create a user account",
1264: img => "Header",
1265: logo => "Main Logo",
1266: domlogo => "Domain Logo",
1267: login => "Log-in Header",
1268: textcol => "Text color",
1269: bgcol => "Box color",
1270: bgs => "Background colors",
1271: links => "Link colors",
1272: font => "Font color",
1273: pgbg => "Header",
1274: mainbg => "Page",
1275: sidebg => "Login box",
1276: link => "Link",
1277: alink => "Active link",
1278: vlink => "Visited link",
1.160.6.56 raeburn 1279: headtag => "Custom markup",
1280: action => "Action",
1281: current => "Current",
1.6 raeburn 1282: );
1283: return %choices;
1284: }
1285:
1286: sub print_rolecolors {
1.30 raeburn 1287: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1288: my %choices = &color_font_choices();
1289: my @bgs = ('pgbg','tabbg','sidebg');
1290: my @links = ('link','alink','vlink');
1291: my @images = ('img');
1292: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1293: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1294: my %defaultdesign = %Apache::loncommon::defaultdesign;
1295: my (%is_custom,%designs);
1.160.6.22 raeburn 1296: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1297: if (ref($settings) eq 'HASH') {
1298: if (ref($settings->{$role}) eq 'HASH') {
1299: if ($settings->{$role}->{'img'} ne '') {
1300: $designs{'img'} = $settings->{$role}->{'img'};
1301: $is_custom{'img'} = 1;
1302: }
1303: if ($settings->{$role}->{'font'} ne '') {
1304: $designs{'font'} = $settings->{$role}->{'font'};
1305: $is_custom{'font'} = 1;
1306: }
1.97 tempelho 1307: if ($settings->{$role}->{'fontmenu'} ne '') {
1308: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1309: $is_custom{'fontmenu'} = 1;
1310: }
1.6 raeburn 1311: foreach my $item (@bgs) {
1312: if ($settings->{$role}->{$item} ne '') {
1313: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1314: $is_custom{$item} = 1;
1315: }
1316: }
1317: foreach my $item (@links) {
1318: if ($settings->{$role}->{$item} ne '') {
1319: $designs{'links'}{$item} = $settings->{$role}->{$item};
1320: $is_custom{$item} = 1;
1321: }
1322: }
1323: }
1324: } else {
1325: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1326: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1327: $is_custom{'img'} = 1;
1328: }
1.97 tempelho 1329: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1330: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1331: $is_custom{'fontmenu'} = 1;
1332: }
1.6 raeburn 1333: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1334: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1335: $is_custom{'font'} = 1;
1336: }
1337: foreach my $item (@bgs) {
1338: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1339: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1340: $is_custom{$item} = 1;
1341:
1342: }
1343: }
1344: foreach my $item (@links) {
1345: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1346: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1347: $is_custom{$item} = 1;
1348: }
1349: }
1350: }
1351: my $itemcount = 1;
1.30 raeburn 1352: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1353: $datatable .= '</tr></table></td></tr>';
1354: return $datatable;
1355: }
1356:
1.160.6.22 raeburn 1357: sub role_defaults {
1358: my ($role,$bgs,$links,$images,$logintext) = @_;
1359: my %defaults;
1360: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1361: return %defaults;
1362: }
1363: my %defaultdesign = %Apache::loncommon::defaultdesign;
1364: if ($role eq 'login') {
1365: %defaults = (
1366: font => $defaultdesign{$role.'.font'},
1367: );
1368: if (ref($logintext) eq 'ARRAY') {
1369: foreach my $item (@{$logintext}) {
1370: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1371: }
1372: }
1373: foreach my $item (@{$images}) {
1374: $defaults{'showlogo'}{$item} = 1;
1375: }
1376: } else {
1377: %defaults = (
1378: img => $defaultdesign{$role.'.img'},
1379: font => $defaultdesign{$role.'.font'},
1380: fontmenu => $defaultdesign{$role.'.fontmenu'},
1381: );
1382: }
1383: foreach my $item (@{$bgs}) {
1384: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1385: }
1386: foreach my $item (@{$links}) {
1387: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1388: }
1389: foreach my $item (@{$images}) {
1390: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1391: }
1392: return %defaults;
1393: }
1394:
1.6 raeburn 1395: sub display_color_options {
1.9 raeburn 1396: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1397: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1398: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1399: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1400: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1401: '<td>'.$choices->{'font'}.'</td>';
1402: if (!$is_custom->{'font'}) {
1.30 raeburn 1403: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1404: } else {
1405: $datatable .= '<td> </td>';
1406: }
1.160.6.9 raeburn 1407: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1408:
1.8 raeburn 1409: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1410: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1411: ' value="'.$current_color.'" /> '.
1412: ' </td></tr>';
1.107 raeburn 1413: unless ($role eq 'login') {
1414: $datatable .= '<tr'.$css_class.'>'.
1415: '<td>'.$choices->{'fontmenu'}.'</td>';
1416: if (!$is_custom->{'fontmenu'}) {
1417: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1418: } else {
1419: $datatable .= '<td> </td>';
1420: }
1.160.6.22 raeburn 1421: $current_color = $designs->{'fontmenu'} ?
1422: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1423: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1424: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1425: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1426: ' value="'.$current_color.'" /> '.
1427: ' </td></tr>';
1.97 tempelho 1428: }
1.9 raeburn 1429: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1430: foreach my $img (@{$images}) {
1.18 albertel 1431: $itemcount ++;
1.6 raeburn 1432: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1433: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1434: '<td>'.$choices->{$img};
1.41 raeburn 1435: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1436: if ($role eq 'login') {
1437: if ($img eq 'login') {
1438: $login_hdr_pick =
1.135 bisitz 1439: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1440: $logincolors =
1441: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1442: $designs,$defaults);
1.70 raeburn 1443: } elsif ($img ne 'domlogo') {
1444: $datatable.= &logo_display_options($img,$defaults,$designs);
1445: }
1446: }
1447: $datatable .= '</td>';
1.6 raeburn 1448: if ($designs->{$img} ne '') {
1449: $imgfile = $designs->{$img};
1.18 albertel 1450: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1451: } else {
1452: $imgfile = $defaults->{$img};
1453: }
1454: if ($imgfile) {
1.9 raeburn 1455: my ($showfile,$fullsize);
1456: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1457: my $urldir = $1;
1458: my $filename = $2;
1459: my @info = &Apache::lonnet::stat_file($designs->{$img});
1460: if (@info) {
1461: my $thumbfile = 'tn-'.$filename;
1462: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1463: if (@thumb) {
1464: $showfile = $urldir.'/'.$thumbfile;
1465: } else {
1466: $showfile = $imgfile;
1467: }
1468: } else {
1469: $showfile = '';
1470: }
1471: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1472: $showfile = $imgfile;
1.6 raeburn 1473: my $imgdir = $1;
1474: my $filename = $2;
1.159 raeburn 1475: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1476: $showfile = "/$imgdir/tn-".$filename;
1477: } else {
1.159 raeburn 1478: my $input = $londocroot.$imgfile;
1479: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1480: if (!-e $output) {
1.9 raeburn 1481: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1482: my ($fullwidth,$fullheight) = &check_dimensions($input);
1483: if ($fullwidth ne '' && $fullheight ne '') {
1484: if ($fullwidth > $width && $fullheight > $height) {
1485: my $size = $width.'x'.$height;
1486: system("convert -sample $size $input $output");
1.159 raeburn 1487: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1488: }
1489: }
1.6 raeburn 1490: }
1491: }
1.16 raeburn 1492: }
1.6 raeburn 1493: if ($showfile) {
1.40 raeburn 1494: if ($showfile =~ m{^/(adm|res)/}) {
1495: if ($showfile =~ m{^/res/}) {
1496: my $local_showfile =
1497: &Apache::lonnet::filelocation('',$showfile);
1498: &Apache::lonnet::repcopy($local_showfile);
1499: }
1500: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1501: }
1502: if ($imgfile) {
1503: if ($imgfile =~ m{^/(adm|res)/}) {
1504: if ($imgfile =~ m{^/res/}) {
1505: my $local_imgfile =
1506: &Apache::lonnet::filelocation('',$imgfile);
1507: &Apache::lonnet::repcopy($local_imgfile);
1508: }
1509: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1510: } else {
1511: $fullsize = $imgfile;
1512: }
1513: }
1.41 raeburn 1514: $datatable .= '<td>';
1515: if ($img eq 'login') {
1.135 bisitz 1516: $datatable .= $login_hdr_pick;
1517: }
1.41 raeburn 1518: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1519: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1520: } else {
1.160.6.22 raeburn 1521: $datatable .= '<td> </td><td class="LC_left_item">'.
1522: &mt('Upload:').'<br />';
1.6 raeburn 1523: }
1524: } else {
1.160.6.22 raeburn 1525: $datatable .= '<td> </td><td class="LC_left_item">'.
1526: &mt('Upload:').'<br />';
1.6 raeburn 1527: }
1.9 raeburn 1528: if ($switchserver) {
1529: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1530: } else {
1.135 bisitz 1531: if ($img ne 'login') { # suppress file selection for Log-in header
1532: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1533: }
1.9 raeburn 1534: }
1535: $datatable .= '</td></tr>';
1.6 raeburn 1536: }
1537: $itemcount ++;
1538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1539: $datatable .= '<tr'.$css_class.'>'.
1540: '<td>'.$choices->{'bgs'}.'</td>';
1541: my $bgs_def;
1542: foreach my $item (@{$bgs}) {
1543: if (!$is_custom->{$item}) {
1.70 raeburn 1544: $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 1545: }
1546: }
1547: if ($bgs_def) {
1.8 raeburn 1548: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1549: } else {
1550: $datatable .= '<td> </td>';
1551: }
1552: $datatable .= '<td class="LC_right_item">'.
1553: '<table border="0"><tr>';
1.160.6.13 raeburn 1554:
1.6 raeburn 1555: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1556: $datatable .= '<td align="center">'.$choices->{$item};
1557: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1558: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1559: $datatable .= ' ';
1.6 raeburn 1560: }
1.160.6.9 raeburn 1561: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1562: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1563: }
1564: $datatable .= '</tr></table></td></tr>';
1565: $itemcount ++;
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: $datatable .= '<tr'.$css_class.'>'.
1568: '<td>'.$choices->{'links'}.'</td>';
1569: my $links_def;
1570: foreach my $item (@{$links}) {
1571: if (!$is_custom->{$item}) {
1.30 raeburn 1572: $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 1573: }
1574: }
1575: if ($links_def) {
1.8 raeburn 1576: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1580: $datatable .= '<td class="LC_right_item">'.
1581: '<table border="0"><tr>';
1582: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1583: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1584: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1585: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1586: $datatable.=' ';
1.6 raeburn 1587: }
1.160.6.9 raeburn 1588: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1589: '" /></td>';
1590: }
1.30 raeburn 1591: $$rowtotal += $itemcount;
1.3 raeburn 1592: return $datatable;
1593: }
1594:
1.70 raeburn 1595: sub logo_display_options {
1596: my ($img,$defaults,$designs) = @_;
1597: my $checkedon;
1598: if (ref($defaults) eq 'HASH') {
1599: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1600: if ($defaults->{'showlogo'}{$img}) {
1601: $checkedon = 'checked="checked" ';
1602: }
1603: }
1604: }
1605: if (ref($designs) eq 'HASH') {
1606: if (ref($designs->{'showlogo'}) eq 'HASH') {
1607: if (defined($designs->{'showlogo'}{$img})) {
1608: if ($designs->{'showlogo'}{$img} == 0) {
1609: $checkedon = '';
1610: } elsif ($designs->{'showlogo'}{$img} == 1) {
1611: $checkedon = 'checked="checked" ';
1612: }
1613: }
1614: }
1615: }
1616: return '<br /><label> <input type="checkbox" name="'.
1617: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1618: &mt('show').'</label>'."\n";
1619: }
1620:
1.41 raeburn 1621: sub login_header_options {
1.135 bisitz 1622: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1623: my $output = '';
1.41 raeburn 1624: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1625: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1626: if (!$is_custom->{'textcol'}) {
1627: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1628: ' ';
1629: }
1630: if (!$is_custom->{'bgcol'}) {
1631: $output .= $choices->{'bgcol'}.': '.
1632: '<span id="css_'.$role.'_font" style="background-color: '.
1633: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1634: }
1635: $output .= '<br />';
1636: }
1637: $output .='<br />';
1638: return $output;
1639: }
1640:
1641: sub login_text_colors {
1.160.6.22 raeburn 1642: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1643: my $color_menu = '<table border="0"><tr>';
1644: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1645: $color_menu .= '<td align="center">'.$choices->{$item};
1646: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1647: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1648: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1649: }
1650: $color_menu .= '</tr></table><br />';
1651: return $color_menu;
1652: }
1653:
1654: sub image_changes {
1655: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1656: my $output;
1.135 bisitz 1657: if ($img eq 'login') {
1658: # suppress image for Log-in header
1659: } elsif (!$is_custom) {
1.70 raeburn 1660: if ($img ne 'domlogo') {
1.41 raeburn 1661: $output .= &mt('Default image:').'<br />';
1662: } else {
1663: $output .= &mt('Default in use:').'<br />';
1664: }
1665: }
1.135 bisitz 1666: if ($img eq 'login') { # suppress image for Log-in header
1667: $output .= '<td>'.$logincolors;
1.41 raeburn 1668: } else {
1.135 bisitz 1669: if ($img_import) {
1670: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1671: }
1672: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1673: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1674: if ($is_custom) {
1675: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1676: '<input type="checkbox" name="'.
1677: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1678: '</label> '.&mt('Replace:').'</span><br />';
1679: } else {
1.160.6.22 raeburn 1680: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1681: }
1.41 raeburn 1682: }
1683: return $output;
1684: }
1685:
1.3 raeburn 1686: sub print_quotas {
1.86 raeburn 1687: my ($dom,$settings,$rowtotal,$action) = @_;
1688: my $context;
1689: if ($action eq 'quotas') {
1690: $context = 'tools';
1691: } else {
1692: $context = $action;
1693: }
1.160.6.20 raeburn 1694: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1696: my $typecount = 0;
1.101 raeburn 1697: my ($css_class,%titles);
1.86 raeburn 1698: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1699: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1700: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1701: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1702: %titles = &courserequest_titles();
1.160.6.5 raeburn 1703: } elsif ($context eq 'requestauthor') {
1704: @usertools = ('author');
1705: @options = ('norequest','approval','automatic');
1706: %titles = &authorrequest_titles();
1.86 raeburn 1707: } else {
1.160.6.4 raeburn 1708: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1709: %titles = &tool_titles();
1.86 raeburn 1710: }
1.26 raeburn 1711: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1712: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1713: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1714: unless (($context eq 'requestcourses') ||
1715: ($context eq 'requestauthor')) {
1.86 raeburn 1716: if (ref($settings) eq 'HASH') {
1717: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1718: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1719: } else {
1720: $currdefquota = $settings->{$type};
1721: }
1.160.6.20 raeburn 1722: if (ref($settings->{authorquota}) eq 'HASH') {
1723: $currauthorquota = $settings->{authorquota}->{$type};
1724: }
1.78 raeburn 1725: }
1.72 raeburn 1726: }
1.3 raeburn 1727: if (defined($usertypes->{$type})) {
1728: $typecount ++;
1729: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1730: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1731: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1732: '<td class="LC_left_item">';
1.101 raeburn 1733: if ($context eq 'requestcourses') {
1734: $datatable .= '<table><tr>';
1735: }
1736: my %cell;
1.72 raeburn 1737: foreach my $item (@usertools) {
1.101 raeburn 1738: if ($context eq 'requestcourses') {
1739: my ($curroption,$currlimit);
1740: if (ref($settings) eq 'HASH') {
1741: if (ref($settings->{$item}) eq 'HASH') {
1742: $curroption = $settings->{$item}->{$type};
1743: if ($curroption =~ /^autolimit=(\d*)$/) {
1744: $currlimit = $1;
1745: }
1746: }
1747: }
1748: if (!$curroption) {
1749: $curroption = 'norequest';
1750: }
1751: $datatable .= '<th>'.$titles{$item}.'</th>';
1752: foreach my $option (@options) {
1753: my $val = $option;
1754: if ($option eq 'norequest') {
1755: $val = 0;
1756: }
1757: if ($option eq 'validate') {
1758: my $canvalidate = 0;
1759: if (ref($validations{$item}) eq 'HASH') {
1760: if ($validations{$item}{$type}) {
1761: $canvalidate = 1;
1762: }
1763: }
1764: next if (!$canvalidate);
1765: }
1766: my $checked = '';
1767: if ($option eq $curroption) {
1768: $checked = ' checked="checked"';
1769: } elsif ($option eq 'autolimit') {
1770: if ($curroption =~ /^autolimit/) {
1771: $checked = ' checked="checked"';
1772: }
1773: }
1774: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1775: '<input type="radio" name="crsreq_'.$item.
1776: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1777: $titles{$option}.'</label>';
1.101 raeburn 1778: if ($option eq 'autolimit') {
1.127 raeburn 1779: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1780: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1781: 'value="'.$currlimit.'" />';
1.101 raeburn 1782: }
1.127 raeburn 1783: $cell{$item} .= '</span> ';
1.103 raeburn 1784: if ($option eq 'autolimit') {
1.127 raeburn 1785: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1786: }
1.101 raeburn 1787: }
1.160.6.5 raeburn 1788: } elsif ($context eq 'requestauthor') {
1789: my $curroption;
1790: if (ref($settings) eq 'HASH') {
1791: $curroption = $settings->{$type};
1792: }
1793: if (!$curroption) {
1794: $curroption = 'norequest';
1795: }
1796: foreach my $option (@options) {
1797: my $val = $option;
1798: if ($option eq 'norequest') {
1799: $val = 0;
1800: }
1801: my $checked = '';
1802: if ($option eq $curroption) {
1803: $checked = ' checked="checked"';
1804: }
1805: $datatable .= '<span class="LC_nobreak"><label>'.
1806: '<input type="radio" name="authorreq_'.$type.
1807: '" value="'.$val.'"'.$checked.' />'.
1808: $titles{$option}.'</label></span> ';
1809: }
1.101 raeburn 1810: } else {
1811: my $checked = 'checked="checked" ';
1812: if (ref($settings) eq 'HASH') {
1813: if (ref($settings->{$item}) eq 'HASH') {
1814: if ($settings->{$item}->{$type} == 0) {
1815: $checked = '';
1816: } elsif ($settings->{$item}->{$type} == 1) {
1817: $checked = 'checked="checked" ';
1818: }
1.78 raeburn 1819: }
1.72 raeburn 1820: }
1.101 raeburn 1821: $datatable .= '<span class="LC_nobreak"><label>'.
1822: '<input type="checkbox" name="'.$context.'_'.$item.
1823: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1824: '</label></span> ';
1.72 raeburn 1825: }
1.101 raeburn 1826: }
1827: if ($context eq 'requestcourses') {
1828: $datatable .= '</tr><tr>';
1829: foreach my $item (@usertools) {
1.106 raeburn 1830: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1831: }
1832: $datatable .= '</tr></table>';
1.72 raeburn 1833: }
1.86 raeburn 1834: $datatable .= '</td>';
1.160.6.5 raeburn 1835: unless (($context eq 'requestcourses') ||
1836: ($context eq 'requestauthor')) {
1.86 raeburn 1837: $datatable .=
1.160.6.20 raeburn 1838: '<td class="LC_right_item">'.
1839: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1840: '<input type="text" name="quota_'.$type.
1.72 raeburn 1841: '" value="'.$currdefquota.
1.160.6.20 raeburn 1842: '" size="5" /></span>'.(' ' x 2).
1843: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1844: '<input type="text" name="authorquota_'.$type.
1845: '" value="'.$currauthorquota.
1846: '" size="5" /></span></td>';
1.86 raeburn 1847: }
1848: $datatable .= '</tr>';
1.3 raeburn 1849: }
1850: }
1851: }
1.160.6.5 raeburn 1852: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1853: $defaultquota = '20';
1.160.6.20 raeburn 1854: $authorquota = '500';
1.86 raeburn 1855: if (ref($settings) eq 'HASH') {
1856: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1857: $defaultquota = $settings->{'defaultquota'}->{'default'};
1858: } elsif (defined($settings->{'default'})) {
1859: $defaultquota = $settings->{'default'};
1860: }
1.160.6.20 raeburn 1861: if (ref($settings->{'authorquota'}) eq 'HASH') {
1862: $authorquota = $settings->{'authorquota'}->{'default'};
1863: }
1.3 raeburn 1864: }
1865: }
1866: $typecount ++;
1867: $css_class = $typecount%2?' class="LC_odd_row"':'';
1868: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1869: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1870: '<td class="LC_left_item">';
1.101 raeburn 1871: if ($context eq 'requestcourses') {
1872: $datatable .= '<table><tr>';
1873: }
1874: my %defcell;
1.72 raeburn 1875: foreach my $item (@usertools) {
1.101 raeburn 1876: if ($context eq 'requestcourses') {
1877: my ($curroption,$currlimit);
1878: if (ref($settings) eq 'HASH') {
1879: if (ref($settings->{$item}) eq 'HASH') {
1880: $curroption = $settings->{$item}->{'default'};
1881: if ($curroption =~ /^autolimit=(\d*)$/) {
1882: $currlimit = $1;
1883: }
1884: }
1885: }
1886: if (!$curroption) {
1887: $curroption = 'norequest';
1888: }
1889: $datatable .= '<th>'.$titles{$item}.'</th>';
1890: foreach my $option (@options) {
1891: my $val = $option;
1892: if ($option eq 'norequest') {
1893: $val = 0;
1894: }
1895: if ($option eq 'validate') {
1896: my $canvalidate = 0;
1897: if (ref($validations{$item}) eq 'HASH') {
1898: if ($validations{$item}{'default'}) {
1899: $canvalidate = 1;
1900: }
1901: }
1902: next if (!$canvalidate);
1903: }
1904: my $checked = '';
1905: if ($option eq $curroption) {
1906: $checked = ' checked="checked"';
1907: } elsif ($option eq 'autolimit') {
1908: if ($curroption =~ /^autolimit/) {
1909: $checked = ' checked="checked"';
1910: }
1911: }
1912: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1913: '<input type="radio" name="crsreq_'.$item.
1914: '_default" value="'.$val.'"'.$checked.' />'.
1915: $titles{$option}.'</label>';
1916: if ($option eq 'autolimit') {
1.127 raeburn 1917: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1918: $item.'_limit_default" size="1" '.
1919: 'value="'.$currlimit.'" />';
1920: }
1.127 raeburn 1921: $defcell{$item} .= '</span> ';
1.104 raeburn 1922: if ($option eq 'autolimit') {
1.127 raeburn 1923: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1924: }
1.101 raeburn 1925: }
1.160.6.5 raeburn 1926: } elsif ($context eq 'requestauthor') {
1927: my $curroption;
1928: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1929: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1930: }
1931: if (!$curroption) {
1932: $curroption = 'norequest';
1933: }
1934: foreach my $option (@options) {
1935: my $val = $option;
1936: if ($option eq 'norequest') {
1937: $val = 0;
1938: }
1939: my $checked = '';
1940: if ($option eq $curroption) {
1941: $checked = ' checked="checked"';
1942: }
1943: $datatable .= '<span class="LC_nobreak"><label>'.
1944: '<input type="radio" name="authorreq_default"'.
1945: ' value="'.$val.'"'.$checked.' />'.
1946: $titles{$option}.'</label></span> ';
1947: }
1.101 raeburn 1948: } else {
1949: my $checked = 'checked="checked" ';
1950: if (ref($settings) eq 'HASH') {
1951: if (ref($settings->{$item}) eq 'HASH') {
1952: if ($settings->{$item}->{'default'} == 0) {
1953: $checked = '';
1954: } elsif ($settings->{$item}->{'default'} == 1) {
1955: $checked = 'checked="checked" ';
1956: }
1.78 raeburn 1957: }
1.72 raeburn 1958: }
1.101 raeburn 1959: $datatable .= '<span class="LC_nobreak"><label>'.
1960: '<input type="checkbox" name="'.$context.'_'.$item.
1961: '" value="default" '.$checked.'/>'.$titles{$item}.
1962: '</label></span> ';
1963: }
1964: }
1965: if ($context eq 'requestcourses') {
1966: $datatable .= '</tr><tr>';
1967: foreach my $item (@usertools) {
1.106 raeburn 1968: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1969: }
1.101 raeburn 1970: $datatable .= '</tr></table>';
1.72 raeburn 1971: }
1.86 raeburn 1972: $datatable .= '</td>';
1.160.6.5 raeburn 1973: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1974: $datatable .= '<td class="LC_right_item">'.
1975: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1976: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1977: $defaultquota.'" size="5" /></span>'.(' ' x2).
1978: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1979: '<input type="text" name="authorquota" value="'.
1980: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1981: }
1982: $datatable .= '</tr>';
1.72 raeburn 1983: $typecount ++;
1984: $css_class = $typecount%2?' class="LC_odd_row"':'';
1985: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1986: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1987: if ($context eq 'requestcourses') {
1.109 raeburn 1988: $datatable .= &mt('(overrides affiliation, if set)').
1989: '</td>'.
1990: '<td class="LC_left_item">'.
1991: '<table><tr>';
1.101 raeburn 1992: } else {
1.109 raeburn 1993: $datatable .= &mt('(overrides affiliation, if checked)').
1994: '</td>'.
1995: '<td class="LC_left_item" colspan="2">'.
1996: '<br />';
1.101 raeburn 1997: }
1998: my %advcell;
1.72 raeburn 1999: foreach my $item (@usertools) {
1.101 raeburn 2000: if ($context eq 'requestcourses') {
2001: my ($curroption,$currlimit);
2002: if (ref($settings) eq 'HASH') {
2003: if (ref($settings->{$item}) eq 'HASH') {
2004: $curroption = $settings->{$item}->{'_LC_adv'};
2005: if ($curroption =~ /^autolimit=(\d*)$/) {
2006: $currlimit = $1;
2007: }
2008: }
2009: }
2010: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2011: my $checked = '';
2012: if ($curroption eq '') {
2013: $checked = ' checked="checked"';
2014: }
2015: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2016: '<input type="radio" name="crsreq_'.$item.
2017: '__LC_adv" value=""'.$checked.' />'.
2018: &mt('No override set').'</label></span> ';
1.101 raeburn 2019: foreach my $option (@options) {
2020: my $val = $option;
2021: if ($option eq 'norequest') {
2022: $val = 0;
2023: }
2024: if ($option eq 'validate') {
2025: my $canvalidate = 0;
2026: if (ref($validations{$item}) eq 'HASH') {
2027: if ($validations{$item}{'_LC_adv'}) {
2028: $canvalidate = 1;
2029: }
2030: }
2031: next if (!$canvalidate);
2032: }
2033: my $checked = '';
1.104 raeburn 2034: if ($val eq $curroption) {
1.101 raeburn 2035: $checked = ' checked="checked"';
2036: } elsif ($option eq 'autolimit') {
2037: if ($curroption =~ /^autolimit/) {
2038: $checked = ' checked="checked"';
2039: }
2040: }
2041: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2042: '<input type="radio" name="crsreq_'.$item.
2043: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2044: $titles{$option}.'</label>';
2045: if ($option eq 'autolimit') {
1.127 raeburn 2046: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2047: $item.'_limit__LC_adv" size="1" '.
2048: 'value="'.$currlimit.'" />';
2049: }
1.127 raeburn 2050: $advcell{$item} .= '</span> ';
1.104 raeburn 2051: if ($option eq 'autolimit') {
1.127 raeburn 2052: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2053: }
1.101 raeburn 2054: }
1.160.6.5 raeburn 2055: } elsif ($context eq 'requestauthor') {
2056: my $curroption;
2057: if (ref($settings) eq 'HASH') {
2058: $curroption = $settings->{'_LC_adv'};
2059: }
2060: my $checked = '';
2061: if ($curroption eq '') {
2062: $checked = ' checked="checked"';
2063: }
2064: $datatable .= '<span class="LC_nobreak"><label>'.
2065: '<input type="radio" name="authorreq__LC_adv"'.
2066: ' value=""'.$checked.' />'.
2067: &mt('No override set').'</label></span> ';
2068: foreach my $option (@options) {
2069: my $val = $option;
2070: if ($option eq 'norequest') {
2071: $val = 0;
2072: }
2073: my $checked = '';
2074: if ($val eq $curroption) {
2075: $checked = ' checked="checked"';
2076: }
2077: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2078: '<input type="radio" name="authorreq__LC_adv"'.
2079: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2080: $titles{$option}.'</label></span> ';
2081: }
1.101 raeburn 2082: } else {
2083: my $checked = 'checked="checked" ';
2084: if (ref($settings) eq 'HASH') {
2085: if (ref($settings->{$item}) eq 'HASH') {
2086: if ($settings->{$item}->{'_LC_adv'} == 0) {
2087: $checked = '';
2088: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2089: $checked = 'checked="checked" ';
2090: }
1.79 raeburn 2091: }
1.72 raeburn 2092: }
1.101 raeburn 2093: $datatable .= '<span class="LC_nobreak"><label>'.
2094: '<input type="checkbox" name="'.$context.'_'.$item.
2095: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2096: '</label></span> ';
2097: }
2098: }
2099: if ($context eq 'requestcourses') {
2100: $datatable .= '</tr><tr>';
2101: foreach my $item (@usertools) {
1.106 raeburn 2102: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2103: }
1.101 raeburn 2104: $datatable .= '</tr></table>';
1.72 raeburn 2105: }
1.98 raeburn 2106: $datatable .= '</td></tr>';
1.30 raeburn 2107: $$rowtotal += $typecount;
1.3 raeburn 2108: return $datatable;
2109: }
2110:
1.160.6.5 raeburn 2111: sub print_requestmail {
2112: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2113: my ($now,$datatable,%currapp);
1.102 raeburn 2114: $now = time;
2115: if (ref($settings) eq 'HASH') {
2116: if (ref($settings->{'notify'}) eq 'HASH') {
2117: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2118: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2119: }
2120: }
2121: }
1.160.6.16 raeburn 2122: my $numinrow = 2;
1.160.6.34 raeburn 2123: my $css_class;
2124: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2125: my $text;
2126: if ($action eq 'requestcourses') {
2127: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2128: } elsif ($action eq 'requestauthor') {
2129: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2130: } else {
1.160.6.34 raeburn 2131: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2132: }
1.160.6.34 raeburn 2133: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2134: ' <td>'.$text.'</td>'.
1.102 raeburn 2135: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2136: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2137: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2138: if ($numdc > 0) {
2139: $datatable .= $table;
1.102 raeburn 2140: } else {
2141: $datatable .= &mt('There are no active Domain Coordinators');
2142: }
2143: $datatable .='</td></tr>';
2144: return $datatable;
2145: }
2146:
1.160.6.30 raeburn 2147: sub print_studentcode {
2148: my ($settings,$rowtotal) = @_;
2149: my $rownum = 0;
2150: my ($output,%current);
2151: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2152: if (ref($settings) eq 'HASH') {
2153: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2154: foreach my $type (@crstypes) {
2155: $current{$type} = $settings->{'uniquecode'}{$type};
2156: }
1.160.6.30 raeburn 2157: }
2158: }
2159: $output .= '<tr>'.
2160: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2161: '<td class="LC_left_item">';
2162: foreach my $type (@crstypes) {
2163: my $check = ' ';
2164: if ($current{$type}) {
2165: $check = ' checked="checked" ';
2166: }
2167: $output .= '<span class="LC_nobreak"><label>'.
2168: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2169: &mt($type).'</label></span>'.(' 'x2).' ';
2170: }
2171: $output .= '</td></tr>';
2172: $$rowtotal ++;
2173: return $output;
2174: }
2175:
2176: sub print_textbookcourses {
1.160.6.46 raeburn 2177: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2178: my $rownum = 0;
2179: my $css_class;
2180: my $itemcount = 1;
2181: my $maxnum = 0;
2182: my $bookshash;
2183: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2184: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2185: }
2186: my %ordered;
2187: if (ref($bookshash) eq 'HASH') {
2188: foreach my $item (keys(%{$bookshash})) {
2189: if (ref($bookshash->{$item}) eq 'HASH') {
2190: my $num = $bookshash->{$item}{'order'};
2191: $ordered{$num} = $item;
2192: }
2193: }
2194: }
2195: my $confname = $dom.'-domainconfig';
2196: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2197: my $maxnum = scalar(keys(%ordered));
2198: my $datatable;
1.160.6.30 raeburn 2199: if (keys(%ordered)) {
2200: my @items = sort { $a <=> $b } keys(%ordered);
2201: for (my $i=0; $i<@items; $i++) {
2202: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2203: my $key = $ordered{$items[$i]};
2204: my %coursehash=&Apache::lonnet::coursedescription($key);
2205: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2206: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2207: if (ref($bookshash->{$key}) eq 'HASH') {
2208: $subject = $bookshash->{$key}->{'subject'};
2209: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2210: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2211: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2212: $author = $bookshash->{$key}->{'author'};
2213: $image = $bookshash->{$key}->{'image'};
2214: if ($image ne '') {
2215: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2216: my $imagethumb = "$path/tn-".$imagefile;
2217: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2218: }
1.160.6.30 raeburn 2219: }
2220: }
1.160.6.46 raeburn 2221: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2222: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2223: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2224: for (my $k=0; $k<=$maxnum; $k++) {
2225: my $vpos = $k+1;
2226: my $selstr;
2227: if ($k == $i) {
2228: $selstr = ' selected="selected" ';
2229: }
2230: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2231: }
2232: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2233: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2234: &mt('Delete?').'</label></span></td>'.
2235: '<td colspan="2">'.
1.160.6.46 raeburn 2236: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2237: (' 'x2).
1.160.6.46 raeburn 2238: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2239: if ($type eq 'textbooks') {
2240: $datatable .= (' 'x2).
1.160.6.47 raeburn 2241: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2242: (' 'x2).
1.160.6.46 raeburn 2243: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2244: (' 'x2).
2245: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2246: if ($image) {
2247: $datatable .= '<span class="LC_nobreak">'.
2248: $imgsrc.
2249: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2250: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2251: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2252: }
2253: if ($switchserver) {
2254: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2255: } else {
2256: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2257: }
1.160.6.30 raeburn 2258: }
1.160.6.46 raeburn 2259: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2260: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2261: $coursetitle.'</span></td></tr>'."\n";
2262: $itemcount ++;
2263: }
2264: }
2265: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2266: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2267: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2268: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2269: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2270: for (my $k=0; $k<$maxnum+1; $k++) {
2271: my $vpos = $k+1;
2272: my $selstr;
2273: if ($k == $maxnum) {
2274: $selstr = ' selected="selected" ';
2275: }
2276: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2277: }
2278: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2279: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2280: '<td colspan="2">'.
1.160.6.46 raeburn 2281: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2282: (' 'x2).
1.160.6.46 raeburn 2283: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2284: (' 'x2);
2285: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2286: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2287: (' 'x2).
2288: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2289: (' 'x2).
2290: '<span class="LC_nobreak">'.&mt('Image:').' ';
2291: if ($switchserver) {
2292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2293: } else {
2294: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2295: }
1.160.6.30 raeburn 2296: }
2297: $datatable .= '</span>'."\n".
2298: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2299: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2300: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2301: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2302: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2303: '</span></td>'."\n".
2304: '</tr>'."\n";
2305: $itemcount ++;
2306: return $datatable;
2307: }
2308:
2309: sub textbookcourses_javascript {
1.160.6.46 raeburn 2310: my ($settings) = @_;
2311: return unless(ref($settings) eq 'HASH');
2312: my (%ordered,%total,%jstext);
2313: foreach my $type ('textbooks','templates') {
2314: $total{$type} = 0;
2315: if (ref($settings->{$type}) eq 'HASH') {
2316: foreach my $item (keys(%{$settings->{$type}})) {
2317: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2318: my $num = $settings->{$type}->{$item}{'order'};
2319: $ordered{$type}{$num} = $item;
2320: }
2321: }
2322: $total{$type} = scalar(keys(%{$settings->{$type}}));
2323: }
2324: my @jsarray = ();
2325: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2326: push(@jsarray,$ordered{$type}{$item});
2327: }
2328: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2329: }
2330: return <<"ENDSCRIPT";
2331: <script type="text/javascript">
2332: // <![CDATA[
1.160.6.46 raeburn 2333: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2334: var changedVal;
1.160.6.46 raeburn 2335: $jstext{'textbooks'};
2336: $jstext{'templates'};
2337: var newpos;
2338: var maxh;
2339: if (caller == 'textbooks') {
2340: newpos = 'textbooks_addbook_pos';
2341: maxh = 1 + $total{'textbooks'};
2342: } else {
2343: newpos = 'templates_addbook_pos';
2344: maxh = 1 + $total{'templates'};
2345: }
1.160.6.30 raeburn 2346: var current = new Array;
2347: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2348: if (item == newpos) {
2349: changedVal = newitemVal;
2350: } else {
2351: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2352: current[newitemVal] = newpos;
2353: }
1.160.6.46 raeburn 2354: if (caller == 'textbooks') {
2355: for (var i=0; i<textbooks.length; i++) {
2356: var elementName = 'textbooks_'+textbooks[i];
2357: if (elementName != item) {
2358: if (form.elements[elementName]) {
2359: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2360: current[currVal] = elementName;
2361: }
2362: }
2363: }
2364: }
2365: if (caller == 'templates') {
2366: for (var i=0; i<templates.length; i++) {
2367: var elementName = 'templates_'+templates[i];
2368: if (elementName != item) {
2369: if (form.elements[elementName]) {
2370: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2371: current[currVal] = elementName;
2372: }
1.160.6.30 raeburn 2373: }
2374: }
2375: }
2376: var oldVal;
2377: for (var j=0; j<maxh; j++) {
2378: if (current[j] == undefined) {
2379: oldVal = j;
2380: }
2381: }
2382: if (oldVal < changedVal) {
2383: for (var k=oldVal+1; k<=changedVal ; k++) {
2384: var elementName = current[k];
2385: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2386: }
2387: } else {
2388: for (var k=changedVal; k<oldVal; k++) {
2389: var elementName = current[k];
2390: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2391: }
2392: }
2393: return;
2394: }
2395:
2396: // ]]>
2397: </script>
2398:
2399: ENDSCRIPT
2400: }
2401:
1.3 raeburn 2402: sub print_autoenroll {
1.30 raeburn 2403: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2404: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2405: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2406: if (ref($settings) eq 'HASH') {
2407: if (exists($settings->{'run'})) {
2408: if ($settings->{'run'} eq '0') {
2409: $runoff = ' checked="checked" ';
2410: $runon = ' ';
2411: } else {
2412: $runon = ' checked="checked" ';
2413: $runoff = ' ';
2414: }
2415: } else {
2416: if ($autorun) {
2417: $runon = ' checked="checked" ';
2418: $runoff = ' ';
2419: } else {
2420: $runoff = ' checked="checked" ';
2421: $runon = ' ';
2422: }
2423: }
1.129 raeburn 2424: if (exists($settings->{'co-owners'})) {
2425: if ($settings->{'co-owners'} eq '0') {
2426: $coownersoff = ' checked="checked" ';
2427: $coownerson = ' ';
2428: } else {
2429: $coownerson = ' checked="checked" ';
2430: $coownersoff = ' ';
2431: }
2432: } else {
2433: $coownersoff = ' checked="checked" ';
2434: $coownerson = ' ';
2435: }
1.3 raeburn 2436: if (exists($settings->{'sender_domain'})) {
2437: $defdom = $settings->{'sender_domain'};
2438: }
1.160.6.68 raeburn 2439: if (exists($settings->{'autofailsafe'})) {
2440: $failsafe = $settings->{'autofailsafe'};
2441: }
1.14 raeburn 2442: } else {
2443: if ($autorun) {
2444: $runon = ' checked="checked" ';
2445: $runoff = ' ';
2446: } else {
2447: $runoff = ' checked="checked" ';
2448: $runon = ' ';
2449: }
1.3 raeburn 2450: }
2451: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2452: my $notif_sender;
2453: if (ref($settings) eq 'HASH') {
2454: $notif_sender = $settings->{'sender_uname'};
2455: }
1.3 raeburn 2456: my $datatable='<tr class="LC_odd_row">'.
2457: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2458: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2459: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2460: $runon.' value="1" />'.&mt('Yes').'</label> '.
2461: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2462: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2463: '</tr><tr>'.
2464: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2465: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2466: &mt('username').': '.
2467: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2468: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2469: ': '.$domform.'</span></td></tr>'.
2470: '<tr class="LC_odd_row">'.
2471: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2472: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2473: '<input type="radio" name="autoassign_coowners"'.
2474: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2475: '<label><input type="radio" name="autoassign_coowners"'.
2476: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2477: '</tr><tr>'.
2478: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2479: '<td class="LC_right_item"><span class="LC_nobreak">'.
2480: '<input type="text" name="autoenroll_failsafe"'.
2481: ' value="'.$failsafe.'" size="4" /></td></tr>';
2482: $$rowtotal += 4;
1.3 raeburn 2483: return $datatable;
2484: }
2485:
2486: sub print_autoupdate {
1.30 raeburn 2487: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2488: my $datatable;
2489: if ($position eq 'top') {
2490: my $updateon = ' ';
2491: my $updateoff = ' checked="checked" ';
2492: my $classlistson = ' ';
2493: my $classlistsoff = ' checked="checked" ';
2494: if (ref($settings) eq 'HASH') {
2495: if ($settings->{'run'} eq '1') {
2496: $updateon = $updateoff;
2497: $updateoff = ' ';
2498: }
2499: if ($settings->{'classlists'} eq '1') {
2500: $classlistson = $classlistsoff;
2501: $classlistsoff = ' ';
2502: }
2503: }
2504: my %title = (
2505: run => 'Auto-update active?',
2506: classlists => 'Update information in classlists?',
2507: );
2508: $datatable = '<tr class="LC_odd_row">'.
2509: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2510: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2511: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2512: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2513: '<label><input type="radio" name="autoupdate_run"'.
2514: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2515: '</tr><tr>'.
2516: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2517: '<td class="LC_right_item"><span class="LC_nobreak">'.
2518: '<label><input type="radio" name="classlists"'.
2519: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2520: '<label><input type="radio" name="classlists"'.
2521: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2522: '</tr>';
1.30 raeburn 2523: $$rowtotal += 2;
1.131 raeburn 2524: } elsif ($position eq 'middle') {
2525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2526: my $numinrow = 3;
2527: my $locknamesettings;
2528: $datatable .= &insttypes_row($settings,$types,$usertypes,
2529: $dom,$numinrow,$othertitle,
2530: 'lockablenames');
2531: $$rowtotal ++;
1.3 raeburn 2532: } else {
1.44 raeburn 2533: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2534: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2535: 'permanentemail','id');
1.33 raeburn 2536: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2537: my $numrows = 0;
1.26 raeburn 2538: if (ref($types) eq 'ARRAY') {
2539: if (@{$types} > 0) {
2540: $datatable =
2541: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2542: \@fields,$types,\$numrows);
1.30 raeburn 2543: $$rowtotal += @{$types};
1.26 raeburn 2544: }
1.3 raeburn 2545: }
2546: $datatable .=
2547: &usertype_update_row($settings,{'default' => $othertitle},
2548: \%fieldtitles,\@fields,['default'],
2549: \$numrows);
1.30 raeburn 2550: $$rowtotal ++;
1.3 raeburn 2551: }
2552: return $datatable;
2553: }
2554:
1.125 raeburn 2555: sub print_autocreate {
2556: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2557: my (%createon,%createoff,%currhash);
1.125 raeburn 2558: my @types = ('xml','req');
2559: if (ref($settings) eq 'HASH') {
2560: foreach my $item (@types) {
2561: $createoff{$item} = ' checked="checked" ';
2562: $createon{$item} = ' ';
2563: if (exists($settings->{$item})) {
2564: if ($settings->{$item}) {
2565: $createon{$item} = ' checked="checked" ';
2566: $createoff{$item} = ' ';
2567: }
2568: }
2569: }
1.160.6.16 raeburn 2570: if ($settings->{'xmldc'} ne '') {
2571: $currhash{$settings->{'xmldc'}} = 1;
2572: }
1.125 raeburn 2573: } else {
2574: foreach my $item (@types) {
2575: $createoff{$item} = ' checked="checked" ';
2576: $createon{$item} = ' ';
2577: }
2578: }
2579: $$rowtotal += 2;
1.160.6.16 raeburn 2580: my $numinrow = 2;
1.125 raeburn 2581: my $datatable='<tr class="LC_odd_row">'.
2582: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2583: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2584: '<input type="radio" name="autocreate_xml"'.
2585: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2586: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2587: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2588: '</td></tr><tr>'.
2589: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2590: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2591: '<input type="radio" name="autocreate_req"'.
2592: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2593: '<label><input type="radio" name="autocreate_req"'.
2594: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2595: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2596: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2597: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2598: if ($numdc > 1) {
1.160.6.50 raeburn 2599: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2600: '</td><td class="LC_left_item">';
1.125 raeburn 2601: } else {
1.160.6.50 raeburn 2602: $datatable .= &mt('Course creation processed as:').
2603: '</td><td class="LC_right_item">';
1.125 raeburn 2604: }
1.160.6.50 raeburn 2605: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2606: $$rowtotal += $rows;
1.125 raeburn 2607: return $datatable;
2608: }
2609:
1.23 raeburn 2610: sub print_directorysrch {
1.160.6.72! raeburn 2611: my ($position,$dom,$settings,$rowtotal) = @_;
! 2612: my $datatable;
! 2613: if ($position eq 'top') {
! 2614: my $instsrchon = ' ';
! 2615: my $instsrchoff = ' checked="checked" ';
! 2616: my ($exacton,$containson,$beginson);
! 2617: my $instlocalon = ' ';
! 2618: my $instlocaloff = ' checked="checked" ';
! 2619: if (ref($settings) eq 'HASH') {
! 2620: if ($settings->{'available'} eq '1') {
! 2621: $instsrchon = $instsrchoff;
! 2622: $instsrchoff = ' ';
! 2623: }
! 2624: if ($settings->{'localonly'} eq '1') {
! 2625: $instlocalon = $instlocaloff;
! 2626: $instlocaloff = ' ';
! 2627: }
! 2628: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
! 2629: foreach my $type (@{$settings->{'searchtypes'}}) {
! 2630: if ($type eq 'exact') {
! 2631: $exacton = ' checked="checked" ';
! 2632: } elsif ($type eq 'contains') {
! 2633: $containson = ' checked="checked" ';
! 2634: } elsif ($type eq 'begins') {
! 2635: $beginson = ' checked="checked" ';
! 2636: }
! 2637: }
! 2638: } else {
! 2639: if ($settings->{'searchtypes'} eq 'exact') {
! 2640: $exacton = ' checked="checked" ';
! 2641: } elsif ($settings->{'searchtypes'} eq 'contains') {
! 2642: $containson = ' checked="checked" ';
! 2643: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2644: $exacton = ' checked="checked" ';
2645: $containson = ' checked="checked" ';
2646: }
2647: }
1.23 raeburn 2648: }
1.160.6.72! raeburn 2649: my ($searchtitles,$titleorder) = &sorted_searchtitles();
! 2650: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2651:
1.160.6.72! raeburn 2652: my $numinrow = 4;
! 2653: my $cansrchrow = 0;
! 2654: $datatable='<tr class="LC_odd_row">'.
! 2655: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
! 2656: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2657: '<input type="radio" name="dirsrch_available"'.
! 2658: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
! 2659: '<label><input type="radio" name="dirsrch_available"'.
! 2660: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
! 2661: '</tr><tr>'.
! 2662: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
! 2663: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2664: '<input type="radio" name="dirsrch_instlocalonly"'.
! 2665: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
! 2666: '<label><input type="radio" name="dirsrch_instlocalonly"'.
! 2667: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
! 2668: '</tr>';
! 2669: $$rowtotal += 2;
! 2670: if (ref($usertypes) eq 'HASH') {
! 2671: if (keys(%{$usertypes}) > 0) {
! 2672: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
! 2673: $numinrow,$othertitle,'cansearch');
! 2674: $cansrchrow = 1;
! 2675: }
1.26 raeburn 2676: }
1.160.6.72! raeburn 2677: if ($cansrchrow) {
! 2678: $$rowtotal ++;
! 2679: $datatable .= '<tr>';
! 2680: } else {
! 2681: $datatable .= '<tr class="LC_odd_row">';
! 2682: }
! 2683: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
! 2684: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
! 2685: foreach my $title (@{$titleorder}) {
! 2686: if (defined($searchtitles->{$title})) {
! 2687: my $check = ' ';
! 2688: if (ref($settings) eq 'HASH') {
! 2689: if (ref($settings->{'searchby'}) eq 'ARRAY') {
! 2690: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
! 2691: $check = ' checked="checked" ';
! 2692: }
1.39 raeburn 2693: }
1.25 raeburn 2694: }
1.160.6.72! raeburn 2695: $datatable .= '<td class="LC_left_item">'.
! 2696: '<span class="LC_nobreak"><label>'.
! 2697: '<input type="checkbox" name="searchby" '.
! 2698: 'value="'.$title.'"'.$check.'/>'.
! 2699: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2700: }
2701: }
1.160.6.72! raeburn 2702: $datatable .= '</tr></table></td></tr>';
! 2703: $$rowtotal ++;
! 2704: if ($cansrchrow) {
! 2705: $datatable .= '<tr class="LC_odd_row">';
! 2706: } else {
! 2707: $datatable .= '<tr>';
! 2708: }
! 2709: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
! 2710: '<td class="LC_left_item" colspan="2">'.
! 2711: '<span class="LC_nobreak"><label>'.
! 2712: '<input type="checkbox" name="searchtypes" '.
! 2713: $exacton.' value="exact" />'.&mt('Exact match').
! 2714: '</label> '.
! 2715: '<label><input type="checkbox" name="searchtypes" '.
! 2716: $beginson.' value="begins" />'.&mt('Begins with').
! 2717: '</label> '.
! 2718: '<label><input type="checkbox" name="searchtypes" '.
! 2719: $containson.' value="contains" />'.&mt('Contains').
! 2720: '</label></span></td></tr>';
! 2721: $$rowtotal ++;
1.26 raeburn 2722: } else {
1.160.6.72! raeburn 2723: my $domsrchon = ' checked="checked" ';
! 2724: my $domsrchoff = ' ';
! 2725: my $domlocalon = ' ';
! 2726: my $domlocaloff = ' checked="checked" ';
! 2727: if (ref($settings) eq 'HASH') {
! 2728: if ($settings->{'lclocalonly'} eq '1') {
! 2729: $domlocalon = $domlocaloff;
! 2730: $domlocaloff = ' ';
! 2731: }
! 2732: if ($settings->{'lcavailable'} eq '0') {
! 2733: $domsrchoff = $domsrchon;
! 2734: $domsrchon = ' ';
! 2735: }
! 2736: }
! 2737: $datatable='<tr class="LC_odd_row">'.
! 2738: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
! 2739: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2740: '<input type="radio" name="dirsrch_domavailable"'.
! 2741: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
! 2742: '<label><input type="radio" name="dirsrch_domavailable"'.
! 2743: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
! 2744: '</tr><tr>'.
! 2745: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
! 2746: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
! 2747: '<input type="radio" name="dirsrch_domlocalonly"'.
! 2748: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
! 2749: '<label><input type="radio" name="dirsrch_domlocalonly"'.
! 2750: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
! 2751: '</tr>';
! 2752: $$rowtotal += 2;
1.26 raeburn 2753: }
1.25 raeburn 2754: return $datatable;
2755: }
2756:
1.28 raeburn 2757: sub print_contacts {
1.30 raeburn 2758: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2759: my $datatable;
2760: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2761: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2762: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2763: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2764: foreach my $type (@mailings) {
2765: $otheremails{$type} = '';
2766: }
1.134 raeburn 2767: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2768: if (ref($settings) eq 'HASH') {
2769: foreach my $item (@contacts) {
2770: if (exists($settings->{$item})) {
2771: $to{$item} = $settings->{$item};
2772: }
2773: }
2774: foreach my $type (@mailings) {
2775: if (exists($settings->{$type})) {
2776: if (ref($settings->{$type}) eq 'HASH') {
2777: foreach my $item (@contacts) {
2778: if ($settings->{$type}{$item}) {
2779: $checked{$type}{$item} = ' checked="checked" ';
2780: }
2781: }
2782: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2783: if ($type eq 'helpdeskmail') {
2784: $bccemails{$type} = $settings->{$type}{'bcc'};
2785: }
1.28 raeburn 2786: }
1.89 raeburn 2787: } elsif ($type eq 'lonstatusmail') {
2788: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2789: }
2790: }
2791: } else {
2792: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2793: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2794: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2795: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2796: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2797: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2798: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2799: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2800: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2801: }
2802: my ($titles,$short_titles) = &contact_titles();
2803: my $rownum = 0;
2804: my $css_class;
2805: foreach my $item (@contacts) {
1.69 raeburn 2806: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2807: $datatable .= '<tr'.$css_class.'>'.
2808: '<td><span class="LC_nobreak">'.$titles->{$item}.
2809: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2810: '<input type="text" name="'.$item.'" value="'.
2811: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2812: $rownum ++;
1.28 raeburn 2813: }
2814: foreach my $type (@mailings) {
1.69 raeburn 2815: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2816: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2817: '<td><span class="LC_nobreak">'.
2818: $titles->{$type}.': </span></td>'.
1.28 raeburn 2819: '<td class="LC_left_item">'.
2820: '<span class="LC_nobreak">';
2821: foreach my $item (@contacts) {
2822: $datatable .= '<label>'.
2823: '<input type="checkbox" name="'.$type.'"'.
2824: $checked{$type}{$item}.
2825: ' value="'.$item.'" />'.$short_titles->{$item}.
2826: '</label> ';
2827: }
2828: $datatable .= '</span><br />'.&mt('Others').': '.
2829: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2830: 'value="'.$otheremails{$type}.'" />';
2831: if ($type eq 'helpdeskmail') {
1.136 raeburn 2832: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2833: '<input type="text" name="'.$type.'_bcc" '.
2834: 'value="'.$bccemails{$type}.'" />';
2835: }
2836: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2837: $rownum ++;
1.28 raeburn 2838: }
1.160.6.23 raeburn 2839: my %choices;
2840: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2841: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2842: &mt('LON-CAPA core group - MSU'),600,500));
2843: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2844: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2845: &mt('LON-CAPA core group - MSU'),600,500));
2846: my @toggles = ('reporterrors','reportupdates');
2847: my %defaultchecked = ('reporterrors' => 'on',
2848: 'reportupdates' => 'on');
2849: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2850: \%choices,$rownum);
2851: $datatable .= $reports;
1.30 raeburn 2852: $$rowtotal += $rownum;
1.28 raeburn 2853: return $datatable;
2854: }
2855:
1.118 jms 2856: sub print_helpsettings {
1.160.6.5 raeburn 2857: my ($dom,$confname,$settings,$rowtotal) = @_;
2858: my ($datatable,$itemcount);
2859: $itemcount = 1;
2860: my (%choices,%defaultchecked,@toggles);
2861: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2862: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2863: &mt('LON-CAPA bug tracker'),600,500));
2864: %defaultchecked = ('submitbugs' => 'on');
2865: @toggles = ('submitbugs',);
1.122 jms 2866:
1.160.6.5 raeburn 2867: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2868: \%choices,$itemcount);
2869: return $datatable;
1.121 raeburn 2870: }
2871:
2872: sub radiobutton_prefs {
1.160.6.16 raeburn 2873: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 2874: $additional,$align) = @_;
1.121 raeburn 2875: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2876: (ref($choices) eq 'HASH'));
2877:
2878: my (%checkedon,%checkedoff,$datatable,$css_class);
2879:
2880: foreach my $item (@{$toggles}) {
2881: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2882: $checkedon{$item} = ' checked="checked" ';
2883: $checkedoff{$item} = ' ';
1.121 raeburn 2884: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2885: $checkedoff{$item} = ' checked="checked" ';
2886: $checkedon{$item} = ' ';
2887: }
2888: }
2889: if (ref($settings) eq 'HASH') {
1.121 raeburn 2890: foreach my $item (@{$toggles}) {
1.118 jms 2891: if ($settings->{$item} eq '1') {
2892: $checkedon{$item} = ' checked="checked" ';
2893: $checkedoff{$item} = ' ';
2894: } elsif ($settings->{$item} eq '0') {
2895: $checkedoff{$item} = ' checked="checked" ';
2896: $checkedon{$item} = ' ';
2897: }
2898: }
1.121 raeburn 2899: }
1.160.6.16 raeburn 2900: if ($onclick) {
2901: $onclick = ' onclick="'.$onclick.'"';
2902: }
1.121 raeburn 2903: foreach my $item (@{$toggles}) {
1.118 jms 2904: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2905: $datatable .=
1.160.6.16 raeburn 2906: '<tr'.$css_class.'><td valign="top">'.
2907: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 2908: '</span></td>';
2909: if ($align eq 'left') {
2910: $datatable .= '<td class="LC_left_item">';
2911: } else {
2912: $datatable .= '<td class="LC_right_item">';
2913: }
2914: $datatable .=
2915: '<span class="LC_nobreak">'.
1.118 jms 2916: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2917: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2918: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2919: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2920: '</span>'.$additional.
2921: '</td>'.
1.118 jms 2922: '</tr>';
2923: $itemcount ++;
1.121 raeburn 2924: }
2925: return ($datatable,$itemcount);
2926: }
2927:
2928: sub print_coursedefaults {
1.139 raeburn 2929: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2930: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2931: my $itemcount = 1;
1.160.6.16 raeburn 2932: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 2933: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2934: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2935: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 2936: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2937: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2938: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 2939: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 2940: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 2941: );
1.160.6.21 raeburn 2942: my %staticdefaults = (
2943: anonsurvey_threshold => 10,
2944: uploadquota => 500,
1.160.6.57 raeburn 2945: postsubmit => 60,
1.160.6.70 raeburn 2946: mysqltables => 172800,
1.160.6.21 raeburn 2947: );
1.139 raeburn 2948: if ($position eq 'top') {
1.160.6.57 raeburn 2949: %defaultchecked = (
2950: 'uselcmath' => 'on',
2951: 'usejsme' => 'on',
1.160.6.64 raeburn 2952: 'canclone' => 'none',
1.160.6.57 raeburn 2953: );
2954: @toggles = ('uselcmath','usejsme');
1.139 raeburn 2955: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 2956: \%choices,$itemcount);
1.160.6.64 raeburn 2957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2958: $datatable .=
2959: '<tr'.$css_class.'><td valign="top">'.
2960: '<span class="LC_nobreak">'.$choices{'canclone'}.
2961: '</span></td><td class="LC_left_item">';
2962: my $currcanclone = 'none';
2963: my $onclick;
2964: my @cloneoptions = ('none','domain');
2965: my %clonetitles = (
2966: none => 'No additional course requesters',
2967: domain => "Any course requester in course's domain",
2968: instcode => 'Course requests for official courses ...',
2969: );
2970: my (%codedefaults,@code_order,@posscodes);
2971: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
2972: \@code_order) eq 'ok') {
2973: if (@code_order > 0) {
2974: push(@cloneoptions,'instcode');
2975: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
2976: }
2977: }
2978: if (ref($settings) eq 'HASH') {
2979: if ($settings->{'canclone'}) {
2980: if (ref($settings->{'canclone'}) eq 'HASH') {
2981: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
2982: if (@code_order > 0) {
2983: $currcanclone = 'instcode';
2984: @posscodes = @{$settings->{'canclone'}{'instcode'}};
2985: }
2986: }
2987: } elsif ($settings->{'canclone'} eq 'domain') {
2988: $currcanclone = $settings->{'canclone'};
2989: }
2990: }
2991: }
2992: foreach my $option (@cloneoptions) {
2993: my ($checked,$additional);
2994: if ($currcanclone eq $option) {
2995: $checked = ' checked="checked"';
2996: }
2997: if ($option eq 'instcode') {
2998: if (@code_order) {
2999: my $show = 'none';
3000: if ($checked) {
3001: $show = 'block';
3002: }
3003: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3004: &mt('Institutional codes for new and cloned course have identical:').
3005: '<br />';
3006: foreach my $item (@code_order) {
3007: my $codechk;
3008: if ($checked) {
3009: if (grep(/^\Q$item\E$/,@posscodes)) {
3010: $codechk = ' checked="checked"';
3011: }
3012: }
3013: $additional .= '<label>'.
3014: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3015: $item.'</label>';
3016: }
3017: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3018: }
3019: }
3020: $datatable .=
3021: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3022: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3023: '</label> '.$additional.'</span><br />';
3024: }
3025: $datatable .= '</td>'.
3026: '</tr>';
3027: $itemcount ++;
1.139 raeburn 3028: } else {
3029: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3030: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3031: my $currusecredits = 0;
1.160.6.57 raeburn 3032: my $postsubmitclient = 1;
1.160.6.30 raeburn 3033: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3034: if (ref($settings) eq 'HASH') {
3035: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3036: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3037: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3038: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3039: }
3040: }
1.160.6.16 raeburn 3041: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3042: foreach my $type (@types) {
3043: next if ($type eq 'community');
3044: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3045: if ($defcredits{$type} ne '') {
3046: $currusecredits = 1;
3047: }
3048: }
3049: }
3050: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3051: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3052: $postsubmitclient = 0;
3053: foreach my $type (@types) {
3054: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3055: }
3056: } else {
3057: foreach my $type (@types) {
3058: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3059: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3060: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3061: } else {
3062: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3063: }
3064: } else {
3065: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3066: }
3067: }
3068: }
3069: } else {
3070: foreach my $type (@types) {
3071: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3072: }
3073: }
1.160.6.70 raeburn 3074: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3075: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3076: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3077: }
3078: } else {
3079: foreach my $type (@types) {
3080: $currmysql{$type} = $staticdefaults{'mysqltables'};
3081: }
3082: }
1.160.6.58 raeburn 3083: } else {
3084: foreach my $type (@types) {
3085: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3086: }
1.139 raeburn 3087: }
3088: if (!$currdefresponder) {
1.160.6.21 raeburn 3089: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3090: } elsif ($currdefresponder < 1) {
3091: $currdefresponder = 1;
3092: }
1.160.6.21 raeburn 3093: foreach my $type (@types) {
3094: if ($curruploadquota{$type} eq '') {
3095: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3096: }
3097: }
1.139 raeburn 3098: $datatable .=
1.160.6.16 raeburn 3099: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3100: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3101: '</span></td>'.
3102: '<td class="LC_right_item"><span class="LC_nobreak">'.
3103: '<input type="text" name="anonsurvey_threshold"'.
3104: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3105: '</td></tr>'."\n";
3106: $itemcount ++;
3107: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3108: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3109: $choices{'uploadquota'}.
3110: '</span></td>'.
3111: '<td align="right" class="LC_right_item">'.
3112: '<table><tr>';
1.160.6.21 raeburn 3113: foreach my $type (@types) {
3114: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3115: '<input type="text" name="uploadquota_'.$type.'"'.
3116: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3117: }
3118: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3119: $itemcount ++;
1.160.6.40 raeburn 3120: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3121: my $display = 'none';
3122: if ($currusecredits) {
3123: $display = 'block';
3124: }
3125: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3126: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3127: foreach my $type (@types) {
3128: next if ($type eq 'community');
3129: $additional .= '<td align="center">'.&mt($type).'<br />'.
3130: '<input type="text" name="'.$type.'_credits"'.
3131: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3132: }
3133: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3134: %defaultchecked = ('coursecredits' => 'off');
3135: @toggles = ('coursecredits');
3136: my $current = {
3137: 'coursecredits' => $currusecredits,
3138: };
3139: (my $table,$itemcount) =
3140: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3141: \%choices,$itemcount,$onclick,$additional,'left');
3142: $datatable .= $table;
3143: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3144: my $display = 'none';
3145: if ($postsubmitclient) {
3146: $display = 'block';
3147: }
3148: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3149: &mt('Number of seconds submit is disabled').'<br />'.
3150: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3151: '<table><tr>';
1.160.6.57 raeburn 3152: foreach my $type (@types) {
3153: $additional .= '<td align="center">'.&mt($type).'<br />'.
3154: '<input type="text" name="'.$type.'_timeout" value="'.
3155: $deftimeout{$type}.'" size="5" /></td>';
3156: }
3157: $additional .= '</tr></table></div>'."\n";
3158: %defaultchecked = ('postsubmit' => 'on');
3159: @toggles = ('postsubmit');
1.160.6.70 raeburn 3160: $current = {
3161: 'postsubmit' => $postsubmitclient,
3162: };
1.160.6.57 raeburn 3163: ($table,$itemcount) =
3164: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3165: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3166: $datatable .= $table;
1.160.6.70 raeburn 3167: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3168: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3169: $choices{'mysqltables'}.
3170: '</span></td>'.
3171: '<td align="right" class="LC_right_item">'.
3172: '<table><tr>';
3173: foreach my $type (@types) {
3174: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3175: '<input type="text" name="mysqltables_'.$type.'"'.
3176: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3177: }
3178: $datatable .= '</tr></table></td></tr>'."\n";
3179: $itemcount ++;
3180:
1.160.6.37 raeburn 3181: }
3182: $$rowtotal += $itemcount;
3183: return $datatable;
3184: }
3185:
3186: sub print_selfenrollment {
3187: my ($position,$dom,$settings,$rowtotal) = @_;
3188: my ($css_class,$datatable);
3189: my $itemcount = 1;
3190: my @types = ('official','unofficial','community','textbook');
3191: if (($position eq 'top') || ($position eq 'middle')) {
3192: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3193: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3194: my @rows;
3195: my $key;
3196: if ($position eq 'top') {
3197: $key = 'admin';
3198: if (ref($rowsref) eq 'ARRAY') {
3199: @rows = @{$rowsref};
3200: }
3201: } elsif ($position eq 'middle') {
3202: $key = 'default';
3203: @rows = ('types','registered','approval','limit');
3204: }
3205: foreach my $row (@rows) {
3206: if (defined($titlesref->{$row})) {
3207: $itemcount ++;
3208: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3209: $datatable .= '<tr'.$css_class.'>'.
3210: '<td>'.$titlesref->{$row}.'</td>'.
3211: '<td class="LC_left_item">'.
3212: '<table><tr>';
3213: my (%current,%currentcap);
3214: if (ref($settings) eq 'HASH') {
3215: if (ref($settings->{$key}) eq 'HASH') {
3216: foreach my $type (@types) {
3217: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3218: $current{$type} = $settings->{$key}->{$type}->{$row};
3219: }
3220: if (($row eq 'limit') && ($key eq 'default')) {
3221: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3222: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3223: }
3224: }
3225: }
3226: }
3227: }
3228: my %roles = (
3229: '0' => &Apache::lonnet::plaintext('dc'),
3230: );
3231:
3232: foreach my $type (@types) {
3233: unless (($row eq 'registered') && ($key eq 'default')) {
3234: $datatable .= '<th>'.&mt($type).'</th>';
3235: }
3236: }
3237: unless (($row eq 'registered') && ($key eq 'default')) {
3238: $datatable .= '</tr><tr>';
3239: }
3240: foreach my $type (@types) {
3241: if ($type eq 'community') {
3242: $roles{'1'} = &mt('Community personnel');
3243: } else {
3244: $roles{'1'} = &mt('Course personnel');
3245: }
3246: $datatable .= '<td style="vertical-align: top">';
3247: if ($position eq 'top') {
3248: my %checked;
3249: if ($current{$type} eq '0') {
3250: $checked{'0'} = ' checked="checked"';
3251: } else {
3252: $checked{'1'} = ' checked="checked"';
3253: }
3254: foreach my $role ('1','0') {
3255: $datatable .= '<span class="LC_nobreak"><label>'.
3256: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3257: 'value="'.$role.'"'.$checked{$role}.' />'.
3258: $roles{$role}.'</label></span> ';
3259: }
3260: } else {
3261: if ($row eq 'types') {
3262: my %checked;
3263: if ($current{$type} =~ /^(all|dom)$/) {
3264: $checked{$1} = ' checked="checked"';
3265: } else {
3266: $checked{''} = ' checked="checked"';
3267: }
3268: foreach my $val ('','dom','all') {
3269: $datatable .= '<span class="LC_nobreak"><label>'.
3270: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3271: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3272: }
3273: } elsif ($row eq 'registered') {
3274: my %checked;
3275: if ($current{$type} eq '1') {
3276: $checked{'1'} = ' checked="checked"';
3277: } else {
3278: $checked{'0'} = ' checked="checked"';
3279: }
3280: foreach my $val ('0','1') {
3281: $datatable .= '<span class="LC_nobreak"><label>'.
3282: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3283: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3284: }
3285: } elsif ($row eq 'approval') {
3286: my %checked;
3287: if ($current{$type} =~ /^([12])$/) {
3288: $checked{$1} = ' checked="checked"';
3289: } else {
3290: $checked{'0'} = ' checked="checked"';
3291: }
3292: for my $val (0..2) {
3293: $datatable .= '<span class="LC_nobreak"><label>'.
3294: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3295: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3296: }
3297: } elsif ($row eq 'limit') {
3298: my %checked;
3299: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3300: $checked{$1} = ' checked="checked"';
3301: } else {
3302: $checked{'none'} = ' checked="checked"';
3303: }
3304: my $cap;
3305: if ($currentcap{$type} =~ /^\d+$/) {
3306: $cap = $currentcap{$type};
3307: }
3308: foreach my $val ('none','allstudents','selfenrolled') {
3309: $datatable .= '<span class="LC_nobreak"><label>'.
3310: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3311: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3312: }
3313: $datatable .= '<br />'.
3314: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3315: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3316: '</span>';
3317: }
3318: }
3319: $datatable .= '</td>';
3320: }
3321: $datatable .= '</tr>';
3322: }
3323: $datatable .= '</table></td></tr>';
3324: }
3325: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3326: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3327: }
3328: $$rowtotal += $itemcount;
3329: return $datatable;
3330: }
3331:
3332: sub print_validation_rows {
3333: my ($caller,$dom,$settings,$rowtotal) = @_;
3334: my ($itemsref,$namesref,$fieldsref);
3335: if ($caller eq 'selfenroll') {
3336: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3337: } elsif ($caller eq 'requestcourses') {
3338: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3339: }
3340: my %currvalidation;
3341: if (ref($settings) eq 'HASH') {
3342: if (ref($settings->{'validation'}) eq 'HASH') {
3343: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3344: }
1.160.6.39 raeburn 3345: }
3346: my $datatable;
3347: my $itemcount = 0;
3348: foreach my $item (@{$itemsref}) {
3349: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3350: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3351: $namesref->{$item}.
3352: '</span></td>'.
3353: '<td class="LC_left_item">';
3354: if (($item eq 'url') || ($item eq 'button')) {
3355: $datatable .= '<span class="LC_nobreak">'.
3356: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3357: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3358: } elsif ($item eq 'fields') {
3359: my @currfields;
3360: if (ref($currvalidation{$item}) eq 'ARRAY') {
3361: @currfields = @{$currvalidation{$item}};
3362: }
3363: foreach my $field (@{$fieldsref}) {
3364: my $check = '';
3365: if (grep(/^\Q$field\E$/,@currfields)) {
3366: $check = ' checked="checked"';
3367: }
3368: $datatable .= '<span class="LC_nobreak"><label>'.
3369: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3370: ' value="'.$field.'"'.$check.' />'.$field.
3371: '</label></span> ';
3372: }
3373: } elsif ($item eq 'markup') {
3374: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3375: $currvalidation{$item}.
1.160.6.37 raeburn 3376: '</textarea>';
1.160.6.39 raeburn 3377: }
3378: $datatable .= '</td></tr>'."\n";
3379: if (ref($rowtotal)) {
1.160.6.37 raeburn 3380: $itemcount ++;
3381: }
1.139 raeburn 3382: }
1.160.6.39 raeburn 3383: if ($caller eq 'requestcourses') {
3384: my %currhash;
1.160.6.51 raeburn 3385: if (ref($settings) eq 'HASH') {
3386: if (ref($settings->{'validation'}) eq 'HASH') {
3387: if ($settings->{'validation'}{'dc'} ne '') {
3388: $currhash{$settings->{'validation'}{'dc'}} = 1;
3389: }
1.160.6.39 raeburn 3390: }
3391: }
3392: my $numinrow = 2;
3393: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3394: 'validationdc',%currhash);
1.160.6.50 raeburn 3395: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3396: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3397: if ($numdc > 1) {
1.160.6.50 raeburn 3398: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3399: } else {
1.160.6.50 raeburn 3400: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3401: }
1.160.6.50 raeburn 3402: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3403: $itemcount ++;
3404: }
3405: if (ref($rowtotal)) {
3406: $$rowtotal += $itemcount;
3407: }
1.121 raeburn 3408: return $datatable;
1.118 jms 3409: }
3410:
1.137 raeburn 3411: sub print_usersessions {
3412: my ($position,$dom,$settings,$rowtotal) = @_;
3413: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3414: my (%by_ip,%by_location,@intdoms);
3415: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3416:
3417: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3418: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3419: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3420: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3421: my $itemcount = 1;
3422: if ($position eq 'top') {
1.152 raeburn 3423: if (keys(%serverhomes) > 1) {
1.145 raeburn 3424: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3425: my $curroffloadnow;
3426: if (ref($settings) eq 'HASH') {
3427: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3428: $curroffloadnow = $settings->{'offloadnow'};
3429: }
3430: }
3431: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3432: } else {
1.140 raeburn 3433: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3434: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3435: }
1.137 raeburn 3436: } else {
1.145 raeburn 3437: if (keys(%by_location) == 0) {
3438: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3439: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3440: } else {
3441: my %lt = &usersession_titles();
3442: my $numinrow = 5;
3443: my $prefix;
3444: my @types;
3445: if ($position eq 'bottom') {
3446: $prefix = 'remote';
3447: @types = ('version','excludedomain','includedomain');
3448: } else {
3449: $prefix = 'hosted';
3450: @types = ('excludedomain','includedomain');
3451: }
3452: my (%current,%checkedon,%checkedoff);
3453: my @lcversions = &Apache::lonnet::all_loncaparevs();
3454: my @locations = sort(keys(%by_location));
3455: foreach my $type (@types) {
3456: $checkedon{$type} = '';
3457: $checkedoff{$type} = ' checked="checked"';
3458: }
3459: if (ref($settings) eq 'HASH') {
3460: if (ref($settings->{$prefix}) eq 'HASH') {
3461: foreach my $key (keys(%{$settings->{$prefix}})) {
3462: $current{$key} = $settings->{$prefix}{$key};
3463: if ($key eq 'version') {
3464: if ($current{$key} ne '') {
3465: $checkedon{$key} = ' checked="checked"';
3466: $checkedoff{$key} = '';
3467: }
3468: } elsif (ref($current{$key}) eq 'ARRAY') {
3469: $checkedon{$key} = ' checked="checked"';
3470: $checkedoff{$key} = '';
3471: }
1.137 raeburn 3472: }
3473: }
3474: }
1.145 raeburn 3475: foreach my $type (@types) {
3476: next if ($type ne 'version' && !@locations);
3477: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3478: $datatable .= '<tr'.$css_class.'>
3479: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3480: <span class="LC_nobreak">
3481: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3482: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3483: if ($type eq 'version') {
3484: my $selector = '<select name="'.$prefix.'_version">';
3485: foreach my $version (@lcversions) {
3486: my $selected = '';
3487: if ($current{'version'} eq $version) {
3488: $selected = ' selected="selected"';
3489: }
3490: $selector .= ' <option value="'.$version.'"'.
3491: $selected.'>'.$version.'</option>';
3492: }
3493: $selector .= '</select> ';
3494: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3495: } else {
3496: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3497: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3498: ' />'.(' 'x2).
3499: '<input type="button" value="'.&mt('uncheck all').'" '.
3500: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3501: "\n".
3502: '</div><div><table>';
3503: my $rem;
3504: for (my $i=0; $i<@locations; $i++) {
3505: my ($showloc,$value,$checkedtype);
3506: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3507: my $ip = $by_location{$locations[$i]}->[0];
3508: if (ref($by_ip{$ip}) eq 'ARRAY') {
3509: $value = join(':',@{$by_ip{$ip}});
3510: $showloc = join(', ',@{$by_ip{$ip}});
3511: if (ref($current{$type}) eq 'ARRAY') {
3512: foreach my $loc (@{$by_ip{$ip}}) {
3513: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3514: $checkedtype = ' checked="checked"';
3515: last;
3516: }
3517: }
1.138 raeburn 3518: }
3519: }
3520: }
1.145 raeburn 3521: $rem = $i%($numinrow);
3522: if ($rem == 0) {
3523: if ($i > 0) {
3524: $datatable .= '</tr>';
3525: }
3526: $datatable .= '<tr>';
3527: }
3528: $datatable .= '<td class="LC_left_item">'.
3529: '<span class="LC_nobreak"><label>'.
3530: '<input type="checkbox" name="'.$prefix.'_'.$type.
3531: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3532: '</label></span></td>';
1.137 raeburn 3533: }
1.145 raeburn 3534: $rem = @locations%($numinrow);
3535: my $colsleft = $numinrow - $rem;
3536: if ($colsleft > 1 ) {
3537: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3538: ' </td>';
3539: } elsif ($colsleft == 1) {
3540: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3541: }
1.145 raeburn 3542: $datatable .= '</tr></table>';
1.137 raeburn 3543: }
1.145 raeburn 3544: $datatable .= '</td></tr>';
3545: $itemcount ++;
1.137 raeburn 3546: }
3547: }
3548: }
3549: $$rowtotal += $itemcount;
3550: return $datatable;
3551: }
3552:
1.138 raeburn 3553: sub build_location_hashes {
3554: my ($intdoms,$by_ip,$by_location) = @_;
3555: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3556: (ref($by_location) eq 'HASH'));
3557: my %iphost = &Apache::lonnet::get_iphost();
3558: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3559: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3560: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3561: foreach my $id (@{$iphost{$primary_ip}}) {
3562: my $intdom = &Apache::lonnet::internet_dom($id);
3563: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3564: push(@{$intdoms},$intdom);
3565: }
3566: }
3567: }
3568: foreach my $ip (keys(%iphost)) {
3569: if (ref($iphost{$ip}) eq 'ARRAY') {
3570: foreach my $id (@{$iphost{$ip}}) {
3571: my $location = &Apache::lonnet::internet_dom($id);
3572: if ($location) {
3573: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3574: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3575: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3576: push(@{$by_ip->{$ip}},$location);
3577: }
3578: } else {
3579: $by_ip->{$ip} = [$location];
3580: }
3581: }
3582: }
3583: }
3584: }
3585: foreach my $ip (sort(keys(%{$by_ip}))) {
3586: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3587: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3588: my $first = $by_ip->{$ip}->[0];
3589: if (ref($by_location->{$first}) eq 'ARRAY') {
3590: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3591: push(@{$by_location->{$first}},$ip);
3592: }
3593: } else {
3594: $by_location->{$first} = [$ip];
3595: }
3596: }
3597: }
3598: return;
3599: }
3600:
1.145 raeburn 3601: sub current_offloads_to {
3602: my ($dom,$settings,$servers) = @_;
3603: my (%spareid,%otherdomconfigs);
1.152 raeburn 3604: if (ref($servers) eq 'HASH') {
1.145 raeburn 3605: foreach my $lonhost (sort(keys(%{$servers}))) {
3606: my $gotspares;
1.152 raeburn 3607: if (ref($settings) eq 'HASH') {
3608: if (ref($settings->{'spares'}) eq 'HASH') {
3609: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3610: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3611: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3612: $gotspares = 1;
3613: }
1.145 raeburn 3614: }
3615: }
3616: unless ($gotspares) {
3617: my $gotspares;
3618: my $serverhomeID =
3619: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3620: my $serverhomedom =
3621: &Apache::lonnet::host_domain($serverhomeID);
3622: if ($serverhomedom ne $dom) {
3623: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3624: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3625: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3626: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3627: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3628: $gotspares = 1;
3629: }
3630: }
3631: } else {
3632: $otherdomconfigs{$serverhomedom} =
3633: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3634: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3635: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3636: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3637: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3638: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3639: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3640: $gotspares = 1;
3641: }
3642: }
3643: }
3644: }
3645: }
3646: }
3647: }
3648: unless ($gotspares) {
3649: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3650: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3651: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3652: } else {
3653: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3654: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3655: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3656: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3657: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3658: } else {
1.150 raeburn 3659: my %what = (
3660: spareid => 1,
3661: );
3662: my ($result,$returnhash) =
3663: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3664: if ($result eq 'ok') {
3665: if (ref($returnhash) eq 'HASH') {
3666: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3667: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3668: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3669: }
3670: }
1.145 raeburn 3671: }
3672: }
3673: }
3674: }
3675: }
3676: }
3677: return %spareid;
3678: }
3679:
3680: sub spares_row {
1.160.6.61 raeburn 3681: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 3682: my $css_class;
3683: my $numinrow = 4;
3684: my $itemcount = 1;
3685: my $datatable;
1.152 raeburn 3686: my %typetitles = &sparestype_titles();
3687: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3688: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3689: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3690: my ($othercontrol,$serverdom);
3691: if ($serverhome ne $server) {
3692: $serverdom = &Apache::lonnet::host_domain($serverhome);
3693: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3694: } else {
3695: $serverdom = &Apache::lonnet::host_domain($server);
3696: if ($serverdom ne $dom) {
3697: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3698: }
3699: }
3700: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 3701: my $checkednow;
3702: if (ref($curroffloadnow) eq 'HASH') {
3703: if ($curroffloadnow->{$server}) {
3704: $checkednow = ' checked="checked"';
3705: }
3706: }
1.145 raeburn 3707: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3708: $datatable .= '<tr'.$css_class.'>
3709: <td rowspan="2">
1.160.6.13 raeburn 3710: <span class="LC_nobreak">'.
3711: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 3712: ,'<b>'.$server.'</b>').'</span><br />'.
3713: '<span class="LC_nobreak">'."\n".
3714: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
3715: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 3716: "\n";
1.145 raeburn 3717: my (%current,%canselect);
1.152 raeburn 3718: my @choices =
3719: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3720: foreach my $type ('primary','default') {
3721: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3722: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3723: my @spares = @{$spareid->{$server}{$type}};
3724: if (@spares > 0) {
1.152 raeburn 3725: if ($othercontrol) {
3726: $current{$type} = join(', ',@spares);
3727: } else {
3728: $current{$type} .= '<table>';
3729: my $numspares = scalar(@spares);
3730: for (my $i=0; $i<@spares; $i++) {
3731: my $rem = $i%($numinrow);
3732: if ($rem == 0) {
3733: if ($i > 0) {
3734: $current{$type} .= '</tr>';
3735: }
3736: $current{$type} .= '<tr>';
1.145 raeburn 3737: }
1.152 raeburn 3738: $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'".');" /> '.
3739: $spareid->{$server}{$type}[$i].
3740: '</label></td>'."\n";
3741: }
3742: my $rem = @spares%($numinrow);
3743: my $colsleft = $numinrow - $rem;
3744: if ($colsleft > 1 ) {
3745: $current{$type} .= '<td colspan="'.$colsleft.
3746: '" class="LC_left_item">'.
3747: ' </td>';
3748: } elsif ($colsleft == 1) {
3749: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3750: }
1.152 raeburn 3751: $current{$type} .= '</tr></table>';
1.150 raeburn 3752: }
1.145 raeburn 3753: }
3754: }
3755: if ($current{$type} eq '') {
3756: $current{$type} = &mt('None specified');
3757: }
1.152 raeburn 3758: if ($othercontrol) {
3759: if ($type eq 'primary') {
3760: $canselect{$type} = $othercontrol;
3761: }
3762: } else {
3763: $canselect{$type} =
3764: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3765: '<select name="newspare_'.$type.'_'.$server.'" '.
3766: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3767: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3768: if (@choices > 0) {
3769: foreach my $lonhost (@choices) {
3770: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3771: }
3772: }
3773: $canselect{$type} .= '</select>'."\n";
3774: }
3775: } else {
3776: $current{$type} = &mt('Could not be determined');
3777: if ($type eq 'primary') {
3778: $canselect{$type} = $othercontrol;
3779: }
1.145 raeburn 3780: }
1.152 raeburn 3781: if ($type eq 'default') {
3782: $datatable .= '<tr'.$css_class.'>';
3783: }
3784: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3785: '<td>'.$current{$type}.'</td>'."\n".
3786: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3787: }
3788: $itemcount ++;
3789: }
3790: }
3791: $$rowtotal += $itemcount;
3792: return $datatable;
3793: }
3794:
1.152 raeburn 3795: sub possible_newspares {
3796: my ($server,$currspares,$serverhomes,$altids) = @_;
3797: my $serverhostname = &Apache::lonnet::hostname($server);
3798: my %excluded;
3799: if ($serverhostname ne '') {
3800: %excluded = (
3801: $serverhostname => 1,
3802: );
3803: }
3804: if (ref($currspares) eq 'HASH') {
3805: foreach my $type (keys(%{$currspares})) {
3806: if (ref($currspares->{$type}) eq 'ARRAY') {
3807: if (@{$currspares->{$type}} > 0) {
3808: foreach my $curr (@{$currspares->{$type}}) {
3809: my $hostname = &Apache::lonnet::hostname($curr);
3810: $excluded{$hostname} = 1;
3811: }
3812: }
3813: }
3814: }
3815: }
3816: my @choices;
3817: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3818: if (keys(%{$serverhomes}) > 1) {
3819: foreach my $name (sort(keys(%{$serverhomes}))) {
3820: unless ($excluded{$name}) {
3821: if (exists($altids->{$serverhomes->{$name}})) {
3822: push(@choices,$altids->{$serverhomes->{$name}});
3823: } else {
3824: push(@choices,$serverhomes->{$name});
1.145 raeburn 3825: }
3826: }
3827: }
3828: }
3829: }
1.152 raeburn 3830: return sort(@choices);
1.145 raeburn 3831: }
3832:
1.150 raeburn 3833: sub print_loadbalancing {
3834: my ($dom,$settings,$rowtotal) = @_;
3835: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3836: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3837: my $numinrow = 1;
3838: my $datatable;
3839: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3840: my (%currbalancer,%currtargets,%currrules,%existing);
3841: if (ref($settings) eq 'HASH') {
3842: %existing = %{$settings};
3843: }
3844: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3845: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3846: \%currtargets,\%currrules);
1.150 raeburn 3847: } else {
3848: return;
3849: }
3850: my ($othertitle,$usertypes,$types) =
3851: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3852: my $rownum = 8;
1.150 raeburn 3853: if (ref($types) eq 'ARRAY') {
3854: $rownum += scalar(@{$types});
3855: }
1.160.6.7 raeburn 3856: my @css_class = ('LC_odd_row','LC_even_row');
3857: my $balnum = 0;
3858: my $islast;
3859: my (@toshow,$disabledtext);
3860: if (keys(%currbalancer) > 0) {
3861: @toshow = sort(keys(%currbalancer));
3862: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3863: push(@toshow,'');
3864: }
3865: } else {
3866: @toshow = ('');
3867: $disabledtext = &mt('No existing load balancer');
3868: }
3869: foreach my $lonhost (@toshow) {
3870: if ($balnum == scalar(@toshow)-1) {
3871: $islast = 1;
3872: } else {
3873: $islast = 0;
3874: }
3875: my $cssidx = $balnum%2;
3876: my $targets_div_style = 'display: none';
3877: my $disabled_div_style = 'display: block';
3878: my $homedom_div_style = 'display: none';
3879: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3880: '<td rowspan="'.$rownum.'" valign="top">'.
3881: '<p>';
3882: if ($lonhost eq '') {
3883: $datatable .= '<span class="LC_nobreak">';
3884: if (keys(%currbalancer) > 0) {
3885: $datatable .= &mt('Add balancer:');
3886: } else {
3887: $datatable .= &mt('Enable balancer:');
3888: }
3889: $datatable .= ' '.
3890: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3891: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3892: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3893: '<option value="" selected="selected">'.&mt('None').
3894: '</option>'."\n";
3895: foreach my $server (sort(keys(%servers))) {
3896: next if ($currbalancer{$server});
3897: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3898: }
3899: $datatable .=
3900: '</select>'."\n".
3901: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3902: } else {
3903: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3904: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3905: &mt('Stop balancing').'</label>'.
3906: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3907: $targets_div_style = 'display: block';
3908: $disabled_div_style = 'display: none';
3909: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3910: $homedom_div_style = 'display: block';
3911: }
3912: }
3913: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3914: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3915: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3916: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3917: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3918: my @sparestypes = ('primary','default');
3919: my %typetitles = &sparestype_titles();
3920: foreach my $sparetype (@sparestypes) {
3921: my $targettable;
3922: for (my $i=0; $i<$numspares; $i++) {
3923: my $checked;
3924: if (ref($currtargets{$lonhost}) eq 'HASH') {
3925: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3926: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3927: $checked = ' checked="checked"';
3928: }
3929: }
3930: }
3931: my ($chkboxval,$disabled);
3932: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3933: $chkboxval = $spares[$i];
3934: }
3935: if (exists($currbalancer{$spares[$i]})) {
3936: $disabled = ' disabled="disabled"';
3937: }
3938: $targettable .=
1.160.6.55 raeburn 3939: '<td><span class="LC_nobreak"><label>'.
3940: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 3941: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 3942: '</span></label></span></td>';
1.160.6.7 raeburn 3943: my $rem = $i%($numinrow);
3944: if ($rem == 0) {
3945: if (($i > 0) && ($i < $numspares-1)) {
3946: $targettable .= '</tr>';
3947: }
3948: if ($i < $numspares-1) {
3949: $targettable .= '<tr>';
1.150 raeburn 3950: }
3951: }
3952: }
1.160.6.7 raeburn 3953: if ($targettable ne '') {
3954: my $rem = $numspares%($numinrow);
3955: my $colsleft = $numinrow - $rem;
3956: if ($colsleft > 1 ) {
3957: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3958: ' </td>';
3959: } elsif ($colsleft == 1) {
3960: $targettable .= '<td class="LC_left_item"> </td>';
3961: }
3962: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3963: '<table><tr>'.$targettable.'</tr></table><br />';
3964: }
3965: }
3966: $datatable .= '</div></td></tr>'.
3967: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3968: $othertitle,$usertypes,$types,\%servers,
3969: \%currbalancer,$lonhost,
3970: $targets_div_style,$homedom_div_style,
3971: $css_class[$cssidx],$balnum,$islast);
3972: $$rowtotal += $rownum;
3973: $balnum ++;
3974: }
3975: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3976: return $datatable;
3977: }
3978:
3979: sub get_loadbalancers_config {
3980: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3981: return unless ((ref($servers) eq 'HASH') &&
3982: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3983: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3984: if (keys(%{$existing}) > 0) {
3985: my $oldlonhost;
3986: foreach my $key (sort(keys(%{$existing}))) {
3987: if ($key eq 'lonhost') {
3988: $oldlonhost = $existing->{'lonhost'};
3989: $currbalancer->{$oldlonhost} = 1;
3990: } elsif ($key eq 'targets') {
3991: if ($oldlonhost) {
3992: $currtargets->{$oldlonhost} = $existing->{'targets'};
3993: }
3994: } elsif ($key eq 'rules') {
3995: if ($oldlonhost) {
3996: $currrules->{$oldlonhost} = $existing->{'rules'};
3997: }
3998: } elsif (ref($existing->{$key}) eq 'HASH') {
3999: $currbalancer->{$key} = 1;
4000: $currtargets->{$key} = $existing->{$key}{'targets'};
4001: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4002: }
4003: }
1.160.6.7 raeburn 4004: } else {
4005: my ($balancerref,$targetsref) =
4006: &Apache::lonnet::get_lonbalancer_config($servers);
4007: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4008: foreach my $server (sort(keys(%{$balancerref}))) {
4009: $currbalancer->{$server} = 1;
4010: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4011: }
4012: }
4013: }
1.160.6.7 raeburn 4014: return;
1.150 raeburn 4015: }
4016:
4017: sub loadbalancing_rules {
4018: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4019: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4020: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4021: my $output;
1.160.6.7 raeburn 4022: my $num = 0;
4023: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4024: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4025: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4026: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4027: $num ++;
1.150 raeburn 4028: my $current;
4029: if (ref($currrules) eq 'HASH') {
4030: $current = $currrules->{$type};
4031: }
1.160.6.55 raeburn 4032: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4033: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4034: $current = '';
4035: }
4036: }
4037: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4038: $servers,$currbalancer,$lonhost,$dom,
4039: $targets_div_style,$homedom_div_style,
4040: $css_class,$balnum,$num,$islast);
1.150 raeburn 4041: }
4042: }
4043: return $output;
4044: }
4045:
4046: sub loadbalancing_titles {
4047: my ($dom,$intdom,$usertypes,$types) = @_;
4048: my %othertypes = (
4049: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4050: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4051: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4052: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4053: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4054: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4055: );
1.160.6.26 raeburn 4056: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4057: if (ref($types) eq 'ARRAY') {
4058: unshift(@alltypes,@{$types},'default');
4059: }
4060: my %titles;
4061: foreach my $type (@alltypes) {
4062: if ($type =~ /^_LC_/) {
4063: $titles{$type} = $othertypes{$type};
4064: } elsif ($type eq 'default') {
4065: $titles{$type} = &mt('All users from [_1]',$dom);
4066: if (ref($types) eq 'ARRAY') {
4067: if (@{$types} > 0) {
4068: $titles{$type} = &mt('Other users from [_1]',$dom);
4069: }
4070: }
4071: } elsif (ref($usertypes) eq 'HASH') {
4072: $titles{$type} = $usertypes->{$type};
4073: }
4074: }
4075: return (\@alltypes,\%othertypes,\%titles);
4076: }
4077:
4078: sub loadbalance_rule_row {
1.160.6.7 raeburn 4079: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4080: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4081: my @rulenames;
1.150 raeburn 4082: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4083: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4084: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4085: } else {
1.160.6.26 raeburn 4086: @rulenames = ('default','homeserver');
4087: if ($type eq '_LC_external') {
4088: push(@rulenames,'externalbalancer');
4089: } else {
4090: push(@rulenames,'specific');
4091: }
4092: push(@rulenames,'none');
1.150 raeburn 4093: }
4094: my $style = $targets_div_style;
1.160.6.55 raeburn 4095: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4096: $style = $homedom_div_style;
4097: }
1.160.6.7 raeburn 4098: my $space;
4099: if ($islast && $num == 1) {
4100: $space = '<div display="inline-block"> </div>';
4101: }
4102: my $output =
4103: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4104: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4105: '<td valaign="top">'.$space.
4106: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4107: for (my $i=0; $i<@rulenames; $i++) {
4108: my $rule = $rulenames[$i];
4109: my ($checked,$extra);
4110: if ($rulenames[$i] eq 'default') {
4111: $rule = '';
4112: }
4113: if ($rulenames[$i] eq 'specific') {
4114: if (ref($servers) eq 'HASH') {
4115: my $default;
4116: if (($current ne '') && (exists($servers->{$current}))) {
4117: $checked = ' checked="checked"';
4118: }
4119: unless ($checked) {
4120: $default = ' selected="selected"';
4121: }
1.160.6.7 raeburn 4122: $extra =
4123: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4124: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4125: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4126: '<option value=""'.$default.'></option>'."\n";
4127: foreach my $server (sort(keys(%{$servers}))) {
4128: if (ref($currbalancer) eq 'HASH') {
4129: next if (exists($currbalancer->{$server}));
4130: }
1.150 raeburn 4131: my $selected;
1.160.6.7 raeburn 4132: if ($server eq $current) {
1.150 raeburn 4133: $selected = ' selected="selected"';
4134: }
1.160.6.7 raeburn 4135: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4136: }
4137: $extra .= '</select>';
4138: }
4139: } elsif ($rule eq $current) {
4140: $checked = ' checked="checked"';
4141: }
4142: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4143: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4144: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4145: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4146: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4147: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4148: $output .= $ruletitles{'particular'};
4149: } else {
4150: $output .= $ruletitles{$rulenames[$i]};
4151: }
4152: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4153: }
4154: $output .= '</div></td></tr>'."\n";
4155: return $output;
4156: }
4157:
4158: sub offloadtype_text {
4159: my %ruletitles = &Apache::lonlocal::texthash (
4160: 'default' => 'Offloads to default destinations',
4161: 'homeserver' => "Offloads to user's home server",
4162: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4163: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4164: 'none' => 'No offload',
1.160.6.26 raeburn 4165: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4166: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4167: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4168: );
4169: return %ruletitles;
4170: }
4171:
4172: sub sparestype_titles {
4173: my %typestitles = &Apache::lonlocal::texthash (
4174: 'primary' => 'primary',
4175: 'default' => 'default',
4176: );
4177: return %typestitles;
4178: }
4179:
1.28 raeburn 4180: sub contact_titles {
4181: my %titles = &Apache::lonlocal::texthash (
4182: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4183: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4184: 'errormail' => 'Error reports to be e-mailed to',
4185: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4186: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4187: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4188: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 4189: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4190: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4191: );
4192: my %short_titles = &Apache::lonlocal::texthash (
4193: adminemail => 'Admin E-mail address',
4194: supportemail => 'Support E-mail',
4195: );
4196: return (\%titles,\%short_titles);
4197: }
4198:
1.72 raeburn 4199: sub tool_titles {
4200: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4201: aboutme => 'Personal web page',
1.86 raeburn 4202: blog => 'Blog',
1.160.6.4 raeburn 4203: webdav => 'WebDAV',
1.86 raeburn 4204: portfolio => 'Portfolio',
1.88 bisitz 4205: official => 'Official courses (with institutional codes)',
4206: unofficial => 'Unofficial courses',
1.98 raeburn 4207: community => 'Communities',
1.160.6.30 raeburn 4208: textbook => 'Textbook courses',
1.86 raeburn 4209: );
1.72 raeburn 4210: return %titles;
4211: }
4212:
1.101 raeburn 4213: sub courserequest_titles {
4214: my %titles = &Apache::lonlocal::texthash (
4215: official => 'Official',
4216: unofficial => 'Unofficial',
4217: community => 'Communities',
1.160.6.30 raeburn 4218: textbook => 'Textbook',
1.101 raeburn 4219: norequest => 'Not allowed',
1.104 raeburn 4220: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4221: validate => 'With validation',
4222: autolimit => 'Numerical limit',
1.103 raeburn 4223: unlimited => '(blank for unlimited)',
1.101 raeburn 4224: );
4225: return %titles;
4226: }
4227:
1.160.6.5 raeburn 4228: sub authorrequest_titles {
4229: my %titles = &Apache::lonlocal::texthash (
4230: norequest => 'Not allowed',
4231: approval => 'Approval by Dom. Coord.',
4232: automatic => 'Automatic approval',
4233: );
4234: return %titles;
4235: }
4236:
1.101 raeburn 4237: sub courserequest_conditions {
4238: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4239: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4240: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4241: );
4242: return %conditions;
4243: }
4244:
4245:
1.27 raeburn 4246: sub print_usercreation {
1.30 raeburn 4247: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4248: my $numinrow = 4;
1.28 raeburn 4249: my $datatable;
4250: if ($position eq 'top') {
1.30 raeburn 4251: $$rowtotal ++;
1.34 raeburn 4252: my $rowcount = 0;
1.32 raeburn 4253: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4254: if (ref($rules) eq 'HASH') {
4255: if (keys(%{$rules}) > 0) {
1.32 raeburn 4256: $datatable .= &user_formats_row('username',$settings,$rules,
4257: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4258: $$rowtotal ++;
1.32 raeburn 4259: $rowcount ++;
4260: }
4261: }
4262: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4263: if (ref($idrules) eq 'HASH') {
4264: if (keys(%{$idrules}) > 0) {
4265: $datatable .= &user_formats_row('id',$settings,$idrules,
4266: $idruleorder,$numinrow,$rowcount);
4267: $$rowtotal ++;
4268: $rowcount ++;
1.28 raeburn 4269: }
4270: }
1.39 raeburn 4271: if ($rowcount == 0) {
4272: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4273: $$rowtotal ++;
4274: $rowcount ++;
4275: }
1.34 raeburn 4276: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4277: my @creators = ('author','course','requestcrs');
1.37 raeburn 4278: my ($rules,$ruleorder) =
4279: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4280: my %lt = &usercreation_types();
4281: my %checked;
4282: if (ref($settings) eq 'HASH') {
4283: if (ref($settings->{'cancreate'}) eq 'HASH') {
4284: foreach my $item (@creators) {
4285: $checked{$item} = $settings->{'cancreate'}{$item};
4286: }
4287: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4288: foreach my $item (@creators) {
4289: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4290: $checked{$item} = 'none';
4291: }
4292: }
4293: }
4294: }
4295: my $rownum = 0;
4296: foreach my $item (@creators) {
4297: $rownum ++;
1.160.6.34 raeburn 4298: if ($checked{$item} eq '') {
4299: $checked{$item} = 'any';
1.34 raeburn 4300: }
4301: my $css_class;
4302: if ($rownum%2) {
4303: $css_class = '';
4304: } else {
4305: $css_class = ' class="LC_odd_row" ';
4306: }
4307: $datatable .= '<tr'.$css_class.'>'.
4308: '<td><span class="LC_nobreak">'.$lt{$item}.
4309: '</span></td><td align="right">';
1.160.6.34 raeburn 4310: my @options = ('any');
4311: if (ref($rules) eq 'HASH') {
4312: if (keys(%{$rules}) > 0) {
4313: push(@options,('official','unofficial'));
1.37 raeburn 4314: }
4315: }
1.160.6.34 raeburn 4316: push(@options,'none');
1.37 raeburn 4317: foreach my $option (@options) {
1.50 raeburn 4318: my $type = 'radio';
1.34 raeburn 4319: my $check = ' ';
1.160.6.34 raeburn 4320: if ($checked{$item} eq $option) {
4321: $check = ' checked="checked" ';
1.34 raeburn 4322: }
4323: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4324: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4325: $item.'" value="'.$option.'"'.$check.'/> '.
4326: $lt{$option}.'</label> </span>';
4327: }
4328: $datatable .= '</td></tr>';
4329: }
1.28 raeburn 4330: } else {
4331: my @contexts = ('author','course','domain');
4332: my @authtypes = ('int','krb4','krb5','loc');
4333: my %checked;
4334: if (ref($settings) eq 'HASH') {
4335: if (ref($settings->{'authtypes'}) eq 'HASH') {
4336: foreach my $item (@contexts) {
4337: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4338: foreach my $auth (@authtypes) {
4339: if ($settings->{'authtypes'}{$item}{$auth}) {
4340: $checked{$item}{$auth} = ' checked="checked" ';
4341: }
4342: }
4343: }
4344: }
1.27 raeburn 4345: }
1.35 raeburn 4346: } else {
4347: foreach my $item (@contexts) {
1.36 raeburn 4348: foreach my $auth (@authtypes) {
1.35 raeburn 4349: $checked{$item}{$auth} = ' checked="checked" ';
4350: }
4351: }
1.27 raeburn 4352: }
1.28 raeburn 4353: my %title = &context_names();
4354: my %authname = &authtype_names();
4355: my $rownum = 0;
4356: my $css_class;
4357: foreach my $item (@contexts) {
4358: if ($rownum%2) {
4359: $css_class = '';
4360: } else {
4361: $css_class = ' class="LC_odd_row" ';
4362: }
1.30 raeburn 4363: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4364: '<td>'.$title{$item}.
4365: '</td><td class="LC_left_item">'.
4366: '<span class="LC_nobreak">';
4367: foreach my $auth (@authtypes) {
4368: $datatable .= '<label>'.
4369: '<input type="checkbox" name="'.$item.'_auth" '.
4370: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4371: $authname{$auth}.'</label> ';
4372: }
4373: $datatable .= '</span></td></tr>';
4374: $rownum ++;
1.27 raeburn 4375: }
1.30 raeburn 4376: $$rowtotal += $rownum;
1.27 raeburn 4377: }
4378: return $datatable;
4379: }
4380:
1.160.6.34 raeburn 4381: sub print_selfcreation {
4382: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4383: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4384: if (ref($settings) eq 'HASH') {
4385: if (ref($settings->{'cancreate'}) eq 'HASH') {
4386: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4387: if (ref($createsettings) eq 'HASH') {
4388: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4389: @selfcreate = @{$createsettings->{'selfcreate'}};
4390: } elsif ($createsettings->{'selfcreate'} ne '') {
4391: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4392: @selfcreate = ('email','login','sso');
4393: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4394: @selfcreate = ($createsettings->{'selfcreate'});
4395: }
4396: }
4397: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4398: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4399: }
4400: }
4401: }
4402: }
4403: my %radiohash;
4404: my $numinrow = 4;
4405: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4406: if ($position eq 'top') {
4407: my %choices = &Apache::lonlocal::texthash (
4408: cancreate_login => 'Institutional Login',
4409: cancreate_sso => 'Institutional Single Sign On',
4410: );
4411: my @toggles = sort(keys(%choices));
4412: my %defaultchecked = (
4413: 'cancreate_login' => 'off',
4414: 'cancreate_sso' => 'off',
4415: );
1.160.6.35 raeburn 4416: my ($onclick,$itemcount);
1.160.6.34 raeburn 4417: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4418: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4419: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4420:
1.160.6.34 raeburn 4421: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4422:
4423: if (ref($usertypes) eq 'HASH') {
4424: if (keys(%{$usertypes}) > 0) {
4425: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4426: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4427: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4428: $$rowtotal ++;
4429: }
4430: }
1.160.6.44 raeburn 4431: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4432: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4433: $fieldtitles{'inststatus'} = &mt('Institutional status');
4434: my $rem;
4435: my $numperrow = 2;
4436: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4437: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 4438: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 4439: '<td class="LC_left_item">'."\n".
4440: '<table><tr><td>'."\n";
4441: for (my $i=0; $i<@fields; $i++) {
4442: $rem = $i%($numperrow);
4443: if ($rem == 0) {
4444: if ($i > 0) {
4445: $datatable .= '</tr>';
4446: }
4447: $datatable .= '<tr>';
4448: }
4449: my $currval;
1.160.6.51 raeburn 4450: if (ref($createsettings) eq 'HASH') {
4451: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4452: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4453: }
1.160.6.44 raeburn 4454: }
4455: $datatable .= '<td class="LC_left_item">'.
4456: '<span class="LC_nobreak">'.
4457: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4458: 'value="'.$currval.'" size="10" /> '.
4459: $fieldtitles{$fields[$i]}.'</span></td>';
4460: }
4461: my $colsleft = $numperrow - $rem;
4462: if ($colsleft > 1 ) {
4463: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4464: ' </td>';
4465: } elsif ($colsleft == 1) {
4466: $datatable .= '<td class="LC_left_item"> </td>';
4467: }
4468: $datatable .= '</tr></table></td></tr>';
4469: $$rowtotal ++;
1.160.6.34 raeburn 4470: } elsif ($position eq 'middle') {
4471: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4472: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4473: $usertypes->{'default'} = $othertitle;
4474: if (ref($types) eq 'ARRAY') {
4475: push(@{$types},'default');
4476: $usertypes->{'default'} = $othertitle;
4477: foreach my $status (@{$types}) {
4478: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4479: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 4480: $$rowtotal ++;
1.160.6.34 raeburn 4481: }
4482: }
4483: } else {
1.160.6.40 raeburn 4484: my %choices = &Apache::lonlocal::texthash (
4485: cancreate_email => 'E-mail address as username',
4486: );
4487: my @toggles = sort(keys(%choices));
4488: my %defaultchecked = (
4489: 'cancreate_email' => 'off',
4490: );
4491: my $itemcount = 0;
4492: my $display = 'none';
4493: if (grep(/^\Qemail\E$/,@selfcreate)) {
4494: $display = 'block';
4495: }
4496: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4497: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4498: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4499: my $usertypes = {};
4500: my $order = [];
4501: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4502: $usertypes = $domdefaults{'inststatustypes'};
4503: $order = $domdefaults{'inststatusguest'};
4504: }
4505: if (ref($order) eq 'ARRAY') {
4506: push(@{$order},'default');
4507: if (@{$order} > 1) {
4508: $usertypes->{'default'} = &mt('Other users');
4509: $additional .= '<table><tr>';
4510: foreach my $status (@{$order}) {
4511: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4512: }
4513: $additional .= '</tr><tr>';
4514: foreach my $status (@{$order}) {
4515: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4516: }
1.160.6.40 raeburn 4517: $additional .= '</tr></table>';
1.160.6.34 raeburn 4518: } else {
1.160.6.40 raeburn 4519: $usertypes->{'default'} = &mt('All users');
4520: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4521: }
4522: }
1.160.6.40 raeburn 4523: $additional .= '</div>'."\n";
4524:
4525: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 4526: \%choices,$$rowtotal,$onclick,$additional);
4527: $$rowtotal ++;
1.160.6.40 raeburn 4528: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4529: $$rowtotal ++;
1.160.6.35 raeburn 4530: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4531: $numinrow = 1;
1.160.6.40 raeburn 4532: if (ref($order) eq 'ARRAY') {
4533: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4534: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4535: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4536: $$rowtotal ++;
4537: }
4538: }
1.160.6.34 raeburn 4539: my ($emailrules,$emailruleorder) =
4540: &Apache::lonnet::inst_userrules($dom,'email');
4541: if (ref($emailrules) eq 'HASH') {
4542: if (keys(%{$emailrules}) > 0) {
4543: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4544: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4545: $$rowtotal ++;
4546: }
4547: }
1.160.6.35 raeburn 4548: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4549: }
4550: return $datatable;
4551: }
4552:
1.160.6.40 raeburn 4553: sub email_as_username {
4554: my ($rowtotal,$processing,$type) = @_;
4555: my %choices =
4556: &Apache::lonlocal::texthash (
4557: automatic => 'Automatic approval',
4558: approval => 'Queued for approval',
4559: );
4560: my $output;
4561: foreach my $option ('automatic','approval') {
4562: my $checked;
4563: if (ref($processing) eq 'HASH') {
4564: if ($type eq '') {
4565: if (!exists($processing->{'default'})) {
4566: if ($option eq 'automatic') {
4567: $checked = ' checked="checked"';
4568: }
4569: } else {
4570: if ($processing->{'default'} eq $option) {
4571: $checked = ' checked="checked"';
4572: }
4573: }
4574: } else {
4575: if (!exists($processing->{$type})) {
4576: if ($option eq 'automatic') {
4577: $checked = ' checked="checked"';
4578: }
4579: } else {
4580: if ($processing->{$type} eq $option) {
4581: $checked = ' checked="checked"';
4582: }
4583: }
4584: }
4585: } elsif ($option eq 'automatic') {
4586: $checked = ' checked="checked"';
4587: }
4588: my $name = 'cancreate_emailprocess';
4589: if (($type ne '') && ($type ne 'default')) {
4590: $name .= '_'.$type;
4591: }
4592: $output .= '<span class="LC_nobreak"><label>'.
4593: '<input type="radio" name="'.$name.'"'.
4594: $checked.' value="'.$option.'" />'.
4595: $choices{$option}.'</label></span>';
4596: if ($type eq '') {
4597: $output .= ' ';
4598: } else {
4599: $output .= '<br />';
4600: }
4601: }
4602: $$rowtotal ++;
4603: return $output;
4604: }
4605:
1.160.6.5 raeburn 4606: sub captcha_choice {
4607: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 4608: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4609: $vertext,$currver);
1.160.6.5 raeburn 4610: my %lt = &captcha_phrases();
4611: $keyentry = 'hidden';
4612: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4613: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4614: } elsif ($context eq 'login') {
4615: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4616: }
4617: if (ref($settings) eq 'HASH') {
4618: if ($settings->{'captcha'}) {
4619: $checked{$settings->{'captcha'}} = ' checked="checked"';
4620: } else {
4621: $checked{'original'} = ' checked="checked"';
4622: }
4623: if ($settings->{'captcha'} eq 'recaptcha') {
4624: $pubtext = $lt{'pub'};
4625: $privtext = $lt{'priv'};
4626: $keyentry = 'text';
1.160.6.69 raeburn 4627: $vertext = $lt{'ver'};
4628: $currver = $settings->{'recaptchaversion'};
4629: if ($currver ne '2') {
4630: $currver = 1;
4631: }
1.160.6.5 raeburn 4632: }
4633: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4634: $currpub = $settings->{'recaptchakeys'}{'public'};
4635: $currpriv = $settings->{'recaptchakeys'}{'private'};
4636: }
4637: } else {
4638: $checked{'original'} = ' checked="checked"';
4639: }
4640: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4641: my $output = '<tr'.$css_class.'>'.
4642: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4643: '<table><tr><td>'."\n";
4644: foreach my $option ('original','recaptcha','notused') {
4645: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4646: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4647: $lt{$option}.'</label></span>';
4648: unless ($option eq 'notused') {
4649: $output .= (' 'x2)."\n";
4650: }
4651: }
4652: #
4653: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4654: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4655: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4656: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4657: #
4658: $output .= '</td></tr>'."\n".
4659: '<tr><td>'."\n".
4660: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4661: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4662: $currpub.'" size="40" /></span><br />'."\n".
4663: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4664: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 4665: $currpriv.'" size="40" /></span><br />'.
4666: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
4667: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
4668: $currver.'" size="3" /></span><br />'.
4669: '</td></tr></table>'."\n".
1.160.6.5 raeburn 4670: '</td></tr>';
4671: return $output;
4672: }
4673:
1.32 raeburn 4674: sub user_formats_row {
4675: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4676: my $output;
4677: my %text = (
4678: 'username' => 'new usernames',
4679: 'id' => 'IDs',
1.45 raeburn 4680: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4681: );
4682: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4683: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4684: '<td><span class="LC_nobreak">';
4685: if ($type eq 'email') {
4686: $output .= &mt("Formats disallowed for $text{$type}: ");
4687: } else {
4688: $output .= &mt("Format rules to check for $text{$type}: ");
4689: }
4690: $output .= '</span></td>'.
4691: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4692: my $rem;
4693: if (ref($ruleorder) eq 'ARRAY') {
4694: for (my $i=0; $i<@{$ruleorder}; $i++) {
4695: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4696: my $rem = $i%($numinrow);
4697: if ($rem == 0) {
4698: if ($i > 0) {
4699: $output .= '</tr>';
4700: }
4701: $output .= '<tr>';
4702: }
4703: my $check = ' ';
1.39 raeburn 4704: if (ref($settings) eq 'HASH') {
4705: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4706: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4707: $check = ' checked="checked" ';
4708: }
1.27 raeburn 4709: }
4710: }
4711: $output .= '<td class="LC_left_item">'.
4712: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4713: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4714: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4715: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4716: }
4717: }
4718: $rem = @{$ruleorder}%($numinrow);
4719: }
4720: my $colsleft = $numinrow - $rem;
4721: if ($colsleft > 1 ) {
4722: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4723: ' </td>';
4724: } elsif ($colsleft == 1) {
4725: $output .= '<td class="LC_left_item"> </td>';
4726: }
4727: $output .= '</tr></table></td></tr>';
4728: return $output;
4729: }
4730:
1.34 raeburn 4731: sub usercreation_types {
4732: my %lt = &Apache::lonlocal::texthash (
4733: author => 'When adding a co-author',
4734: course => 'When adding a user to a course',
1.100 raeburn 4735: requestcrs => 'When requesting a course',
1.34 raeburn 4736: any => 'Any',
4737: official => 'Institutional only ',
4738: unofficial => 'Non-institutional only',
4739: none => 'None',
4740: );
4741: return %lt;
1.48 raeburn 4742: }
1.34 raeburn 4743:
1.160.6.34 raeburn 4744: sub selfcreation_types {
4745: my %lt = &Apache::lonlocal::texthash (
4746: selfcreate => 'User creates own account',
4747: any => 'Any',
4748: official => 'Institutional only ',
4749: unofficial => 'Non-institutional only',
4750: email => 'E-mail address',
4751: login => 'Institutional Login',
4752: sso => 'SSO',
4753: );
4754: }
4755:
1.28 raeburn 4756: sub authtype_names {
4757: my %lt = &Apache::lonlocal::texthash(
4758: int => 'Internal',
4759: krb4 => 'Kerberos 4',
4760: krb5 => 'Kerberos 5',
4761: loc => 'Local',
4762: );
4763: return %lt;
4764: }
4765:
4766: sub context_names {
4767: my %context_title = &Apache::lonlocal::texthash(
4768: author => 'Creating users when an Author',
4769: course => 'Creating users when in a course',
4770: domain => 'Creating users when a Domain Coordinator',
4771: );
4772: return %context_title;
4773: }
4774:
1.33 raeburn 4775: sub print_usermodification {
4776: my ($position,$dom,$settings,$rowtotal) = @_;
4777: my $numinrow = 4;
4778: my ($context,$datatable,$rowcount);
4779: if ($position eq 'top') {
4780: $rowcount = 0;
4781: $context = 'author';
4782: foreach my $role ('ca','aa') {
4783: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4784: $numinrow,$rowcount);
4785: $$rowtotal ++;
4786: $rowcount ++;
4787: }
1.160.6.37 raeburn 4788: } elsif ($position eq 'bottom') {
1.33 raeburn 4789: $context = 'course';
4790: $rowcount = 0;
4791: foreach my $role ('st','ep','ta','in','cr') {
4792: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4793: $numinrow,$rowcount);
4794: $$rowtotal ++;
4795: $rowcount ++;
4796: }
4797: }
4798: return $datatable;
4799: }
4800:
1.43 raeburn 4801: sub print_defaults {
1.160.6.40 raeburn 4802: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4803: my $rownum = 0;
4804: my ($datatable,$css_class);
1.160.6.40 raeburn 4805: if ($position eq 'top') {
4806: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4807: 'datelocale_def','portal_def');
4808: my %defaults;
4809: if (ref($settings) eq 'HASH') {
4810: %defaults = %{$settings};
1.43 raeburn 4811: } else {
1.160.6.40 raeburn 4812: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4813: foreach my $item (@items) {
4814: $defaults{$item} = $domdefaults{$item};
4815: }
1.43 raeburn 4816: }
1.160.6.40 raeburn 4817: my $titles = &defaults_titles($dom);
4818: foreach my $item (@items) {
4819: if ($rownum%2) {
4820: $css_class = '';
4821: } else {
4822: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4823: }
1.160.6.40 raeburn 4824: $datatable .= '<tr'.$css_class.'>'.
4825: '<td><span class="LC_nobreak">'.$titles->{$item}.
4826: '</span></td><td class="LC_right_item" colspan="3">';
4827: if ($item eq 'auth_def') {
4828: my @authtypes = ('internal','krb4','krb5','localauth');
4829: my %shortauth = (
4830: internal => 'int',
4831: krb4 => 'krb4',
4832: krb5 => 'krb5',
4833: localauth => 'loc'
4834: );
4835: my %authnames = &authtype_names();
4836: foreach my $auth (@authtypes) {
4837: my $checked = ' ';
4838: if ($defaults{$item} eq $auth) {
4839: $checked = ' checked="checked" ';
4840: }
4841: $datatable .= '<label><input type="radio" name="'.$item.
4842: '" value="'.$auth.'"'.$checked.'/>'.
4843: $authnames{$shortauth{$auth}}.'</label> ';
4844: }
4845: } elsif ($item eq 'timezone_def') {
4846: my $includeempty = 1;
4847: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4848: } elsif ($item eq 'datelocale_def') {
4849: my $includeempty = 1;
4850: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4851: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 4852: my $includeempty = 1;
4853: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 4854: } else {
4855: my $size;
4856: if ($item eq 'portal_def') {
4857: $size = ' size="25"';
4858: }
4859: $datatable .= '<input type="text" name="'.$item.'" value="'.
4860: $defaults{$item}.'"'.$size.' />';
4861: }
4862: $datatable .= '</td></tr>';
4863: $rownum ++;
4864: }
4865: } else {
4866: my (%defaults);
4867: if (ref($settings) eq 'HASH') {
4868: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4869: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4870: my $maxnum = @{$settings->{'inststatusorder'}};
4871: for (my $i=0; $i<$maxnum; $i++) {
4872: $css_class = $rownum%2?' class="LC_odd_row"':'';
4873: my $item = $settings->{'inststatusorder'}->[$i];
4874: my $title = $settings->{'inststatustypes'}->{$item};
4875: my $guestok;
4876: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4877: $guestok = 1;
4878: }
4879: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4880: $datatable .= '<tr'.$css_class.'>'.
4881: '<td><span class="LC_nobreak">'.
4882: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4883: for (my $k=0; $k<=$maxnum; $k++) {
4884: my $vpos = $k+1;
4885: my $selstr;
4886: if ($k == $i) {
4887: $selstr = ' selected="selected" ';
4888: }
4889: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4890: }
4891: my ($checkedon,$checkedoff);
4892: $checkedoff = ' checked="checked"';
4893: if ($guestok) {
4894: $checkedon = $checkedoff;
4895: $checkedoff = '';
4896: }
4897: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4898: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4899: &mt('delete').'</span></td>'.
4900: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4901: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4902: '</span></td>'.
4903: '<td class="LC_right_item"><span class="LC_nobreak">'.
4904: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4905: &mt('Yes').'</label>'.(' 'x2).
4906: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4907: &mt('No').'</label></span></td></tr>';
4908: }
4909: $css_class = $rownum%2?' class="LC_odd_row"':'';
4910: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4911: $datatable .= '<tr '.$css_class.'>'.
4912: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4913: for (my $k=0; $k<=$maxnum; $k++) {
4914: my $vpos = $k+1;
4915: my $selstr;
4916: if ($k == $maxnum) {
4917: $selstr = ' selected="selected" ';
4918: }
4919: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4920: }
4921: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 4922: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 4923: ' '.&mt('(new)').
4924: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4925: &mt('Name displayed:').
4926: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4927: '<td class="LC_right_item"><span class="LC_nobreak">'.
4928: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4929: &mt('Yes').'</label>'.(' 'x2).
4930: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4931: &mt('No').'</label></span></td></tr>';
4932: '</tr>'."\n";
4933: $rownum ++;
1.141 raeburn 4934: }
1.43 raeburn 4935: }
4936: }
4937: $$rowtotal += $rownum;
4938: return $datatable;
4939: }
4940:
1.160.6.5 raeburn 4941: sub get_languages_hash {
4942: my %langchoices;
4943: foreach my $id (&Apache::loncommon::languageids()) {
4944: my $code = &Apache::loncommon::supportedlanguagecode($id);
4945: if ($code ne '') {
4946: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4947: }
4948: }
4949: return %langchoices;
4950: }
4951:
1.43 raeburn 4952: sub defaults_titles {
1.141 raeburn 4953: my ($dom) = @_;
1.43 raeburn 4954: my %titles = &Apache::lonlocal::texthash (
4955: 'auth_def' => 'Default authentication type',
4956: 'auth_arg_def' => 'Default authentication argument',
4957: 'lang_def' => 'Default language',
1.54 raeburn 4958: 'timezone_def' => 'Default timezone',
1.68 raeburn 4959: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4960: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4961: );
1.141 raeburn 4962: if ($dom) {
4963: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4964: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4965: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4966: $protocol = 'http' if ($protocol ne 'https');
4967: if ($uint_dom) {
4968: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4969: $uint_dom);
4970: }
4971: }
1.43 raeburn 4972: return (\%titles);
4973: }
4974:
1.46 raeburn 4975: sub print_scantronformat {
4976: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4977: my $itemcount = 1;
1.60 raeburn 4978: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4979: %confhash);
1.46 raeburn 4980: my $switchserver = &check_switchserver($dom,$confname);
4981: my %lt = &Apache::lonlocal::texthash (
1.95 www 4982: default => 'Default bubblesheet format file error',
4983: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4984: );
4985: my %scantronfiles = (
4986: default => 'default.tab',
4987: custom => 'custom.tab',
4988: );
4989: foreach my $key (keys(%scantronfiles)) {
4990: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4991: .$scantronfiles{$key};
4992: }
4993: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4994: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4995: if (!$switchserver) {
4996: my $servadm = $r->dir_config('lonAdmEMail');
4997: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4998: if ($configuserok eq 'ok') {
4999: if ($author_ok eq 'ok') {
5000: my %legacyfile = (
5001: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5002: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5003: );
5004: my %md5chk;
5005: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5006: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5007: chomp($md5chk{$type});
1.46 raeburn 5008: }
5009: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5010: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5011: ($scantronurls{$type},my $error) =
1.46 raeburn 5012: &legacy_scantronformat($r,$dom,$confname,
5013: $type,$legacyfile{$type},
5014: $scantronurls{$type},
5015: $scantronfiles{$type});
1.60 raeburn 5016: if ($error ne '') {
5017: $error{$type} = $error;
5018: }
5019: }
5020: if (keys(%error) == 0) {
5021: $is_custom = 1;
5022: $confhash{'scantron'}{'scantronformat'} =
5023: $scantronurls{'custom'};
5024: my $putresult =
5025: &Apache::lonnet::put_dom('configuration',
5026: \%confhash,$dom);
5027: if ($putresult ne 'ok') {
5028: $error{'custom'} =
5029: '<span class="LC_error">'.
5030: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5031: }
1.46 raeburn 5032: }
5033: } else {
1.60 raeburn 5034: ($scantronurls{'default'},my $error) =
1.46 raeburn 5035: &legacy_scantronformat($r,$dom,$confname,
5036: 'default',$legacyfile{'default'},
5037: $scantronurls{'default'},
5038: $scantronfiles{'default'});
1.60 raeburn 5039: if ($error eq '') {
5040: $confhash{'scantron'}{'scantronformat'} = '';
5041: my $putresult =
5042: &Apache::lonnet::put_dom('configuration',
5043: \%confhash,$dom);
5044: if ($putresult ne 'ok') {
5045: $error{'default'} =
5046: '<span class="LC_error">'.
5047: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5048: }
5049: } else {
5050: $error{'default'} = $error;
5051: }
1.46 raeburn 5052: }
5053: }
5054: }
5055: } else {
1.95 www 5056: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5057: }
5058: }
5059: if (ref($settings) eq 'HASH') {
5060: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5061: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5062: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5063: $scantronurl = '';
5064: } else {
5065: $scantronurl = $settings->{'scantronformat'};
5066: }
5067: $is_custom = 1;
5068: } else {
5069: $scantronurl = $scantronurls{'default'};
5070: }
5071: } else {
1.60 raeburn 5072: if ($is_custom) {
5073: $scantronurl = $scantronurls{'custom'};
5074: } else {
5075: $scantronurl = $scantronurls{'default'};
5076: }
1.46 raeburn 5077: }
5078: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5079: $datatable .= '<tr'.$css_class.'>';
5080: if (!$is_custom) {
1.65 raeburn 5081: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5082: '<span class="LC_nobreak">';
1.46 raeburn 5083: if ($scantronurl) {
1.160.6.21 raeburn 5084: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5085: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5086: } else {
5087: $datatable = &mt('File unavailable for display');
5088: }
1.65 raeburn 5089: $datatable .= '</span></td>';
1.60 raeburn 5090: if (keys(%error) == 0) {
5091: $datatable .= '<td valign="bottom">';
5092: if (!$switchserver) {
5093: $datatable .= &mt('Upload:').'<br />';
5094: }
5095: } else {
5096: my $errorstr;
5097: foreach my $key (sort(keys(%error))) {
5098: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5099: }
5100: $datatable .= '<td>'.$errorstr;
5101: }
1.46 raeburn 5102: } else {
5103: if (keys(%error) > 0) {
5104: my $errorstr;
5105: foreach my $key (sort(keys(%error))) {
5106: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5107: }
1.60 raeburn 5108: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5109: } elsif ($scantronurl) {
1.160.6.26 raeburn 5110: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5111: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5112: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5113: $link.
5114: '<label><input type="checkbox" name="scantronformat_del"'.
5115: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5116: '<td><span class="LC_nobreak"> '.
5117: &mt('Replace:').'</span><br />';
1.46 raeburn 5118: }
5119: }
5120: if (keys(%error) == 0) {
5121: if ($switchserver) {
5122: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5123: } else {
1.65 raeburn 5124: $datatable .='<span class="LC_nobreak"> '.
5125: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5126: }
5127: }
5128: $datatable .= '</td></tr>';
5129: $$rowtotal ++;
5130: return $datatable;
5131: }
5132:
5133: sub legacy_scantronformat {
5134: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5135: my ($url,$error);
5136: my @statinfo = &Apache::lonnet::stat_file($newurl);
5137: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5138: (my $result,$url) =
5139: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5140: '','',$newfile);
5141: if ($result ne 'ok') {
1.130 raeburn 5142: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5143: }
5144: }
5145: return ($url,$error);
5146: }
1.43 raeburn 5147:
1.49 raeburn 5148: sub print_coursecategories {
1.57 raeburn 5149: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5150: my $datatable;
5151: if ($position eq 'top') {
1.160.6.42 raeburn 5152: my (%checked);
5153: my @catitems = ('unauth','auth');
5154: my @cattypes = ('std','domonly','codesrch','none');
5155: $checked{'unauth'} = 'std';
5156: $checked{'auth'} = 'std';
5157: if (ref($settings) eq 'HASH') {
5158: foreach my $type (@cattypes) {
5159: if ($type eq $settings->{'unauth'}) {
5160: $checked{'unauth'} = $type;
5161: }
5162: if ($type eq $settings->{'auth'}) {
5163: $checked{'auth'} = $type;
5164: }
5165: }
5166: }
5167: my %lt = &Apache::lonlocal::texthash (
5168: unauth => 'Catalog type for unauthenticated users',
5169: auth => 'Catalog type for authenticated users',
5170: none => 'No catalog',
5171: std => 'Standard catalog',
5172: domonly => 'Domain-only catalog',
5173: codesrch => "Code search form",
5174: );
5175: my $itemcount = 0;
5176: foreach my $item (@catitems) {
5177: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5178: $datatable .= '<tr '.$css_class.'>'.
5179: '<td>'.$lt{$item}.'</td>'.
5180: '<td class="LC_right_item"><span class="LC_nobreak">';
5181: foreach my $type (@cattypes) {
5182: my $ischecked;
5183: if ($checked{$item} eq $type) {
5184: $ischecked=' checked="checked"';
5185: }
5186: $datatable .= '<label>'.
5187: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5188: ' />'.$lt{$type}.'</label> ';
5189: }
5190: $datatable .= '</td></tr>';
5191: $itemcount ++;
5192: }
5193: $$rowtotal += $itemcount;
5194: } elsif ($position eq 'middle') {
1.57 raeburn 5195: my $toggle_cats_crs = ' ';
5196: my $toggle_cats_dom = ' checked="checked" ';
5197: my $can_cat_crs = ' ';
5198: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5199: my $toggle_catscomm_comm = ' ';
5200: my $toggle_catscomm_dom = ' checked="checked" ';
5201: my $can_catcomm_comm = ' ';
5202: my $can_catcomm_dom = ' checked="checked" ';
5203:
1.57 raeburn 5204: if (ref($settings) eq 'HASH') {
5205: if ($settings->{'togglecats'} eq 'crs') {
5206: $toggle_cats_crs = $toggle_cats_dom;
5207: $toggle_cats_dom = ' ';
5208: }
5209: if ($settings->{'categorize'} eq 'crs') {
5210: $can_cat_crs = $can_cat_dom;
5211: $can_cat_dom = ' ';
5212: }
1.120 raeburn 5213: if ($settings->{'togglecatscomm'} eq 'comm') {
5214: $toggle_catscomm_comm = $toggle_catscomm_dom;
5215: $toggle_catscomm_dom = ' ';
5216: }
5217: if ($settings->{'categorizecomm'} eq 'comm') {
5218: $can_catcomm_comm = $can_catcomm_dom;
5219: $can_catcomm_dom = ' ';
5220: }
1.57 raeburn 5221: }
5222: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5223: togglecats => 'Show/Hide a course in catalog',
5224: togglecatscomm => 'Show/Hide a community in catalog',
5225: categorize => 'Assign a category to a course',
5226: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5227: );
5228: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5229: dom => 'Set in Domain',
5230: crs => 'Set in Course',
5231: comm => 'Set in Community',
1.57 raeburn 5232: );
5233: $datatable = '<tr class="LC_odd_row">'.
5234: '<td>'.$title{'togglecats'}.'</td>'.
5235: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5236: '<input type="radio" name="togglecats"'.
5237: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5238: '<label><input type="radio" name="togglecats"'.
5239: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5240: '</tr><tr>'.
5241: '<td>'.$title{'categorize'}.'</td>'.
5242: '<td class="LC_right_item"><span class="LC_nobreak">'.
5243: '<label><input type="radio" name="categorize"'.
5244: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5245: '<label><input type="radio" name="categorize"'.
5246: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5247: '</tr><tr class="LC_odd_row">'.
5248: '<td>'.$title{'togglecatscomm'}.'</td>'.
5249: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5250: '<input type="radio" name="togglecatscomm"'.
5251: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5252: '<label><input type="radio" name="togglecatscomm"'.
5253: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5254: '</tr><tr>'.
5255: '<td>'.$title{'categorizecomm'}.'</td>'.
5256: '<td class="LC_right_item"><span class="LC_nobreak">'.
5257: '<label><input type="radio" name="categorizecomm"'.
5258: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5259: '<label><input type="radio" name="categorizecomm"'.
5260: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5261: '</tr>';
1.120 raeburn 5262: $$rowtotal += 4;
1.57 raeburn 5263: } else {
5264: my $css_class;
5265: my $itemcount = 1;
5266: my $cathash;
5267: if (ref($settings) eq 'HASH') {
5268: $cathash = $settings->{'cats'};
5269: }
5270: if (ref($cathash) eq 'HASH') {
5271: my (@cats,@trails,%allitems,%idx,@jsarray);
5272: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5273: \%allitems,\%idx,\@jsarray);
5274: my $maxdepth = scalar(@cats);
5275: my $colattrib = '';
5276: if ($maxdepth > 2) {
5277: $colattrib = ' colspan="2" ';
5278: }
5279: my @path;
5280: if (@cats > 0) {
5281: if (ref($cats[0]) eq 'ARRAY') {
5282: my $numtop = @{$cats[0]};
5283: my $maxnum = $numtop;
1.120 raeburn 5284: my %default_names = (
5285: instcode => &mt('Official courses'),
5286: communities => &mt('Communities'),
5287: );
5288:
5289: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5290: ($cathash->{'instcode::0'} eq '') ||
5291: (!grep(/^communities$/,@{$cats[0]})) ||
5292: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5293: $maxnum ++;
5294: }
5295: my $lastidx;
5296: for (my $i=0; $i<$numtop; $i++) {
5297: my $parent = $cats[0][$i];
5298: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5299: my $item = &escape($parent).'::0';
5300: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5301: $lastidx = $idx{$item};
5302: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5303: .'<select name="'.$item.'"'.$chgstr.'>';
5304: for (my $k=0; $k<=$maxnum; $k++) {
5305: my $vpos = $k+1;
5306: my $selstr;
5307: if ($k == $i) {
5308: $selstr = ' selected="selected" ';
5309: }
5310: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5311: }
1.160.6.29 raeburn 5312: $datatable .= '</select></span></td><td>';
1.120 raeburn 5313: if ($parent eq 'instcode' || $parent eq 'communities') {
5314: $datatable .= '<span class="LC_nobreak">'
5315: .$default_names{$parent}.'</span>';
5316: if ($parent eq 'instcode') {
5317: $datatable .= '<br /><span class="LC_nobreak">('
5318: .&mt('with institutional codes')
5319: .')</span></td><td'.$colattrib.'>';
5320: } else {
5321: $datatable .= '<table><tr><td>';
5322: }
5323: $datatable .= '<span class="LC_nobreak">'
5324: .'<label><input type="radio" name="'
5325: .$parent.'" value="1" checked="checked" />'
5326: .&mt('Display').'</label>';
5327: if ($parent eq 'instcode') {
5328: $datatable .= ' ';
5329: } else {
5330: $datatable .= '</span></td></tr><tr><td>'
5331: .'<span class="LC_nobreak">';
5332: }
5333: $datatable .= '<label><input type="radio" name="'
5334: .$parent.'" value="0" />'
5335: .&mt('Do not display').'</label></span>';
5336: if ($parent eq 'communities') {
5337: $datatable .= '</td></tr></table>';
5338: }
5339: $datatable .= '</td>';
1.57 raeburn 5340: } else {
5341: $datatable .= $parent
1.160.6.29 raeburn 5342: .' <span class="LC_nobreak"><label>'
5343: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5344: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5345: }
5346: my $depth = 1;
5347: push(@path,$parent);
5348: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5349: pop(@path);
5350: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5351: $itemcount ++;
5352: }
1.48 raeburn 5353: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5354: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5355: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5356: for (my $k=0; $k<=$maxnum; $k++) {
5357: my $vpos = $k+1;
5358: my $selstr;
1.57 raeburn 5359: if ($k == $numtop) {
1.48 raeburn 5360: $selstr = ' selected="selected" ';
5361: }
5362: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5363: }
1.59 bisitz 5364: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5365: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5366: .'</tr>'."\n";
1.48 raeburn 5367: $itemcount ++;
1.120 raeburn 5368: foreach my $default ('instcode','communities') {
5369: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5371: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5372: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5373: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5374: for (my $k=0; $k<=$maxnum; $k++) {
5375: my $vpos = $k+1;
5376: my $selstr;
5377: if ($k == $maxnum) {
5378: $selstr = ' selected="selected" ';
5379: }
5380: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5381: }
1.120 raeburn 5382: $datatable .= '</select></span></td>'.
5383: '<td><span class="LC_nobreak">'.
5384: $default_names{$default}.'</span>';
5385: if ($default eq 'instcode') {
5386: $datatable .= '<br /><span class="LC_nobreak">('
5387: .&mt('with institutional codes').')</span>';
5388: }
5389: $datatable .= '</td>'
5390: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5391: .&mt('Display').'</label> '
5392: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5393: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5394: }
5395: }
5396: }
1.57 raeburn 5397: } else {
5398: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5399: }
5400: } else {
1.160.6.42 raeburn 5401: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5402: .&initialize_categories($itemcount);
1.48 raeburn 5403: }
1.57 raeburn 5404: $$rowtotal += $itemcount;
1.48 raeburn 5405: }
5406: return $datatable;
5407: }
5408:
1.69 raeburn 5409: sub print_serverstatuses {
5410: my ($dom,$settings,$rowtotal) = @_;
5411: my $datatable;
5412: my @pages = &serverstatus_pages();
5413: my (%namedaccess,%machineaccess);
5414: foreach my $type (@pages) {
5415: $namedaccess{$type} = '';
5416: $machineaccess{$type}= '';
5417: }
5418: if (ref($settings) eq 'HASH') {
5419: foreach my $type (@pages) {
5420: if (exists($settings->{$type})) {
5421: if (ref($settings->{$type}) eq 'HASH') {
5422: foreach my $key (keys(%{$settings->{$type}})) {
5423: if ($key eq 'namedusers') {
5424: $namedaccess{$type} = $settings->{$type}->{$key};
5425: } elsif ($key eq 'machines') {
5426: $machineaccess{$type} = $settings->{$type}->{$key};
5427: }
5428: }
5429: }
5430: }
5431: }
5432: }
1.81 raeburn 5433: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5434: my $rownum = 0;
5435: my $css_class;
5436: foreach my $type (@pages) {
5437: $rownum ++;
5438: $css_class = $rownum%2?' class="LC_odd_row"':'';
5439: $datatable .= '<tr'.$css_class.'>'.
5440: '<td><span class="LC_nobreak">'.
5441: $titles->{$type}.'</span></td>'.
5442: '<td class="LC_left_item">'.
5443: '<input type="text" name="'.$type.'_namedusers" '.
5444: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5445: '<td class="LC_right_item">'.
5446: '<span class="LC_nobreak">'.
5447: '<input type="text" name="'.$type.'_machines" '.
5448: 'value="'.$machineaccess{$type}.'" size="10" />'.
5449: '</td></tr>'."\n";
5450: }
5451: $$rowtotal += $rownum;
5452: return $datatable;
5453: }
5454:
5455: sub serverstatus_pages {
5456: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5457: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5458: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 5459: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5460: }
5461:
1.160.6.40 raeburn 5462: sub defaults_javascript {
5463: my ($settings) = @_;
1.160.6.51 raeburn 5464: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 5465: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5466: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5467: if ($maxnum eq '') {
5468: $maxnum = 0;
5469: }
5470: $maxnum ++;
1.160.6.51 raeburn 5471: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 5472: return <<"ENDSCRIPT";
5473: <script type="text/javascript">
5474: // <![CDATA[
5475: function reorderTypes(form,caller) {
5476: var changedVal;
5477: $jstext
5478: var newpos = 'addinststatus_pos';
5479: var current = new Array;
5480: var maxh = $maxnum;
5481: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5482: var oldVal;
5483: if (caller == newpos) {
5484: changedVal = newitemVal;
5485: } else {
5486: var curritem = 'inststatus_pos_'+caller;
5487: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5488: current[newitemVal] = newpos;
5489: }
5490: for (var i=0; i<inststatuses.length; i++) {
5491: if (inststatuses[i] != caller) {
5492: var elementName = 'inststatus_pos_'+inststatuses[i];
5493: if (form.elements[elementName]) {
5494: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5495: current[currVal] = elementName;
5496: }
5497: }
5498: }
5499: for (var j=0; j<maxh; j++) {
5500: if (current[j] == undefined) {
5501: oldVal = j;
5502: }
5503: }
5504: if (oldVal < changedVal) {
5505: for (var k=oldVal+1; k<=changedVal ; k++) {
5506: var elementName = current[k];
5507: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5508: }
5509: } else {
5510: for (var k=changedVal; k<oldVal; k++) {
5511: var elementName = current[k];
5512: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5513: }
5514: }
5515: return;
5516: }
5517:
5518: // ]]>
5519: </script>
5520:
5521: ENDSCRIPT
5522: }
5523: }
5524:
1.49 raeburn 5525: sub coursecategories_javascript {
5526: my ($settings) = @_;
1.57 raeburn 5527: my ($output,$jstext,$cathash);
1.49 raeburn 5528: if (ref($settings) eq 'HASH') {
1.57 raeburn 5529: $cathash = $settings->{'cats'};
5530: }
5531: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5532: my (@cats,@jsarray,%idx);
1.57 raeburn 5533: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5534: if (@jsarray > 0) {
5535: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5536: for (my $i=0; $i<@jsarray; $i++) {
5537: if (ref($jsarray[$i]) eq 'ARRAY') {
5538: my $catstr = join('","',@{$jsarray[$i]});
5539: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5540: }
5541: }
5542: }
5543: } else {
5544: $jstext = ' var categories = Array(1);'."\n".
5545: ' categories[0] = Array("instcode_pos");'."\n";
5546: }
1.160.6.42 raeburn 5547: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5548: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 5549: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5550: &js_escape(\$instcode_reserved);
5551: &js_escape(\$communities_reserved);
5552: &js_escape(\$choose_again);
1.49 raeburn 5553: $output = <<"ENDSCRIPT";
5554: <script type="text/javascript">
1.109 raeburn 5555: // <![CDATA[
1.49 raeburn 5556: function reorderCats(form,parent,item,idx) {
5557: var changedVal;
5558: $jstext
5559: var newpos = 'addcategory_pos';
5560: if (parent == '') {
5561: var has_instcode = 0;
5562: var maxtop = categories[idx].length;
5563: for (var j=0; j<maxtop; j++) {
5564: if (categories[idx][j] == 'instcode::0') {
5565: has_instcode == 1;
5566: }
5567: }
5568: if (has_instcode == 0) {
5569: categories[idx][maxtop] = 'instcode_pos';
5570: }
5571: } else {
5572: newpos += '_'+parent;
5573: }
5574: var maxh = 1 + categories[idx].length;
5575: var current = new Array;
5576: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5577: if (item == newpos) {
5578: changedVal = newitemVal;
5579: } else {
5580: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5581: current[newitemVal] = newpos;
5582: }
5583: for (var i=0; i<categories[idx].length; i++) {
5584: var elementName = categories[idx][i];
5585: if (elementName != item) {
5586: if (form.elements[elementName]) {
5587: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5588: current[currVal] = elementName;
5589: }
5590: }
5591: }
5592: var oldVal;
5593: for (var j=0; j<maxh; j++) {
5594: if (current[j] == undefined) {
5595: oldVal = j;
5596: }
5597: }
5598: if (oldVal < changedVal) {
5599: for (var k=oldVal+1; k<=changedVal ; k++) {
5600: var elementName = current[k];
5601: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5602: }
5603: } else {
5604: for (var k=changedVal; k<oldVal; k++) {
5605: var elementName = current[k];
5606: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5607: }
5608: }
5609: return;
5610: }
1.120 raeburn 5611:
5612: function categoryCheck(form) {
5613: if (form.elements['addcategory_name'].value == 'instcode') {
5614: alert('$instcode_reserved\\n$choose_again');
5615: return false;
5616: }
5617: if (form.elements['addcategory_name'].value == 'communities') {
5618: alert('$communities_reserved\\n$choose_again');
5619: return false;
5620: }
5621: return true;
5622: }
5623:
1.109 raeburn 5624: // ]]>
1.49 raeburn 5625: </script>
5626:
5627: ENDSCRIPT
5628: return $output;
5629: }
5630:
1.48 raeburn 5631: sub initialize_categories {
5632: my ($itemcount) = @_;
1.120 raeburn 5633: my ($datatable,$css_class,$chgstr);
5634: my %default_names = (
5635: instcode => 'Official courses (with institutional codes)',
5636: communities => 'Communities',
5637: );
5638: my $select0 = ' selected="selected"';
5639: my $select1 = '';
5640: foreach my $default ('instcode','communities') {
5641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5642: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5643: if ($default eq 'communities') {
5644: $select1 = $select0;
5645: $select0 = '';
5646: }
5647: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5648: .'<select name="'.$default.'_pos">'
5649: .'<option value="0"'.$select0.'>1</option>'
5650: .'<option value="1"'.$select1.'>2</option>'
5651: .'<option value="2">3</option></select> '
5652: .$default_names{$default}
5653: .'</span></td><td><span class="LC_nobreak">'
5654: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5655: .&mt('Display').'</label> <label>'
5656: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5657: .'</label></span></td></tr>';
1.120 raeburn 5658: $itemcount ++;
5659: }
1.48 raeburn 5660: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5661: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5662: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5663: .'<select name="addcategory_pos"'.$chgstr.'>'
5664: .'<option value="0">1</option>'
5665: .'<option value="1">2</option>'
5666: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5667: .&mt('Add category').'</td><td>'.&mt('Name:')
5668: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5669: return $datatable;
5670: }
5671:
5672: sub build_category_rows {
1.49 raeburn 5673: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5674: my ($text,$name,$item,$chgstr);
1.48 raeburn 5675: if (ref($cats) eq 'ARRAY') {
5676: my $maxdepth = scalar(@{$cats});
5677: if (ref($cats->[$depth]) eq 'HASH') {
5678: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5679: my $numchildren = @{$cats->[$depth]{$parent}};
5680: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5681: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5682: my ($idxnum,$parent_name,$parent_item);
5683: my $higher = $depth - 1;
5684: if ($higher == 0) {
5685: $parent_name = &escape($parent).'::'.$higher;
5686: } else {
5687: if (ref($path) eq 'ARRAY') {
5688: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5689: }
5690: }
5691: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5692: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5693: if ($j < $numchildren) {
1.48 raeburn 5694: $name = $cats->[$depth]{$parent}[$j];
5695: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5696: $idxnum = $idx->{$item};
5697: } else {
5698: $name = $parent_name;
5699: $item = $parent_item;
1.48 raeburn 5700: }
1.49 raeburn 5701: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5702: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5703: for (my $i=0; $i<=$numchildren; $i++) {
5704: my $vpos = $i+1;
5705: my $selstr;
5706: if ($j == $i) {
5707: $selstr = ' selected="selected" ';
5708: }
5709: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5710: }
5711: $text .= '</select> ';
5712: if ($j < $numchildren) {
5713: my $deeper = $depth+1;
5714: $text .= $name.' '
5715: .'<label><input type="checkbox" name="deletecategory" value="'
5716: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5717: if(ref($path) eq 'ARRAY') {
5718: push(@{$path},$name);
1.49 raeburn 5719: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5720: pop(@{$path});
5721: }
5722: } else {
1.59 bisitz 5723: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5724: if ($j == $numchildren) {
5725: $text .= $name;
5726: } else {
5727: $text .= $item;
5728: }
5729: $text .= '" value="" />';
5730: }
5731: $text .= '</td></tr>';
5732: }
5733: $text .= '</table></td>';
5734: } else {
5735: my $higher = $depth-1;
5736: if ($higher == 0) {
5737: $name = &escape($parent).'::'.$higher;
5738: } else {
5739: if (ref($path) eq 'ARRAY') {
5740: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5741: }
5742: }
5743: my $colspan;
5744: if ($parent ne 'instcode') {
5745: $colspan = $maxdepth - $depth - 1;
5746: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5747: }
5748: }
5749: }
5750: }
5751: return $text;
5752: }
5753:
1.33 raeburn 5754: sub modifiable_userdata_row {
1.160.6.35 raeburn 5755: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5756: my ($role,$rolename,$statustype);
5757: $role = $item;
1.160.6.34 raeburn 5758: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5759: if ($item =~ /^emailusername_(.+)$/) {
5760: $statustype = $1;
5761: $role = 'emailusername';
5762: if (ref($usertypes) eq 'HASH') {
5763: if ($usertypes->{$statustype}) {
5764: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5765: } else {
5766: $rolename = &mt('Data provided by user');
5767: }
5768: }
1.160.6.34 raeburn 5769: }
5770: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5771: if (ref($usertypes) eq 'HASH') {
5772: $rolename = $usertypes->{$role};
5773: } else {
5774: $rolename = $role;
5775: }
1.33 raeburn 5776: } else {
1.63 raeburn 5777: if ($role eq 'cr') {
5778: $rolename = &mt('Custom role');
5779: } else {
5780: $rolename = &Apache::lonnet::plaintext($role);
5781: }
1.33 raeburn 5782: }
1.160.6.34 raeburn 5783: my (@fields,%fieldtitles);
5784: if (ref($fieldsref) eq 'ARRAY') {
5785: @fields = @{$fieldsref};
5786: } else {
5787: @fields = ('lastname','firstname','middlename','generation',
5788: 'permanentemail','id');
5789: }
5790: if ((ref($titlesref) eq 'HASH')) {
5791: %fieldtitles = %{$titlesref};
5792: } else {
5793: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5794: }
1.33 raeburn 5795: my $output;
5796: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5797: $output = '<tr '.$css_class.'>'.
5798: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5799: '<td class="LC_left_item" colspan="2"><table>';
5800: my $rem;
5801: my %checks;
5802: if (ref($settings) eq 'HASH') {
5803: if (ref($settings->{$context}) eq 'HASH') {
5804: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5805: my $hashref = $settings->{$context}->{$role};
5806: if ($role eq 'emailusername') {
5807: if ($statustype) {
5808: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5809: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5810: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5811: foreach my $field (@fields) {
5812: if ($hashref->{$field}) {
5813: $checks{$field} = $hashref->{$field};
5814: }
5815: }
5816: }
5817: }
5818: }
5819: } else {
5820: if (ref($hashref) eq 'HASH') {
5821: foreach my $field (@fields) {
5822: if ($hashref->{$field}) {
5823: $checks{$field} = ' checked="checked" ';
5824: }
5825: }
1.33 raeburn 5826: }
5827: }
5828: }
5829: }
5830: }
1.160.6.39 raeburn 5831:
1.33 raeburn 5832: for (my $i=0; $i<@fields; $i++) {
5833: my $rem = $i%($numinrow);
5834: if ($rem == 0) {
5835: if ($i > 0) {
5836: $output .= '</tr>';
5837: }
5838: $output .= '<tr>';
5839: }
5840: my $check = ' ';
1.160.6.35 raeburn 5841: unless ($role eq 'emailusername') {
5842: if (exists($checks{$fields[$i]})) {
5843: $check = $checks{$fields[$i]}
5844: } else {
5845: if ($role eq 'st') {
5846: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5847: $check = ' checked="checked" ';
1.160.6.35 raeburn 5848: }
1.33 raeburn 5849: }
5850: }
5851: }
5852: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5853: '<span class="LC_nobreak">';
5854: if ($role eq 'emailusername') {
5855: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5856: $checks{$fields[$i]} = 'omit';
5857: }
5858: foreach my $option ('required','optional','omit') {
5859: my $checked='';
5860: if ($checks{$fields[$i]} eq $option) {
5861: $checked='checked="checked" ';
5862: }
5863: $output .= '<label>'.
5864: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5865: &mt($option).'</label>'.(' ' x2);
5866: }
5867: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5868: } else {
5869: $output .= '<label>'.
5870: '<input type="checkbox" name="canmodify_'.$role.'" '.
5871: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5872: '</label>';
5873: }
5874: $output .= '</span></td>';
1.33 raeburn 5875: $rem = @fields%($numinrow);
5876: }
5877: my $colsleft = $numinrow - $rem;
5878: if ($colsleft > 1 ) {
5879: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5880: ' </td>';
5881: } elsif ($colsleft == 1) {
5882: $output .= '<td class="LC_left_item"> </td>';
5883: }
5884: $output .= '</tr></table></td></tr>';
5885: return $output;
5886: }
1.28 raeburn 5887:
1.93 raeburn 5888: sub insttypes_row {
1.160.6.34 raeburn 5889: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5890: my %lt = &Apache::lonlocal::texthash (
5891: cansearch => 'Users allowed to search',
5892: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5893: lockablenames => 'User preference to lock name',
1.93 raeburn 5894: );
5895: my $showdom;
5896: if ($context eq 'cansearch') {
5897: $showdom = ' ('.$dom.')';
5898: }
1.160.6.5 raeburn 5899: my $class = 'LC_left_item';
5900: if ($context eq 'statustocreate') {
5901: $class = 'LC_right_item';
5902: }
1.160.6.34 raeburn 5903: my $css_class = ' class="LC_odd_row"';
5904: if ($rownum ne '') {
5905: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5906: }
5907: my $output = '<tr'.$css_class.'>'.
5908: '<td>'.$lt{$context}.$showdom.
5909: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5910: my $rem;
5911: if (ref($types) eq 'ARRAY') {
5912: for (my $i=0; $i<@{$types}; $i++) {
5913: if (defined($usertypes->{$types->[$i]})) {
5914: my $rem = $i%($numinrow);
5915: if ($rem == 0) {
5916: if ($i > 0) {
5917: $output .= '</tr>';
5918: }
5919: $output .= '<tr>';
1.23 raeburn 5920: }
1.26 raeburn 5921: my $check = ' ';
1.99 raeburn 5922: if (ref($settings) eq 'HASH') {
5923: if (ref($settings->{$context}) eq 'ARRAY') {
5924: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5925: $check = ' checked="checked" ';
5926: }
5927: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5928: $check = ' checked="checked" ';
5929: }
1.23 raeburn 5930: }
1.26 raeburn 5931: $output .= '<td class="LC_left_item">'.
5932: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5933: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5934: 'value="'.$types->[$i].'"'.$check.'/>'.
5935: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5936: }
5937: }
1.26 raeburn 5938: $rem = @{$types}%($numinrow);
1.23 raeburn 5939: }
5940: my $colsleft = $numinrow - $rem;
1.131 raeburn 5941: if (($rem == 0) && (@{$types} > 0)) {
5942: $output .= '<tr>';
5943: }
1.23 raeburn 5944: if ($colsleft > 1) {
1.25 raeburn 5945: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5946: } else {
1.25 raeburn 5947: $output .= '<td class="LC_left_item">';
1.23 raeburn 5948: }
5949: my $defcheck = ' ';
1.99 raeburn 5950: if (ref($settings) eq 'HASH') {
5951: if (ref($settings->{$context}) eq 'ARRAY') {
5952: if (grep(/^default$/,@{$settings->{$context}})) {
5953: $defcheck = ' checked="checked" ';
5954: }
5955: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5956: $defcheck = ' checked="checked" ';
5957: }
1.23 raeburn 5958: }
1.25 raeburn 5959: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5960: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5961: 'value="default"'.$defcheck.'/>'.
5962: $othertitle.'</label></span></td>'.
5963: '</tr></table></td></tr>';
5964: return $output;
1.23 raeburn 5965: }
5966:
5967: sub sorted_searchtitles {
5968: my %searchtitles = &Apache::lonlocal::texthash(
5969: 'uname' => 'username',
5970: 'lastname' => 'last name',
5971: 'lastfirst' => 'last name, first name',
5972: );
5973: my @titleorder = ('uname','lastname','lastfirst');
5974: return (\%searchtitles,\@titleorder);
5975: }
5976:
1.25 raeburn 5977: sub sorted_searchtypes {
5978: my %srchtypes_desc = (
5979: exact => 'is exact match',
5980: contains => 'contains ..',
5981: begins => 'begins with ..',
5982: );
5983: my @srchtypeorder = ('exact','begins','contains');
5984: return (\%srchtypes_desc,\@srchtypeorder);
5985: }
5986:
1.3 raeburn 5987: sub usertype_update_row {
5988: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5989: my $datatable;
5990: my $numinrow = 4;
5991: foreach my $type (@{$types}) {
5992: if (defined($usertypes->{$type})) {
5993: $$rownums ++;
5994: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5995: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5996: '</td><td class="LC_left_item"><table>';
5997: for (my $i=0; $i<@{$fields}; $i++) {
5998: my $rem = $i%($numinrow);
5999: if ($rem == 0) {
6000: if ($i > 0) {
6001: $datatable .= '</tr>';
6002: }
6003: $datatable .= '<tr>';
6004: }
6005: my $check = ' ';
1.39 raeburn 6006: if (ref($settings) eq 'HASH') {
6007: if (ref($settings->{'fields'}) eq 'HASH') {
6008: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6009: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6010: $check = ' checked="checked" ';
6011: }
1.3 raeburn 6012: }
6013: }
6014: }
6015:
6016: if ($i == @{$fields}-1) {
6017: my $colsleft = $numinrow - $rem;
6018: if ($colsleft > 1) {
6019: $datatable .= '<td colspan="'.$colsleft.'">';
6020: } else {
6021: $datatable .= '<td>';
6022: }
6023: } else {
6024: $datatable .= '<td>';
6025: }
1.8 raeburn 6026: $datatable .= '<span class="LC_nobreak"><label>'.
6027: '<input type="checkbox" name="updateable_'.$type.
6028: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6029: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6030: }
6031: $datatable .= '</tr></table></td></tr>';
6032: }
6033: }
6034: return $datatable;
1.1 raeburn 6035: }
6036:
6037: sub modify_login {
1.160.6.24 raeburn 6038: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6039: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6040: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6041: %title = ( coursecatalog => 'Display course catalog',
6042: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6043: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6044: newuser => 'Link for visitors to create a user account',
6045: loginheader => 'Log-in box header');
6046: @offon = ('off','on');
1.112 raeburn 6047: if (ref($domconfig{login}) eq 'HASH') {
6048: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6049: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6050: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6051: }
6052: }
6053: }
1.9 raeburn 6054: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6055: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6056: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6057: foreach my $item (@toggles) {
6058: $loginhash{login}{$item} = $env{'form.'.$item};
6059: }
1.41 raeburn 6060: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6061: if (ref($colchanges{'login'}) eq 'HASH') {
6062: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6063: \%loginhash);
6064: }
1.110 raeburn 6065:
1.149 raeburn 6066: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6067: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6068: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6069: if (keys(%servers) > 1) {
6070: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6071: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6072: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6073: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6074: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6075: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6076: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6077: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6078: $changes{'loginvia'}{$lonhost} = 1;
6079: } else {
6080: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6081: $changes{'loginvia'}{$lonhost} = 1;
6082: }
6083: } else {
6084: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6085: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6086: $changes{'loginvia'}{$lonhost} = 1;
6087: }
6088: }
6089: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6090: foreach my $item (@loginvia_attribs) {
6091: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6092: }
6093: } else {
6094: foreach my $item (@loginvia_attribs) {
6095: my $new = $env{'form.'.$lonhost.'_'.$item};
6096: if (($item eq 'serverpath') && ($new eq 'custom')) {
6097: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6098: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6099: $new = '/';
6100: }
6101: }
6102: if (($item eq 'custompath') &&
6103: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6104: $new = '';
6105: }
6106: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6107: $changes{'loginvia'}{$lonhost} = 1;
6108: }
6109: if ($item eq 'exempt') {
1.160.6.56 raeburn 6110: $new = &check_exempt_addresses($new);
1.128 raeburn 6111: }
6112: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6113: }
6114: }
1.112 raeburn 6115: } else {
1.128 raeburn 6116: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6117: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6118: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6119: foreach my $item (@loginvia_attribs) {
6120: my $new = $env{'form.'.$lonhost.'_'.$item};
6121: if (($item eq 'serverpath') && ($new eq 'custom')) {
6122: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6123: $new = '/';
6124: }
6125: }
6126: if (($item eq 'custompath') &&
6127: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6128: $new = '';
6129: }
6130: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6131: }
1.110 raeburn 6132: }
6133: }
6134: }
6135: }
1.119 raeburn 6136:
1.160.6.5 raeburn 6137: my $servadm = $r->dir_config('lonAdmEMail');
6138: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6139: if (ref($domconfig{'login'}) eq 'HASH') {
6140: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6141: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6142: if ($lang eq 'nolang') {
6143: push(@currlangs,$lang);
6144: } elsif (defined($langchoices{$lang})) {
6145: push(@currlangs,$lang);
6146: } else {
6147: next;
6148: }
6149: }
6150: }
6151: }
6152: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6153: if (@currlangs > 0) {
6154: foreach my $lang (@currlangs) {
6155: if (grep(/^\Q$lang\E$/,@delurls)) {
6156: $changes{'helpurl'}{$lang} = 1;
6157: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6158: $changes{'helpurl'}{$lang} = 1;
6159: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6160: push(@newlangs,$lang);
6161: } else {
6162: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6163: }
6164: }
6165: }
6166: unless (grep(/^nolang$/,@currlangs)) {
6167: if ($env{'form.loginhelpurl_nolang.filename'}) {
6168: $changes{'helpurl'}{'nolang'} = 1;
6169: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6170: push(@newlangs,'nolang');
6171: }
6172: }
6173: if ($env{'form.loginhelpurl_add_lang'}) {
6174: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6175: ($env{'form.loginhelpurl_add_file.filename'})) {
6176: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6177: $addedfile = $env{'form.loginhelpurl_add_lang'};
6178: }
6179: }
6180: if ((@newlangs > 0) || ($addedfile)) {
6181: my $error;
6182: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6183: if ($configuserok eq 'ok') {
6184: if ($switchserver) {
6185: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6186: } elsif ($author_ok eq 'ok') {
6187: my @allnew = @newlangs;
6188: if ($addedfile ne '') {
6189: push(@allnew,$addedfile);
6190: }
6191: foreach my $lang (@allnew) {
6192: my $formelem = 'loginhelpurl_'.$lang;
6193: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6194: $formelem = 'loginhelpurl_add_file';
6195: }
6196: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6197: "help/$lang",'','',$newfile{$lang});
6198: if ($result eq 'ok') {
6199: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6200: $changes{'helpurl'}{$lang} = 1;
6201: } else {
6202: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6203: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6204: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6205: (!grep(/^\Q$lang\E$/,@delurls))) {
6206:
6207: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6208: }
6209: }
6210: }
6211: } else {
6212: $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);
6213: }
6214: } else {
6215: $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);
6216: }
6217: if ($error) {
6218: &Apache::lonnet::logthis($error);
6219: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6220: }
6221: }
1.160.6.56 raeburn 6222:
6223: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6224: if (ref($domconfig{'login'}) eq 'HASH') {
6225: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6226: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6227: if ($domservers{$lonhost}) {
6228: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6229: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.67 raeburn 6230: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'}
1.160.6.56 raeburn 6231: }
6232: }
6233: }
6234: }
6235: }
6236: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6237: foreach my $lonhost (sort(keys(%domservers))) {
6238: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6239: $changes{'headtag'}{$lonhost} = 1;
6240: } else {
6241: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6242: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6243: }
6244: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6245: push(@newhosts,$lonhost);
6246: } elsif ($currheadtagurls{$lonhost}) {
6247: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6248: if ($currexempt{$lonhost}) {
6249: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6250: $changes{'headtag'}{$lonhost} = 1;
6251: }
6252: } elsif ($possexempt{$lonhost}) {
6253: $changes{'headtag'}{$lonhost} = 1;
6254: }
6255: if ($possexempt{$lonhost}) {
6256: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6257: }
6258: }
6259: }
6260: }
6261: if (@newhosts) {
6262: my $error;
6263: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6264: if ($configuserok eq 'ok') {
6265: if ($switchserver) {
6266: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6267: } elsif ($author_ok eq 'ok') {
6268: foreach my $lonhost (@newhosts) {
6269: my $formelem = 'loginheadtag_'.$lonhost;
6270: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6271: "login/headtag/$lonhost",'','',
6272: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6273: if ($result eq 'ok') {
6274: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6275: $changes{'headtag'}{$lonhost} = 1;
6276: if ($possexempt{$lonhost}) {
6277: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6278: }
6279: } else {
6280: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6281: $newheadtagurls{$lonhost},$result);
6282: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6283: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6284: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6285: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6286: }
6287: }
6288: }
6289: } else {
6290: $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
6291: }
6292: } else {
6293: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
6294: }
6295: if ($error) {
6296: &Apache::lonnet::logthis($error);
6297: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6298: }
6299: }
6300:
1.160.6.5 raeburn 6301: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
6302:
6303: my $defaulthelpfile = '/adm/loginproblems.html';
6304: my $defaulttext = &mt('Default in use');
6305:
1.1 raeburn 6306: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6307: $dom);
6308: if ($putresult eq 'ok') {
1.160.6.14 raeburn 6309: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6310: my %defaultchecked = (
6311: 'coursecatalog' => 'on',
1.160.6.14 raeburn 6312: 'helpdesk' => 'on',
1.42 raeburn 6313: 'adminmail' => 'off',
1.43 raeburn 6314: 'newuser' => 'off',
1.42 raeburn 6315: );
1.55 raeburn 6316: if (ref($domconfig{'login'}) eq 'HASH') {
6317: foreach my $item (@toggles) {
6318: if ($defaultchecked{$item} eq 'on') {
6319: if (($domconfig{'login'}{$item} eq '0') &&
6320: ($env{'form.'.$item} eq '1')) {
6321: $changes{$item} = 1;
6322: } elsif (($domconfig{'login'}{$item} eq '' ||
6323: $domconfig{'login'}{$item} eq '1') &&
6324: ($env{'form.'.$item} eq '0')) {
6325: $changes{$item} = 1;
6326: }
6327: } elsif ($defaultchecked{$item} eq 'off') {
6328: if (($domconfig{'login'}{$item} eq '1') &&
6329: ($env{'form.'.$item} eq '0')) {
6330: $changes{$item} = 1;
6331: } elsif (($domconfig{'login'}{$item} eq '' ||
6332: $domconfig{'login'}{$item} eq '0') &&
6333: ($env{'form.'.$item} eq '1')) {
6334: $changes{$item} = 1;
6335: }
1.42 raeburn 6336: }
6337: }
1.41 raeburn 6338: }
1.6 raeburn 6339: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6340: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6341: if (ref($lastactref) eq 'HASH') {
6342: $lastactref->{'domainconfig'} = 1;
6343: }
1.1 raeburn 6344: $resulttext = &mt('Changes made:').'<ul>';
6345: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6346: if ($item eq 'loginvia') {
1.112 raeburn 6347: if (ref($changes{$item}) eq 'HASH') {
6348: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6349: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6350: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6351: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6352: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6353: $protocol = 'http' if ($protocol ne 'https');
6354: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6355:
6356: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6357: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6358: } else {
6359: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6360: }
6361: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6362: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6363: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6364: }
6365: $resulttext .= '</li>';
6366: } else {
6367: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6368: }
1.112 raeburn 6369: } else {
1.128 raeburn 6370: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6371: }
6372: }
1.128 raeburn 6373: $resulttext .= '</ul></li>';
1.112 raeburn 6374: }
1.160.6.5 raeburn 6375: } elsif ($item eq 'helpurl') {
6376: if (ref($changes{$item}) eq 'HASH') {
6377: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6378: if (grep(/^\Q$lang\E$/,@delurls)) {
6379: my ($chg,$link);
6380: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6381: if ($lang eq 'nolang') {
6382: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6383: } else {
6384: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6385: }
6386: $resulttext .= '<li>'.$chg.'</li>';
6387: } else {
6388: my $chg;
6389: if ($lang eq 'nolang') {
6390: $chg = &mt('custom log-in help file for no preferred language');
6391: } else {
6392: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6393: }
6394: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6395: $loginhash{'login'}{'helpurl'}{$lang}.
6396: '?inhibitmenu=yes',$chg,600,500).
6397: '</li>';
6398: }
6399: }
6400: }
1.160.6.56 raeburn 6401: } elsif ($item eq 'headtag') {
6402: if (ref($changes{$item}) eq 'HASH') {
6403: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6404: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6405: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6406: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6407: $resulttext .= '<li><a href="'.
6408: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6409: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6410: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6411: if ($possexempt{$lonhost}) {
6412: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6413: } else {
6414: $resulttext .= &mt('included for any client IP');
6415: }
6416: $resulttext .= '</li>';
6417: }
6418: }
6419: }
1.160.6.5 raeburn 6420: } elsif ($item eq 'captcha') {
6421: if (ref($loginhash{'login'}) eq 'HASH') {
6422: my $chgtxt;
6423: if ($loginhash{'login'}{$item} eq 'notused') {
6424: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6425: } else {
6426: my %captchas = &captcha_phrases();
6427: if ($captchas{$loginhash{'login'}{$item}}) {
6428: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6429: } else {
6430: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6431: }
6432: }
6433: $resulttext .= '<li>'.$chgtxt.'</li>';
6434: }
6435: } elsif ($item eq 'recaptchakeys') {
6436: if (ref($loginhash{'login'}) eq 'HASH') {
6437: my ($privkey,$pubkey);
6438: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6439: $pubkey = $loginhash{'login'}{$item}{'public'};
6440: $privkey = $loginhash{'login'}{$item}{'private'};
6441: }
6442: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6443: if (!$pubkey) {
6444: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6445: } else {
6446: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6447: }
6448: if (!$privkey) {
6449: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6450: } else {
1.160.6.53 raeburn 6451: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 6452: }
6453: $chgtxt .= '</ul>';
6454: $resulttext .= '<li>'.$chgtxt.'</li>';
6455: }
1.160.6.69 raeburn 6456: } elsif ($item eq 'recaptchaversion') {
6457: if (ref($loginhash{'login'}) eq 'HASH') {
6458: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
6459: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
6460: '</li>';
6461: }
6462: }
1.41 raeburn 6463: } else {
6464: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6465: }
1.1 raeburn 6466: }
1.6 raeburn 6467: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6468: } else {
6469: $resulttext = &mt('No changes made to log-in page settings');
6470: }
6471: } else {
1.11 albertel 6472: $resulttext = '<span class="LC_error">'.
6473: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6474: }
1.6 raeburn 6475: if ($errors) {
1.9 raeburn 6476: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6477: $errors.'</ul>';
6478: }
6479: return $resulttext;
6480: }
6481:
1.160.6.56 raeburn 6482: sub check_exempt_addresses {
6483: my ($iplist) = @_;
6484: $iplist =~ s/^\s+//;
6485: $iplist =~ s/\s+$//;
6486: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6487: my (@okips,$new);
6488: foreach my $ip (@poss_ips) {
6489: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6490: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6491: push(@okips,$ip);
6492: }
6493: }
6494: }
6495: if (@okips > 0) {
6496: $new = join(',',@okips);
6497: } else {
6498: $new = '';
6499: }
6500: return $new;
6501: }
6502:
1.6 raeburn 6503: sub color_font_choices {
6504: my %choices =
6505: &Apache::lonlocal::texthash (
6506: img => "Header",
6507: bgs => "Background colors",
6508: links => "Link colors",
1.55 raeburn 6509: images => "Images",
1.6 raeburn 6510: font => "Font color",
1.160.6.22 raeburn 6511: fontmenu => "Font menu",
1.76 raeburn 6512: pgbg => "Page",
1.6 raeburn 6513: tabbg => "Header",
6514: sidebg => "Border",
6515: link => "Link",
6516: alink => "Active link",
6517: vlink => "Visited link",
6518: );
6519: return %choices;
6520: }
6521:
6522: sub modify_rolecolors {
1.160.6.24 raeburn 6523: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6524: my ($resulttext,%rolehash);
6525: $rolehash{'rolecolors'} = {};
1.55 raeburn 6526: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6527: if ($domconfig{'rolecolors'} eq '') {
6528: $domconfig{'rolecolors'} = {};
6529: }
6530: }
1.9 raeburn 6531: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6532: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6533: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6534: $dom);
6535: if ($putresult eq 'ok') {
6536: if (keys(%changes) > 0) {
1.41 raeburn 6537: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6538: if (ref($lastactref) eq 'HASH') {
6539: $lastactref->{'domainconfig'} = 1;
6540: }
1.6 raeburn 6541: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6542: $rolehash{'rolecolors'});
6543: } else {
6544: $resulttext = &mt('No changes made to default color schemes');
6545: }
6546: } else {
1.11 albertel 6547: $resulttext = '<span class="LC_error">'.
6548: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6549: }
6550: if ($errors) {
6551: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6552: $errors.'</ul>';
6553: }
6554: return $resulttext;
6555: }
6556:
6557: sub modify_colors {
1.9 raeburn 6558: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6559: my (%changes,%choices);
1.51 raeburn 6560: my @bgs;
1.6 raeburn 6561: my @links = ('link','alink','vlink');
1.41 raeburn 6562: my @logintext;
1.6 raeburn 6563: my @images;
6564: my $servadm = $r->dir_config('lonAdmEMail');
6565: my $errors;
1.160.6.22 raeburn 6566: my %defaults;
1.6 raeburn 6567: foreach my $role (@{$roles}) {
6568: if ($role eq 'login') {
1.12 raeburn 6569: %choices = &login_choices();
1.41 raeburn 6570: @logintext = ('textcol','bgcol');
1.12 raeburn 6571: } else {
6572: %choices = &color_font_choices();
6573: }
6574: if ($role eq 'login') {
1.41 raeburn 6575: @images = ('img','logo','domlogo','login');
1.51 raeburn 6576: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6577: } else {
6578: @images = ('img');
1.160.6.22 raeburn 6579: @bgs = ('pgbg','tabbg','sidebg');
6580: }
6581: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6582: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6583: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6584: }
6585: if ($role eq 'login') {
6586: foreach my $item (@logintext) {
1.160.6.39 raeburn 6587: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6588: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6589: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6590: }
6591: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6592: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6593: }
6594: }
6595: } else {
1.160.6.39 raeburn 6596: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6597: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6598: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6599: }
6600: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6601: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6602: }
1.6 raeburn 6603: }
1.160.6.22 raeburn 6604: foreach my $item (@bgs) {
1.160.6.39 raeburn 6605: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6606: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6607: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6608: }
6609: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6610: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6611: }
6612: }
6613: foreach my $item (@links) {
1.160.6.39 raeburn 6614: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6615: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6616: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6617: }
6618: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6619: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6620: }
1.6 raeburn 6621: }
1.46 raeburn 6622: my ($configuserok,$author_ok,$switchserver) =
6623: &config_check($dom,$confname,$servadm);
1.9 raeburn 6624: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6625: if (ref($domconfig->{$role}) ne 'HASH') {
6626: $domconfig->{$role} = {};
6627: }
1.8 raeburn 6628: foreach my $img (@images) {
1.70 raeburn 6629: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6630: if (defined($env{'form.login_showlogo_'.$img})) {
6631: $confhash->{$role}{'showlogo'}{$img} = 1;
6632: } else {
6633: $confhash->{$role}{'showlogo'}{$img} = 0;
6634: }
6635: }
1.18 albertel 6636: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6637: && !defined($domconfig->{$role}{$img})
6638: && !$env{'form.'.$role.'_del_'.$img}
6639: && $env{'form.'.$role.'_import_'.$img}) {
6640: # import the old configured image from the .tab setting
6641: # if they haven't provided a new one
6642: $domconfig->{$role}{$img} =
6643: $env{'form.'.$role.'_import_'.$img};
6644: }
1.6 raeburn 6645: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6646: my $error;
1.6 raeburn 6647: if ($configuserok eq 'ok') {
1.9 raeburn 6648: if ($switchserver) {
1.12 raeburn 6649: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6650: } else {
6651: if ($author_ok eq 'ok') {
6652: my ($result,$logourl) =
6653: &publishlogo($r,'upload',$role.'_'.$img,
6654: $dom,$confname,$img,$width,$height);
6655: if ($result eq 'ok') {
6656: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6657: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6658: } else {
1.12 raeburn 6659: $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 6660: }
6661: } else {
1.46 raeburn 6662: $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 6663: }
6664: }
6665: } else {
1.46 raeburn 6666: $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 6667: }
6668: if ($error) {
1.8 raeburn 6669: &Apache::lonnet::logthis($error);
1.11 albertel 6670: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6671: }
6672: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6673: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6674: my $error;
6675: if ($configuserok eq 'ok') {
6676: # is confname an author?
6677: if ($switchserver eq '') {
6678: if ($author_ok eq 'ok') {
6679: my ($result,$logourl) =
6680: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6681: $dom,$confname,$img,$width,$height);
6682: if ($result eq 'ok') {
6683: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6684: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6685: }
6686: }
6687: }
6688: }
1.6 raeburn 6689: }
6690: }
6691: }
6692: if (ref($domconfig) eq 'HASH') {
6693: if (ref($domconfig->{$role}) eq 'HASH') {
6694: foreach my $img (@images) {
6695: if ($domconfig->{$role}{$img} ne '') {
6696: if ($env{'form.'.$role.'_del_'.$img}) {
6697: $confhash->{$role}{$img} = '';
1.12 raeburn 6698: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6699: } else {
1.9 raeburn 6700: if ($confhash->{$role}{$img} eq '') {
6701: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6702: }
1.6 raeburn 6703: }
6704: } else {
6705: if ($env{'form.'.$role.'_del_'.$img}) {
6706: $confhash->{$role}{$img} = '';
1.12 raeburn 6707: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6708: }
6709: }
1.70 raeburn 6710: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6711: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6712: if ($confhash->{$role}{'showlogo'}{$img} ne
6713: $domconfig->{$role}{'showlogo'}{$img}) {
6714: $changes{$role}{'showlogo'}{$img} = 1;
6715: }
6716: } else {
6717: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6718: $changes{$role}{'showlogo'}{$img} = 1;
6719: }
6720: }
6721: }
6722: }
1.6 raeburn 6723: if ($domconfig->{$role}{'font'} ne '') {
6724: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6725: $changes{$role}{'font'} = 1;
6726: }
6727: } else {
6728: if ($confhash->{$role}{'font'}) {
6729: $changes{$role}{'font'} = 1;
6730: }
6731: }
1.107 raeburn 6732: if ($role ne 'login') {
6733: if ($domconfig->{$role}{'fontmenu'} ne '') {
6734: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6735: $changes{$role}{'fontmenu'} = 1;
6736: }
6737: } else {
6738: if ($confhash->{$role}{'fontmenu'}) {
6739: $changes{$role}{'fontmenu'} = 1;
6740: }
1.97 tempelho 6741: }
6742: }
1.6 raeburn 6743: foreach my $item (@bgs) {
6744: if ($domconfig->{$role}{$item} ne '') {
6745: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6746: $changes{$role}{'bgs'}{$item} = 1;
6747: }
6748: } else {
6749: if ($confhash->{$role}{$item}) {
6750: $changes{$role}{'bgs'}{$item} = 1;
6751: }
6752: }
6753: }
6754: foreach my $item (@links) {
6755: if ($domconfig->{$role}{$item} ne '') {
6756: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6757: $changes{$role}{'links'}{$item} = 1;
6758: }
6759: } else {
6760: if ($confhash->{$role}{$item}) {
6761: $changes{$role}{'links'}{$item} = 1;
6762: }
6763: }
6764: }
1.41 raeburn 6765: foreach my $item (@logintext) {
6766: if ($domconfig->{$role}{$item} ne '') {
6767: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6768: $changes{$role}{'logintext'}{$item} = 1;
6769: }
6770: } else {
6771: if ($confhash->{$role}{$item}) {
6772: $changes{$role}{'logintext'}{$item} = 1;
6773: }
6774: }
6775: }
1.6 raeburn 6776: } else {
6777: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6778: \@logintext,$confhash,\%changes);
1.6 raeburn 6779: }
6780: } else {
6781: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6782: \@logintext,$confhash,\%changes);
1.6 raeburn 6783: }
6784: }
6785: return ($errors,%changes);
6786: }
6787:
1.46 raeburn 6788: sub config_check {
6789: my ($dom,$confname,$servadm) = @_;
6790: my ($configuserok,$author_ok,$switchserver,%currroles);
6791: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6792: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6793: $confname,$servadm);
6794: if ($configuserok eq 'ok') {
6795: $switchserver = &check_switchserver($dom,$confname);
6796: if ($switchserver eq '') {
6797: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6798: }
6799: }
6800: return ($configuserok,$author_ok,$switchserver);
6801: }
6802:
1.6 raeburn 6803: sub default_change_checker {
1.41 raeburn 6804: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6805: foreach my $item (@{$links}) {
6806: if ($confhash->{$role}{$item}) {
6807: $changes->{$role}{'links'}{$item} = 1;
6808: }
6809: }
6810: foreach my $item (@{$bgs}) {
6811: if ($confhash->{$role}{$item}) {
6812: $changes->{$role}{'bgs'}{$item} = 1;
6813: }
6814: }
1.41 raeburn 6815: foreach my $item (@{$logintext}) {
6816: if ($confhash->{$role}{$item}) {
6817: $changes->{$role}{'logintext'}{$item} = 1;
6818: }
6819: }
1.6 raeburn 6820: foreach my $img (@{$images}) {
6821: if ($env{'form.'.$role.'_del_'.$img}) {
6822: $confhash->{$role}{$img} = '';
1.12 raeburn 6823: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6824: }
1.70 raeburn 6825: if ($role eq 'login') {
6826: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6827: $changes->{$role}{'showlogo'}{$img} = 1;
6828: }
6829: }
1.6 raeburn 6830: }
6831: if ($confhash->{$role}{'font'}) {
6832: $changes->{$role}{'font'} = 1;
6833: }
1.48 raeburn 6834: }
1.6 raeburn 6835:
6836: sub display_colorchgs {
6837: my ($dom,$changes,$roles,$confhash) = @_;
6838: my (%choices,$resulttext);
6839: if (!grep(/^login$/,@{$roles})) {
6840: $resulttext = &mt('Changes made:').'<br />';
6841: }
6842: foreach my $role (@{$roles}) {
6843: if ($role eq 'login') {
6844: %choices = &login_choices();
6845: } else {
6846: %choices = &color_font_choices();
6847: }
6848: if (ref($changes->{$role}) eq 'HASH') {
6849: if ($role ne 'login') {
6850: $resulttext .= '<h4>'.&mt($role).'</h4>';
6851: }
6852: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6853: if ($role ne 'login') {
6854: $resulttext .= '<ul>';
6855: }
6856: if (ref($changes->{$role}{$key}) eq 'HASH') {
6857: if ($role ne 'login') {
6858: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6859: }
6860: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6861: if (($role eq 'login') && ($key eq 'showlogo')) {
6862: if ($confhash->{$role}{$key}{$item}) {
6863: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6864: } else {
6865: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6866: }
6867: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6868: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6869: } else {
1.12 raeburn 6870: my $newitem = $confhash->{$role}{$item};
6871: if ($key eq 'images') {
6872: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6873: }
6874: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6875: }
6876: }
6877: if ($role ne 'login') {
6878: $resulttext .= '</ul></li>';
6879: }
6880: } else {
6881: if ($confhash->{$role}{$key} eq '') {
6882: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6883: } else {
6884: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6885: }
6886: }
6887: if ($role ne 'login') {
6888: $resulttext .= '</ul>';
6889: }
6890: }
6891: }
6892: }
1.3 raeburn 6893: return $resulttext;
1.1 raeburn 6894: }
6895:
1.9 raeburn 6896: sub thumb_dimensions {
6897: return ('200','50');
6898: }
6899:
1.16 raeburn 6900: sub check_dimensions {
6901: my ($inputfile) = @_;
6902: my ($fullwidth,$fullheight);
6903: if ($inputfile =~ m|^[/\w.\-]+$|) {
6904: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6905: my $imageinfo = <PIPE>;
6906: if (!close(PIPE)) {
6907: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6908: }
6909: chomp($imageinfo);
6910: my ($fullsize) =
1.21 raeburn 6911: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6912: if ($fullsize) {
6913: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6914: }
6915: }
6916: }
6917: return ($fullwidth,$fullheight);
6918: }
6919:
1.9 raeburn 6920: sub check_configuser {
6921: my ($uhome,$dom,$confname,$servadm) = @_;
6922: my ($configuserok,%currroles);
6923: if ($uhome eq 'no_host') {
6924: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6925: my $configpass = &LONCAPA::Enrollment::create_password();
6926: $configuserok =
6927: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6928: $configpass,'','','','','',undef,$servadm);
6929: } else {
6930: $configuserok = 'ok';
6931: %currroles =
6932: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6933: }
6934: return ($configuserok,%currroles);
6935: }
6936:
6937: sub check_authorstatus {
6938: my ($dom,$confname,%currroles) = @_;
6939: my $author_ok;
1.40 raeburn 6940: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6941: my $start = time;
6942: my $end = 0;
6943: $author_ok =
6944: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6945: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6946: } else {
6947: $author_ok = 'ok';
6948: }
6949: return $author_ok;
6950: }
6951:
6952: sub publishlogo {
1.46 raeburn 6953: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6954: my ($output,$fname,$logourl);
6955: if ($action eq 'upload') {
6956: $fname=$env{'form.'.$formname.'.filename'};
6957: chop($env{'form.'.$formname});
6958: } else {
6959: ($fname) = ($formname =~ /([^\/]+)$/);
6960: }
1.46 raeburn 6961: if ($savefileas ne '') {
6962: $fname = $savefileas;
6963: }
1.9 raeburn 6964: $fname=&Apache::lonnet::clean_filename($fname);
6965: # See if there is anything left
6966: unless ($fname) { return ('error: no uploaded file'); }
6967: $fname="$subdir/$fname";
1.160.6.5 raeburn 6968: my $docroot=$r->dir_config('lonDocRoot');
6969: my $filepath="$docroot/priv";
6970: my $relpath = "$dom/$confname";
1.9 raeburn 6971: my ($fnamepath,$file,$fetchthumb);
6972: $file=$fname;
6973: if ($fname=~m|/|) {
6974: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6975: }
1.160.6.26 raeburn 6976: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6977: my $count;
1.160.6.5 raeburn 6978: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6979: $filepath.="/$parts[$count]";
6980: if ((-e $filepath)!=1) {
6981: mkdir($filepath,02770);
6982: }
6983: }
6984: # Check for bad extension and disallow upload
6985: if ($file=~/\.(\w+)$/ &&
6986: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6987: $output =
1.160.6.25 raeburn 6988: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6989: } elsif ($file=~/\.(\w+)$/ &&
6990: !defined(&Apache::loncommon::fileembstyle($1))) {
6991: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6992: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6993: $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 6994: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6995: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6996: } else {
6997: my $source = $filepath.'/'.$file;
6998: my $logfile;
6999: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7000: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7001: }
7002: print $logfile
7003: "\n================= Publish ".localtime()." ================\n".
7004: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7005: # Save the file
7006: if (!open(FH,'>'.$source)) {
7007: &Apache::lonnet::logthis('Failed to create '.$source);
7008: return (&mt('Failed to create file'));
7009: }
7010: if ($action eq 'upload') {
7011: if (!print FH ($env{'form.'.$formname})) {
7012: &Apache::lonnet::logthis('Failed to write to '.$source);
7013: return (&mt('Failed to write file'));
7014: }
7015: } else {
7016: my $original = &Apache::lonnet::filelocation('',$formname);
7017: if(!copy($original,$source)) {
7018: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7019: return (&mt('Failed to write file'));
7020: }
7021: }
7022: close(FH);
7023: chmod(0660, $source); # Permissions to rw-rw---.
7024:
7025: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7026: my $copyfile=$targetdir.'/'.$file;
7027:
7028: my @parts=split(/\//,$targetdir);
7029: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7030: for (my $count=5;$count<=$#parts;$count++) {
7031: $path.="/$parts[$count]";
7032: if (!-e $path) {
7033: print $logfile "\nCreating directory ".$path;
7034: mkdir($path,02770);
7035: }
7036: }
7037: my $versionresult;
7038: if (-e $copyfile) {
7039: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7040: } else {
7041: $versionresult = 'ok';
7042: }
7043: if ($versionresult eq 'ok') {
7044: if (copy($source,$copyfile)) {
7045: print $logfile "\nCopied original source to ".$copyfile."\n";
7046: $output = 'ok';
7047: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7048: push(@{$modified_urls},[$copyfile,$source]);
7049: my $metaoutput =
7050: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7051: unless ($registered_cleanup) {
7052: my $handlers = $r->get_handlers('PerlCleanupHandler');
7053: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7054: $registered_cleanup=1;
7055: }
1.9 raeburn 7056: } else {
7057: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7058: $output = &mt('Failed to copy file to RES space').", $!";
7059: }
7060: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7061: my $inputfile = $filepath.'/'.$file;
7062: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7063: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7064: if ($fullwidth ne '' && $fullheight ne '') {
7065: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7066: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7067: system("convert -sample $thumbsize $inputfile $outfile");
7068: chmod(0660, $filepath.'/tn-'.$file);
7069: if (-e $outfile) {
7070: my $copyfile=$targetdir.'/tn-'.$file;
7071: if (copy($outfile,$copyfile)) {
7072: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7073: my $thumb_metaoutput =
7074: &write_metadata($dom,$confname,$formname,
7075: $targetdir,'tn-'.$file,$logfile);
7076: push(@{$modified_urls},[$copyfile,$outfile]);
7077: unless ($registered_cleanup) {
7078: my $handlers = $r->get_handlers('PerlCleanupHandler');
7079: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7080: $registered_cleanup=1;
7081: }
1.16 raeburn 7082: } else {
7083: print $logfile "\nUnable to write ".$copyfile.
7084: ':'.$!."\n";
7085: }
7086: }
1.9 raeburn 7087: }
7088: }
7089: }
7090: } else {
7091: $output = $versionresult;
7092: }
7093: }
7094: return ($output,$logourl);
7095: }
7096:
7097: sub logo_versioning {
7098: my ($targetdir,$file,$logfile) = @_;
7099: my $target = $targetdir.'/'.$file;
7100: my ($maxversion,$fn,$extn,$output);
7101: $maxversion = 0;
7102: if ($file =~ /^(.+)\.(\w+)$/) {
7103: $fn=$1;
7104: $extn=$2;
7105: }
7106: opendir(DIR,$targetdir);
7107: while (my $filename=readdir(DIR)) {
7108: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7109: $maxversion=($1>$maxversion)?$1:$maxversion;
7110: }
7111: }
7112: $maxversion++;
7113: print $logfile "\nCreating old version ".$maxversion."\n";
7114: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7115: if (copy($target,$copyfile)) {
7116: print $logfile "Copied old target to ".$copyfile."\n";
7117: $copyfile=$copyfile.'.meta';
7118: if (copy($target.'.meta',$copyfile)) {
7119: print $logfile "Copied old target metadata to ".$copyfile."\n";
7120: $output = 'ok';
7121: } else {
7122: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7123: $output = &mt('Failed to copy old meta').", $!, ";
7124: }
7125: } else {
7126: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7127: $output = &mt('Failed to copy old target').", $!, ";
7128: }
7129: return $output;
7130: }
7131:
7132: sub write_metadata {
7133: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7134: my (%metadatafields,%metadatakeys,$output);
7135: $metadatafields{'title'}=$formname;
7136: $metadatafields{'creationdate'}=time;
7137: $metadatafields{'lastrevisiondate'}=time;
7138: $metadatafields{'copyright'}='public';
7139: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7140: $env{'user.domain'};
7141: $metadatafields{'authorspace'}=$confname.':'.$dom;
7142: $metadatafields{'domain'}=$dom;
7143: {
7144: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7145: my $mfh;
1.155 raeburn 7146: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7147: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7148: unless ($_=~/\./) {
7149: my $unikey=$_;
7150: $unikey=~/^([A-Za-z]+)/;
7151: my $tag=$1;
7152: $tag=~tr/A-Z/a-z/;
7153: print $mfh "\n\<$tag";
7154: foreach (split(/\,/,$metadatakeys{$unikey})) {
7155: my $value=$metadatafields{$unikey.'.'.$_};
7156: $value=~s/\"/\'\'/g;
7157: print $mfh ' '.$_.'="'.$value.'"';
7158: }
7159: print $mfh '>'.
7160: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7161: .'</'.$tag.'>';
7162: }
7163: }
7164: $output = 'ok';
7165: print $logfile "\nWrote metadata";
7166: close($mfh);
7167: } else {
7168: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7169: $output = &mt('Could not write metadata');
7170: }
7171: }
1.155 raeburn 7172: return $output;
7173: }
7174:
7175: sub notifysubscribed {
7176: foreach my $targetsource (@{$modified_urls}){
7177: next unless (ref($targetsource) eq 'ARRAY');
7178: my ($target,$source)=@{$targetsource};
7179: if ($source ne '') {
7180: if (open(my $logfh,'>>'.$source.'.log')) {
7181: print $logfh "\nCleanup phase: Notifications\n";
7182: my @subscribed=&subscribed_hosts($target);
7183: foreach my $subhost (@subscribed) {
7184: print $logfh "\nNotifying host ".$subhost.':';
7185: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7186: print $logfh $reply;
7187: }
7188: my @subscribedmeta=&subscribed_hosts("$target.meta");
7189: foreach my $subhost (@subscribedmeta) {
7190: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7191: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7192: $subhost);
7193: print $logfh $reply;
7194: }
7195: print $logfh "\n============ Done ============\n";
1.160 raeburn 7196: close($logfh);
1.155 raeburn 7197: }
7198: }
7199: }
7200: return OK;
7201: }
7202:
7203: sub subscribed_hosts {
7204: my ($target) = @_;
7205: my @subscribed;
7206: if (open(my $fh,"<$target.subscription")) {
7207: while (my $subline=<$fh>) {
7208: if ($subline =~ /^($match_lonid):/) {
7209: my $host = $1;
7210: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7211: unless (grep(/^\Q$host\E$/,@subscribed)) {
7212: push(@subscribed,$host);
7213: }
7214: }
7215: }
7216: }
7217: }
7218: return @subscribed;
1.9 raeburn 7219: }
7220:
7221: sub check_switchserver {
7222: my ($dom,$confname) = @_;
7223: my ($allowed,$switchserver);
7224: my $home = &Apache::lonnet::homeserver($confname,$dom);
7225: if ($home eq 'no_host') {
7226: $home = &Apache::lonnet::domain($dom,'primary');
7227: }
7228: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7229: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7230: if (!$allowed) {
1.160.6.11 raeburn 7231: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7232: }
7233: return $switchserver;
7234: }
7235:
1.1 raeburn 7236: sub modify_quotas {
1.160.6.30 raeburn 7237: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7238: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7239: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7240: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7241: $validationfieldsref);
1.86 raeburn 7242: if ($action eq 'quotas') {
7243: $context = 'tools';
1.160.6.26 raeburn 7244: } else {
1.86 raeburn 7245: $context = $action;
7246: }
7247: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7248: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7249: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7250: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7251: %titles = &courserequest_titles();
7252: $toolregexp = join('|',@usertools);
7253: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7254: $confname = $dom.'-domainconfig';
7255: my $servadm = $r->dir_config('lonAdmEMail');
7256: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7257: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7258: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7259: } elsif ($context eq 'requestauthor') {
7260: @usertools = ('author');
7261: %titles = &authorrequest_titles();
1.86 raeburn 7262: } else {
1.160.6.4 raeburn 7263: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7264: %titles = &tool_titles();
1.86 raeburn 7265: }
1.160.6.27 raeburn 7266: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7267: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7268: foreach my $key (keys(%env)) {
1.101 raeburn 7269: if ($context eq 'requestcourses') {
7270: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7271: my $item = $1;
7272: my $type = $2;
7273: if ($type =~ /^limit_(.+)/) {
7274: $limithash{$item}{$1} = $env{$key};
7275: } else {
7276: $confhash{$item}{$type} = $env{$key};
7277: }
7278: }
1.160.6.5 raeburn 7279: } elsif ($context eq 'requestauthor') {
7280: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7281: $confhash{$1} = $env{$key};
7282: }
1.101 raeburn 7283: } else {
1.86 raeburn 7284: if ($key =~ /^form\.quota_(.+)$/) {
7285: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 7286: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7287: $confhash{'authorquota'}{$1} = $env{$key};
7288: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7289: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7290: }
1.72 raeburn 7291: }
7292: }
1.160.6.5 raeburn 7293: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 7294: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7295: @approvalnotify = sort(@approvalnotify);
7296: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 7297: my @crstypes = ('official','unofficial','community','textbook');
7298: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7299: foreach my $type (@hasuniquecode) {
7300: if (grep(/^\Q$type\E$/,@crstypes)) {
7301: $confhash{'uniquecode'}{$type} = 1;
7302: }
7303: }
1.160.6.46 raeburn 7304: my (%newbook,%allpos);
1.160.6.30 raeburn 7305: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7306: foreach my $type ('textbooks','templates') {
7307: @{$allpos{$type}} = ();
7308: my $invalid;
7309: if ($type eq 'textbooks') {
7310: $invalid = &mt('Invalid LON-CAPA course for textbook');
7311: } else {
7312: $invalid = &mt('Invalid LON-CAPA course for template');
7313: }
7314: if ($env{'form.'.$type.'_addbook'}) {
7315: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7316: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7317: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7318: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7319: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7320: } else {
7321: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7322: my $position = $env{'form.'.$type.'_addbook_pos'};
7323: $position =~ s/\D+//g;
7324: if ($position ne '') {
7325: $allpos{$type}[$position] = $newbook{$type};
7326: }
1.160.6.30 raeburn 7327: }
1.160.6.46 raeburn 7328: } else {
7329: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 7330: }
7331: }
1.160.6.46 raeburn 7332: }
1.160.6.30 raeburn 7333: }
1.102 raeburn 7334: if (ref($domconfig{$action}) eq 'HASH') {
7335: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7336: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7337: $changes{'notify'}{'approval'} = 1;
7338: }
7339: } else {
1.144 raeburn 7340: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7341: $changes{'notify'}{'approval'} = 1;
7342: }
7343: }
1.160.6.30 raeburn 7344: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7345: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7346: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7347: unless ($confhash{'uniquecode'}{$crstype}) {
7348: $changes{'uniquecode'} = 1;
7349: }
7350: }
7351: unless ($changes{'uniquecode'}) {
7352: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7353: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7354: $changes{'uniquecode'} = 1;
7355: }
7356: }
7357: }
7358: } else {
7359: $changes{'uniquecode'} = 1;
7360: }
7361: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7362: $changes{'uniquecode'} = 1;
7363: }
7364: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7365: foreach my $type ('textbooks','templates') {
7366: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7367: my %deletions;
7368: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7369: if (@todelete) {
7370: map { $deletions{$_} = 1; } @todelete;
7371: }
7372: my %imgdeletions;
7373: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7374: if (@todeleteimages) {
7375: map { $imgdeletions{$_} = 1; } @todeleteimages;
7376: }
7377: my $maxnum = $env{'form.'.$type.'_maxnum'};
7378: for (my $i=0; $i<=$maxnum; $i++) {
7379: my $itemid = $env{'form.'.$type.'_id_'.$i};
7380: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7381: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7382: if ($deletions{$key}) {
7383: if ($domconfig{$action}{$type}{$key}{'image'}) {
7384: #FIXME need to obsolete item in RES space
7385: }
7386: next;
7387: } else {
7388: my $newpos = $env{'form.'.$itemid};
7389: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 7390: foreach my $item ('subject','title','publisher','author') {
7391: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7392: ($type eq 'templates'));
1.160.6.46 raeburn 7393: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7394: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7395: $changes{$type}{$key} = 1;
7396: }
7397: }
7398: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 7399: }
1.160.6.46 raeburn 7400: if ($imgdeletions{$key}) {
7401: $changes{$type}{$key} = 1;
7402: #FIXME need to obsolete item in RES space
7403: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7404: my ($cdom,$cnum) = split(/_/,$key);
7405: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7406: $cdom,$cnum,$type,$configuserok,
7407: $switchserver,$author_ok);
7408: if ($imgurl) {
7409: $confhash{$type}{$key}{'image'} = $imgurl;
7410: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 7411: }
1.160.6.46 raeburn 7412: if ($error) {
7413: &Apache::lonnet::logthis($error);
7414: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7415: }
7416: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7417: $confhash{$type}{$key}{'image'} =
7418: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 7419: }
7420: }
7421: }
7422: }
7423: }
7424: }
1.102 raeburn 7425: } else {
1.144 raeburn 7426: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7427: $changes{'notify'}{'approval'} = 1;
7428: }
1.160.6.30 raeburn 7429: if (ref($confhash{'uniquecode'} eq 'HASH')) {
7430: $changes{'uniquecode'} = 1;
7431: }
7432: }
7433: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 7434: foreach my $type ('textbooks','templates') {
7435: if ($newbook{$type}) {
7436: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 7437: foreach my $item ('subject','title','publisher','author') {
7438: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7439: ($type eq 'template'));
1.160.6.46 raeburn 7440: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7441: if ($env{'form.'.$type.'_addbook_'.$item}) {
7442: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7443: }
7444: }
7445: if ($type eq 'textbooks') {
7446: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7447: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7448: my ($imageurl,$error) =
7449: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7450: $configuserok,$switchserver,$author_ok);
7451: if ($imageurl) {
7452: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7453: }
7454: if ($error) {
7455: &Apache::lonnet::logthis($error);
7456: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7457: }
7458: }
1.160.6.30 raeburn 7459: }
7460: }
1.160.6.46 raeburn 7461: if (@{$allpos{$type}} > 0) {
7462: my $idx = 0;
7463: foreach my $item (@{$allpos{$type}}) {
7464: if ($item ne '') {
7465: $confhash{$type}{$item}{'order'} = $idx;
7466: if (ref($domconfig{$action}) eq 'HASH') {
7467: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7468: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7469: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7470: $changes{$type}{$item} = 1;
7471: }
1.160.6.30 raeburn 7472: }
7473: }
7474: }
1.160.6.46 raeburn 7475: $idx ++;
1.160.6.30 raeburn 7476: }
7477: }
7478: }
7479: }
1.160.6.39 raeburn 7480: if (ref($validationitemsref) eq 'ARRAY') {
7481: foreach my $item (@{$validationitemsref}) {
7482: if ($item eq 'fields') {
7483: my @changed;
7484: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7485: if (@{$confhash{'validation'}{$item}} > 0) {
7486: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7487: }
1.160.6.65 raeburn 7488: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7489: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7490: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7491: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7492: $domconfig{'requestcourses'}{'validation'}{$item});
7493: } else {
7494: @changed = @{$confhash{'validation'}{$item}};
7495: }
1.160.6.39 raeburn 7496: } else {
7497: @changed = @{$confhash{'validation'}{$item}};
7498: }
7499: } else {
7500: @changed = @{$confhash{'validation'}{$item}};
7501: }
7502: if (@changed) {
7503: if ($confhash{'validation'}{$item}) {
7504: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7505: } else {
7506: $changes{'validation'}{$item} = &mt('None');
7507: }
7508: }
7509: } else {
7510: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7511: if ($item eq 'markup') {
7512: if ($env{'form.requestcourses_validation_'.$item}) {
7513: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7514: }
7515: }
1.160.6.65 raeburn 7516: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7517: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7518: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7519: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7520: }
7521: } else {
7522: if ($confhash{'validation'}{$item} ne '') {
7523: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7524: }
1.160.6.39 raeburn 7525: }
7526: } else {
7527: if ($confhash{'validation'}{$item} ne '') {
7528: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7529: }
7530: }
7531: }
7532: }
7533: }
7534: if ($env{'form.validationdc'}) {
7535: my $newval = $env{'form.validationdc'};
7536: my %domcoords = &get_active_dcs($dom);
7537: if (exists($domcoords{$newval})) {
7538: $confhash{'validation'}{'dc'} = $newval;
7539: }
7540: }
7541: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 7542: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7543: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7544: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7545: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7546: if ($confhash{'validation'}{'dc'} eq '') {
7547: $changes{'validation'}{'dc'} = &mt('None');
7548: } else {
7549: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7550: }
1.160.6.39 raeburn 7551: }
1.160.6.65 raeburn 7552: } elsif ($confhash{'validation'}{'dc'} ne '') {
7553: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 7554: }
7555: } elsif ($confhash{'validation'}{'dc'} ne '') {
7556: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7557: }
7558: } elsif ($confhash{'validation'}{'dc'} ne '') {
7559: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7560: }
1.160.6.65 raeburn 7561: } else {
7562: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7563: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7564: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7565: $changes{'validation'}{'dc'} = &mt('None');
7566: }
7567: }
1.160.6.39 raeburn 7568: }
7569: }
1.102 raeburn 7570: }
7571: } else {
1.86 raeburn 7572: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7573: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7574: }
1.72 raeburn 7575: foreach my $item (@usertools) {
7576: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7577: my $unset;
1.101 raeburn 7578: if ($context eq 'requestcourses') {
1.104 raeburn 7579: $unset = '0';
7580: if ($type eq '_LC_adv') {
7581: $unset = '';
7582: }
1.101 raeburn 7583: if ($confhash{$item}{$type} eq 'autolimit') {
7584: $confhash{$item}{$type} .= '=';
7585: unless ($limithash{$item}{$type} =~ /\D/) {
7586: $confhash{$item}{$type} .= $limithash{$item}{$type};
7587: }
7588: }
1.160.6.5 raeburn 7589: } elsif ($context eq 'requestauthor') {
7590: $unset = '0';
7591: if ($type eq '_LC_adv') {
7592: $unset = '';
7593: }
1.72 raeburn 7594: } else {
1.101 raeburn 7595: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7596: $confhash{$item}{$type} = 1;
7597: } else {
7598: $confhash{$item}{$type} = 0;
7599: }
1.72 raeburn 7600: }
1.86 raeburn 7601: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7602: if ($action eq 'requestauthor') {
7603: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7604: $changes{$type} = 1;
7605: }
7606: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7607: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7608: $changes{$item}{$type} = 1;
7609: }
7610: } else {
7611: if ($context eq 'requestcourses') {
1.104 raeburn 7612: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7613: $changes{$item}{$type} = 1;
7614: }
7615: } else {
7616: if (!$confhash{$item}{$type}) {
7617: $changes{$item}{$type} = 1;
7618: }
7619: }
7620: }
7621: } else {
7622: if ($context eq 'requestcourses') {
1.104 raeburn 7623: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7624: $changes{$item}{$type} = 1;
7625: }
1.160.6.5 raeburn 7626: } elsif ($context eq 'requestauthor') {
7627: if ($confhash{$type} ne $unset) {
7628: $changes{$type} = 1;
7629: }
1.72 raeburn 7630: } else {
7631: if (!$confhash{$item}{$type}) {
7632: $changes{$item}{$type} = 1;
7633: }
7634: }
7635: }
1.1 raeburn 7636: }
7637: }
1.160.6.5 raeburn 7638: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7639: if (ref($domconfig{'quotas'}) eq 'HASH') {
7640: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7641: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7642: if (exists($confhash{'defaultquota'}{$key})) {
7643: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7644: $changes{'defaultquota'}{$key} = 1;
7645: }
7646: } else {
7647: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7648: }
7649: }
1.86 raeburn 7650: } else {
7651: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7652: if (exists($confhash{'defaultquota'}{$key})) {
7653: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7654: $changes{'defaultquota'}{$key} = 1;
7655: }
7656: } else {
7657: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7658: }
1.1 raeburn 7659: }
7660: }
1.160.6.20 raeburn 7661: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7662: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7663: if (exists($confhash{'authorquota'}{$key})) {
7664: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7665: $changes{'authorquota'}{$key} = 1;
7666: }
7667: } else {
7668: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7669: }
7670: }
7671: }
1.1 raeburn 7672: }
1.86 raeburn 7673: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7674: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7675: if (ref($domconfig{'quotas'}) eq 'HASH') {
7676: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7677: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7678: $changes{'defaultquota'}{$key} = 1;
7679: }
7680: } else {
7681: if (!exists($domconfig{'quotas'}{$key})) {
7682: $changes{'defaultquota'}{$key} = 1;
7683: }
1.72 raeburn 7684: }
7685: } else {
1.86 raeburn 7686: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7687: }
1.1 raeburn 7688: }
7689: }
1.160.6.20 raeburn 7690: if (ref($confhash{'authorquota'}) eq 'HASH') {
7691: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7692: if (ref($domconfig{'quotas'}) eq 'HASH') {
7693: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7694: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7695: $changes{'authorquota'}{$key} = 1;
7696: }
7697: } else {
7698: $changes{'authorquota'}{$key} = 1;
7699: }
7700: } else {
7701: $changes{'authorquota'}{$key} = 1;
7702: }
7703: }
7704: }
1.1 raeburn 7705: }
1.72 raeburn 7706:
1.160.6.5 raeburn 7707: if ($context eq 'requestauthor') {
7708: $domdefaults{'requestauthor'} = \%confhash;
7709: } else {
7710: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 7711: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 7712: $domdefaults{$key} = $confhash{$key};
7713: }
1.160.6.5 raeburn 7714: }
1.72 raeburn 7715: }
1.160.6.5 raeburn 7716:
1.1 raeburn 7717: my %quotahash = (
1.86 raeburn 7718: $action => { %confhash }
1.1 raeburn 7719: );
7720: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7721: $dom);
7722: if ($putresult eq 'ok') {
7723: if (keys(%changes) > 0) {
1.72 raeburn 7724: my $cachetime = 24*60*60;
7725: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7726: if (ref($lastactref) eq 'HASH') {
7727: $lastactref->{'domdefaults'} = 1;
7728: }
1.1 raeburn 7729: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7730: unless (($context eq 'requestcourses') ||
7731: ($context eq 'requestauthor')) {
1.86 raeburn 7732: if (ref($changes{'defaultquota'}) eq 'HASH') {
7733: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7734: foreach my $type (@{$types},'default') {
7735: if (defined($changes{'defaultquota'}{$type})) {
7736: my $typetitle = $usertypes->{$type};
7737: if ($type eq 'default') {
7738: $typetitle = $othertitle;
7739: }
1.160.6.28 raeburn 7740: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7741: }
7742: }
1.86 raeburn 7743: $resulttext .= '</ul></li>';
1.72 raeburn 7744: }
1.160.6.20 raeburn 7745: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7746: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7747: foreach my $type (@{$types},'default') {
7748: if (defined($changes{'authorquota'}{$type})) {
7749: my $typetitle = $usertypes->{$type};
7750: if ($type eq 'default') {
7751: $typetitle = $othertitle;
7752: }
1.160.6.28 raeburn 7753: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7754: }
7755: }
7756: $resulttext .= '</ul></li>';
7757: }
1.72 raeburn 7758: }
1.80 raeburn 7759: my %newenv;
1.72 raeburn 7760: foreach my $item (@usertools) {
1.160.6.5 raeburn 7761: my (%haschgs,%inconf);
7762: if ($context eq 'requestauthor') {
7763: %haschgs = %changes;
7764: %inconf = %confhash;
7765: } else {
7766: if (ref($changes{$item}) eq 'HASH') {
7767: %haschgs = %{$changes{$item}};
7768: }
7769: if (ref($confhash{$item}) eq 'HASH') {
7770: %inconf = %{$confhash{$item}};
7771: }
7772: }
7773: if (keys(%haschgs) > 0) {
1.80 raeburn 7774: my $newacc =
7775: &Apache::lonnet::usertools_access($env{'user.name'},
7776: $env{'user.domain'},
1.86 raeburn 7777: $item,'reload',$context);
1.160.6.5 raeburn 7778: if (($context eq 'requestcourses') ||
7779: ($context eq 'requestauthor')) {
1.108 raeburn 7780: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7781: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7782: }
7783: } else {
7784: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7785: $newenv{'environment.availabletools.'.$item} = $newacc;
7786: }
1.80 raeburn 7787: }
1.160.6.5 raeburn 7788: unless ($context eq 'requestauthor') {
7789: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7790: }
1.72 raeburn 7791: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7792: if ($haschgs{$type}) {
1.72 raeburn 7793: my $typetitle = $usertypes->{$type};
7794: if ($type eq 'default') {
7795: $typetitle = $othertitle;
7796: } elsif ($type eq '_LC_adv') {
7797: $typetitle = 'LON-CAPA Advanced Users';
7798: }
1.160.6.5 raeburn 7799: if ($inconf{$type}) {
1.101 raeburn 7800: if ($context eq 'requestcourses') {
7801: my $cond;
1.160.6.5 raeburn 7802: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7803: if ($1 eq '') {
7804: $cond = &mt('(Automatic processing of any request).');
7805: } else {
7806: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7807: }
7808: } else {
1.160.6.5 raeburn 7809: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7810: }
7811: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7812: } elsif ($context eq 'requestauthor') {
7813: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7814: $titles{$inconf{$type}},$typetitle);
7815:
1.101 raeburn 7816: } else {
7817: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7818: }
1.72 raeburn 7819: } else {
1.104 raeburn 7820: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7821: if ($inconf{$type} eq '0') {
1.104 raeburn 7822: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7823: } else {
7824: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7825: }
7826: } else {
7827: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7828: }
1.72 raeburn 7829: }
7830: }
1.26 raeburn 7831: }
1.160.6.5 raeburn 7832: unless ($context eq 'requestauthor') {
7833: $resulttext .= '</ul></li>';
7834: }
1.26 raeburn 7835: }
1.1 raeburn 7836: }
1.160.6.5 raeburn 7837: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7838: if (ref($changes{'notify'}) eq 'HASH') {
7839: if ($changes{'notify'}{'approval'}) {
7840: if (ref($confhash{'notify'}) eq 'HASH') {
7841: if ($confhash{'notify'}{'approval'}) {
7842: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7843: } else {
1.160.6.5 raeburn 7844: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7845: }
7846: }
7847: }
7848: }
7849: }
1.160.6.30 raeburn 7850: if ($action eq 'requestcourses') {
7851: my @offon = ('off','on');
7852: if ($changes{'uniquecode'}) {
7853: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7854: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7855: $resulttext .= '<li>'.
7856: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7857: '</li>';
7858: } else {
7859: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7860: '</li>';
7861: }
7862: }
1.160.6.46 raeburn 7863: foreach my $type ('textbooks','templates') {
7864: if (ref($changes{$type}) eq 'HASH') {
7865: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7866: foreach my $key (sort(keys(%{$changes{$type}}))) {
7867: my %coursehash = &Apache::lonnet::coursedescription($key);
7868: my $coursetitle = $coursehash{'description'};
7869: my $position = $confhash{$type}{$key}{'order'} + 1;
7870: $resulttext .= '<li>';
1.160.6.47 raeburn 7871: foreach my $item ('subject','title','publisher','author') {
7872: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7873: ($type eq 'templates'));
1.160.6.46 raeburn 7874: my $name = $item.':';
7875: $name =~ s/^(\w)/\U$1/;
7876: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7877: }
7878: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7879: if ($type eq 'textbooks') {
7880: if ($confhash{$type}{$key}{'image'}) {
7881: $resulttext .= ' '.&mt('Image: [_1]',
7882: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7883: ' alt="Textbook cover" />').'<br />';
7884: }
7885: }
7886: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 7887: }
1.160.6.46 raeburn 7888: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 7889: }
7890: }
1.160.6.39 raeburn 7891: if (ref($changes{'validation'}) eq 'HASH') {
7892: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7893: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7894: foreach my $item (@{$validationitemsref}) {
7895: if (exists($changes{'validation'}{$item})) {
7896: if ($item eq 'markup') {
7897: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7898: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7899: } else {
7900: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7901: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7902: }
7903: }
7904: }
7905: if (exists($changes{'validation'}{'dc'})) {
7906: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7907: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7908: }
7909: }
7910: }
1.160.6.30 raeburn 7911: }
1.1 raeburn 7912: $resulttext .= '</ul>';
1.80 raeburn 7913: if (keys(%newenv)) {
7914: &Apache::lonnet::appenv(\%newenv);
7915: }
1.1 raeburn 7916: } else {
1.86 raeburn 7917: if ($context eq 'requestcourses') {
7918: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7919: } elsif ($context eq 'requestauthor') {
7920: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7921: } else {
1.90 weissno 7922: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7923: }
1.1 raeburn 7924: }
7925: } else {
1.11 albertel 7926: $resulttext = '<span class="LC_error">'.
7927: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7928: }
1.160.6.30 raeburn 7929: if ($errors) {
7930: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7931: '<ul>'.$errors.'</ul></p>';
7932: }
1.3 raeburn 7933: return $resulttext;
1.1 raeburn 7934: }
7935:
1.160.6.30 raeburn 7936: sub process_textbook_image {
1.160.6.46 raeburn 7937: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 7938: my $filename = $env{'form.'.$caller.'.filename'};
7939: my ($error,$url);
7940: my ($width,$height) = (50,50);
7941: if ($configuserok eq 'ok') {
7942: if ($switchserver) {
7943: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7944: $switchserver);
7945: } elsif ($author_ok eq 'ok') {
7946: my ($result,$imageurl) =
7947: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 7948: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 7949: if ($result eq 'ok') {
7950: $url = $imageurl;
7951: } else {
7952: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7953: }
7954: } else {
7955: $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);
7956: }
7957: } else {
7958: $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);
7959: }
7960: return ($url,$error);
7961: }
7962:
1.3 raeburn 7963: sub modify_autoenroll {
1.160.6.24 raeburn 7964: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7965: my ($resulttext,%changes);
7966: my %currautoenroll;
7967: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7968: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7969: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7970: }
7971: }
7972: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7973: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7974: sender => 'Sender for notification messages',
1.160.6.68 raeburn 7975: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
7976: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 7977: my @offon = ('off','on');
1.17 raeburn 7978: my $sender_uname = $env{'form.sender_uname'};
7979: my $sender_domain = $env{'form.sender_domain'};
7980: if ($sender_domain eq '') {
7981: $sender_uname = '';
7982: } elsif ($sender_uname eq '') {
7983: $sender_domain = '';
7984: }
1.129 raeburn 7985: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 7986: my $failsafe = $env{'form.autoenroll_failsafe'};
7987: $failsafe =~ s{^\s+|\s+$}{}g;
7988: if ($failsafe =~ /\D/) {
7989: undef($failsafe);
7990: }
1.1 raeburn 7991: my %autoenrollhash = (
1.129 raeburn 7992: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7993: 'sender_uname' => $sender_uname,
7994: 'sender_domain' => $sender_domain,
7995: 'co-owners' => $coowners,
1.160.6.68 raeburn 7996: 'autofailsafe' => $failsafe,
1.1 raeburn 7997: }
7998: );
1.4 raeburn 7999: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8000: $dom);
1.1 raeburn 8001: if ($putresult eq 'ok') {
8002: if (exists($currautoenroll{'run'})) {
8003: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8004: $changes{'run'} = 1;
8005: }
8006: } elsif ($autorun) {
8007: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8008: $changes{'run'} = 1;
1.1 raeburn 8009: }
8010: }
1.17 raeburn 8011: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8012: $changes{'sender'} = 1;
8013: }
1.17 raeburn 8014: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8015: $changes{'sender'} = 1;
8016: }
1.129 raeburn 8017: if ($currautoenroll{'co-owners'} ne '') {
8018: if ($currautoenroll{'co-owners'} ne $coowners) {
8019: $changes{'coowners'} = 1;
8020: }
8021: } elsif ($coowners) {
8022: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8023: }
8024: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8025: $changes{'autofailsafe'} = 1;
8026: }
1.1 raeburn 8027: if (keys(%changes) > 0) {
8028: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8029: if ($changes{'run'}) {
1.1 raeburn 8030: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8031: }
8032: if ($changes{'sender'}) {
1.17 raeburn 8033: if ($sender_uname eq '' || $sender_domain eq '') {
8034: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8035: } else {
8036: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8037: }
1.1 raeburn 8038: }
1.129 raeburn 8039: if ($changes{'coowners'}) {
8040: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8041: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8042: if (ref($lastactref) eq 'HASH') {
8043: $lastactref->{'domainconfig'} = 1;
8044: }
1.129 raeburn 8045: }
1.160.6.68 raeburn 8046: if ($changes{'autofailsafe'}) {
8047: if ($failsafe ne '') {
8048: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8049: } else {
8050: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8051: }
8052: &Apache::lonnet::get_domain_defaults($dom,1);
8053: if (ref($lastactref) eq 'HASH') {
8054: $lastactref->{'domdefaults'} = 1;
8055: }
8056: }
1.1 raeburn 8057: $resulttext .= '</ul>';
8058: } else {
8059: $resulttext = &mt('No changes made to auto-enrollment settings');
8060: }
8061: } else {
1.11 albertel 8062: $resulttext = '<span class="LC_error">'.
8063: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8064: }
1.3 raeburn 8065: return $resulttext;
1.1 raeburn 8066: }
8067:
8068: sub modify_autoupdate {
1.3 raeburn 8069: my ($dom,%domconfig) = @_;
1.1 raeburn 8070: my ($resulttext,%currautoupdate,%fields,%changes);
8071: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8072: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8073: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8074: }
8075: }
8076: my @offon = ('off','on');
8077: my %title = &Apache::lonlocal::texthash (
8078: run => 'Auto-update:',
8079: classlists => 'Updates to user information in classlists?'
8080: );
1.44 raeburn 8081: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8082: my %fieldtitles = &Apache::lonlocal::texthash (
8083: id => 'Student/Employee ID',
1.20 raeburn 8084: permanentemail => 'E-mail address',
1.1 raeburn 8085: lastname => 'Last Name',
8086: firstname => 'First Name',
8087: middlename => 'Middle Name',
1.132 raeburn 8088: generation => 'Generation',
1.1 raeburn 8089: );
1.142 raeburn 8090: $othertitle = &mt('All users');
1.1 raeburn 8091: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8092: $othertitle = &mt('Other users');
1.1 raeburn 8093: }
8094: foreach my $key (keys(%env)) {
8095: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8096: my ($usertype,$item) = ($1,$2);
8097: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8098: if ($usertype eq 'default') {
8099: push(@{$fields{$1}},$2);
8100: } elsif (ref($types) eq 'ARRAY') {
8101: if (grep(/^\Q$usertype\E$/,@{$types})) {
8102: push(@{$fields{$1}},$2);
8103: }
8104: }
8105: }
1.1 raeburn 8106: }
8107: }
1.131 raeburn 8108: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8109: @lockablenames = sort(@lockablenames);
8110: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8111: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8112: if (@changed) {
8113: $changes{'lockablenames'} = 1;
8114: }
8115: } else {
8116: if (@lockablenames) {
8117: $changes{'lockablenames'} = 1;
8118: }
8119: }
1.1 raeburn 8120: my %updatehash = (
8121: autoupdate => { run => $env{'form.autoupdate_run'},
8122: classlists => $env{'form.classlists'},
8123: fields => {%fields},
1.131 raeburn 8124: lockablenames => \@lockablenames,
1.1 raeburn 8125: }
8126: );
8127: foreach my $key (keys(%currautoupdate)) {
8128: if (($key eq 'run') || ($key eq 'classlists')) {
8129: if (exists($updatehash{autoupdate}{$key})) {
8130: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8131: $changes{$key} = 1;
8132: }
8133: }
8134: } elsif ($key eq 'fields') {
8135: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8136: foreach my $item (@{$types},'default') {
1.1 raeburn 8137: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8138: my $change = 0;
8139: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8140: if (!exists($fields{$item})) {
8141: $change = 1;
1.132 raeburn 8142: last;
1.1 raeburn 8143: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8144: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8145: $change = 1;
1.132 raeburn 8146: last;
1.1 raeburn 8147: }
8148: }
8149: }
8150: if ($change) {
8151: push(@{$changes{$key}},$item);
8152: }
1.26 raeburn 8153: }
1.1 raeburn 8154: }
8155: }
1.131 raeburn 8156: } elsif ($key eq 'lockablenames') {
8157: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8158: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8159: if (@changed) {
8160: $changes{'lockablenames'} = 1;
8161: }
8162: } else {
8163: if (@lockablenames) {
8164: $changes{'lockablenames'} = 1;
8165: }
8166: }
8167: }
8168: }
8169: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8170: if (@lockablenames) {
8171: $changes{'lockablenames'} = 1;
1.1 raeburn 8172: }
8173: }
1.26 raeburn 8174: foreach my $item (@{$types},'default') {
8175: if (defined($fields{$item})) {
8176: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8177: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8178: my $change = 0;
8179: if (ref($fields{$item}) eq 'ARRAY') {
8180: foreach my $type (@{$fields{$item}}) {
8181: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8182: $change = 1;
8183: last;
8184: }
8185: }
8186: }
8187: if ($change) {
8188: push(@{$changes{'fields'}},$item);
8189: }
8190: } else {
1.26 raeburn 8191: push(@{$changes{'fields'}},$item);
8192: }
8193: } else {
8194: push(@{$changes{'fields'}},$item);
1.1 raeburn 8195: }
8196: }
8197: }
8198: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8199: $dom);
8200: if ($putresult eq 'ok') {
8201: if (keys(%changes) > 0) {
8202: $resulttext = &mt('Changes made:').'<ul>';
8203: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8204: if ($key eq 'lockablenames') {
8205: $resulttext .= '<li>';
8206: if (@lockablenames) {
8207: $usertypes->{'default'} = $othertitle;
8208: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8209: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8210: } else {
8211: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8212: }
8213: $resulttext .= '</li>';
8214: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8215: foreach my $item (@{$changes{$key}}) {
8216: my @newvalues;
8217: foreach my $type (@{$fields{$item}}) {
8218: push(@newvalues,$fieldtitles{$type});
8219: }
1.3 raeburn 8220: my $newvaluestr;
8221: if (@newvalues > 0) {
8222: $newvaluestr = join(', ',@newvalues);
8223: } else {
8224: $newvaluestr = &mt('none');
1.6 raeburn 8225: }
1.1 raeburn 8226: if ($item eq 'default') {
1.26 raeburn 8227: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8228: } else {
1.26 raeburn 8229: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8230: }
8231: }
8232: } else {
8233: my $newvalue;
8234: if ($key eq 'run') {
8235: $newvalue = $offon[$env{'form.autoupdate_run'}];
8236: } else {
8237: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8238: }
1.1 raeburn 8239: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8240: }
8241: }
8242: $resulttext .= '</ul>';
8243: } else {
1.3 raeburn 8244: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8245: }
8246: } else {
1.11 albertel 8247: $resulttext = '<span class="LC_error">'.
8248: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8249: }
1.3 raeburn 8250: return $resulttext;
1.1 raeburn 8251: }
8252:
1.125 raeburn 8253: sub modify_autocreate {
8254: my ($dom,%domconfig) = @_;
8255: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8256: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8257: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8258: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8259: }
8260: }
8261: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8262: req => 'Auto-creation of validated requests for official courses',
8263: xmldc => 'Identity of course creator of courses from XML files',
8264: );
8265: my @types = ('xml','req');
8266: foreach my $item (@types) {
8267: $newvals{$item} = $env{'form.autocreate_'.$item};
8268: $newvals{$item} =~ s/\D//g;
8269: $newvals{$item} = 0 if ($newvals{$item} eq '');
8270: }
8271: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8272: my %domcoords = &get_active_dcs($dom);
8273: unless (exists($domcoords{$newvals{'xmldc'}})) {
8274: $newvals{'xmldc'} = '';
8275: }
8276: %autocreatehash = (
8277: autocreate => { xml => $newvals{'xml'},
8278: req => $newvals{'req'},
8279: }
8280: );
8281: if ($newvals{'xmldc'} ne '') {
8282: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8283: }
8284: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8285: $dom);
8286: if ($putresult eq 'ok') {
8287: my @items = @types;
8288: if ($newvals{'xml'}) {
8289: push(@items,'xmldc');
8290: }
8291: foreach my $item (@items) {
8292: if (exists($currautocreate{$item})) {
8293: if ($currautocreate{$item} ne $newvals{$item}) {
8294: $changes{$item} = 1;
8295: }
8296: } elsif ($newvals{$item}) {
8297: $changes{$item} = 1;
8298: }
8299: }
8300: if (keys(%changes) > 0) {
8301: my @offon = ('off','on');
8302: $resulttext = &mt('Changes made:').'<ul>';
8303: foreach my $item (@types) {
8304: if ($changes{$item}) {
8305: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 8306: $resulttext .= '<li>'.
8307: &mt("$title{$item} set to [_1]$newtxt [_2]",
8308: '<b>','</b>').
8309: '</li>';
1.125 raeburn 8310: }
8311: }
8312: if ($changes{'xmldc'}) {
8313: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8314: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 8315: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8316: }
8317: $resulttext .= '</ul>';
8318: } else {
8319: $resulttext = &mt('No changes made to auto-creation settings');
8320: }
8321: } else {
8322: $resulttext = '<span class="LC_error">'.
8323: &mt('An error occurred: [_1]',$putresult).'</span>';
8324: }
8325: return $resulttext;
8326: }
8327:
1.23 raeburn 8328: sub modify_directorysrch {
8329: my ($dom,%domconfig) = @_;
8330: my ($resulttext,%changes);
8331: my %currdirsrch;
8332: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8333: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8334: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8335: }
8336: }
1.160.6.72! raeburn 8337: my %title = ( available => 'Institutional directory search available',
! 8338: localonly => 'Other domains can search institution',
! 8339: lcavailable => 'LON-CAPA directory search available',
! 8340: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 8341: searchby => 'Search types',
8342: searchtypes => 'Search latitude');
8343: my @offon = ('off','on');
1.24 raeburn 8344: my @otherdoms = ('Yes','No');
1.23 raeburn 8345:
1.25 raeburn 8346: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8347: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8348: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8349:
1.44 raeburn 8350: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8351: if (keys(%{$usertypes}) == 0) {
8352: @cansearch = ('default');
8353: } else {
8354: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8355: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8356: if (!grep(/^\Q$type\E$/,@cansearch)) {
8357: push(@{$changes{'cansearch'}},$type);
8358: }
1.23 raeburn 8359: }
1.26 raeburn 8360: foreach my $type (@cansearch) {
8361: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8362: push(@{$changes{'cansearch'}},$type);
8363: }
1.23 raeburn 8364: }
1.26 raeburn 8365: } else {
8366: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8367: }
8368: }
8369:
8370: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8371: foreach my $by (@{$currdirsrch{'searchby'}}) {
8372: if (!grep(/^\Q$by\E$/,@searchby)) {
8373: push(@{$changes{'searchby'}},$by);
8374: }
8375: }
8376: foreach my $by (@searchby) {
8377: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8378: push(@{$changes{'searchby'}},$by);
8379: }
8380: }
8381: } else {
8382: push(@{$changes{'searchby'}},@searchby);
8383: }
1.25 raeburn 8384:
8385: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8386: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8387: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8388: push(@{$changes{'searchtypes'}},$type);
8389: }
8390: }
8391: foreach my $type (@searchtypes) {
8392: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8393: push(@{$changes{'searchtypes'}},$type);
8394: }
8395: }
8396: } else {
8397: if (exists($currdirsrch{'searchtypes'})) {
8398: foreach my $type (@searchtypes) {
8399: if ($type ne $currdirsrch{'searchtypes'}) {
8400: push(@{$changes{'searchtypes'}},$type);
8401: }
8402: }
8403: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8404: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8405: }
8406: } else {
8407: push(@{$changes{'searchtypes'}},@searchtypes);
8408: }
8409: }
8410:
1.23 raeburn 8411: my %dirsrch_hash = (
8412: directorysrch => { available => $env{'form.dirsrch_available'},
8413: cansearch => \@cansearch,
1.160.6.72! raeburn 8414: localonly => $env{'form.dirsrch_instlocalonly'},
! 8415: lclocalonly => $env{'form.dirsrch_domlocalonly'},
! 8416: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 8417: searchby => \@searchby,
1.25 raeburn 8418: searchtypes => \@searchtypes,
1.23 raeburn 8419: }
8420: );
8421: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8422: $dom);
8423: if ($putresult eq 'ok') {
8424: if (exists($currdirsrch{'available'})) {
8425: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8426: $changes{'available'} = 1;
8427: }
8428: } else {
8429: if ($env{'form.dirsrch_available'} eq '1') {
8430: $changes{'available'} = 1;
8431: }
8432: }
1.160.6.72! raeburn 8433: if (exists($currdirsrch{'lcavailable'})) {
! 8434: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
! 8435: $changes{'lcavailable'} = 1;
1.24 raeburn 8436: }
8437: } else {
1.160.6.72! raeburn 8438: if ($env{'form.dirsrch_lcavailable'} eq '1') {
! 8439: $changes{'lcavailable'} = 1;
! 8440: }
! 8441: }
! 8442: if (exists($currdirsrch{'localonly'})) {
! 8443: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 8444: $changes{'localonly'} = 1;
8445: }
1.160.6.72! raeburn 8446: } else {
! 8447: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
! 8448: $changes{'localonly'} = 1;
! 8449: }
! 8450: }
! 8451: if (exists($currdirsrch{'lclocalonly'})) {
! 8452: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
! 8453: $changes{'lclocalonly'} = 1;
! 8454: }
! 8455: } else {
! 8456: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
! 8457: $changes{'lclocalonly'} = 1;
! 8458: }
1.24 raeburn 8459: }
1.23 raeburn 8460: if (keys(%changes) > 0) {
8461: $resulttext = &mt('Changes made:').'<ul>';
8462: if ($changes{'available'}) {
8463: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8464: }
1.160.6.72! raeburn 8465: if ($changes{'lcavailable'}) {
! 8466: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
! 8467: }
1.24 raeburn 8468: if ($changes{'localonly'}) {
1.160.6.72! raeburn 8469: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
! 8470: }
! 8471: if ($changes{'lclocalonly'}) {
! 8472: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 8473: }
1.23 raeburn 8474: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8475: my $chgtext;
1.26 raeburn 8476: if (ref($usertypes) eq 'HASH') {
8477: if (keys(%{$usertypes}) > 0) {
8478: foreach my $type (@{$types}) {
8479: if (grep(/^\Q$type\E$/,@cansearch)) {
8480: $chgtext .= $usertypes->{$type}.'; ';
8481: }
8482: }
8483: if (grep(/^default$/,@cansearch)) {
8484: $chgtext .= $othertitle;
8485: } else {
8486: $chgtext =~ s/\; $//;
8487: }
1.160.6.13 raeburn 8488: $resulttext .=
8489: '<li>'.
8490: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8491: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8492: '</li>';
1.23 raeburn 8493: }
8494: }
8495: }
8496: if (ref($changes{'searchby'}) eq 'ARRAY') {
8497: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8498: my $chgtext;
8499: foreach my $type (@{$titleorder}) {
8500: if (grep(/^\Q$type\E$/,@searchby)) {
8501: if (defined($searchtitles->{$type})) {
8502: $chgtext .= $searchtitles->{$type}.'; ';
8503: }
8504: }
8505: }
8506: $chgtext =~ s/\; $//;
8507: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8508: }
1.25 raeburn 8509: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8510: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8511: my $chgtext;
8512: foreach my $type (@{$srchtypeorder}) {
8513: if (grep(/^\Q$type\E$/,@searchtypes)) {
8514: if (defined($srchtypes_desc->{$type})) {
8515: $chgtext .= $srchtypes_desc->{$type}.'; ';
8516: }
8517: }
8518: }
8519: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 8520: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8521: }
8522: $resulttext .= '</ul>';
8523: } else {
1.160.6.72! raeburn 8524: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 8525: }
8526: } else {
8527: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8528: &mt('An error occurred: [_1]',$putresult).'</span>';
8529: }
8530: return $resulttext;
8531: }
8532:
1.28 raeburn 8533: sub modify_contacts {
1.160.6.24 raeburn 8534: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8535: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8536: if (ref($domconfig{'contacts'}) eq 'HASH') {
8537: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8538: $currsetting{$key} = $domconfig{'contacts'}{$key};
8539: }
8540: }
1.134 raeburn 8541: my (%others,%to,%bcc);
1.28 raeburn 8542: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8543: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 8544: 'requestsmail','updatesmail','idconflictsmail');
8545: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8546: foreach my $type (@mailings) {
8547: @{$newsetting{$type}} =
8548: &Apache::loncommon::get_env_multiple('form.'.$type);
8549: foreach my $item (@contacts) {
8550: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8551: $contacts_hash{contacts}{$type}{$item} = 1;
8552: } else {
8553: $contacts_hash{contacts}{$type}{$item} = 0;
8554: }
8555: }
8556: $others{$type} = $env{'form.'.$type.'_others'};
8557: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8558: if ($type eq 'helpdeskmail') {
8559: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8560: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8561: }
1.28 raeburn 8562: }
8563: foreach my $item (@contacts) {
8564: $to{$item} = $env{'form.'.$item};
8565: $contacts_hash{'contacts'}{$item} = $to{$item};
8566: }
1.160.6.23 raeburn 8567: foreach my $item (@toggles) {
8568: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8569: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8570: }
8571: }
1.28 raeburn 8572: if (keys(%currsetting) > 0) {
8573: foreach my $item (@contacts) {
8574: if ($to{$item} ne $currsetting{$item}) {
8575: $changes{$item} = 1;
8576: }
8577: }
8578: foreach my $type (@mailings) {
8579: foreach my $item (@contacts) {
8580: if (ref($currsetting{$type}) eq 'HASH') {
8581: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8582: push(@{$changes{$type}},$item);
8583: }
8584: } else {
8585: push(@{$changes{$type}},@{$newsetting{$type}});
8586: }
8587: }
8588: if ($others{$type} ne $currsetting{$type}{'others'}) {
8589: push(@{$changes{$type}},'others');
8590: }
1.134 raeburn 8591: if ($type eq 'helpdeskmail') {
8592: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8593: push(@{$changes{$type}},'bcc');
8594: }
8595: }
1.28 raeburn 8596: }
8597: } else {
8598: my %default;
8599: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8600: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8601: $default{'errormail'} = 'adminemail';
8602: $default{'packagesmail'} = 'adminemail';
8603: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8604: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8605: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 8606: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8607: foreach my $item (@contacts) {
8608: if ($to{$item} ne $default{$item}) {
8609: $changes{$item} = 1;
1.160.6.23 raeburn 8610: }
1.28 raeburn 8611: }
8612: foreach my $type (@mailings) {
8613: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8614:
8615: push(@{$changes{$type}},@{$newsetting{$type}});
8616: }
8617: if ($others{$type} ne '') {
8618: push(@{$changes{$type}},'others');
1.134 raeburn 8619: }
8620: if ($type eq 'helpdeskmail') {
8621: if ($bcc{$type} ne '') {
8622: push(@{$changes{$type}},'bcc');
8623: }
8624: }
1.28 raeburn 8625: }
8626: }
1.160.6.23 raeburn 8627: foreach my $item (@toggles) {
8628: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8629: $changes{$item} = 1;
8630: } elsif ((!$env{'form.'.$item}) &&
8631: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8632: $changes{$item} = 1;
8633: }
8634: }
1.28 raeburn 8635: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8636: $dom);
8637: if ($putresult eq 'ok') {
8638: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8639: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8640: if (ref($lastactref) eq 'HASH') {
8641: $lastactref->{'domainconfig'} = 1;
8642: }
1.28 raeburn 8643: my ($titles,$short_titles) = &contact_titles();
8644: $resulttext = &mt('Changes made:').'<ul>';
8645: foreach my $item (@contacts) {
8646: if ($changes{$item}) {
8647: $resulttext .= '<li>'.$titles->{$item}.
8648: &mt(' set to: ').
8649: '<span class="LC_cusr_emph">'.
8650: $to{$item}.'</span></li>';
8651: }
8652: }
8653: foreach my $type (@mailings) {
8654: if (ref($changes{$type}) eq 'ARRAY') {
8655: $resulttext .= '<li>'.$titles->{$type}.': ';
8656: my @text;
8657: foreach my $item (@{$newsetting{$type}}) {
8658: push(@text,$short_titles->{$item});
8659: }
8660: if ($others{$type} ne '') {
8661: push(@text,$others{$type});
8662: }
8663: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8664: join(', ',@text).'</span>';
8665: if ($type eq 'helpdeskmail') {
8666: if ($bcc{$type} ne '') {
8667: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8668: }
8669: }
8670: $resulttext .= '</li>';
1.28 raeburn 8671: }
8672: }
1.160.6.23 raeburn 8673: my @offon = ('off','on');
8674: if ($changes{'reporterrors'}) {
8675: $resulttext .= '<li>'.
8676: &mt('E-mail error reports to [_1] set to "'.
8677: $offon[$env{'form.reporterrors'}].'".',
8678: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8679: &mt('LON-CAPA core group - MSU'),600,500)).
8680: '</li>';
8681: }
8682: if ($changes{'reportupdates'}) {
8683: $resulttext .= '<li>'.
8684: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8685: $offon[$env{'form.reportupdates'}].'".',
8686: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8687: &mt('LON-CAPA core group - MSU'),600,500)).
8688: '</li>';
8689: }
1.28 raeburn 8690: $resulttext .= '</ul>';
8691: } else {
1.34 raeburn 8692: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8693: }
8694: } else {
8695: $resulttext = '<span class="LC_error">'.
8696: &mt('An error occurred: [_1].',$putresult).'</span>';
8697: }
8698: return $resulttext;
8699: }
8700:
8701: sub modify_usercreation {
1.27 raeburn 8702: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8703: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8704: my $warningmsg;
1.27 raeburn 8705: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8706: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8707: if ($key eq 'cancreate') {
8708: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8709: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8710: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 8711: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
8712: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 8713: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8714: } else {
8715: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8716: }
1.50 raeburn 8717: }
1.43 raeburn 8718: }
1.160.6.34 raeburn 8719: } elsif ($key eq 'email_rule') {
8720: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8721: } else {
8722: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8723: }
8724: }
1.34 raeburn 8725: }
1.160.6.34 raeburn 8726: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8727: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8728: my @contexts = ('author','course','requestcrs');
8729: foreach my $item(@contexts) {
8730: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8731: }
1.34 raeburn 8732: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8733: foreach my $item (@contexts) {
1.160.6.34 raeburn 8734: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8735: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8736: }
1.27 raeburn 8737: }
1.34 raeburn 8738: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8739: foreach my $item (@contexts) {
1.43 raeburn 8740: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8741: if ($cancreate{$item} ne 'any') {
8742: push(@{$changes{'cancreate'}},$item);
8743: }
8744: } else {
8745: if ($cancreate{$item} ne 'none') {
8746: push(@{$changes{'cancreate'}},$item);
8747: }
1.27 raeburn 8748: }
8749: }
8750: } else {
1.43 raeburn 8751: foreach my $item (@contexts) {
1.34 raeburn 8752: push(@{$changes{'cancreate'}},$item);
8753: }
1.27 raeburn 8754: }
1.34 raeburn 8755:
1.27 raeburn 8756: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8757: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8758: if (!grep(/^\Q$type\E$/,@username_rule)) {
8759: push(@{$changes{'username_rule'}},$type);
8760: }
8761: }
8762: foreach my $type (@username_rule) {
8763: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8764: push(@{$changes{'username_rule'}},$type);
8765: }
8766: }
8767: } else {
8768: push(@{$changes{'username_rule'}},@username_rule);
8769: }
8770:
1.32 raeburn 8771: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8772: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8773: if (!grep(/^\Q$type\E$/,@id_rule)) {
8774: push(@{$changes{'id_rule'}},$type);
8775: }
8776: }
8777: foreach my $type (@id_rule) {
8778: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8779: push(@{$changes{'id_rule'}},$type);
8780: }
8781: }
8782: } else {
8783: push(@{$changes{'id_rule'}},@id_rule);
8784: }
8785:
1.43 raeburn 8786: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8787: my @authtypes = ('int','krb4','krb5','loc');
8788: my %authhash;
1.43 raeburn 8789: foreach my $item (@authen_contexts) {
1.28 raeburn 8790: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8791: foreach my $auth (@authtypes) {
8792: if (grep(/^\Q$auth\E$/,@authallowed)) {
8793: $authhash{$item}{$auth} = 1;
8794: } else {
8795: $authhash{$item}{$auth} = 0;
8796: }
8797: }
8798: }
8799: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8800: foreach my $item (@authen_contexts) {
1.28 raeburn 8801: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8802: foreach my $auth (@authtypes) {
8803: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8804: push(@{$changes{'authtypes'}},$item);
8805: last;
8806: }
8807: }
8808: }
8809: }
8810: } else {
1.43 raeburn 8811: foreach my $item (@authen_contexts) {
1.28 raeburn 8812: push(@{$changes{'authtypes'}},$item);
8813: }
8814: }
8815:
1.160.6.34 raeburn 8816: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8817: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8818: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8819: $save_usercreate{'id_rule'} = \@id_rule;
8820: $save_usercreate{'username_rule'} = \@username_rule,
8821: $save_usercreate{'authtypes'} = \%authhash;
8822:
1.27 raeburn 8823: my %usercreation_hash = (
1.160.6.34 raeburn 8824: usercreation => \%save_usercreate,
8825: );
1.27 raeburn 8826:
8827: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8828: $dom);
1.50 raeburn 8829:
1.160.6.34 raeburn 8830: if ($putresult eq 'ok') {
8831: if (keys(%changes) > 0) {
8832: $resulttext = &mt('Changes made:').'<ul>';
8833: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8834: my %lt = &usercreation_types();
8835: foreach my $type (@{$changes{'cancreate'}}) {
8836: my $chgtext = $lt{$type}.', ';
8837: if ($cancreate{$type} eq 'none') {
8838: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8839: } elsif ($cancreate{$type} eq 'any') {
8840: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8841: } elsif ($cancreate{$type} eq 'official') {
8842: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8843: } elsif ($cancreate{$type} eq 'unofficial') {
8844: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8845: }
8846: $resulttext .= '<li>'.$chgtext.'</li>';
8847: }
8848: }
8849: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8850: my ($rules,$ruleorder) =
8851: &Apache::lonnet::inst_userrules($dom,'username');
8852: my $chgtext = '<ul>';
8853: foreach my $type (@username_rule) {
8854: if (ref($rules->{$type}) eq 'HASH') {
8855: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8856: }
8857: }
8858: $chgtext .= '</ul>';
8859: if (@username_rule > 0) {
8860: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8861: } else {
8862: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8863: }
8864: }
8865: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8866: my ($idrules,$idruleorder) =
8867: &Apache::lonnet::inst_userrules($dom,'id');
8868: my $chgtext = '<ul>';
8869: foreach my $type (@id_rule) {
8870: if (ref($idrules->{$type}) eq 'HASH') {
8871: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8872: }
8873: }
8874: $chgtext .= '</ul>';
8875: if (@id_rule > 0) {
8876: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8877: } else {
8878: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8879: }
8880: }
8881: my %authname = &authtype_names();
8882: my %context_title = &context_names();
8883: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8884: my $chgtext = '<ul>';
8885: foreach my $type (@{$changes{'authtypes'}}) {
8886: my @allowed;
8887: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8888: foreach my $auth (@authtypes) {
8889: if ($authhash{$type}{$auth}) {
8890: push(@allowed,$authname{$auth});
8891: }
8892: }
8893: if (@allowed > 0) {
8894: $chgtext .= join(', ',@allowed).'</li>';
8895: } else {
8896: $chgtext .= &mt('none').'</li>';
8897: }
8898: }
8899: $chgtext .= '</ul>';
8900: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8901: $resulttext .= '</li>';
8902: }
8903: $resulttext .= '</ul>';
8904: } else {
8905: $resulttext = &mt('No changes made to user creation settings');
8906: }
8907: } else {
8908: $resulttext = '<span class="LC_error">'.
8909: &mt('An error occurred: [_1]',$putresult).'</span>';
8910: }
8911: if ($warningmsg ne '') {
8912: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8913: }
8914: return $resulttext;
8915: }
8916:
8917: sub modify_selfcreation {
8918: my ($dom,%domconfig) = @_;
8919: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8920: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8921: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8922: if (ref($types) eq 'ARRAY') {
8923: $usertypes->{'default'} = $othertitle;
8924: push(@{$types},'default');
8925: }
1.160.6.34 raeburn 8926: #
8927: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8928: #
8929: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8930: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8931: if ($key eq 'cancreate') {
8932: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8933: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8934: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8935: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 8936: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 8937: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 8938: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 8939: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8940: } else {
8941: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8942: }
8943: }
8944: }
8945: } elsif ($key eq 'email_rule') {
8946: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8947: } else {
8948: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8949: }
8950: }
8951: }
8952: #
8953: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8954: #
8955: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8956: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8957: if ($key eq 'selfcreate') {
8958: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8959: } else {
8960: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8961: }
8962: }
8963: }
8964:
8965: my @contexts = ('selfcreate');
8966: @{$cancreate{'selfcreate'}} = ();
8967: %{$cancreate{'emailusername'}} = ();
8968: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8969: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 8970: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8971: my %selfcreatetypes = (
8972: sso => 'users authenticated by institutional single sign on',
8973: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8974: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8975: );
1.160.6.34 raeburn 8976: #
8977: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8978: # is permitted.
8979: #
1.160.6.40 raeburn 8980:
8981: my @statuses;
8982: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8983: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8984: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8985: }
8986: }
8987: push(@statuses,'default');
8988:
1.160.6.35 raeburn 8989: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8990: if ($item eq 'email') {
1.160.6.40 raeburn 8991: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8992: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8993: push(@contexts,'selfcreateprocessing');
8994: foreach my $type (@statuses) {
8995: if ($type eq 'default') {
8996: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8997: } else {
8998: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8999: }
9000: }
1.160.6.34 raeburn 9001: }
9002: } else {
9003: if ($env{'form.cancreate_'.$item}) {
9004: push(@{$cancreate{'selfcreate'}},$item);
9005: }
9006: }
9007: }
9008: my (@email_rule,%userinfo,%savecaptcha);
9009: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9010: #
1.160.6.35 raeburn 9011: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9012: # 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 9013: #
1.160.6.40 raeburn 9014:
1.160.6.48 raeburn 9015: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9016: push(@contexts,'emailusername');
1.160.6.35 raeburn 9017: if (ref($types) eq 'ARRAY') {
9018: foreach my $type (@{$types}) {
9019: if (ref($infofields) eq 'ARRAY') {
9020: foreach my $field (@{$infofields}) {
9021: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9022: $cancreate{'emailusername'}{$type}{$field} = $1;
9023: }
9024: }
1.160.6.34 raeburn 9025: }
9026: }
9027: }
9028: #
9029: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9030: # queued requests for self-creation of account using e-mail address as username
9031: #
9032:
9033: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9034: @approvalnotify = sort(@approvalnotify);
9035: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9036: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9037: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9038: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9039: push(@{$changes{'cancreate'}},'notify');
9040: }
9041: } else {
9042: if ($cancreate{'notify'}{'approval'}) {
9043: push(@{$changes{'cancreate'}},'notify');
9044: }
9045: }
9046: } elsif ($cancreate{'notify'}{'approval'}) {
9047: push(@{$changes{'cancreate'}},'notify');
9048: }
9049:
9050: #
9051: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9052: #
9053: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9054: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9055: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9056: if (@{$curr_usercreation{'email_rule'}} > 0) {
9057: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9058: if (!grep(/^\Q$type\E$/,@email_rule)) {
9059: push(@{$changes{'email_rule'}},$type);
9060: }
9061: }
9062: }
9063: if (@email_rule > 0) {
9064: foreach my $type (@email_rule) {
9065: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9066: push(@{$changes{'email_rule'}},$type);
9067: }
9068: }
9069: }
9070: } elsif (@email_rule > 0) {
9071: push(@{$changes{'email_rule'}},@email_rule);
9072: }
9073: }
9074: #
1.160.6.40 raeburn 9075: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9076: # institutional log-in.
9077: #
9078: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9079: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9080: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9081: ($domdefaults{'auth_def'} eq 'localauth'))) {
9082: $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.').' '.
9083: &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.');
9084: }
9085: }
9086: my @fields = ('lastname','firstname','middlename','generation',
9087: 'permanentemail','id');
1.160.6.44 raeburn 9088: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9089: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9090: #
9091: # Where usernames may created for institutional log-in and/or institutional single sign on:
9092: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9093: # may self-create accounts
9094: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9095: # which the user may supply, if institutional data is unavailable.
9096: #
9097: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9098: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9099: if (@{$types} > 1) {
1.160.6.34 raeburn 9100: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9101: push(@contexts,'statustocreate');
9102: } else {
9103: undef($cancreate{'statustocreate'});
9104: }
9105: foreach my $type (@{$types}) {
9106: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9107: foreach my $field (@fields) {
9108: if (grep(/^\Q$field\E$/,@modifiable)) {
9109: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9110: } else {
9111: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9112: }
9113: }
9114: }
9115: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9116: foreach my $type (@{$types}) {
9117: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9118: foreach my $field (@fields) {
9119: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9120: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9121: push(@{$changes{'selfcreate'}},$type);
9122: last;
9123: }
9124: }
9125: }
9126: }
9127: } else {
9128: foreach my $type (@{$types}) {
9129: push(@{$changes{'selfcreate'}},$type);
9130: }
9131: }
9132: }
1.160.6.44 raeburn 9133: foreach my $field (@shibfields) {
9134: if ($env{'form.shibenv_'.$field} ne '') {
9135: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9136: }
9137: }
9138: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9139: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9140: foreach my $field (@shibfields) {
9141: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9142: push(@{$changes{'cancreate'}},'shibenv');
9143: }
9144: }
9145: } else {
9146: foreach my $field (@shibfields) {
9147: if ($env{'form.shibenv_'.$field}) {
9148: push(@{$changes{'cancreate'}},'shibenv');
9149: last;
9150: }
9151: }
9152: }
9153: }
1.160.6.34 raeburn 9154: }
9155: foreach my $item (@contexts) {
9156: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9157: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9158: if (ref($cancreate{$item}) eq 'ARRAY') {
9159: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9160: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9161: push(@{$changes{'cancreate'}},$item);
9162: }
9163: }
9164: }
9165: }
9166: if (ref($cancreate{$item}) eq 'ARRAY') {
9167: foreach my $type (@{$cancreate{$item}}) {
9168: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9169: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9170: push(@{$changes{'cancreate'}},$item);
9171: }
9172: }
9173: }
9174: }
9175: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9176: if (ref($cancreate{$item}) eq 'HASH') {
9177: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 9178: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9179: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9180: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9181: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9182: push(@{$changes{'cancreate'}},$item);
9183: }
9184: }
9185: }
1.160.6.40 raeburn 9186: } elsif ($item eq 'selfcreateprocessing') {
9187: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9188: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9189: push(@{$changes{'cancreate'}},$item);
9190: }
9191: }
1.160.6.35 raeburn 9192: } else {
9193: if (!$cancreate{$item}{$curr}) {
9194: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9195: push(@{$changes{'cancreate'}},$item);
9196: }
1.160.6.34 raeburn 9197: }
9198: }
9199: }
9200: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 9201: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9202: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9203: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9204: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9205: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9206: push(@{$changes{'cancreate'}},$item);
9207: }
9208: }
9209: } else {
9210: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9211: push(@{$changes{'cancreate'}},$item);
9212: }
9213: }
9214: }
1.160.6.40 raeburn 9215: } elsif ($item eq 'selfcreateprocessing') {
9216: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
9217: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9218: push(@{$changes{'cancreate'}},$item);
9219: }
9220: }
1.160.6.35 raeburn 9221: } else {
9222: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
9223: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9224: push(@{$changes{'cancreate'}},$item);
9225: }
1.160.6.34 raeburn 9226: }
9227: }
9228: }
9229: }
9230: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9231: if (ref($cancreate{$item}) eq 'ARRAY') {
9232: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9233: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9234: push(@{$changes{'cancreate'}},$item);
9235: }
9236: }
9237: } elsif (ref($cancreate{$item}) eq 'HASH') {
9238: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9239: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9240: push(@{$changes{'cancreate'}},$item);
9241: }
9242: }
9243: }
9244: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 9245: if (ref($cancreate{$item}) eq 'HASH') {
9246: foreach my $type (keys(%{$cancreate{$item}})) {
9247: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9248: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9249: if ($cancreate{$item}{$type}{$field}) {
9250: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9251: push(@{$changes{'cancreate'}},$item);
9252: }
9253: last;
9254: }
9255: }
9256: }
9257: }
1.160.6.34 raeburn 9258: }
9259: }
9260: }
9261: #
9262: # Populate %save_usercreate hash with updates to self-creation configuration.
9263: #
9264: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9265: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 9266: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 9267: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9268: if (ref($cancreate{'notify'}) eq 'HASH') {
9269: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9270: }
1.160.6.40 raeburn 9271: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9272: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9273: }
1.160.6.34 raeburn 9274: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9275: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9276: }
1.160.6.44 raeburn 9277: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9278: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9279: }
1.160.6.34 raeburn 9280: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9281: $save_usercreate{'emailrule'} = \@email_rule;
9282:
9283: my %userconfig_hash = (
9284: usercreation => \%save_usercreate,
9285: usermodification => \%save_usermodify,
9286: );
9287: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9288: $dom);
9289: #
9290: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9291: #
1.27 raeburn 9292: if ($putresult eq 'ok') {
9293: if (keys(%changes) > 0) {
9294: $resulttext = &mt('Changes made:').'<ul>';
9295: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 9296: my %lt = &selfcreation_types();
1.34 raeburn 9297: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9298: my $chgtext;
1.45 raeburn 9299: if ($type eq 'selfcreate') {
1.50 raeburn 9300: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 9301: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9302: } else {
1.160.6.34 raeburn 9303: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9304: '<ul>';
1.50 raeburn 9305: foreach my $case (@{$cancreate{$type}}) {
9306: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9307: }
9308: $chgtext .= '</ul>';
1.100 raeburn 9309: if (ref($cancreate{$type}) eq 'ARRAY') {
9310: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9311: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9312: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 9313: $chgtext .= '<br />'.
9314: '<span class="LC_warning">'.
9315: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9316: '</span>';
1.100 raeburn 9317: }
9318: }
9319: }
9320: }
1.43 raeburn 9321: }
1.160.6.44 raeburn 9322: } elsif ($type eq 'shibenv') {
9323: if (keys(%{$cancreate{$type}}) == 0) {
9324: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9325: } else {
9326: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9327: '<ul>';
9328: foreach my $field (@shibfields) {
9329: next if ($cancreate{$type}{$field} eq '');
9330: if ($field eq 'inststatus') {
9331: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9332: } else {
9333: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9334: }
9335: }
9336: $chgtext .= '</ul>';
9337: }
1.93 raeburn 9338: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9339: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9340: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9341: if (@{$cancreate{'selfcreate'}} > 0) {
9342: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9343: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9344: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9345: $chgtext .= '<br />'.
9346: '<span class="LC_warning">'.
9347: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9348: '</span>';
9349: }
1.96 raeburn 9350: } elsif (ref($usertypes) eq 'HASH') {
9351: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9352: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9353: } else {
9354: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9355: }
9356: $chgtext .= '<ul>';
9357: foreach my $case (@{$cancreate{$type}}) {
9358: if ($case eq 'default') {
9359: $chgtext .= '<li>'.$othertitle.'</li>';
9360: } else {
9361: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9362: }
9363: }
1.100 raeburn 9364: $chgtext .= '</ul>';
9365: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 9366: $chgtext .= '<br /><span class="LC_warning">'.
9367: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9368: '</span>';
1.100 raeburn 9369: }
9370: }
9371: } else {
9372: if (@{$cancreate{$type}} == 0) {
9373: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9374: } else {
9375: $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 9376: }
9377: }
9378: }
1.160.6.40 raeburn 9379: } elsif ($type eq 'selfcreateprocessing') {
9380: my %choices = &Apache::lonlocal::texthash (
9381: automatic => 'Automatic approval',
9382: approval => 'Queued for approval',
9383: );
9384: if (@statuses > 1) {
9385: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9386: '<ul>';
9387: foreach my $type (@statuses) {
9388: if ($type eq 'default') {
9389: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9390: } else {
9391: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9392: }
9393: }
9394: $chgtext .= '</ul>';
9395: } else {
9396: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9397: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9398: }
1.160.6.5 raeburn 9399: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 9400: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 9401: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9402: } else {
9403: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 9404: if ($captchas{$savecaptcha{$type}}) {
9405: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 9406: } else {
9407: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
9408: }
9409: }
9410: } elsif ($type eq 'recaptchakeys') {
9411: my ($privkey,$pubkey);
1.160.6.34 raeburn 9412: if (ref($savecaptcha{$type}) eq 'HASH') {
9413: $pubkey = $savecaptcha{$type}{'public'};
9414: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 9415: }
9416: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9417: if (!$pubkey) {
9418: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9419: } else {
9420: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9421: }
9422: if (!$privkey) {
9423: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9424: } else {
9425: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9426: }
9427: $chgtext .= '</ul>';
1.160.6.69 raeburn 9428: } elsif ($type eq 'recaptchaversion') {
9429: if ($savecaptcha{'captcha'} eq 'recaptcha') {
9430: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
9431: }
1.160.6.34 raeburn 9432: } elsif ($type eq 'emailusername') {
9433: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 9434: if (ref($types) eq 'ARRAY') {
9435: foreach my $type (@{$types}) {
9436: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9437: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 9438: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 9439: '<ul>';
9440: foreach my $field (@{$infofields}) {
9441: if ($cancreate{'emailusername'}{$type}{$field}) {
9442: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9443: }
9444: }
1.160.6.50 raeburn 9445: $chgtext .= '</ul>';
9446: } else {
9447: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35 raeburn 9448: }
9449: } else {
1.160.6.50 raeburn 9450: $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 9451: }
9452: }
9453: }
9454: }
9455: } elsif ($type eq 'notify') {
9456: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9457: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9458: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9459: if ($cancreate{'notify'}{'approval'}) {
9460: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9461: }
9462: }
1.43 raeburn 9463: }
1.34 raeburn 9464: }
1.160.6.34 raeburn 9465: if ($chgtext) {
9466: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9467: }
9468: }
9469: }
1.43 raeburn 9470: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9471: my ($emailrules,$emailruleorder) =
9472: &Apache::lonnet::inst_userrules($dom,'email');
9473: my $chgtext = '<ul>';
9474: foreach my $type (@email_rule) {
9475: if (ref($emailrules->{$type}) eq 'HASH') {
9476: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9477: }
9478: }
9479: $chgtext .= '</ul>';
9480: if (@email_rule > 0) {
1.160.6.34 raeburn 9481: $resulttext .= '<li>'.
9482: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9483: $chgtext.
9484: '</li>';
1.43 raeburn 9485: } else {
1.160.6.34 raeburn 9486: $resulttext .= '<li>'.
9487: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9488: '</li>';
1.43 raeburn 9489: }
9490: }
1.160.6.34 raeburn 9491: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9492: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9493: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9494: foreach my $type (@{$changes{'selfcreate'}}) {
9495: my $typename = $type;
9496: if (ref($usertypes) eq 'HASH') {
9497: if ($usertypes->{$type} ne '') {
9498: $typename = $usertypes->{$type};
1.28 raeburn 9499: }
9500: }
1.160.6.34 raeburn 9501: my @modifiable;
9502: $resulttext .= '<li>'.
9503: &mt('Self-creation of account by users with status: [_1]',
9504: '<span class="LC_cusr_emph">'.$typename.'</span>').
9505: ' - '.&mt('modifiable fields (if institutional data blank): ');
9506: foreach my $field (@fields) {
9507: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9508: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
9509: }
9510: }
9511: if (@modifiable > 0) {
9512: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9513: } else {
1.160.6.34 raeburn 9514: $resulttext .= &mt('none');
1.43 raeburn 9515: }
1.160.6.34 raeburn 9516: $resulttext .= '</li>';
1.28 raeburn 9517: }
1.160.6.34 raeburn 9518: $resulttext .= '</ul></li>';
1.28 raeburn 9519: }
1.27 raeburn 9520: $resulttext .= '</ul>';
9521: } else {
1.160.6.34 raeburn 9522: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9523: }
9524: } else {
9525: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9526: &mt('An error occurred: [_1]',$putresult).'</span>';
9527: }
1.43 raeburn 9528: if ($warningmsg ne '') {
9529: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9530: }
1.23 raeburn 9531: return $resulttext;
9532: }
9533:
1.160.6.5 raeburn 9534: sub process_captcha {
9535: my ($container,$changes,$newsettings,$current) = @_;
9536: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9537: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9538: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9539: $newsettings->{'captcha'} = 'original';
9540: }
9541: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
9542: if ($container eq 'cancreate') {
9543: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9544: push(@{$changes->{'cancreate'}},'captcha');
9545: } elsif (!defined($changes->{'cancreate'})) {
9546: $changes->{'cancreate'} = ['captcha'];
9547: }
9548: } else {
9549: $changes->{'captcha'} = 1;
9550: }
9551: }
1.160.6.69 raeburn 9552: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 9553: if ($newsettings->{'captcha'} eq 'recaptcha') {
9554: $newpub = $env{'form.'.$container.'_recaptchapub'};
9555: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 9556: $newpub =~ s/[^\w\-]//g;
9557: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 9558: $newsettings->{'recaptchakeys'} = {
9559: public => $newpub,
9560: private => $newpriv,
9561: };
1.160.6.69 raeburn 9562: $newversion = $env{'form.'.$container.'_recaptchaversion'};
9563: $newversion =~ s/\D//g;
9564: if ($newversion ne '2') {
9565: $newversion = 1;
9566: }
9567: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 9568: }
9569: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9570: $currpub = $current->{'recaptchakeys'}{'public'};
9571: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 9572: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9573: $newsettings->{'recaptchakeys'} = {
9574: public => '',
9575: private => '',
9576: }
9577: }
1.160.6.5 raeburn 9578: }
1.160.6.69 raeburn 9579: if ($current->{'captcha'} eq 'recaptcha') {
9580: $currversion = $current->{'recaptchaversion'};
9581: if ($currversion ne '2') {
9582: $currversion = 1;
9583: }
9584: }
9585: if ($currversion ne $newversion) {
9586: if ($container eq 'cancreate') {
9587: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9588: push(@{$changes->{'cancreate'}},'recaptchaversion');
9589: } elsif (!defined($changes->{'cancreate'})) {
9590: $changes->{'cancreate'} = ['recaptchaversion'];
9591: }
9592: } else {
9593: $changes->{'recaptchaversion'} = 1;
9594: }
9595: }
1.160.6.5 raeburn 9596: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
9597: if ($container eq 'cancreate') {
9598: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9599: push(@{$changes->{'cancreate'}},'recaptchakeys');
9600: } elsif (!defined($changes->{'cancreate'})) {
9601: $changes->{'cancreate'} = ['recaptchakeys'];
9602: }
9603: } else {
9604: $changes->{'recaptchakeys'} = 1;
9605: }
9606: }
9607: return;
9608: }
9609:
1.33 raeburn 9610: sub modify_usermodification {
9611: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9612: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9613: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9614: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 9615: if ($key eq 'selfcreate') {
9616: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9617: } else {
9618: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9619: }
1.33 raeburn 9620: }
9621: }
1.160.6.34 raeburn 9622: my @contexts = ('author','course');
1.33 raeburn 9623: my %context_title = (
9624: author => 'In author context',
9625: course => 'In course context',
9626: );
9627: my @fields = ('lastname','firstname','middlename','generation',
9628: 'permanentemail','id');
9629: my %roles = (
9630: author => ['ca','aa'],
9631: course => ['st','ep','ta','in','cr'],
9632: );
9633: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9634: foreach my $context (@contexts) {
9635: foreach my $role (@{$roles{$context}}) {
9636: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9637: foreach my $item (@fields) {
9638: if (grep(/^\Q$item\E$/,@modifiable)) {
9639: $modifyhash{$context}{$role}{$item} = 1;
9640: } else {
9641: $modifyhash{$context}{$role}{$item} = 0;
9642: }
9643: }
9644: }
9645: if (ref($curr_usermodification{$context}) eq 'HASH') {
9646: foreach my $role (@{$roles{$context}}) {
9647: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9648: foreach my $field (@fields) {
9649: if ($modifyhash{$context}{$role}{$field} ne
9650: $curr_usermodification{$context}{$role}{$field}) {
9651: push(@{$changes{$context}},$role);
9652: last;
9653: }
9654: }
9655: }
9656: }
9657: } else {
9658: foreach my $context (@contexts) {
9659: foreach my $role (@{$roles{$context}}) {
9660: push(@{$changes{$context}},$role);
9661: }
9662: }
9663: }
9664: }
9665: my %usermodification_hash = (
9666: usermodification => \%modifyhash,
9667: );
9668: my $putresult = &Apache::lonnet::put_dom('configuration',
9669: \%usermodification_hash,$dom);
9670: if ($putresult eq 'ok') {
9671: if (keys(%changes) > 0) {
9672: $resulttext = &mt('Changes made: ').'<ul>';
9673: foreach my $context (@contexts) {
9674: if (ref($changes{$context}) eq 'ARRAY') {
9675: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9676: if (ref($changes{$context}) eq 'ARRAY') {
9677: foreach my $role (@{$changes{$context}}) {
9678: my $rolename;
1.160.6.34 raeburn 9679: if ($role eq 'cr') {
9680: $rolename = &mt('Custom');
1.33 raeburn 9681: } else {
1.160.6.34 raeburn 9682: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9683: }
9684: my @modifiable;
1.160.6.34 raeburn 9685: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9686: foreach my $field (@fields) {
9687: if ($modifyhash{$context}{$role}{$field}) {
9688: push(@modifiable,$fieldtitles{$field});
9689: }
9690: }
9691: if (@modifiable > 0) {
9692: $resulttext .= join(', ',@modifiable);
9693: } else {
9694: $resulttext .= &mt('none');
9695: }
9696: $resulttext .= '</li>';
9697: }
9698: $resulttext .= '</ul></li>';
9699: }
9700: }
9701: }
9702: $resulttext .= '</ul>';
9703: } else {
9704: $resulttext = &mt('No changes made to user modification settings');
9705: }
9706: } else {
9707: $resulttext = '<span class="LC_error">'.
9708: &mt('An error occurred: [_1]',$putresult).'</span>';
9709: }
9710: return $resulttext;
9711: }
9712:
1.43 raeburn 9713: sub modify_defaults {
1.160.6.27 raeburn 9714: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9715: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9716: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9717: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9718: my @authtypes = ('internal','krb4','krb5','localauth');
9719: foreach my $item (@items) {
9720: $newvalues{$item} = $env{'form.'.$item};
9721: if ($item eq 'auth_def') {
9722: if ($newvalues{$item} ne '') {
9723: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9724: push(@errors,$item);
9725: }
9726: }
9727: } elsif ($item eq 'lang_def') {
9728: if ($newvalues{$item} ne '') {
9729: if ($newvalues{$item} =~ /^(\w+)/) {
9730: my $langcode = $1;
1.103 raeburn 9731: if ($langcode ne 'x_chef') {
9732: if (code2language($langcode) eq '') {
9733: push(@errors,$item);
9734: }
1.43 raeburn 9735: }
9736: } else {
9737: push(@errors,$item);
9738: }
9739: }
1.54 raeburn 9740: } elsif ($item eq 'timezone_def') {
9741: if ($newvalues{$item} ne '') {
1.62 raeburn 9742: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9743: push(@errors,$item);
9744: }
9745: }
1.68 raeburn 9746: } elsif ($item eq 'datelocale_def') {
9747: if ($newvalues{$item} ne '') {
9748: my @datelocale_ids = DateTime::Locale->ids();
9749: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9750: push(@errors,$item);
9751: }
9752: }
1.141 raeburn 9753: } elsif ($item eq 'portal_def') {
9754: if ($newvalues{$item} ne '') {
9755: 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])\/?$/) {
9756: push(@errors,$item);
9757: }
9758: }
1.43 raeburn 9759: }
9760: if (grep(/^\Q$item\E$/,@errors)) {
9761: $newvalues{$item} = $domdefaults{$item};
9762: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9763: $changes{$item} = 1;
9764: }
1.72 raeburn 9765: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9766: }
9767: my %defaults_hash = (
1.72 raeburn 9768: defaults => \%newvalues,
9769: );
1.43 raeburn 9770: my $title = &defaults_titles();
1.160.6.40 raeburn 9771:
9772: my $currinststatus;
9773: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9774: $currinststatus = $domconfig{'inststatus'};
9775: } else {
9776: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9777: $currinststatus = {
9778: inststatustypes => $usertypes,
9779: inststatusorder => $types,
9780: inststatusguest => [],
9781: };
9782: }
9783: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9784: my @allpos;
9785: my %guests;
9786: my %alltypes;
9787: my ($currtitles,$currguests,$currorder);
9788: if (ref($currinststatus) eq 'HASH') {
9789: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9790: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9791: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9792: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9793: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9794: }
9795: }
9796: unless (grep(/^\Q$type\E$/,@todelete)) {
9797: my $position = $env{'form.inststatus_pos_'.$type};
9798: $position =~ s/\D+//g;
9799: $allpos[$position] = $type;
9800: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9801: $alltypes{$type} =~ s/`//g;
9802: if ($env{'form.inststatus_guest_'.$type}) {
9803: $guests{$type} = 1;
9804: }
9805: }
9806: }
9807: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9808: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9809: }
9810: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9811: $currtitles =~ s/,$//;
9812: }
9813: }
9814: if ($env{'form.addinststatus'}) {
9815: my $newtype = $env{'form.addinststatus'};
9816: $newtype =~ s/\W//g;
9817: unless (exists($alltypes{$newtype})) {
9818: if ($env{'form.addinststatus_guest'}) {
9819: $guests{$newtype} = 1;
9820: }
9821: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9822: $alltypes{$newtype} =~ s/`//g;
9823: my $position = $env{'form.addinststatus_pos'};
9824: $position =~ s/\D+//g;
9825: if ($position ne '') {
9826: $allpos[$position] = $newtype;
9827: }
9828: }
9829: }
9830: my (@orderedstatus,@orderedguests);
9831: foreach my $type (@allpos) {
9832: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9833: push(@orderedstatus,$type);
9834: if ($guests{$type}) {
9835: push(@orderedguests,$type);
9836: }
9837: }
9838: }
9839: foreach my $type (keys(%alltypes)) {
9840: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9841: delete($alltypes{$type});
9842: }
9843: }
9844: $defaults_hash{'inststatus'} = {
9845: inststatustypes => \%alltypes,
9846: inststatusorder => \@orderedstatus,
9847: inststatusguest => \@orderedguests,
9848: };
9849: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9850: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9851: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9852: }
9853: }
9854: if ($currorder ne join(',',@orderedstatus)) {
9855: $changes{'inststatus'}{'inststatusorder'} = 1;
9856: }
9857: if ($currguests ne join(',',@orderedguests)) {
9858: $changes{'inststatus'}{'inststatusguest'} = 1;
9859: }
9860: my $newtitles;
9861: foreach my $item (@orderedstatus) {
9862: $newtitles .= $alltypes{$item}.',';
9863: }
9864: $newtitles =~ s/,$//;
9865: if ($currtitles ne $newtitles) {
9866: $changes{'inststatus'}{'inststatustypes'} = 1;
9867: }
1.43 raeburn 9868: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9869: $dom);
9870: if ($putresult eq 'ok') {
9871: if (keys(%changes) > 0) {
9872: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9873: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9874: 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";
9875: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9876: if ($item eq 'inststatus') {
9877: if (ref($changes{'inststatus'}) eq 'HASH') {
9878: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9879: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9880: foreach my $type (@orderedstatus) {
9881: $resulttext .= $alltypes{$type}.', ';
9882: }
9883: $resulttext =~ s/, $//;
9884: $resulttext .= '</li>';
9885: }
9886: if ($changes{'inststatus'}{'inststatusguest'}) {
9887: $resulttext .= '<li>';
9888: if (@orderedguests) {
9889: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9890: foreach my $type (@orderedguests) {
9891: $resulttext .= $alltypes{$type}.', ';
9892: }
9893: $resulttext =~ s/, $//;
9894: } else {
9895: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9896: }
9897: $resulttext .= '</li>';
9898: }
9899: }
9900: } else {
9901: my $value = $env{'form.'.$item};
9902: if ($value eq '') {
9903: $value = &mt('none');
9904: } elsif ($item eq 'auth_def') {
9905: my %authnames = &authtype_names();
9906: my %shortauth = (
9907: internal => 'int',
9908: krb4 => 'krb4',
9909: krb5 => 'krb5',
9910: localauth => 'loc',
9911: );
9912: $value = $authnames{$shortauth{$value}};
9913: }
9914: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9915: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9916: }
9917: }
9918: $resulttext .= '</ul>';
9919: $mailmsgtext .= "\n";
9920: my $cachetime = 24*60*60;
1.72 raeburn 9921: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9922: if (ref($lastactref) eq 'HASH') {
9923: $lastactref->{'domdefaults'} = 1;
9924: }
1.68 raeburn 9925: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9926: my $notify = 1;
9927: if (ref($domconfig{'contacts'}) eq 'HASH') {
9928: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9929: $notify = 0;
9930: }
9931: }
9932: if ($notify) {
9933: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9934: "LON-CAPA Domain Settings Change - $dom",
9935: $mailmsgtext);
9936: }
1.54 raeburn 9937: }
1.43 raeburn 9938: } else {
1.54 raeburn 9939: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9940: }
9941: } else {
9942: $resulttext = '<span class="LC_error">'.
9943: &mt('An error occurred: [_1]',$putresult).'</span>';
9944: }
9945: if (@errors > 0) {
9946: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9947: foreach my $item (@errors) {
9948: $resulttext .= ' "'.$title->{$item}.'",';
9949: }
9950: $resulttext =~ s/,$//;
9951: }
9952: return $resulttext;
9953: }
9954:
1.46 raeburn 9955: sub modify_scantron {
1.160.6.24 raeburn 9956: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9957: my ($resulttext,%confhash,%changes,$errors);
9958: my $custom = 'custom.tab';
9959: my $default = 'default.tab';
9960: my $servadm = $r->dir_config('lonAdmEMail');
9961: my ($configuserok,$author_ok,$switchserver) =
9962: &config_check($dom,$confname,$servadm);
9963: if ($env{'form.scantronformat.filename'} ne '') {
9964: my $error;
9965: if ($configuserok eq 'ok') {
9966: if ($switchserver) {
1.130 raeburn 9967: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9968: } else {
9969: if ($author_ok eq 'ok') {
9970: my ($result,$scantronurl) =
9971: &publishlogo($r,'upload','scantronformat',$dom,
9972: $confname,'scantron','','',$custom);
9973: if ($result eq 'ok') {
9974: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9975: $changes{'scantronformat'} = 1;
1.46 raeburn 9976: } else {
9977: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9978: }
9979: } else {
9980: $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);
9981: }
9982: }
9983: } else {
9984: $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);
9985: }
9986: if ($error) {
9987: &Apache::lonnet::logthis($error);
9988: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9989: }
9990: }
1.48 raeburn 9991: if (ref($domconfig{'scantron'}) eq 'HASH') {
9992: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9993: if ($env{'form.scantronformat_del'}) {
9994: $confhash{'scantron'}{'scantronformat'} = '';
9995: $changes{'scantronformat'} = 1;
1.46 raeburn 9996: }
9997: }
9998: }
9999: if (keys(%confhash) > 0) {
10000: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10001: $dom);
10002: if ($putresult eq 'ok') {
10003: if (keys(%changes) > 0) {
1.48 raeburn 10004: if (ref($confhash{'scantron'}) eq 'HASH') {
10005: $resulttext = &mt('Changes made:').'<ul>';
10006: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10007: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10008: } else {
1.130 raeburn 10009: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10010: }
1.48 raeburn 10011: $resulttext .= '</ul>';
10012: } else {
1.130 raeburn 10013: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10014: }
10015: $resulttext .= '</ul>';
10016: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10017: if (ref($lastactref) eq 'HASH') {
10018: $lastactref->{'domainconfig'} = 1;
10019: }
1.46 raeburn 10020: } else {
1.130 raeburn 10021: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10022: }
10023: } else {
10024: $resulttext = '<span class="LC_error">'.
10025: &mt('An error occurred: [_1]',$putresult).'</span>';
10026: }
10027: } else {
1.130 raeburn 10028: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10029: }
10030: if ($errors) {
10031: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10032: $errors.'</ul>';
10033: }
10034: return $resulttext;
10035: }
10036:
1.48 raeburn 10037: sub modify_coursecategories {
1.160.6.43 raeburn 10038: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10039: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10040: $cathash);
1.48 raeburn 10041: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10042: my @catitems = ('unauth','auth');
10043: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10044: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10045: $cathash = $domconfig{'coursecategories'}{'cats'};
10046: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10047: $changes{'togglecats'} = 1;
10048: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10049: }
10050: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10051: $changes{'categorize'} = 1;
10052: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10053: }
1.120 raeburn 10054: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10055: $changes{'togglecatscomm'} = 1;
10056: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10057: }
10058: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10059: $changes{'categorizecomm'} = 1;
10060: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10061: }
1.160.6.42 raeburn 10062: foreach my $item (@catitems) {
10063: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10064: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10065: $changes{$item} = 1;
10066: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10067: }
10068: }
10069: }
1.57 raeburn 10070: } else {
10071: $changes{'togglecats'} = 1;
10072: $changes{'categorize'} = 1;
1.124 raeburn 10073: $changes{'togglecatscomm'} = 1;
10074: $changes{'categorizecomm'} = 1;
1.87 raeburn 10075: $domconfig{'coursecategories'} = {
10076: togglecats => $env{'form.togglecats'},
10077: categorize => $env{'form.categorize'},
1.124 raeburn 10078: togglecatscomm => $env{'form.togglecatscomm'},
10079: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10080: };
1.160.6.42 raeburn 10081: foreach my $item (@catitems) {
10082: if ($env{'form.coursecat_'.$item} ne 'std') {
10083: $changes{$item} = 1;
10084: }
10085: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10086: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10087: }
10088: }
1.57 raeburn 10089: }
10090: if (ref($cathash) eq 'HASH') {
10091: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10092: push (@deletecategory,'instcode::0');
10093: }
1.120 raeburn 10094: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10095: push(@deletecategory,'communities::0');
10096: }
1.48 raeburn 10097: }
1.57 raeburn 10098: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10099: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10100: if (@deletecategory > 0) {
10101: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10102: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10103: foreach my $item (@deletecategory) {
1.57 raeburn 10104: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10105: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10106: $deletions{$item} = 1;
1.57 raeburn 10107: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10108: }
10109: }
10110: }
1.57 raeburn 10111: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10112: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10113: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10114: $reorderings{$item} = 1;
1.57 raeburn 10115: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10116: }
10117: if ($env{'form.addcategory_name_'.$item} ne '') {
10118: my $newcat = $env{'form.addcategory_name_'.$item};
10119: my $newdepth = $depth+1;
10120: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10121: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10122: $adds{$newitem} = 1;
10123: }
10124: if ($env{'form.subcat_'.$item} ne '') {
10125: my $newcat = $env{'form.subcat_'.$item};
10126: my $newdepth = $depth+1;
10127: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10128: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10129: $adds{$newitem} = 1;
10130: }
10131: }
10132: }
10133: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10134: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10135: my $newitem = 'instcode::0';
1.57 raeburn 10136: if ($cathash->{$newitem} eq '') {
10137: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10138: $adds{$newitem} = 1;
10139: }
10140: } else {
10141: my $newitem = 'instcode::0';
1.57 raeburn 10142: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10143: $adds{$newitem} = 1;
10144: }
10145: }
1.120 raeburn 10146: if ($env{'form.communities'} eq '1') {
10147: if (ref($cathash) eq 'HASH') {
10148: my $newitem = 'communities::0';
10149: if ($cathash->{$newitem} eq '') {
10150: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10151: $adds{$newitem} = 1;
10152: }
10153: } else {
10154: my $newitem = 'communities::0';
10155: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10156: $adds{$newitem} = 1;
10157: }
10158: }
1.48 raeburn 10159: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10160: if (($env{'form.addcategory_name'} ne 'instcode') &&
10161: ($env{'form.addcategory_name'} ne 'communities')) {
10162: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10163: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10164: $adds{$newitem} = 1;
10165: }
1.48 raeburn 10166: }
1.57 raeburn 10167: my $putresult;
1.48 raeburn 10168: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10169: if (keys(%deletions) > 0) {
10170: foreach my $key (keys(%deletions)) {
10171: if ($predelallitems{$key} ne '') {
10172: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10173: }
10174: }
10175: }
10176: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10177: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10178: if (ref($chkcats[0]) eq 'ARRAY') {
10179: my $depth = 0;
10180: my $chg = 0;
10181: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10182: my $name = $chkcats[0][$i];
10183: my $item;
10184: if ($name eq '') {
10185: $chg ++;
10186: } else {
10187: $item = &escape($name).'::0';
10188: if ($chg) {
1.57 raeburn 10189: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10190: }
10191: $depth ++;
1.57 raeburn 10192: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10193: $depth --;
10194: }
10195: }
10196: }
1.57 raeburn 10197: }
10198: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10199: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10200: if ($putresult eq 'ok') {
1.57 raeburn 10201: my %title = (
1.120 raeburn 10202: togglecats => 'Show/Hide a course in catalog',
10203: categorize => 'Assign a category to a course',
10204: togglecatscomm => 'Show/Hide a community in catalog',
10205: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10206: );
10207: my %level = (
1.120 raeburn 10208: dom => 'set in Domain ("Modify Course/Community")',
10209: crs => 'set in Course ("Course Configuration")',
10210: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 10211: none => 'No catalog',
10212: std => 'Standard catalog',
10213: domonly => 'Domain-only catalog',
10214: codesrch => 'Code search form',
1.57 raeburn 10215: );
1.48 raeburn 10216: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 10217: if ($changes{'togglecats'}) {
10218: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
10219: }
10220: if ($changes{'categorize'}) {
10221: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 10222: }
1.120 raeburn 10223: if ($changes{'togglecatscomm'}) {
10224: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
10225: }
10226: if ($changes{'categorizecomm'}) {
10227: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
10228: }
1.160.6.42 raeburn 10229: if ($changes{'unauth'}) {
10230: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
10231: }
10232: if ($changes{'auth'}) {
10233: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
10234: }
1.57 raeburn 10235: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10236: my $cathash;
10237: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10238: $cathash = $domconfig{'coursecategories'}{'cats'};
10239: } else {
10240: $cathash = {};
10241: }
10242: my (@cats,@trails,%allitems);
10243: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
10244: if (keys(%deletions) > 0) {
10245: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
10246: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
10247: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
10248: }
10249: $resulttext .= '</ul></li>';
10250: }
10251: if (keys(%reorderings) > 0) {
10252: my %sort_by_trail;
10253: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10254: foreach my $key (keys(%reorderings)) {
10255: if ($allitems{$key} ne '') {
10256: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10257: }
1.48 raeburn 10258: }
1.57 raeburn 10259: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10260: $resulttext .= '<li>'.$trails[$trail].'</li>';
10261: }
10262: $resulttext .= '</ul></li>';
1.48 raeburn 10263: }
1.57 raeburn 10264: if (keys(%adds) > 0) {
10265: my %sort_by_trail;
10266: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10267: foreach my $key (keys(%adds)) {
10268: if ($allitems{$key} ne '') {
10269: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10270: }
10271: }
10272: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10273: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10274: }
1.57 raeburn 10275: $resulttext .= '</ul></li>';
1.48 raeburn 10276: }
10277: }
10278: $resulttext .= '</ul>';
1.160.6.43 raeburn 10279: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 10280: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10281: if ($changes{'auth'}) {
10282: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10283: }
10284: if ($changes{'unauth'}) {
10285: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10286: }
10287: my $cachetime = 24*60*60;
10288: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 10289: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 10290: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 10291: }
10292: }
1.48 raeburn 10293: } else {
10294: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10295: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10296: }
10297: } else {
1.120 raeburn 10298: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10299: }
10300: return $resulttext;
10301: }
10302:
1.69 raeburn 10303: sub modify_serverstatuses {
10304: my ($dom,%domconfig) = @_;
10305: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10306: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10307: %currserverstatus = %{$domconfig{'serverstatuses'}};
10308: }
10309: my @pages = &serverstatus_pages();
10310: foreach my $type (@pages) {
10311: $newserverstatus{$type}{'namedusers'} = '';
10312: $newserverstatus{$type}{'machines'} = '';
10313: if (defined($env{'form.'.$type.'_namedusers'})) {
10314: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10315: my @okusers;
10316: foreach my $user (@users) {
10317: my ($uname,$udom) = split(/:/,$user);
10318: if (($udom =~ /^$match_domain$/) &&
10319: (&Apache::lonnet::domain($udom)) &&
10320: ($uname =~ /^$match_username$/)) {
10321: if (!grep(/^\Q$user\E/,@okusers)) {
10322: push(@okusers,$user);
10323: }
10324: }
10325: }
10326: if (@okusers > 0) {
10327: @okusers = sort(@okusers);
10328: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10329: }
10330: }
10331: if (defined($env{'form.'.$type.'_machines'})) {
10332: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10333: my @okmachines;
10334: foreach my $ip (@machines) {
10335: my @parts = split(/\./,$ip);
10336: next if (@parts < 4);
10337: my $badip = 0;
10338: for (my $i=0; $i<4; $i++) {
10339: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10340: $badip = 1;
10341: last;
10342: }
10343: }
10344: if (!$badip) {
10345: push(@okmachines,$ip);
10346: }
10347: }
10348: @okmachines = sort(@okmachines);
10349: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10350: }
10351: }
10352: my %serverstatushash = (
10353: serverstatuses => \%newserverstatus,
10354: );
10355: foreach my $type (@pages) {
1.83 raeburn 10356: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10357: my (@current,@new);
1.83 raeburn 10358: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10359: if ($currserverstatus{$type}{$setting} ne '') {
10360: @current = split(/,/,$currserverstatus{$type}{$setting});
10361: }
10362: }
10363: if ($newserverstatus{$type}{$setting} ne '') {
10364: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10365: }
10366: if (@current > 0) {
10367: if (@new > 0) {
10368: foreach my $item (@current) {
10369: if (!grep(/^\Q$item\E$/,@new)) {
10370: $changes{$type}{$setting} = 1;
1.82 raeburn 10371: last;
10372: }
10373: }
1.84 raeburn 10374: foreach my $item (@new) {
10375: if (!grep(/^\Q$item\E$/,@current)) {
10376: $changes{$type}{$setting} = 1;
10377: last;
1.82 raeburn 10378: }
10379: }
10380: } else {
1.83 raeburn 10381: $changes{$type}{$setting} = 1;
1.69 raeburn 10382: }
1.83 raeburn 10383: } elsif (@new > 0) {
10384: $changes{$type}{$setting} = 1;
1.69 raeburn 10385: }
10386: }
10387: }
10388: if (keys(%changes) > 0) {
1.81 raeburn 10389: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10390: my $putresult = &Apache::lonnet::put_dom('configuration',
10391: \%serverstatushash,$dom);
10392: if ($putresult eq 'ok') {
10393: $resulttext .= &mt('Changes made:').'<ul>';
10394: foreach my $type (@pages) {
1.84 raeburn 10395: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10396: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10397: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10398: if ($newserverstatus{$type}{'namedusers'} eq '') {
10399: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10400: } else {
10401: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10402: }
1.84 raeburn 10403: }
10404: if ($changes{$type}{'machines'}) {
1.69 raeburn 10405: if ($newserverstatus{$type}{'machines'} eq '') {
10406: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10407: } else {
10408: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10409: }
10410:
10411: }
10412: $resulttext .= '</ul></li>';
10413: }
10414: }
10415: $resulttext .= '</ul>';
10416: } else {
10417: $resulttext = '<span class="LC_error">'.
10418: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10419:
10420: }
10421: } else {
10422: $resulttext = &mt('No changes made to access to server status pages');
10423: }
10424: return $resulttext;
10425: }
10426:
1.118 jms 10427: sub modify_helpsettings {
1.122 jms 10428: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 10429: my ($resulttext,$errors,%changes,%helphash);
10430: my %defaultchecked = ('submitbugs' => 'on');
10431: my @offon = ('off','on');
1.118 jms 10432: my @toggles = ('submitbugs');
10433: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10434: foreach my $item (@toggles) {
1.160.6.5 raeburn 10435: if ($defaultchecked{$item} eq 'on') {
10436: if ($domconfig{'helpsettings'}{$item} eq '') {
10437: if ($env{'form.'.$item} eq '0') {
10438: $changes{$item} = 1;
10439: }
10440: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10441: $changes{$item} = 1;
10442: }
10443: } elsif ($defaultchecked{$item} eq 'off') {
10444: if ($domconfig{'helpsettings'}{$item} eq '') {
10445: if ($env{'form.'.$item} eq '1') {
10446: $changes{$item} = 1;
10447: }
10448: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10449: $changes{$item} = 1;
10450: }
1.160.6.26 raeburn 10451: }
1.160.6.5 raeburn 10452: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
10453: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 10454: }
10455: }
1.118 jms 10456: }
1.123 jms 10457: my $putresult;
10458: if (keys(%changes) > 0) {
1.160.6.5 raeburn 10459: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
10460: if ($putresult eq 'ok') {
10461: $resulttext = &mt('Changes made:').'<ul>';
10462: foreach my $item (sort(keys(%changes))) {
10463: if ($item eq 'submitbugs') {
10464: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10465: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10466: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10467: }
10468: }
10469: $resulttext .= '</ul>';
10470: } else {
10471: $resulttext = &mt('No changes made to help settings');
10472: $errors .= '<li><span class="LC_error">'.
10473: &mt('An error occurred storing the settings: [_1]',
10474: $putresult).'</span></li>';
10475: }
1.118 jms 10476: }
10477: if ($errors) {
1.160.6.5 raeburn 10478: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10479: $errors.'</ul>';
10480: }
10481: return $resulttext;
10482: }
10483:
1.121 raeburn 10484: sub modify_coursedefaults {
1.160.6.27 raeburn 10485: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10486: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 10487: my %defaultchecked = (
10488: 'uselcmath' => 'on',
10489: 'usejsme' => 'on'
10490: );
10491: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 10492: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 10493: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
10494: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 10495: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 10496: my %staticdefaults = (
10497: anonsurvey_threshold => 10,
10498: uploadquota => 500,
1.160.6.57 raeburn 10499: postsubmit => 60,
1.160.6.70 raeburn 10500: mysqltables => 172800,
1.160.6.21 raeburn 10501: );
1.121 raeburn 10502:
10503: $defaultshash{'coursedefaults'} = {};
10504:
10505: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10506: if ($domconfig{'coursedefaults'} eq '') {
10507: $domconfig{'coursedefaults'} = {};
10508: }
10509: }
10510:
10511: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10512: foreach my $item (@toggles) {
10513: if ($defaultchecked{$item} eq 'on') {
10514: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10515: ($env{'form.'.$item} eq '0')) {
10516: $changes{$item} = 1;
1.160.6.16 raeburn 10517: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10518: $changes{$item} = 1;
10519: }
10520: } elsif ($defaultchecked{$item} eq 'off') {
10521: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10522: ($env{'form.'.$item} eq '1')) {
10523: $changes{$item} = 1;
10524: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10525: $changes{$item} = 1;
10526: }
10527: }
10528: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10529: }
1.160.6.21 raeburn 10530: foreach my $item (@numbers) {
10531: my ($currdef,$newdef);
1.160.6.26 raeburn 10532: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 10533: if ($item eq 'anonsurvey_threshold') {
10534: $currdef = $domconfig{'coursedefaults'}{$item};
10535: $newdef =~ s/\D//g;
10536: if ($newdef eq '' || $newdef < 1) {
10537: $newdef = 1;
10538: }
10539: $defaultshash{'coursedefaults'}{$item} = $newdef;
10540: } else {
1.160.6.70 raeburn 10541: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
10542: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
10543: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 10544: }
10545: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 10546: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 10547: }
10548: if ($currdef ne $newdef) {
10549: my $staticdef;
10550: if ($item eq 'anonsurvey_threshold') {
10551: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10552: $changes{$item} = 1;
10553: }
1.160.6.70 raeburn 10554: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
10555: my $setting = $1;
10556: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
10557: $changes{$setting} = 1;
1.160.6.21 raeburn 10558: }
10559: }
1.139 raeburn 10560: }
10561: }
1.160.6.64 raeburn 10562: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
10563: my @currclonecode;
10564: if (ref($currclone) eq 'HASH') {
10565: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
10566: @currclonecode = @{$currclone->{'instcode'}};
10567: }
10568: }
10569: my $newclone;
10570: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
10571: $newclone = $env{'form.canclone'};
10572: }
10573: if ($newclone eq 'instcode') {
10574: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
10575: my (%codedefaults,@code_order,@clonecode);
10576: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
10577: \@code_order);
10578: foreach my $item (@code_order) {
10579: if (grep(/^\Q$item\E$/,@newcodes)) {
10580: push(@clonecode,$item);
10581: }
10582: }
10583: if (@clonecode) {
10584: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
10585: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
10586: if (@diffs) {
10587: $changes{'canclone'} = 1;
10588: }
10589: } else {
10590: $newclone eq '';
10591: }
10592: } elsif ($newclone ne '') {
10593: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
10594: }
10595: if ($newclone ne $currclone) {
10596: $changes{'canclone'} = 1;
10597: }
1.160.6.57 raeburn 10598: my %credits;
10599: foreach my $type (@types) {
10600: unless ($type eq 'community') {
10601: $credits{$type} = $env{'form.'.$type.'_credits'};
10602: $credits{$type} =~ s/[^\d.]+//g;
10603: }
10604: }
10605: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10606: ($env{'form.coursecredits'} eq '1')) {
10607: $changes{'coursecredits'} = 1;
10608: foreach my $type (keys(%credits)) {
10609: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10610: }
10611: } else {
10612: if ($env{'form.coursecredits'} eq '1') {
10613: foreach my $type (@types) {
10614: unless ($type eq 'community') {
10615: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10616: $changes{'coursecredits'} = 1;
10617: }
10618: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10619: }
10620: }
10621: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10622: foreach my $type (@types) {
10623: unless ($type eq 'community') {
10624: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10625: $changes{'coursecredits'} = 1;
10626: last;
10627: }
10628: }
10629: }
10630: }
10631: }
10632: if ($env{'form.postsubmit'} eq '1') {
10633: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10634: my %currtimeout;
10635: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10636: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10637: $changes{'postsubmit'} = 1;
10638: }
10639: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10640: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10641: }
10642: } else {
10643: $changes{'postsubmit'} = 1;
10644: }
10645: foreach my $type (@types) {
10646: my $timeout = $env{'form.'.$type.'_timeout'};
10647: $timeout =~ s/\D//g;
10648: if ($timeout == $staticdefaults{'postsubmit'}) {
10649: $timeout = '';
10650: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10651: $timeout = '0';
10652: }
10653: unless ($timeout eq '') {
10654: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10655: }
10656: if (exists($currtimeout{$type})) {
10657: if ($timeout ne $currtimeout{$type}) {
10658: $changes{'postsubmit'} = 1;
10659: }
10660: } elsif ($timeout ne '') {
10661: $changes{'postsubmit'} = 1;
10662: }
10663: }
10664: } else {
10665: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10666: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10667: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10668: $changes{'postsubmit'} = 1;
10669: }
10670: } else {
10671: $changes{'postsubmit'} = 1;
10672: }
1.160.6.16 raeburn 10673: }
1.121 raeburn 10674: }
10675: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10676: $dom);
10677: if ($putresult eq 'ok') {
10678: if (keys(%changes) > 0) {
1.160.6.27 raeburn 10679: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 10680: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 10681: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 10682: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 10683: foreach my $item ('uselcmath','usejsme') {
10684: if ($changes{$item}) {
10685: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10686: }
1.160.6.16 raeburn 10687: }
10688: if ($changes{'coursecredits'}) {
10689: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 10690: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10691: $domdefaults{$type.'credits'} =
10692: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10693: }
10694: }
10695: }
10696: if ($changes{'postsubmit'}) {
10697: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10698: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10699: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10700: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10701: $domdefaults{$type.'postsubtimeout'} =
10702: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10703: }
10704: }
1.160.6.16 raeburn 10705: }
10706: }
1.160.6.21 raeburn 10707: if ($changes{'uploadquota'}) {
10708: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10709: foreach my $type (@types) {
10710: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10711: }
10712: }
10713: }
1.160.6.64 raeburn 10714: if ($changes{'canclone'}) {
10715: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10716: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10717: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
10718: if (@clonecodes) {
10719: $domdefaults{'canclone'} = join('+',@clonecodes);
10720: }
10721: }
10722: } else {
10723: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
10724: }
10725: }
1.121 raeburn 10726: my $cachetime = 24*60*60;
10727: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10728: if (ref($lastactref) eq 'HASH') {
10729: $lastactref->{'domdefaults'} = 1;
10730: }
1.121 raeburn 10731: }
10732: $resulttext = &mt('Changes made:').'<ul>';
10733: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 10734: if ($item eq 'uselcmath') {
1.121 raeburn 10735: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 10736: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 10737: } else {
1.160.6.57 raeburn 10738: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10739: }
10740: } elsif ($item eq 'usejsme') {
10741: if ($env{'form.'.$item} eq '1') {
10742: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10743: } else {
10744: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 10745: }
1.139 raeburn 10746: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 10747: $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 10748: } elsif ($item eq 'uploadquota') {
10749: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10750: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10751: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10752: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 10753: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10754:
1.160.6.21 raeburn 10755: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10756: '</ul>'.
10757: '</li>';
10758: } else {
10759: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10760: }
1.160.6.70 raeburn 10761: } elsif ($item eq 'mysqltables') {
10762: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
10763: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
10764: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
10765: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
10766: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
10767: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
10768: '</ul>'.
10769: '</li>';
10770: } else {
10771: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
10772: }
1.160.6.57 raeburn 10773: } elsif ($item eq 'postsubmit') {
10774: if ($domdefaults{'postsubmit'} eq 'off') {
10775: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10776: } else {
10777: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10778: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10779: $resulttext .= &mt('durations:').'<ul>';
10780: foreach my $type (@types) {
10781: $resulttext .= '<li>';
10782: my $timeout;
10783: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10784: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10785: }
10786: my $display;
10787: if ($timeout eq '0') {
10788: $display = &mt('unlimited');
10789: } elsif ($timeout eq '') {
10790: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10791: } else {
10792: $display = &mt('[quant,_1,second]',$timeout);
10793: }
10794: if ($type eq 'community') {
10795: $resulttext .= &mt('Communities');
10796: } elsif ($type eq 'official') {
10797: $resulttext .= &mt('Official courses');
10798: } elsif ($type eq 'unofficial') {
10799: $resulttext .= &mt('Unofficial courses');
10800: } elsif ($type eq 'textbook') {
10801: $resulttext .= &mt('Textbook courses');
10802: }
10803: $resulttext .= ' -- '.$display.'</li>';
10804: }
10805: $resulttext .= '</ul>';
10806: }
10807: $resulttext .= '</li>';
10808: }
1.160.6.16 raeburn 10809: } elsif ($item eq 'coursecredits') {
10810: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10811: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 10812: ($domdefaults{'unofficialcredits'} eq '') &&
10813: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 10814: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10815: } else {
10816: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10817: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10818: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 10819: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 10820: '</ul>'.
10821: '</li>';
10822: }
10823: } else {
10824: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10825: }
1.160.6.64 raeburn 10826: } elsif ($item eq 'canclone') {
10827: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
10828: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
10829: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
10830: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
10831: }
10832: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
10833: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
10834: } else {
10835: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
10836: }
1.140 raeburn 10837: }
1.121 raeburn 10838: }
10839: $resulttext .= '</ul>';
10840: } else {
10841: $resulttext = &mt('No changes made to course defaults');
10842: }
10843: } else {
10844: $resulttext = '<span class="LC_error">'.
10845: &mt('An error occurred: [_1]',$putresult).'</span>';
10846: }
10847: return $resulttext;
10848: }
10849:
1.160.6.37 raeburn 10850: sub modify_selfenrollment {
10851: my ($dom,$lastactref,%domconfig) = @_;
10852: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10853: my @types = ('official','unofficial','community','textbook');
10854: my %titles = &tool_titles();
10855: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10856: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
10857: $ordered{'default'} = ['types','registered','approval','limit'];
10858:
10859: my (%roles,%shown,%toplevel);
10860: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10861:
10862: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10863: if ($domconfig{'selfenrollment'} eq '') {
10864: $domconfig{'selfenrollment'} = {};
10865: }
10866: }
10867: %toplevel = (
10868: admin => 'Configuration Rights',
10869: default => 'Default settings',
10870: validation => 'Validation of self-enrollment requests',
10871: );
10872: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
10873:
10874: if (ref($ordered{'admin'}) eq 'ARRAY') {
10875: foreach my $item (@{$ordered{'admin'}}) {
10876: foreach my $type (@types) {
10877: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10878: $selfenrollhash{'admin'}{$type}{$item} = 1;
10879: } else {
10880: $selfenrollhash{'admin'}{$type}{$item} = 0;
10881: }
10882: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10883: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10884: if ($selfenrollhash{'admin'}{$type}{$item} ne
10885: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10886: push(@{$changes{'admin'}{$type}},$item);
10887: }
10888: } else {
10889: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10890: push(@{$changes{'admin'}{$type}},$item);
10891: }
10892: }
10893: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10894: push(@{$changes{'admin'}{$type}},$item);
10895: }
10896: }
10897: }
10898: }
10899:
10900: foreach my $item (@{$ordered{'default'}}) {
10901: foreach my $type (@types) {
10902: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10903: if ($item eq 'types') {
10904: unless (($value eq 'all') || ($value eq 'dom')) {
10905: $value = '';
10906: }
10907: } elsif ($item eq 'registered') {
10908: unless ($value eq '1') {
10909: $value = 0;
10910: }
10911: } elsif ($item eq 'approval') {
10912: unless ($value =~ /^[012]$/) {
10913: $value = 0;
10914: }
10915: } else {
10916: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10917: $value = 'none';
10918: }
10919: }
10920: $selfenrollhash{'default'}{$type}{$item} = $value;
10921: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10922: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10923: if ($selfenrollhash{'default'}{$type}{$item} ne
10924: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10925: push(@{$changes{'default'}{$type}},$item);
10926: }
10927: } else {
10928: push(@{$changes{'default'}{$type}},$item);
10929: }
10930: } else {
10931: push(@{$changes{'default'}{$type}},$item);
10932: }
10933: if ($item eq 'limit') {
10934: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10935: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10936: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10937: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10938: }
10939: } else {
10940: $selfenrollhash{'default'}{$type}{'cap'} = '';
10941: }
10942: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10943: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10944: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10945: push(@{$changes{'default'}{$type}},'cap');
10946: }
10947: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10948: push(@{$changes{'default'}{$type}},'cap');
10949: }
10950: }
10951: }
10952: }
10953:
10954: foreach my $item (@{$itemsref}) {
10955: if ($item eq 'fields') {
10956: my @changed;
10957: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10958: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10959: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10960: }
10961: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10962: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10963: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10964: $domconfig{'selfenrollment'}{'validation'}{$item});
10965: } else {
10966: @changed = @{$selfenrollhash{'validation'}{$item}};
10967: }
10968: } else {
10969: @changed = @{$selfenrollhash{'validation'}{$item}};
10970: }
10971: if (@changed) {
10972: if ($selfenrollhash{'validation'}{$item}) {
10973: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10974: } else {
10975: $changes{'validation'}{$item} = &mt('None');
10976: }
10977: }
10978: } else {
10979: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10980: if ($item eq 'markup') {
10981: if ($env{'form.selfenroll_validation_'.$item}) {
10982: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10983: }
10984: }
10985: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10986: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10987: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10988: }
10989: }
10990: }
10991: }
10992:
10993: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10994: $dom);
10995: if ($putresult eq 'ok') {
10996: if (keys(%changes) > 0) {
10997: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10998: $resulttext = &mt('Changes made:').'<ul>';
10999: foreach my $key ('admin','default','validation') {
11000: if (ref($changes{$key}) eq 'HASH') {
11001: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11002: if ($key eq 'validation') {
11003: foreach my $item (@{$itemsref}) {
11004: if (exists($changes{$key}{$item})) {
11005: if ($item eq 'markup') {
11006: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11007: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11008: } else {
11009: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11010: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11011: }
11012: }
11013: }
11014: } else {
11015: foreach my $type (@types) {
11016: if ($type eq 'community') {
11017: $roles{'1'} = &mt('Community personnel');
11018: } else {
11019: $roles{'1'} = &mt('Course personnel');
11020: }
11021: if (ref($changes{$key}{$type}) eq 'ARRAY') {
11022: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11023: if ($key eq 'admin') {
11024: my @mgrdc = ();
11025: if (ref($ordered{$key}) eq 'ARRAY') {
11026: foreach my $item (@{$ordered{'admin'}}) {
11027: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11028: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11029: push(@mgrdc,$item);
11030: }
11031: }
11032: }
11033: if (@mgrdc) {
11034: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11035: } else {
11036: delete($domdefaults{$type.'selfenrolladmdc'});
11037: }
11038: }
11039: } else {
11040: if (ref($ordered{$key}) eq 'ARRAY') {
11041: foreach my $item (@{$ordered{$key}}) {
11042: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11043: $domdefaults{$type.'selfenroll'.$item} =
11044: $selfenrollhash{$key}{$type}{$item};
11045: }
11046: }
11047: }
11048: }
11049: }
11050: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11051: foreach my $item (@{$ordered{$key}}) {
11052: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11053: $resulttext .= '<li>';
11054: if ($key eq 'admin') {
11055: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11056: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11057: } else {
11058: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11059: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11060: }
11061: $resulttext .= '</li>';
11062: }
11063: }
11064: $resulttext .= '</ul></li>';
11065: }
11066: }
11067: $resulttext .= '</ul></li>';
11068: }
11069: }
11070: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11071: my $cachetime = 24*60*60;
11072: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11073: if (ref($lastactref) eq 'HASH') {
11074: $lastactref->{'domdefaults'} = 1;
11075: }
11076: }
11077: }
11078: $resulttext .= '</ul>';
11079: } else {
11080: $resulttext = &mt('No changes made to self-enrollment settings');
11081: }
11082: } else {
11083: $resulttext = '<span class="LC_error">'.
11084: &mt('An error occurred: [_1]',$putresult).'</span>';
11085: }
11086: return $resulttext;
11087: }
11088:
1.137 raeburn 11089: sub modify_usersessions {
1.160.6.27 raeburn 11090: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11091: my @hostingtypes = ('version','excludedomain','includedomain');
11092: my @offloadtypes = ('primary','default');
11093: my %types = (
11094: remote => \@hostingtypes,
11095: hosted => \@hostingtypes,
11096: spares => \@offloadtypes,
11097: );
11098: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11099: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11100: my (%by_ip,%by_location,@intdoms);
11101: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11102: my @locations = sort(keys(%by_location));
1.137 raeburn 11103: my (%defaultshash,%changes);
11104: foreach my $prefix (@prefixes) {
11105: $defaultshash{'usersessions'}{$prefix} = {};
11106: }
1.160.6.27 raeburn 11107: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11108: my $resulttext;
1.138 raeburn 11109: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11110: foreach my $prefix (@prefixes) {
1.145 raeburn 11111: next if ($prefix eq 'spares');
11112: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11113: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11114: if ($type eq 'version') {
11115: my $value = $env{'form.'.$prefix.'_'.$type};
11116: my $okvalue;
11117: if ($value ne '') {
11118: if (grep(/^\Q$value\E$/,@lcversions)) {
11119: $okvalue = $value;
11120: }
11121: }
11122: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11123: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11124: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11125: if ($inuse == 0) {
11126: $changes{$prefix}{$type} = 1;
11127: } else {
11128: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11129: $changes{$prefix}{$type} = 1;
11130: }
11131: if ($okvalue ne '') {
11132: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11133: }
11134: }
11135: } else {
11136: if (($inuse == 1) && ($okvalue ne '')) {
11137: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11138: $changes{$prefix}{$type} = 1;
11139: }
11140: }
11141: } else {
11142: if (($inuse == 1) && ($okvalue ne '')) {
11143: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11144: $changes{$prefix}{$type} = 1;
11145: }
11146: }
11147: } else {
11148: if (($inuse == 1) && ($okvalue ne '')) {
11149: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11150: $changes{$prefix}{$type} = 1;
11151: }
11152: }
11153: } else {
11154: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11155: my @okvals;
11156: foreach my $val (@vals) {
1.138 raeburn 11157: if ($val =~ /:/) {
11158: my @items = split(/:/,$val);
11159: foreach my $item (@items) {
11160: if (ref($by_location{$item}) eq 'ARRAY') {
11161: push(@okvals,$item);
11162: }
11163: }
11164: } else {
11165: if (ref($by_location{$val}) eq 'ARRAY') {
11166: push(@okvals,$val);
11167: }
1.137 raeburn 11168: }
11169: }
11170: @okvals = sort(@okvals);
11171: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11172: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11173: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11174: if ($inuse == 0) {
11175: $changes{$prefix}{$type} = 1;
11176: } else {
11177: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11178: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11179: if (@changed > 0) {
11180: $changes{$prefix}{$type} = 1;
11181: }
11182: }
11183: } else {
11184: if ($inuse == 1) {
11185: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11186: $changes{$prefix}{$type} = 1;
11187: }
11188: }
11189: } else {
11190: if ($inuse == 1) {
11191: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11192: $changes{$prefix}{$type} = 1;
11193: }
11194: }
11195: } else {
11196: if ($inuse == 1) {
11197: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11198: $changes{$prefix}{$type} = 1;
11199: }
11200: }
11201: }
11202: }
11203: }
1.145 raeburn 11204:
11205: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11206: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11207: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11208: my $savespares;
11209:
11210: foreach my $lonhost (sort(keys(%servers))) {
11211: my $serverhomeID =
11212: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 11213: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 11214: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
11215: my %spareschg;
11216: foreach my $type (@{$types{'spares'}}) {
11217: my @okspares;
11218: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
11219: foreach my $server (@checked) {
1.152 raeburn 11220: if (&Apache::lonnet::hostname($server) ne '') {
11221: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
11222: unless (grep(/^\Q$server\E$/,@okspares)) {
11223: push(@okspares,$server);
11224: }
1.145 raeburn 11225: }
11226: }
11227: }
11228: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
11229: my $newspare;
1.152 raeburn 11230: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
11231: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 11232: $newspare = $new;
11233: }
11234: }
1.152 raeburn 11235: my @spares;
11236: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
11237: @spares = sort(@okspares,$newspare);
11238: } else {
11239: @spares = sort(@okspares);
11240: }
11241: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 11242: if (ref($spareid{$lonhost}) eq 'HASH') {
11243: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 11244: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 11245: if (@diffs > 0) {
11246: $spareschg{$type} = 1;
11247: }
11248: }
11249: }
11250: }
11251: if (keys(%spareschg) > 0) {
11252: $changes{'spares'}{$lonhost} = \%spareschg;
11253: }
11254: }
1.160.6.61 raeburn 11255: $defaultshash{'usersessions'}{'offloadnow'} = {};
11256: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
11257: my @okoffload;
11258: if (@offloadnow) {
11259: foreach my $server (@offloadnow) {
11260: if (&Apache::lonnet::hostname($server) ne '') {
11261: unless (grep(/^\Q$server\E$/,@okoffload)) {
11262: push(@okoffload,$server);
11263: }
11264: }
11265: }
11266: if (@okoffload) {
11267: foreach my $lonhost (@okoffload) {
11268: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
11269: }
11270: }
11271: }
1.145 raeburn 11272: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11273: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
11274: if (ref($changes{'spares'}) eq 'HASH') {
11275: if (keys(%{$changes{'spares'}}) > 0) {
11276: $savespares = 1;
11277: }
11278: }
11279: } else {
11280: $savespares = 1;
11281: }
1.160.6.61 raeburn 11282: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
11283: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
11284: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
11285: $changes{'offloadnow'} = 1;
11286: last;
11287: }
11288: }
11289: unless ($changes{'offloadnow'}) {
11290: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
11291: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
11292: $changes{'offloadnow'} = 1;
11293: last;
11294: }
11295: }
11296: }
11297: } elsif (@okoffload) {
11298: $changes{'offloadnow'} = 1;
11299: }
11300: } elsif (@okoffload) {
11301: $changes{'offloadnow'} = 1;
1.145 raeburn 11302: }
1.147 raeburn 11303: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
11304: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 11305: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11306: $dom);
11307: if ($putresult eq 'ok') {
11308: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11309: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
11310: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
11311: }
11312: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
11313: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
11314: }
1.160.6.61 raeburn 11315: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11316: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
11317: }
1.137 raeburn 11318: }
11319: my $cachetime = 24*60*60;
11320: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11321: if (ref($lastactref) eq 'HASH') {
11322: $lastactref->{'domdefaults'} = 1;
11323: }
1.147 raeburn 11324: if (keys(%changes) > 0) {
11325: my %lt = &usersession_titles();
11326: $resulttext = &mt('Changes made:').'<ul>';
11327: foreach my $prefix (@prefixes) {
11328: if (ref($changes{$prefix}) eq 'HASH') {
11329: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
11330: if ($prefix eq 'spares') {
11331: if (ref($changes{$prefix}) eq 'HASH') {
11332: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
11333: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 11334: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 11335: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
11336: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 11337: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
11338: foreach my $type (@{$types{$prefix}}) {
11339: if ($changes{$prefix}{$lonhost}{$type}) {
11340: my $offloadto = &mt('None');
11341: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
11342: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
11343: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
11344: }
1.145 raeburn 11345: }
1.147 raeburn 11346: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 11347: }
1.137 raeburn 11348: }
11349: }
1.147 raeburn 11350: $resulttext .= '</li>';
1.137 raeburn 11351: }
11352: }
1.147 raeburn 11353: } else {
11354: foreach my $type (@{$types{$prefix}}) {
11355: if (defined($changes{$prefix}{$type})) {
11356: my $newvalue;
11357: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11358: if (ref($defaultshash{'usersessions'}{$prefix})) {
11359: if ($type eq 'version') {
11360: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11361: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11362: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11363: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11364: }
1.145 raeburn 11365: }
11366: }
11367: }
1.147 raeburn 11368: if ($newvalue eq '') {
11369: if ($type eq 'version') {
11370: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11371: } else {
11372: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11373: }
1.145 raeburn 11374: } else {
1.147 raeburn 11375: if ($type eq 'version') {
11376: $newvalue .= ' '.&mt('(or later)');
11377: }
11378: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11379: }
1.137 raeburn 11380: }
11381: }
11382: }
1.147 raeburn 11383: $resulttext .= '</ul>';
1.137 raeburn 11384: }
11385: }
1.160.6.61 raeburn 11386: if ($changes{'offloadnow'}) {
11387: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
11388: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
11389: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
11390: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
11391: $resulttext .= '<li>'.$lonhost.'</li>';
11392: }
11393: $resulttext .= '</ul>';
11394: } else {
11395: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
11396: }
11397: } else {
11398: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
11399: }
11400: }
1.147 raeburn 11401: $resulttext .= '</ul>';
11402: } else {
11403: $resulttext = $nochgmsg;
1.137 raeburn 11404: }
11405: } else {
11406: $resulttext = '<span class="LC_error">'.
11407: &mt('An error occurred: [_1]',$putresult).'</span>';
11408: }
11409: } else {
1.147 raeburn 11410: $resulttext = $nochgmsg;
1.137 raeburn 11411: }
11412: return $resulttext;
11413: }
11414:
1.150 raeburn 11415: sub modify_loadbalancing {
11416: my ($dom,%domconfig) = @_;
11417: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11418: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11419: my ($othertitle,$usertypes,$types) =
11420: &Apache::loncommon::sorted_inst_types($dom);
11421: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 11422: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11423: my @sparestypes = ('primary','default');
11424: my %typetitles = &sparestype_titles();
11425: my $resulttext;
1.160.6.7 raeburn 11426: my (%currbalancer,%currtargets,%currrules,%existing);
11427: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11428: %existing = %{$domconfig{'loadbalancing'}};
11429: }
11430: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11431: \%currtargets,\%currrules);
11432: my ($saveloadbalancing,%defaultshash,%changes);
11433: my ($alltypes,$othertypes,$titles) =
11434: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11435: my %ruletitles = &offloadtype_text();
11436: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11437: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11438: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11439: if ($balancer eq '') {
11440: next;
11441: }
11442: if (!exists($servers{$balancer})) {
11443: if (exists($currbalancer{$balancer})) {
11444: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11445: }
1.160.6.7 raeburn 11446: next;
11447: }
11448: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11449: push(@{$changes{'delete'}},$balancer);
11450: next;
11451: }
11452: if (!exists($currbalancer{$balancer})) {
11453: push(@{$changes{'add'}},$balancer);
11454: }
11455: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11456: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11457: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11458: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11459: $saveloadbalancing = 1;
11460: }
11461: foreach my $sparetype (@sparestypes) {
11462: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11463: my @offloadto;
11464: foreach my $target (@targets) {
11465: if (($servers{$target}) && ($target ne $balancer)) {
11466: if ($sparetype eq 'default') {
11467: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11468: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11469: }
11470: }
1.160.6.7 raeburn 11471: unless(grep(/^\Q$target\E$/,@offloadto)) {
11472: push(@offloadto,$target);
11473: }
1.150 raeburn 11474: }
1.160.6.7 raeburn 11475: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11476: }
11477: }
1.160.6.7 raeburn 11478: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11479: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 11480: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11481: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11482: if (@targetdiffs > 0) {
1.160.6.7 raeburn 11483: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11484: }
1.160.6.7 raeburn 11485: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11486: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11487: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11488: }
11489: }
11490: }
11491: } else {
1.160.6.7 raeburn 11492: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
11493: foreach my $sparetype (@sparestypes) {
11494: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11495: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11496: $changes{'curr'}{$balancer}{'targets'} = 1;
11497: }
1.150 raeburn 11498: }
11499: }
1.160.6.7 raeburn 11500: }
1.150 raeburn 11501: }
11502: my $ishomedom;
1.160.6.7 raeburn 11503: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11504: $ishomedom = 1;
1.150 raeburn 11505: }
11506: if (ref($alltypes) eq 'ARRAY') {
11507: foreach my $type (@{$alltypes}) {
11508: my $rule;
1.160.6.7 raeburn 11509: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11510: (!$ishomedom)) {
1.160.6.7 raeburn 11511: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11512: }
11513: if ($rule eq 'specific') {
1.160.6.55 raeburn 11514: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11515: if (exists($servers{$specifiedhost})) {
11516: $rule = $specifiedhost;
11517: }
1.150 raeburn 11518: }
1.160.6.7 raeburn 11519: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11520: if (ref($currrules{$balancer}) eq 'HASH') {
11521: if ($rule ne $currrules{$balancer}{$type}) {
11522: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11523: }
11524: } elsif ($rule ne '') {
1.160.6.7 raeburn 11525: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11526: }
11527: }
11528: }
1.160.6.7 raeburn 11529: }
11530: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11531: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11532: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11533: $defaultshash{'loadbalancing'} = {};
11534: }
11535: my $putresult = &Apache::lonnet::put_dom('configuration',
11536: \%defaultshash,$dom);
11537: if ($putresult eq 'ok') {
11538: if (keys(%changes) > 0) {
1.160.6.54 raeburn 11539: my %toupdate;
1.160.6.7 raeburn 11540: if (ref($changes{'delete'}) eq 'ARRAY') {
11541: foreach my $balancer (sort(@{$changes{'delete'}})) {
11542: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 11543: $toupdate{$balancer} = 1;
1.150 raeburn 11544: }
1.160.6.7 raeburn 11545: }
11546: if (ref($changes{'add'}) eq 'ARRAY') {
11547: foreach my $balancer (sort(@{$changes{'add'}})) {
11548: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 11549: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11550: }
11551: }
11552: if (ref($changes{'curr'}) eq 'HASH') {
11553: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 11554: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 11555: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11556: if ($changes{'curr'}{$balancer}{'targets'}) {
11557: my %offloadstr;
11558: foreach my $sparetype (@sparestypes) {
11559: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11560: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11561: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11562: }
11563: }
1.150 raeburn 11564: }
1.160.6.7 raeburn 11565: if (keys(%offloadstr) == 0) {
11566: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11567: } else {
1.160.6.7 raeburn 11568: my $showoffload;
11569: foreach my $sparetype (@sparestypes) {
11570: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11571: if (defined($offloadstr{$sparetype})) {
11572: $showoffload .= $offloadstr{$sparetype};
11573: } else {
11574: $showoffload .= &mt('None');
11575: }
11576: $showoffload .= (' 'x3);
11577: }
11578: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11579: }
11580: }
11581: }
1.160.6.7 raeburn 11582: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11583: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11584: foreach my $type (@{$alltypes}) {
11585: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11586: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11587: my $balancetext;
11588: if ($rule eq '') {
11589: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 11590: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 11591: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11592: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 11593: foreach my $sparetype (@sparestypes) {
11594: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11595: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11596: }
11597: }
1.160.6.55 raeburn 11598: foreach my $item (@{$alltypes}) {
11599: next if ($item =~ /^_LC_ipchange/);
11600: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11601: if ($hasrule eq 'homeserver') {
11602: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11603: } else {
11604: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11605: if ($servers{$hasrule}) {
11606: $toupdate{$hasrule} = 1;
11607: }
11608: }
11609: }
11610: }
11611: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11612: $balancetext = $ruletitles{$rule};
11613: } else {
11614: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11615: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11616: if ($receiver) {
11617: $toupdate{$receiver};
11618: }
11619: }
11620: } else {
11621: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 11622: }
1.160.6.7 raeburn 11623: } else {
11624: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11625: }
1.160.6.26 raeburn 11626: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11627: }
11628: }
11629: }
11630: }
1.160.6.54 raeburn 11631: if (keys(%toupdate)) {
11632: my %thismachine;
11633: my $updatedhere;
11634: my $cachetime = 60*60*24;
11635: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11636: foreach my $lonhost (keys(%toupdate)) {
11637: if ($thismachine{$lonhost}) {
11638: unless ($updatedhere) {
11639: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11640: $defaultshash{'loadbalancing'},
11641: $cachetime);
11642: $updatedhere = 1;
11643: }
11644: } else {
11645: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11646: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11647: }
11648: }
11649: }
1.150 raeburn 11650: }
1.160.6.7 raeburn 11651: }
11652: if ($resulttext ne '') {
11653: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11654: } else {
11655: $resulttext = $nochgmsg;
11656: }
11657: } else {
1.160.6.7 raeburn 11658: $resulttext = $nochgmsg;
1.150 raeburn 11659: }
11660: } else {
1.160.6.7 raeburn 11661: $resulttext = '<span class="LC_error">'.
11662: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11663: }
11664: } else {
1.160.6.7 raeburn 11665: $resulttext = $nochgmsg;
1.150 raeburn 11666: }
11667: return $resulttext;
11668: }
11669:
1.48 raeburn 11670: sub recurse_check {
11671: my ($chkcats,$categories,$depth,$name) = @_;
11672: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11673: my $chg = 0;
11674: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11675: my $category = $chkcats->[$depth]{$name}[$j];
11676: my $item;
11677: if ($category eq '') {
11678: $chg ++;
11679: } else {
11680: my $deeper = $depth + 1;
11681: $item = &escape($category).':'.&escape($name).':'.$depth;
11682: if ($chg) {
11683: $categories->{$item} -= $chg;
11684: }
11685: &recurse_check($chkcats,$categories,$deeper,$category);
11686: $deeper --;
11687: }
11688: }
11689: }
11690: return;
11691: }
11692:
11693: sub recurse_cat_deletes {
11694: my ($item,$coursecategories,$deletions) = @_;
11695: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11696: my $subdepth = $depth + 1;
11697: if (ref($coursecategories) eq 'HASH') {
11698: foreach my $subitem (keys(%{$coursecategories})) {
11699: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11700: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11701: delete($coursecategories->{$subitem});
11702: $deletions->{$subitem} = 1;
11703: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 11704: }
1.48 raeburn 11705: }
11706: }
11707: return;
11708: }
11709:
1.125 raeburn 11710: sub get_active_dcs {
11711: my ($dom) = @_;
1.160.6.16 raeburn 11712: my $now = time;
11713: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11714: my %domcoords;
11715: my $numdcs = 0;
11716: foreach my $server (keys(%dompersonnel)) {
11717: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11718: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 11719: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11720: }
11721: }
11722: return %domcoords;
11723: }
11724:
11725: sub active_dc_picker {
1.160.6.16 raeburn 11726: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 11727: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 11728: my @domcoord = keys(%domcoords);
11729: if (keys(%currhash)) {
11730: foreach my $dc (keys(%currhash)) {
11731: unless (exists($domcoords{$dc})) {
11732: push(@domcoord,$dc);
11733: }
11734: }
11735: }
11736: @domcoord = sort(@domcoord);
11737: my $numdcs = scalar(@domcoord);
11738: my $rows = 0;
11739: my $table;
1.125 raeburn 11740: if ($numdcs > 1) {
1.160.6.16 raeburn 11741: $table = '<table>';
11742: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11743: my $rem = $i%($numinrow);
11744: if ($rem == 0) {
11745: if ($i > 0) {
1.160.6.16 raeburn 11746: $table .= '</tr>';
1.125 raeburn 11747: }
1.160.6.16 raeburn 11748: $table .= '<tr>';
11749: $rows ++;
1.125 raeburn 11750: }
1.160.6.16 raeburn 11751: my $check = '';
11752: if ($inputtype eq 'radio') {
11753: if (keys(%currhash) == 0) {
11754: if (!$i) {
11755: $check = ' checked="checked"';
11756: }
11757: } elsif (exists($currhash{$domcoord[$i]})) {
11758: $check = ' checked="checked"';
11759: }
11760: } else {
11761: if (exists($currhash{$domcoord[$i]})) {
11762: $check = ' checked="checked"';
1.125 raeburn 11763: }
11764: }
1.160.6.16 raeburn 11765: if ($i == @domcoord - 1) {
1.125 raeburn 11766: my $colsleft = $numinrow - $rem;
11767: if ($colsleft > 1) {
1.160.6.16 raeburn 11768: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11769: } else {
1.160.6.16 raeburn 11770: $table .= '<td class="LC_left_item">';
1.125 raeburn 11771: }
11772: } else {
1.160.6.16 raeburn 11773: $table .= '<td class="LC_left_item">';
11774: }
11775: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11776: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11777: $table .= '<span class="LC_nobreak"><label>'.
11778: '<input type="'.$inputtype.'" name="'.$name.'"'.
11779: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11780: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 11781: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 11782: }
1.160.6.33 raeburn 11783: $table .= '</label></span></td>';
1.125 raeburn 11784: }
1.160.6.16 raeburn 11785: $table .= '</tr></table>';
11786: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 11787: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11788: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 11789: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 11790: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 11791: if ($user ne $dcname.':'.$dcdom) {
11792: $table .= ' ('.$dcname.':'.$dcdom.')';
11793: }
1.160.6.16 raeburn 11794: } else {
11795: my $check;
11796: if (exists($currhash{$domcoord[0]})) {
11797: $check = ' checked="checked"';
11798: }
1.160.6.50 raeburn 11799: $table = '<span class="LC_nobreak"><label>'.
11800: '<input type="checkbox" name="'.$name.'" '.
11801: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 11802: if ($user ne $dcname.':'.$dcdom) {
11803: $table .= ' ('.$dcname.':'.$dcdom.')';
11804: }
11805: $table .= '</label></span>';
1.160.6.16 raeburn 11806: $rows ++;
11807: }
1.125 raeburn 11808: }
1.160.6.16 raeburn 11809: return ($numdcs,$table,$rows);
1.125 raeburn 11810: }
11811:
1.137 raeburn 11812: sub usersession_titles {
11813: return &Apache::lonlocal::texthash(
11814: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11815: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11816: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11817: version => 'LON-CAPA version requirement',
1.138 raeburn 11818: excludedomain => 'Allow all, but exclude specific domains',
11819: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11820: primary => 'Primary (checked first)',
1.154 raeburn 11821: default => 'Default',
1.137 raeburn 11822: );
11823: }
11824:
1.152 raeburn 11825: sub id_for_thisdom {
11826: my (%servers) = @_;
11827: my %altids;
11828: foreach my $server (keys(%servers)) {
11829: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11830: if ($serverhome ne $server) {
11831: $altids{$serverhome} = $server;
11832: }
11833: }
11834: return %altids;
11835: }
11836:
1.150 raeburn 11837: sub count_servers {
11838: my ($currbalancer,%servers) = @_;
11839: my (@spares,$numspares);
11840: foreach my $lonhost (sort(keys(%servers))) {
11841: next if ($currbalancer eq $lonhost);
11842: push(@spares,$lonhost);
11843: }
11844: if ($currbalancer) {
11845: $numspares = scalar(@spares);
11846: } else {
11847: $numspares = scalar(@spares) - 1;
11848: }
11849: return ($numspares,@spares);
11850: }
11851:
11852: sub lonbalance_targets_js {
1.160.6.7 raeburn 11853: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11854: my $select = &mt('Select');
11855: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11856: if (ref($servers) eq 'HASH') {
11857: $alltargets = join("','",sort(keys(%{$servers})));
11858: my @homedoms;
11859: foreach my $server (sort(keys(%{$servers}))) {
11860: if (&Apache::lonnet::host_domain($server) eq $dom) {
11861: push(@homedoms,'1');
11862: } else {
11863: push(@homedoms,'0');
11864: }
11865: }
11866: $allishome = join("','",@homedoms);
11867: }
11868: if (ref($types) eq 'ARRAY') {
11869: if (@{$types} > 0) {
11870: @alltypes = @{$types};
11871: }
11872: }
11873: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11874: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 11875: my (%currbalancer,%currtargets,%currrules,%existing);
11876: if (ref($settings) eq 'HASH') {
11877: %existing = %{$settings};
11878: }
11879: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11880: \%currtargets,\%currrules);
11881: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11882: return <<"END";
11883:
11884: <script type="text/javascript">
11885: // <![CDATA[
11886:
1.160.6.7 raeburn 11887: currBalancers = new Array('$balancers');
11888:
11889: function toggleTargets(balnum) {
11890: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11891: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11892: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11893: var prevbalancer = prevhostitem.value;
11894: var baltotal = document.getElementById('loadbalancing_total').value;
11895: prevhostitem.value = balancer;
11896: if (prevbalancer != '') {
11897: var prevIdx = currBalancers.indexOf(prevbalancer);
11898: if (prevIdx != -1) {
11899: currBalancers.splice(prevIdx,1);
11900: }
11901: }
1.150 raeburn 11902: if (balancer == '') {
1.160.6.7 raeburn 11903: hideSpares(balnum);
1.150 raeburn 11904: } else {
1.160.6.7 raeburn 11905: var currIdx = currBalancers.indexOf(balancer);
11906: if (currIdx == -1) {
11907: currBalancers.push(balancer);
11908: }
1.150 raeburn 11909: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 11910: var ishomedom = homedoms[lonhostitem.selectedIndex];
11911: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11912: }
1.160.6.7 raeburn 11913: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11914: return;
11915: }
11916:
1.160.6.7 raeburn 11917: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11918: var alltargets = new Array('$alltargets');
11919: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11920: var offloadtypes = new Array('primary','default');
11921:
1.160.6.7 raeburn 11922: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11923: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11924:
1.151 raeburn 11925: for (var i=0; i<offloadtypes.length; i++) {
11926: var count = 0;
11927: for (var j=0; j<alltargets.length; j++) {
11928: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 11929: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11930: item.value = alltargets[j];
11931: item.style.textAlign='left';
11932: item.style.textFace='normal';
11933: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11934: if (currBalancers.indexOf(alltargets[j]) == -1) {
11935: item.disabled = '';
11936: } else {
11937: item.disabled = 'disabled';
11938: item.checked = false;
11939: }
1.151 raeburn 11940: count ++;
11941: }
1.150 raeburn 11942: }
11943: }
1.151 raeburn 11944: for (var k=0; k<insttypes.length; k++) {
11945: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11946: if (ishomedom == 1) {
1.160.6.7 raeburn 11947: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11948: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11949: } else {
1.160.6.7 raeburn 11950: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11951: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11952: }
11953: } else {
1.160.6.7 raeburn 11954: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11955: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11956: }
1.151 raeburn 11957: if ((insttypes[k] != '_LC_external') &&
11958: ((insttypes[k] != '_LC_internetdom') ||
11959: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 11960: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11961: item.options.length = 0;
11962: item.options[0] = new Option("","",true,true);
11963: var idx = 0;
1.151 raeburn 11964: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 11965: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11966: idx ++;
11967: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11968: }
11969: }
11970: }
11971: }
11972: return;
11973: }
11974:
1.160.6.7 raeburn 11975: function hideSpares(balnum) {
1.150 raeburn 11976: var alltargets = new Array('$alltargets');
11977: var insttypes = new Array('$allinsttypes');
11978: var offloadtypes = new Array('primary','default');
11979:
1.160.6.7 raeburn 11980: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11981: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11982:
11983: var total = alltargets.length - 1;
11984: for (var i=0; i<offloadtypes; i++) {
11985: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 11986: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11987: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11988: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11989: }
1.150 raeburn 11990: }
11991: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11992: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11993: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11994: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11995: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11996: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11997: }
11998: }
11999: return;
12000: }
12001:
1.160.6.7 raeburn 12002: function checkOffloads(item,balnum,type) {
1.150 raeburn 12003: var alltargets = new Array('$alltargets');
12004: var offloadtypes = new Array('primary','default');
12005: if (item.checked) {
12006: var total = alltargets.length - 1;
12007: var other;
12008: if (type == offloadtypes[0]) {
1.151 raeburn 12009: other = offloadtypes[1];
1.150 raeburn 12010: } else {
1.151 raeburn 12011: other = offloadtypes[0];
1.150 raeburn 12012: }
12013: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 12014: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12015: if (server == item.value) {
1.160.6.7 raeburn 12016: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12017: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12018: }
12019: }
12020: }
12021: }
12022: return;
12023: }
12024:
1.160.6.7 raeburn 12025: function singleServerToggle(balnum,type) {
12026: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12027: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 12028: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12029: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12030:
12031: } else {
1.160.6.7 raeburn 12032: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12033: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12034: }
12035: return;
12036: }
12037:
1.160.6.7 raeburn 12038: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12039: if (type == '_LC_external') {
1.160.6.26 raeburn 12040: return;
1.150 raeburn 12041: }
1.160.6.7 raeburn 12042: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12043: for (var i=0; i<typesRules.length; i++) {
12044: if (formname.elements[typesRules[i]].checked) {
12045: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 12046: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12047: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12048: } else {
1.160.6.7 raeburn 12049: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12050: }
12051: }
12052: }
12053: return;
12054: }
12055:
12056: function balancerDeleteChange(balnum) {
12057: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12058: var baltotal = document.getElementById('loadbalancing_total').value;
12059: var addtarget;
12060: var removetarget;
12061: var action = 'delete';
12062: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12063: var lonhost = hostitem.value;
12064: var currIdx = currBalancers.indexOf(lonhost);
12065: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12066: if (currIdx != -1) {
12067: currBalancers.splice(currIdx,1);
12068: }
12069: addtarget = lonhost;
12070: } else {
12071: if (currIdx == -1) {
12072: currBalancers.push(lonhost);
12073: }
12074: removetarget = lonhost;
12075: action = 'undelete';
12076: }
12077: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12078: }
12079: return;
12080: }
12081:
12082: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12083: if (baltotal > 1) {
12084: var offloadtypes = new Array('primary','default');
12085: var alltargets = new Array('$alltargets');
12086: var insttypes = new Array('$allinsttypes');
12087: for (var i=0; i<baltotal; i++) {
12088: if (i != balnum) {
12089: for (var j=0; j<offloadtypes.length; j++) {
12090: var total = alltargets.length - 1;
12091: for (var k=0; k<total; k++) {
12092: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12093: var server = serveritem.value;
12094: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12095: if (server == addtarget) {
12096: serveritem.disabled = '';
12097: }
12098: }
12099: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12100: if (server == removetarget) {
12101: serveritem.disabled = 'disabled';
12102: serveritem.checked = false;
12103: }
12104: }
12105: }
12106: }
12107: for (var j=0; j<insttypes.length; j++) {
12108: if (insttypes[j] != '_LC_external') {
12109: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12110: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12111: var currSel = singleserver.selectedIndex;
12112: var currVal = singleserver.options[currSel].value;
12113: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12114: var numoptions = singleserver.options.length;
12115: var needsnew = 1;
12116: for (var k=0; k<numoptions; k++) {
12117: if (singleserver.options[k] == addtarget) {
12118: needsnew = 0;
12119: break;
12120: }
12121: }
12122: if (needsnew == 1) {
12123: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12124: }
12125: }
12126: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12127: singleserver.options.length = 0;
12128: if ((currVal) && (currVal != removetarget)) {
12129: singleserver.options[0] = new Option("","",false,false);
12130: } else {
12131: singleserver.options[0] = new Option("","",true,true);
12132: }
12133: var idx = 0;
12134: for (var m=0; m<alltargets.length; m++) {
12135: if (currBalancers.indexOf(alltargets[m]) == -1) {
12136: idx ++;
12137: if (currVal == alltargets[m]) {
12138: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12139: } else {
12140: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12141: }
12142: }
12143: }
12144: }
12145: }
12146: }
12147: }
1.150 raeburn 12148: }
12149: }
12150: }
12151: return;
12152: }
12153:
1.152 raeburn 12154: // ]]>
12155: </script>
12156:
12157: END
12158: }
12159:
12160: sub new_spares_js {
12161: my @sparestypes = ('primary','default');
12162: my $types = join("','",@sparestypes);
12163: my $select = &mt('Select');
12164: return <<"END";
12165:
12166: <script type="text/javascript">
12167: // <![CDATA[
12168:
12169: function updateNewSpares(formname,lonhost) {
12170: var types = new Array('$types');
12171: var include = new Array();
12172: var exclude = new Array();
12173: for (var i=0; i<types.length; i++) {
12174: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12175: for (var j=0; j<spareboxes.length; j++) {
12176: if (formname.elements[spareboxes[j]].checked) {
12177: exclude.push(formname.elements[spareboxes[j]].value);
12178: } else {
12179: include.push(formname.elements[spareboxes[j]].value);
12180: }
12181: }
12182: }
12183: for (var i=0; i<types.length; i++) {
12184: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12185: var selIdx = newSpare.selectedIndex;
12186: var currnew = newSpare.options[selIdx].value;
12187: var okSpares = new Array();
12188: for (var j=0; j<newSpare.options.length; j++) {
12189: var possible = newSpare.options[j].value;
12190: if (possible != '') {
12191: if (exclude.indexOf(possible) == -1) {
12192: okSpares.push(possible);
12193: } else {
12194: if (currnew == possible) {
12195: selIdx = 0;
12196: }
12197: }
12198: }
12199: }
12200: for (var k=0; k<include.length; k++) {
12201: if (okSpares.indexOf(include[k]) == -1) {
12202: okSpares.push(include[k]);
12203: }
12204: }
12205: okSpares.sort();
12206: newSpare.options.length = 0;
12207: if (selIdx == 0) {
12208: newSpare.options[0] = new Option("$select","",true,true);
12209: } else {
12210: newSpare.options[0] = new Option("$select","",false,false);
12211: }
12212: for (var m=0; m<okSpares.length; m++) {
12213: var idx = m+1;
12214: var selThis = 0;
12215: if (selIdx != 0) {
12216: if (okSpares[m] == currnew) {
12217: selThis = 1;
12218: }
12219: }
12220: if (selThis == 1) {
12221: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
12222: } else {
12223: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
12224: }
12225: }
12226: }
12227: return;
12228: }
12229:
12230: function checkNewSpares(lonhost,type) {
12231: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
12232: var chosen = newSpare.options[newSpare.selectedIndex].value;
12233: if (chosen != '') {
12234: var othertype;
12235: var othernewSpare;
12236: if (type == 'primary') {
12237: othernewSpare = document.getElementById('newspare_default_'+lonhost);
12238: }
12239: if (type == 'default') {
12240: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
12241: }
12242: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
12243: othernewSpare.selectedIndex = 0;
12244: }
12245: }
12246: return;
12247: }
12248:
12249: // ]]>
12250: </script>
12251:
12252: END
12253:
12254: }
12255:
12256: sub common_domprefs_js {
12257: return <<"END";
12258:
12259: <script type="text/javascript">
12260: // <![CDATA[
12261:
1.150 raeburn 12262: function getIndicesByName(formname,item) {
1.152 raeburn 12263: var group = new Array();
1.150 raeburn 12264: for (var i=0;i<formname.elements.length;i++) {
12265: if (formname.elements[i].name == item) {
1.152 raeburn 12266: group.push(formname.elements[i].id);
1.150 raeburn 12267: }
12268: }
1.152 raeburn 12269: return group;
1.150 raeburn 12270: }
12271:
12272: // ]]>
12273: </script>
12274:
12275: END
1.152 raeburn 12276:
1.150 raeburn 12277: }
12278:
1.160.6.5 raeburn 12279: sub recaptcha_js {
12280: my %lt = &captcha_phrases();
12281: return <<"END";
12282:
12283: <script type="text/javascript">
12284: // <![CDATA[
12285:
12286: function updateCaptcha(caller,context) {
12287: var privitem;
12288: var pubitem;
12289: var privtext;
12290: var pubtext;
1.160.6.69 raeburn 12291: var versionitem;
12292: var versiontext;
1.160.6.5 raeburn 12293: if (document.getElementById(context+'_recaptchapub')) {
12294: pubitem = document.getElementById(context+'_recaptchapub');
12295: } else {
12296: return;
12297: }
12298: if (document.getElementById(context+'_recaptchapriv')) {
12299: privitem = document.getElementById(context+'_recaptchapriv');
12300: } else {
12301: return;
12302: }
12303: if (document.getElementById(context+'_recaptchapubtxt')) {
12304: pubtext = document.getElementById(context+'_recaptchapubtxt');
12305: } else {
12306: return;
12307: }
12308: if (document.getElementById(context+'_recaptchaprivtxt')) {
12309: privtext = document.getElementById(context+'_recaptchaprivtxt');
12310: } else {
12311: return;
12312: }
1.160.6.69 raeburn 12313: if (document.getElementById(context+'_recaptchaversion')) {
12314: versionitem = document.getElementById(context+'_recaptchaversion');
12315: } else {
12316: return;
12317: }
12318: if (document.getElementById(context+'_recaptchavertxt')) {
12319: versiontext = document.getElementById(context+'_recaptchavertxt');
12320: } else {
12321: return;
12322: }
1.160.6.5 raeburn 12323: if (caller.checked) {
12324: if (caller.value == 'recaptcha') {
12325: pubitem.type = 'text';
12326: privitem.type = 'text';
12327: pubitem.size = '40';
12328: privitem.size = '40';
12329: pubtext.innerHTML = "$lt{'pub'}";
12330: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 12331: versionitem.type = 'text';
12332: versionitem.size = '3';
12333: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 12334: } else {
12335: pubitem.type = 'hidden';
12336: privitem.type = 'hidden';
1.160.6.69 raeburn 12337: versionitem.type = 'hidden';
1.160.6.5 raeburn 12338: pubtext.innerHTML = '';
12339: privtext.innerHTML = '';
1.160.6.69 raeburn 12340: versiontext.innerHTML = '';
1.160.6.5 raeburn 12341: }
12342: }
12343: return;
12344: }
12345:
12346: // ]]>
12347: </script>
12348:
12349: END
12350:
12351: }
12352:
1.160.6.40 raeburn 12353: sub toggle_display_js {
1.160.6.16 raeburn 12354: return <<"END";
12355:
12356: <script type="text/javascript">
12357: // <![CDATA[
12358:
1.160.6.40 raeburn 12359: function toggleDisplay(domForm,caller) {
12360: if (document.getElementById(caller)) {
12361: var divitem = document.getElementById(caller);
12362: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 12363: var checkval = 1;
12364: var dispval = 'block';
1.160.6.40 raeburn 12365: if (caller == 'emailoptions') {
12366: optionsElement = domForm.cancreate_email;
12367: }
1.160.6.57 raeburn 12368: if (caller == 'studentsubmission') {
12369: optionsElement = domForm.postsubmit;
12370: }
1.160.6.64 raeburn 12371: if (caller == 'cloneinstcode') {
12372: optionsElement = domForm.canclone;
12373: checkval = 'instcode';
12374: }
1.160.6.40 raeburn 12375: if (optionsElement.length) {
1.160.6.16 raeburn 12376: var currval;
1.160.6.40 raeburn 12377: for (var i=0; i<optionsElement.length; i++) {
12378: if (optionsElement[i].checked) {
12379: currval = optionsElement[i].value;
1.160.6.16 raeburn 12380: }
12381: }
1.160.6.64 raeburn 12382: if (currval == checkval) {
12383: divitem.style.display = dispval;
1.160.6.16 raeburn 12384: } else {
1.160.6.40 raeburn 12385: divitem.style.display = 'none';
1.160.6.16 raeburn 12386: }
12387: }
12388: }
12389: return;
12390: }
12391:
12392: // ]]>
12393: </script>
12394:
12395: END
12396:
12397: }
12398:
1.160.6.5 raeburn 12399: sub captcha_phrases {
12400: return &Apache::lonlocal::texthash (
12401: priv => 'Private key',
12402: pub => 'Public key',
12403: original => 'original (CAPTCHA)',
12404: recaptcha => 'successor (ReCAPTCHA)',
12405: notused => 'unused',
1.160.6.69 raeburn 12406: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 12407: );
12408: }
12409:
1.160.6.24 raeburn 12410: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 12411: my ($dom,$cachekeys) = @_;
12412: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 12413: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12414: my %thismachine;
12415: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 12416: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 12417: if (keys(%servers)) {
1.160.6.24 raeburn 12418: foreach my $server (keys(%servers)) {
12419: next if ($thismachine{$server});
1.160.6.27 raeburn 12420: my @cached;
12421: foreach my $name (@posscached) {
12422: if ($cachekeys->{$name}) {
12423: push(@cached,&escape($name).':'.&escape($dom));
12424: }
12425: }
12426: if (@cached) {
12427: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12428: }
1.160.6.24 raeburn 12429: }
12430: }
12431: return;
12432: }
12433:
1.3 raeburn 12434: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>