Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.41
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.41! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.40 2014/04/23 11:08:55 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 90: requestcourses or requestauthor).
1.101 raeburn 91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 97: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 98: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 106: (official, unofficial, community, and textbook). In each case the radio buttons
107: allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.69 raeburn 169: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 170: use LONCAPA::Enrollment;
1.81 raeburn 171: use LONCAPA::lonauthcgi();
1.9 raeburn 172: use File::Copy;
1.43 raeburn 173: use Locale::Language;
1.62 raeburn 174: use DateTime::TimeZone;
1.68 raeburn 175: use DateTime::Locale;
1.1 raeburn 176:
1.155 raeburn 177: my $registered_cleanup;
178: my $modified_urls;
179:
1.1 raeburn 180: sub handler {
181: my $r=shift;
182: if ($r->header_only) {
183: &Apache::loncommon::content_type($r,'text/html');
184: $r->send_http_header;
185: return OK;
186: }
187:
1.91 raeburn 188: my $context = 'domain';
1.1 raeburn 189: my $dom = $env{'request.role.domain'};
1.5 albertel 190: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 191: if (&Apache::lonnet::allowed('mau',$dom)) {
192: &Apache::loncommon::content_type($r,'text/html');
193: $r->send_http_header;
194: } else {
195: $env{'user.error.msg'}=
196: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.155 raeburn 199:
200: $registered_cleanup=0;
201: @{$modified_urls}=();
202:
1.1 raeburn 203: &Apache::lonhtmlcommon::clear_breadcrumbs();
204: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 205: ['phase','actions']);
1.30 raeburn 206: my $phase = 'pickactions';
1.3 raeburn 207: if ( exists($env{'form.phase'}) ) {
208: $phase = $env{'form.phase'};
209: }
1.150 raeburn 210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 211: my %domconfig =
1.6 raeburn 212: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 213: 'quotas','autoenroll','autoupdate','autocreate',
214: 'directorysrch','usercreation','usermodification',
215: 'contacts','defaults','scantron','coursecategories',
1.160.6.16 raeburn 216: 'serverstatuses','requestcourses','coursedefaults',
1.160.6.38 raeburn 217: 'usersessions','loadbalancing','requestauthor',
1.160.6.40 raeburn 218: 'selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 222: 'requestcourses','requestauthor','coursecategories',
1.160.6.41! raeburn 223: 'serverstatuses','coursedefaults','selfenrollment',
1.160.6.37 raeburn 224: 'usersessions');
1.160.6.7 raeburn 225: my %existing;
226: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
227: %existing = %{$domconfig{'loadbalancing'}};
228: }
229: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 230: push(@prefs_order,'loadbalancing');
231: }
1.30 raeburn 232: my %prefs = (
233: 'rolecolors' =>
234: { text => 'Default color schemes',
1.67 raeburn 235: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 236: header => [{col1 => 'Student Settings',
237: col2 => '',},
238: {col1 => 'Coordinator Settings',
239: col2 => '',},
240: {col1 => 'Author Settings',
241: col2 => '',},
242: {col1 => 'Administrator Settings',
243: col2 => '',}],
1.160.6.37 raeburn 244: print => \&print_rolecolors,
245: modify => \&modify_rolecolors,
1.30 raeburn 246: },
1.110 raeburn 247: 'login' =>
1.30 raeburn 248: { text => 'Log-in page options',
1.67 raeburn 249: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
253: col2 => 'Value'}],
1.160.6.37 raeburn 254: print => \&print_login,
255: modify => \&modify_login,
1.30 raeburn 256: },
1.43 raeburn 257: 'defaults' =>
1.160.6.40 raeburn 258: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 259: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 260: header => [{col1 => 'Setting',
1.160.6.40 raeburn 261: col2 => 'Value'},
262: {col1 => 'Institutional user types',
263: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 264: print => \&print_defaults,
265: modify => \&modify_defaults,
1.43 raeburn 266: },
1.30 raeburn 267: 'quotas' =>
1.160.6.20 raeburn 268: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 269: help => 'Domain_Configuration_Quotas',
1.77 raeburn 270: header => [{col1 => 'User affiliation',
1.72 raeburn 271: col2 => 'Available tools',
1.160.6.28 raeburn 272: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 273: print => \&print_quotas,
274: modify => \&modify_quotas,
1.30 raeburn 275: },
276: 'autoenroll' =>
277: { text => 'Auto-enrollment settings',
1.67 raeburn 278: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 279: header => [{col1 => 'Configuration setting',
280: col2 => 'Value(s)'}],
1.160.6.37 raeburn 281: print => \&print_autoenroll,
282: modify => \&modify_autoenroll,
1.30 raeburn 283: },
284: 'autoupdate' =>
285: { text => 'Auto-update settings',
1.67 raeburn 286: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 287: header => [{col1 => 'Setting',
288: col2 => 'Value',},
1.131 raeburn 289: {col1 => 'Setting',
290: col2 => 'Affiliation'},
1.43 raeburn 291: {col1 => 'User population',
1.160.6.35 raeburn 292: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 293: print => \&print_autoupdate,
294: modify => \&modify_autoupdate,
1.30 raeburn 295: },
1.125 raeburn 296: 'autocreate' =>
297: { text => 'Auto-course creation settings',
298: help => 'Domain_Configuration_Auto_Creation',
299: header => [{col1 => 'Configuration Setting',
300: col2 => 'Value',}],
1.160.6.37 raeburn 301: print => \&print_autocreate,
302: modify => \&modify_autocreate,
1.125 raeburn 303: },
1.30 raeburn 304: 'directorysrch' =>
305: { text => 'Institutional directory searches',
1.67 raeburn 306: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 307: header => [{col1 => 'Setting',
308: col2 => 'Value',}],
1.160.6.37 raeburn 309: print => \&print_directorysrch,
310: modify => \&modify_directorysrch,
1.30 raeburn 311: },
312: 'contacts' =>
313: { text => 'Contact Information',
1.67 raeburn 314: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 315: header => [{col1 => 'Setting',
316: col2 => 'Value',}],
1.160.6.37 raeburn 317: print => \&print_contacts,
318: modify => \&modify_contacts,
1.30 raeburn 319: },
320: 'usercreation' =>
321: { text => 'User creation',
1.67 raeburn 322: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 323: header => [{col1 => 'Format rule type',
324: col2 => 'Format rules in force'},
1.34 raeburn 325: {col1 => 'User account creation',
326: col2 => 'Usernames which may be created',},
1.30 raeburn 327: {col1 => 'Context',
1.43 raeburn 328: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 329: print => \&print_usercreation,
330: modify => \&modify_usercreation,
1.30 raeburn 331: },
1.160.6.34 raeburn 332: 'selfcreation' =>
333: { text => 'Users self-creating accounts',
334: help => 'Domain_Configuration_Self_Creation',
335: header => [{col1 => 'Self-creation with institutional username',
336: col2 => 'Enabled?'},
337: {col1 => 'Institutional user type (login/SSO self-creation)',
338: col2 => 'Information user can enter'},
339: {col1 => 'Self-creation with e-mail as username',
340: col2 => 'Settings'}],
1.160.6.37 raeburn 341: print => \&print_selfcreation,
342: modify => \&modify_selfcreation,
1.160.6.34 raeburn 343: },
1.69 raeburn 344: 'usermodification' =>
1.33 raeburn 345: { text => 'User modification',
1.67 raeburn 346: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 347: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 348: col2 => 'User information updatable in author context'},
1.33 raeburn 349: {col1 => 'Target user has role',
1.160.6.35 raeburn 350: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 351: print => \&print_usermodification,
352: modify => \&modify_usermodification,
1.33 raeburn 353: },
1.69 raeburn 354: 'scantron' =>
1.95 www 355: { text => 'Bubblesheet format file',
1.67 raeburn 356: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 357: header => [ {col1 => 'Item',
358: col2 => '',
359: }],
1.160.6.37 raeburn 360: print => \&print_scantron,
361: modify => \&modify_scantron,
1.46 raeburn 362: },
1.86 raeburn 363: 'requestcourses' =>
364: {text => 'Request creation of courses',
365: help => 'Domain_Configuration_Request_Courses',
366: header => [{col1 => 'User affiliation',
1.102 raeburn 367: col2 => 'Availability/Processing of requests',},
368: {col1 => 'Setting',
1.160.6.30 raeburn 369: col2 => 'Value'},
370: {col1 => 'Available textbooks',
1.160.6.39 raeburn 371: col2 => ''},
372: {col1 => 'Validation (not official courses)',
373: col2 => 'Value'},],
1.160.6.37 raeburn 374: print => \&print_quotas,
375: modify => \&modify_quotas,
1.86 raeburn 376: },
1.160.6.5 raeburn 377: 'requestauthor' =>
1.160.6.34 raeburn 378: {text => 'Request Authoring Space',
1.160.6.5 raeburn 379: help => 'Domain_Configuration_Request_Author',
380: header => [{col1 => 'User affiliation',
381: col2 => 'Availability/Processing of requests',},
382: {col1 => 'Setting',
383: col2 => 'Value'}],
1.160.6.37 raeburn 384: print => \&print_quotas,
385: modify => \&modify_quotas,
1.160.6.5 raeburn 386: },
1.69 raeburn 387: 'coursecategories' =>
1.120 raeburn 388: { text => 'Cataloging of courses/communities',
1.67 raeburn 389: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 390: header => [{col1 => 'Category settings',
1.57 raeburn 391: col2 => '',},
392: {col1 => 'Categories',
393: col2 => '',
394: }],
1.160.6.37 raeburn 395: print => \&print_coursecategories,
396: modify => \&modify_coursecategories,
1.69 raeburn 397: },
398: 'serverstatuses' =>
1.77 raeburn 399: {text => 'Access to server status pages',
1.69 raeburn 400: help => 'Domain_Configuration_Server_Status',
401: header => [{col1 => 'Status Page',
402: col2 => 'Other named users',
403: col3 => 'Specific IPs',
404: }],
1.160.6.37 raeburn 405: print => \&print_serverstatuses,
406: modify => \&modify_serverstatuses,
1.69 raeburn 407: },
1.160.6.39 raeburn 408: 'coursedefaults' =>
1.160.6.16 raeburn 409: {text => 'Course/Community defaults',
410: help => 'Domain_Configuration_Course_Defaults',
1.160.6.37 raeburn 411: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
412: col2 => 'Value',},
413: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 414: col2 => 'Value',},],
1.160.6.37 raeburn 415: print => \&print_coursedefaults,
416: modify => \&modify_coursedefaults,
417: },
1.160.6.39 raeburn 418: 'selfenrollment' =>
1.160.6.37 raeburn 419: {text => 'Self-enrollment in Course/Community',
420: help => 'Domain_Configuration_Selfenrollment',
421: header => [{col1 => 'Configuration Rights',
422: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
423: {col1 => 'Defaults',
424: col2 => 'Value'},
425: {col1 => 'Self-enrollment validation (optional)',
426: col2 => 'Value'},],
427: print => \&print_selfenrollment,
428: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 429: },
1.141 raeburn 430: 'usersessions' =>
1.145 raeburn 431: {text => 'User session hosting/offloading',
1.137 raeburn 432: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 433: header => [{col1 => 'Domain server',
434: col2 => 'Servers to offload sessions to when busy'},
435: {col1 => 'Hosting of users from other domains',
1.137 raeburn 436: col2 => 'Rules'},
437: {col1 => "Hosting domain's own users elsewhere",
438: col2 => 'Rules'}],
1.160.6.37 raeburn 439: print => \&print_usersessions,
440: modify => \&modify_usersessions,
1.137 raeburn 441: },
1.150 raeburn 442: 'loadbalancing' =>
1.160.6.7 raeburn 443: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 444: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 445: header => [{col1 => 'Balancers',
1.150 raeburn 446: col2 => 'Default destinations',
1.160.6.13 raeburn 447: col3 => 'User affiliation',
1.150 raeburn 448: col4 => 'Overrides'},
449: ],
1.160.6.37 raeburn 450: print => \&print_loadbalancing,
451: modify => \&modify_loadbalancing,
1.150 raeburn 452: },
1.3 raeburn 453: );
1.110 raeburn 454: if (keys(%servers) > 1) {
455: $prefs{'login'} = { text => 'Log-in page options',
456: help => 'Domain_Configuration_Login_Page',
457: header => [{col1 => 'Log-in Service',
458: col2 => 'Server Setting',},
459: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 460: col2 => ''},
461: {col1 => 'Log-in Help',
462: col2 => 'Value'}],
1.160.6.37 raeburn 463: print => \&print_login,
464: modify => \&modify_login,
1.110 raeburn 465: };
466: }
1.160.6.13 raeburn 467:
1.6 raeburn 468: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 469: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 470: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 471: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 472: text=>"Settings to display/modify"});
1.9 raeburn 473: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 474:
1.3 raeburn 475: if ($phase eq 'process') {
1.160.6.27 raeburn 476: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
477: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 478: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 479: $r->rflush();
1.160.6.27 raeburn 480: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 481: }
1.30 raeburn 482: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 483: my $js = &recaptcha_js().
1.160.6.40 raeburn 484: &toggle_display_js();
1.160.6.7 raeburn 485: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 486: my ($othertitle,$usertypes,$types) =
487: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 488: $js .= &lonbalance_targets_js($dom,$types,\%servers,
489: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 490: &new_spares_js().
491: &common_domprefs_js().
492: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 493: }
1.160.6.30 raeburn 494: if (grep(/^requestcourses$/,@actions)) {
495: my $javascript_validations;
496: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
497: $js .= <<END;
498: <script type="text/javascript">
499: $javascript_validations
500: </script>
501: $coursebrowserjs
502: END
503: }
1.150 raeburn 504: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 505: } else {
1.160.6.11 raeburn 506: # check if domconfig user exists for the domain.
507: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 508: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 509: &config_check($dom,$confname,$servadm);
510: unless ($configuserok eq 'ok') {
511: &Apache::lonconfigsettings::print_header($r,$phase,$context);
512: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
513: $confname).
514: '<br />'
515: );
516: if ($switchserver) {
517: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
518: '<br />'.
519: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
520: '<br />'.
521: &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).
522: '<br />'.
523: &mt('To do that now, use the following link: [_1]',$switchserver)
524: );
525: } else {
526: $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.').
527: '<br />'.
528: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
529: );
530: }
531: $r->print(&Apache::loncommon::end_page());
532: return OK;
533: }
1.21 raeburn 534: if (keys(%domconfig) == 0) {
535: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 536: my @ids=&Apache::lonnet::current_machine_ids();
537: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 538: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 539: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 540: my $custom_img_count = 0;
541: foreach my $img (@loginimages) {
542: if ($designhash{$dom.'.login.'.$img} ne '') {
543: $custom_img_count ++;
544: }
545: }
546: foreach my $role (@roles) {
547: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
548: $custom_img_count ++;
549: }
550: }
551: if ($custom_img_count > 0) {
1.94 raeburn 552: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 553: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 554: $r->print(
555: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
556: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
557: &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 />'.
558: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
559: if ($switch_server) {
1.30 raeburn 560: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 561: }
1.91 raeburn 562: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 563: return OK;
564: }
565: }
566: }
1.91 raeburn 567: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 568: }
569: return OK;
570: }
571:
572: sub process_changes {
1.160.6.24 raeburn 573: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 574: my %domconfig;
575: if (ref($values) eq 'HASH') {
576: %domconfig = %{$values};
577: }
1.3 raeburn 578: my $output;
579: if ($action eq 'login') {
1.160.6.24 raeburn 580: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 581: } elsif ($action eq 'rolecolors') {
1.9 raeburn 582: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 583: $lastactref,%domconfig);
1.3 raeburn 584: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 585: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 586: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 587: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 588: } elsif ($action eq 'autoupdate') {
589: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 590: } elsif ($action eq 'autocreate') {
591: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 592: } elsif ($action eq 'directorysrch') {
593: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 594: } elsif ($action eq 'usercreation') {
1.28 raeburn 595: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 596: } elsif ($action eq 'selfcreation') {
597: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 598: } elsif ($action eq 'usermodification') {
599: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 600: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 601: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 602: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 603: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 604: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 605: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 606: } elsif ($action eq 'coursecategories') {
607: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 608: } elsif ($action eq 'serverstatuses') {
609: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 610: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 611: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 612: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 613: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 614: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 615: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 616: } elsif ($action eq 'selfenrollment') {
617: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 618: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 619: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 620: } elsif ($action eq 'loadbalancing') {
621: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 622: }
623: return $output;
624: }
625:
626: sub print_config_box {
1.9 raeburn 627: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 628: my $rowtotal = 0;
1.49 raeburn 629: my $output;
630: if ($action eq 'coursecategories') {
631: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 632: } elsif ($action eq 'defaults') {
633: $output = &defaults_javascript($settings);
1.91 raeburn 634: }
1.160.6.40 raeburn 635: $output .=
1.30 raeburn 636: '<table class="LC_nested_outer">
1.3 raeburn 637: <tr>
1.66 raeburn 638: <th align="left" valign="middle"><span class="LC_nobreak">'.
639: &mt($item->{text}).' '.
640: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
641: '</tr>';
1.30 raeburn 642: $rowtotal ++;
1.110 raeburn 643: my $numheaders = 1;
644: if (ref($item->{'header'}) eq 'ARRAY') {
645: $numheaders = scalar(@{$item->{'header'}});
646: }
647: if ($numheaders > 1) {
1.64 raeburn 648: my $colspan = '';
1.145 raeburn 649: my $rightcolspan = '';
1.160.6.40 raeburn 650: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'defaults') ||
1.160.6.5 raeburn 651: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 652: $colspan = ' colspan="2"';
653: }
1.145 raeburn 654: if ($action eq 'usersessions') {
655: $rightcolspan = ' colspan="3"';
656: }
1.30 raeburn 657: $output .= '
1.3 raeburn 658: <tr>
659: <td>
660: <table class="LC_nested">
661: <tr class="LC_info_row">
1.59 bisitz 662: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 663: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 664: </tr>';
1.69 raeburn 665: $rowtotal ++;
1.160.6.37 raeburn 666: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.40 raeburn 667: ($action eq 'usermodification') || ($action eq 'defaults') ||
668: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 669: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 670: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 671: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 672: } elsif ($action eq 'login') {
1.160.6.5 raeburn 673: if ($numheaders == 3) {
674: $colspan = ' colspan="2"';
675: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
676: } else {
677: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
678: }
1.160.6.37 raeburn 679: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 680: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 681: } elsif ($action eq 'rolecolors') {
1.30 raeburn 682: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 683: }
1.30 raeburn 684: $output .= '
1.6 raeburn 685: </table>
686: </td>
687: </tr>
688: <tr>
689: <td>
690: <table class="LC_nested">
691: <tr class="LC_info_row">
1.160.6.37 raeburn 692: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 693: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 694: </tr>';
695: $rowtotal ++;
1.160.6.37 raeburn 696: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
697: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
698: ($action eq 'usersessions')) {
699: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal).'
1.63 raeburn 700: </table>
701: </td>
702: </tr>
703: <tr>
704: <td>
705: <table class="LC_nested">
706: <tr class="LC_info_row">
707: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 708: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.37 raeburn 709: </tr>'."\n".
710: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.63 raeburn 711: $rowtotal ++;
1.160.6.40 raeburn 712: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
713: ($action eq 'defaults')) {
1.160.6.37 raeburn 714: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.57 raeburn 715: } elsif ($action eq 'coursecategories') {
716: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 717: } elsif ($action eq 'login') {
1.160.6.5 raeburn 718: if ($numheaders == 3) {
719: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
720: </table>
721: </td>
722: </tr>
723: <tr>
724: <td>
725: <table class="LC_nested">
726: <tr class="LC_info_row">
727: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 728: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 729: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
730: $rowtotal ++;
731: } else {
732: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
733: }
1.102 raeburn 734: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 735: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
736: &print_studentcode($settings,\$rowtotal).'
737: </table>
738: </td>
739: </tr>
740: <tr>
741: <td>
742: <table class="LC_nested">
743: <tr class="LC_info_row">
744: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
745: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.39 raeburn 746: &print_textbookcourses($dom,$settings,\$rowtotal).'
747: </table>
748: </td>
749: </tr>
750: <tr>
751: <td>
752: <table class="LC_nested">
753: <tr class="LC_info_row">
754: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
755: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
756: </tr>'.
757: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 758: } elsif ($action eq 'requestauthor') {
759: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 760: } elsif ($action eq 'rolecolors') {
1.30 raeburn 761: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 762: </table>
763: </td>
764: </tr>
765: <tr>
766: <td>
767: <table class="LC_nested">
768: <tr class="LC_info_row">
1.69 raeburn 769: <td class="LC_left_item"'.$colspan.' valign="top">'.
770: &mt($item->{'header'}->[2]->{'col1'}).'</td>
771: <td class="LC_right_item" valign="top">'.
772: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 773: </tr>'.
1.30 raeburn 774: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 775: </table>
776: </td>
777: </tr>
778: <tr>
779: <td>
780: <table class="LC_nested">
781: <tr class="LC_info_row">
1.59 bisitz 782: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
783: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 784: </tr>'.
1.30 raeburn 785: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
786: $rowtotal += 2;
1.6 raeburn 787: }
1.3 raeburn 788: } else {
1.30 raeburn 789: $output .= '
1.3 raeburn 790: <tr>
791: <td>
792: <table class="LC_nested">
1.30 raeburn 793: <tr class="LC_info_row">';
1.24 raeburn 794: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 795: $output .= '
1.59 bisitz 796: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 797: } elsif ($action eq 'serverstatuses') {
798: $output .= '
799: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
800: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
801:
1.6 raeburn 802: } else {
1.30 raeburn 803: $output .= '
1.69 raeburn 804: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
805: }
1.72 raeburn 806: if (defined($item->{'header'}->[0]->{'col3'})) {
807: $output .= '<td class="LC_left_item" valign="top">'.
808: &mt($item->{'header'}->[0]->{'col2'});
809: if ($action eq 'serverstatuses') {
810: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
811: }
1.69 raeburn 812: } else {
813: $output .= '<td class="LC_right_item" valign="top">'.
814: &mt($item->{'header'}->[0]->{'col2'});
815: }
816: $output .= '</td>';
817: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 818: if (defined($item->{'header'}->[0]->{'col4'})) {
819: $output .= '<td class="LC_left_item" valign="top">'.
820: &mt($item->{'header'}->[0]->{'col3'});
821: } else {
822: $output .= '<td class="LC_right_item" valign="top">'.
823: &mt($item->{'header'}->[0]->{'col3'});
824: }
1.69 raeburn 825: if ($action eq 'serverstatuses') {
826: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
827: }
828: $output .= '</td>';
1.6 raeburn 829: }
1.150 raeburn 830: if ($item->{'header'}->[0]->{'col4'}) {
831: $output .= '<td class="LC_right_item" valign="top">'.
832: &mt($item->{'header'}->[0]->{'col4'});
833: }
1.69 raeburn 834: $output .= '</tr>';
1.48 raeburn 835: $rowtotal ++;
1.160.6.5 raeburn 836: if ($action eq 'quotas') {
1.86 raeburn 837: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 838: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 839: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 840: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 841: } elsif ($action eq 'scantron') {
842: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 843: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 844: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 845: }
1.3 raeburn 846: }
1.30 raeburn 847: $output .= '
1.3 raeburn 848: </table>
849: </td>
850: </tr>
1.30 raeburn 851: </table><br />';
852: return ($output,$rowtotal);
1.1 raeburn 853: }
854:
1.3 raeburn 855: sub print_login {
1.160.6.5 raeburn 856: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 857: my ($css_class,$datatable);
1.6 raeburn 858: my %choices = &login_choices();
1.110 raeburn 859:
1.160.6.5 raeburn 860: if ($caller eq 'service') {
1.149 raeburn 861: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 862: my $choice = $choices{'disallowlogin'};
863: $css_class = ' class="LC_odd_row"';
1.128 raeburn 864: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 865: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 866: '<th>'.$choices{'server'}.'</th>'.
867: '<th>'.$choices{'serverpath'}.'</th>'.
868: '<th>'.$choices{'custompath'}.'</th>'.
869: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 870: my %disallowed;
871: if (ref($settings) eq 'HASH') {
872: if (ref($settings->{'loginvia'}) eq 'HASH') {
873: %disallowed = %{$settings->{'loginvia'}};
874: }
875: }
876: foreach my $lonhost (sort(keys(%servers))) {
877: my $direct = 'selected="selected"';
1.128 raeburn 878: if (ref($disallowed{$lonhost}) eq 'HASH') {
879: if ($disallowed{$lonhost}{'server'} ne '') {
880: $direct = '';
881: }
1.110 raeburn 882: }
1.115 raeburn 883: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 884: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 885: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
886: '</option>';
1.160.6.13 raeburn 887: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 888: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 889: my $selected = '';
1.128 raeburn 890: if (ref($disallowed{$lonhost}) eq 'HASH') {
891: if ($hostid eq $disallowed{$lonhost}{'server'}) {
892: $selected = 'selected="selected"';
893: }
1.110 raeburn 894: }
895: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
896: $servers{$hostid}.'</option>';
897: }
1.128 raeburn 898: $datatable .= '</select></td>'.
899: '<td><select name="'.$lonhost.'_serverpath">';
900: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
901: my $pathname = $path;
902: if ($path eq 'custom') {
903: $pathname = &mt('Custom Path').' ->';
904: }
905: my $selected = '';
906: if (ref($disallowed{$lonhost}) eq 'HASH') {
907: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
908: $selected = 'selected="selected"';
909: }
910: } elsif ($path eq '') {
911: $selected = 'selected="selected"';
912: }
913: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
914: }
915: $datatable .= '</select></td>';
916: my ($custom,$exempt);
917: if (ref($disallowed{$lonhost}) eq 'HASH') {
918: $custom = $disallowed{$lonhost}{'custompath'};
919: $exempt = $disallowed{$lonhost}{'exempt'};
920: }
921: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
922: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
923: '</tr>';
1.110 raeburn 924: }
925: $datatable .= '</table></td></tr>';
926: return $datatable;
1.160.6.5 raeburn 927: } elsif ($caller eq 'page') {
928: my %defaultchecked = (
929: 'coursecatalog' => 'on',
1.160.6.14 raeburn 930: 'helpdesk' => 'on',
1.160.6.5 raeburn 931: 'adminmail' => 'off',
932: 'newuser' => 'off',
933: );
1.160.6.14 raeburn 934: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 935: my (%checkedon,%checkedoff);
1.42 raeburn 936: foreach my $item (@toggles) {
1.160.6.5 raeburn 937: if ($defaultchecked{$item} eq 'on') {
938: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 939: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 940: } elsif ($defaultchecked{$item} eq 'off') {
941: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 942: $checkedon{$item} = ' ';
943: }
1.1 raeburn 944: }
1.160.6.5 raeburn 945: my @images = ('img','logo','domlogo','login');
946: my @logintext = ('textcol','bgcol');
947: my @bgs = ('pgbg','mainbg','sidebg');
948: my @links = ('link','alink','vlink');
949: my %designhash = &Apache::loncommon::get_domainconf($dom);
950: my %defaultdesign = %Apache::loncommon::defaultdesign;
951: my (%is_custom,%designs);
952: my %defaults = (
953: font => $defaultdesign{'login.font'},
954: );
1.6 raeburn 955: foreach my $item (@images) {
1.160.6.5 raeburn 956: $defaults{$item} = $defaultdesign{'login.'.$item};
957: $defaults{'showlogo'}{$item} = 1;
958: }
959: foreach my $item (@bgs) {
960: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 961: }
1.41 raeburn 962: foreach my $item (@logintext) {
1.160.6.5 raeburn 963: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 964: }
1.160.6.5 raeburn 965: foreach my $item (@links) {
966: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 967: }
1.160.6.5 raeburn 968: if (ref($settings) eq 'HASH') {
969: foreach my $item (@toggles) {
970: if ($settings->{$item} eq '1') {
971: $checkedon{$item} = ' checked="checked" ';
972: $checkedoff{$item} = ' ';
973: } elsif ($settings->{$item} eq '0') {
974: $checkedoff{$item} = ' checked="checked" ';
975: $checkedon{$item} = ' ';
976: }
1.6 raeburn 977: }
1.160.6.5 raeburn 978: foreach my $item (@images) {
979: if (defined($settings->{$item})) {
980: $designs{$item} = $settings->{$item};
981: $is_custom{$item} = 1;
982: }
983: if (defined($settings->{'showlogo'}{$item})) {
984: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
985: }
986: }
987: foreach my $item (@logintext) {
988: if ($settings->{$item} ne '') {
989: $designs{'logintext'}{$item} = $settings->{$item};
990: $is_custom{$item} = 1;
991: }
992: }
993: if ($settings->{'font'} ne '') {
994: $designs{'font'} = $settings->{'font'};
995: $is_custom{'font'} = 1;
996: }
997: foreach my $item (@bgs) {
998: if ($settings->{$item} ne '') {
999: $designs{'bgs'}{$item} = $settings->{$item};
1000: $is_custom{$item} = 1;
1001: }
1002: }
1003: foreach my $item (@links) {
1004: if ($settings->{$item} ne '') {
1005: $designs{'links'}{$item} = $settings->{$item};
1006: $is_custom{$item} = 1;
1007: }
1008: }
1009: } else {
1010: if ($designhash{$dom.'.login.font'} ne '') {
1011: $designs{'font'} = $designhash{$dom.'.login.font'};
1012: $is_custom{'font'} = 1;
1013: }
1014: foreach my $item (@images) {
1015: if ($designhash{$dom.'.login.'.$item} ne '') {
1016: $designs{$item} = $designhash{$dom.'.login.'.$item};
1017: $is_custom{$item} = 1;
1018: }
1019: }
1020: foreach my $item (@bgs) {
1021: if ($designhash{$dom.'.login.'.$item} ne '') {
1022: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1023: $is_custom{$item} = 1;
1024: }
1025: }
1026: foreach my $item (@links) {
1027: if ($designhash{$dom.'.login.'.$item} ne '') {
1028: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1029: $is_custom{$item} = 1;
1030: }
1.6 raeburn 1031: }
1032: }
1.160.6.5 raeburn 1033: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1034: logo => 'Institution Logo',
1035: domlogo => 'Domain Logo',
1036: login => 'Login box');
1037: my $itemcount = 1;
1038: foreach my $item (@toggles) {
1039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1040: $datatable .=
1041: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1042: '</td><td>'.
1043: '<span class="LC_nobreak"><label><input type="radio" name="'.
1044: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1045: '</label> <label><input type="radio" name="'.$item.'"'.
1046: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1047: '</tr>';
1048: $itemcount ++;
1.6 raeburn 1049: }
1.160.6.5 raeburn 1050: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1051: $datatable .= '</tr></table></td></tr>';
1052: } elsif ($caller eq 'help') {
1053: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1054: my $switchserver = &check_switchserver($dom,$confname);
1055: my $itemcount = 1;
1056: $defaulturl = '/adm/loginproblems.html';
1057: $defaulttype = 'default';
1058: %lt = &Apache::lonlocal::texthash (
1059: del => 'Delete?',
1060: rep => 'Replace:',
1061: upl => 'Upload:',
1062: default => 'Default',
1063: custom => 'Custom',
1064: );
1065: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1066: my @currlangs;
1067: if (ref($settings) eq 'HASH') {
1068: if (ref($settings->{'helpurl'}) eq 'HASH') {
1069: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1070: next if ($settings->{'helpurl'}{$key} eq '');
1071: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1072: $type{$key} = 'custom';
1073: unless ($key eq 'nolang') {
1074: push(@currlangs,$key);
1075: }
1076: }
1077: } elsif ($settings->{'helpurl'} ne '') {
1078: $type{'nolang'} = 'custom';
1079: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1080: }
1081: }
1.160.6.5 raeburn 1082: foreach my $lang ('nolang',sort(@currlangs)) {
1083: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1084: $datatable .= '<tr'.$css_class.'>';
1085: if ($url{$lang} eq '') {
1086: $url{$lang} = $defaulturl;
1087: }
1088: if ($type{$lang} eq '') {
1089: $type{$lang} = $defaulttype;
1090: }
1091: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1092: if ($lang eq 'nolang') {
1093: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1094: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1095: } else {
1096: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1097: $langchoices{$lang},
1098: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1099: }
1100: $datatable .= '</span></td>'."\n".
1101: '<td class="LC_left_item">';
1102: if ($type{$lang} eq 'custom') {
1103: $datatable .= '<span class="LC_nobreak"><label>'.
1104: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1105: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1106: } else {
1107: $datatable .= $lt{'upl'};
1108: }
1109: $datatable .='<br />';
1110: if ($switchserver) {
1111: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1112: } else {
1113: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1114: }
1.160.6.5 raeburn 1115: $datatable .= '</td></tr>';
1116: $itemcount ++;
1.6 raeburn 1117: }
1.160.6.5 raeburn 1118: my @addlangs;
1119: foreach my $lang (sort(keys(%langchoices))) {
1120: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1121: push(@addlangs,$lang);
1122: }
1123: if (@addlangs > 0) {
1124: my %toadd;
1125: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1126: $toadd{''} = &mt('Select');
1127: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1128: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1129: &mt('Add log-in help page for a specific language:').' '.
1130: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1131: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1132: if ($switchserver) {
1133: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1134: } else {
1135: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1136: }
1.160.6.5 raeburn 1137: $datatable .= '</td></tr>';
1138: $itemcount ++;
1.6 raeburn 1139: }
1.160.6.5 raeburn 1140: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1141: }
1.6 raeburn 1142: return $datatable;
1143: }
1144:
1145: sub login_choices {
1146: my %choices =
1147: &Apache::lonlocal::texthash (
1.116 bisitz 1148: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1149: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1150: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1151: disallowlogin => "Login page requests redirected",
1152: hostid => "Server",
1.128 raeburn 1153: server => "Redirect to:",
1154: serverpath => "Path",
1155: custompath => "Custom",
1156: exempt => "Exempt IP(s)",
1.110 raeburn 1157: directlogin => "No redirect",
1158: newuser => "Link to create a user account",
1159: img => "Header",
1160: logo => "Main Logo",
1161: domlogo => "Domain Logo",
1162: login => "Log-in Header",
1163: textcol => "Text color",
1164: bgcol => "Box color",
1165: bgs => "Background colors",
1166: links => "Link colors",
1167: font => "Font color",
1168: pgbg => "Header",
1169: mainbg => "Page",
1170: sidebg => "Login box",
1171: link => "Link",
1172: alink => "Active link",
1173: vlink => "Visited link",
1.6 raeburn 1174: );
1175: return %choices;
1176: }
1177:
1178: sub print_rolecolors {
1.30 raeburn 1179: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1180: my %choices = &color_font_choices();
1181: my @bgs = ('pgbg','tabbg','sidebg');
1182: my @links = ('link','alink','vlink');
1183: my @images = ('img');
1184: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1185: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1186: my %defaultdesign = %Apache::loncommon::defaultdesign;
1187: my (%is_custom,%designs);
1.160.6.22 raeburn 1188: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1189: if (ref($settings) eq 'HASH') {
1190: if (ref($settings->{$role}) eq 'HASH') {
1191: if ($settings->{$role}->{'img'} ne '') {
1192: $designs{'img'} = $settings->{$role}->{'img'};
1193: $is_custom{'img'} = 1;
1194: }
1195: if ($settings->{$role}->{'font'} ne '') {
1196: $designs{'font'} = $settings->{$role}->{'font'};
1197: $is_custom{'font'} = 1;
1198: }
1.97 tempelho 1199: if ($settings->{$role}->{'fontmenu'} ne '') {
1200: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1201: $is_custom{'fontmenu'} = 1;
1202: }
1.6 raeburn 1203: foreach my $item (@bgs) {
1204: if ($settings->{$role}->{$item} ne '') {
1205: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1206: $is_custom{$item} = 1;
1207: }
1208: }
1209: foreach my $item (@links) {
1210: if ($settings->{$role}->{$item} ne '') {
1211: $designs{'links'}{$item} = $settings->{$role}->{$item};
1212: $is_custom{$item} = 1;
1213: }
1214: }
1215: }
1216: } else {
1217: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1218: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1219: $is_custom{'img'} = 1;
1220: }
1.97 tempelho 1221: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1222: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1223: $is_custom{'fontmenu'} = 1;
1224: }
1.6 raeburn 1225: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1226: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1227: $is_custom{'font'} = 1;
1228: }
1229: foreach my $item (@bgs) {
1230: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1231: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1232: $is_custom{$item} = 1;
1233:
1234: }
1235: }
1236: foreach my $item (@links) {
1237: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1238: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1239: $is_custom{$item} = 1;
1240: }
1241: }
1242: }
1243: my $itemcount = 1;
1.30 raeburn 1244: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1245: $datatable .= '</tr></table></td></tr>';
1246: return $datatable;
1247: }
1248:
1.160.6.22 raeburn 1249: sub role_defaults {
1250: my ($role,$bgs,$links,$images,$logintext) = @_;
1251: my %defaults;
1252: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1253: return %defaults;
1254: }
1255: my %defaultdesign = %Apache::loncommon::defaultdesign;
1256: if ($role eq 'login') {
1257: %defaults = (
1258: font => $defaultdesign{$role.'.font'},
1259: );
1260: if (ref($logintext) eq 'ARRAY') {
1261: foreach my $item (@{$logintext}) {
1262: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1263: }
1264: }
1265: foreach my $item (@{$images}) {
1266: $defaults{'showlogo'}{$item} = 1;
1267: }
1268: } else {
1269: %defaults = (
1270: img => $defaultdesign{$role.'.img'},
1271: font => $defaultdesign{$role.'.font'},
1272: fontmenu => $defaultdesign{$role.'.fontmenu'},
1273: );
1274: }
1275: foreach my $item (@{$bgs}) {
1276: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1277: }
1278: foreach my $item (@{$links}) {
1279: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1280: }
1281: foreach my $item (@{$images}) {
1282: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1283: }
1284: return %defaults;
1285: }
1286:
1.6 raeburn 1287: sub display_color_options {
1.9 raeburn 1288: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1289: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1290: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1291: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1292: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1293: '<td>'.$choices->{'font'}.'</td>';
1294: if (!$is_custom->{'font'}) {
1.30 raeburn 1295: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1296: } else {
1297: $datatable .= '<td> </td>';
1298: }
1.160.6.9 raeburn 1299: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1300:
1.8 raeburn 1301: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1302: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1303: ' value="'.$current_color.'" /> '.
1304: ' </td></tr>';
1.107 raeburn 1305: unless ($role eq 'login') {
1306: $datatable .= '<tr'.$css_class.'>'.
1307: '<td>'.$choices->{'fontmenu'}.'</td>';
1308: if (!$is_custom->{'fontmenu'}) {
1309: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1310: } else {
1311: $datatable .= '<td> </td>';
1312: }
1.160.6.22 raeburn 1313: $current_color = $designs->{'fontmenu'} ?
1314: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1315: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1316: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1317: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1318: ' value="'.$current_color.'" /> '.
1319: ' </td></tr>';
1.97 tempelho 1320: }
1.9 raeburn 1321: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1322: foreach my $img (@{$images}) {
1.18 albertel 1323: $itemcount ++;
1.6 raeburn 1324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1325: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1326: '<td>'.$choices->{$img};
1.41 raeburn 1327: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1328: if ($role eq 'login') {
1329: if ($img eq 'login') {
1330: $login_hdr_pick =
1.135 bisitz 1331: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1332: $logincolors =
1333: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1334: $designs,$defaults);
1.70 raeburn 1335: } elsif ($img ne 'domlogo') {
1336: $datatable.= &logo_display_options($img,$defaults,$designs);
1337: }
1338: }
1339: $datatable .= '</td>';
1.6 raeburn 1340: if ($designs->{$img} ne '') {
1341: $imgfile = $designs->{$img};
1.18 albertel 1342: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1343: } else {
1344: $imgfile = $defaults->{$img};
1345: }
1346: if ($imgfile) {
1.9 raeburn 1347: my ($showfile,$fullsize);
1348: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1349: my $urldir = $1;
1350: my $filename = $2;
1351: my @info = &Apache::lonnet::stat_file($designs->{$img});
1352: if (@info) {
1353: my $thumbfile = 'tn-'.$filename;
1354: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1355: if (@thumb) {
1356: $showfile = $urldir.'/'.$thumbfile;
1357: } else {
1358: $showfile = $imgfile;
1359: }
1360: } else {
1361: $showfile = '';
1362: }
1363: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1364: $showfile = $imgfile;
1.6 raeburn 1365: my $imgdir = $1;
1366: my $filename = $2;
1.159 raeburn 1367: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1368: $showfile = "/$imgdir/tn-".$filename;
1369: } else {
1.159 raeburn 1370: my $input = $londocroot.$imgfile;
1371: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1372: if (!-e $output) {
1.9 raeburn 1373: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1374: my ($fullwidth,$fullheight) = &check_dimensions($input);
1375: if ($fullwidth ne '' && $fullheight ne '') {
1376: if ($fullwidth > $width && $fullheight > $height) {
1377: my $size = $width.'x'.$height;
1378: system("convert -sample $size $input $output");
1.159 raeburn 1379: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1380: }
1381: }
1.6 raeburn 1382: }
1383: }
1.16 raeburn 1384: }
1.6 raeburn 1385: if ($showfile) {
1.40 raeburn 1386: if ($showfile =~ m{^/(adm|res)/}) {
1387: if ($showfile =~ m{^/res/}) {
1388: my $local_showfile =
1389: &Apache::lonnet::filelocation('',$showfile);
1390: &Apache::lonnet::repcopy($local_showfile);
1391: }
1392: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1393: }
1394: if ($imgfile) {
1395: if ($imgfile =~ m{^/(adm|res)/}) {
1396: if ($imgfile =~ m{^/res/}) {
1397: my $local_imgfile =
1398: &Apache::lonnet::filelocation('',$imgfile);
1399: &Apache::lonnet::repcopy($local_imgfile);
1400: }
1401: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1402: } else {
1403: $fullsize = $imgfile;
1404: }
1405: }
1.41 raeburn 1406: $datatable .= '<td>';
1407: if ($img eq 'login') {
1.135 bisitz 1408: $datatable .= $login_hdr_pick;
1409: }
1.41 raeburn 1410: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1411: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1412: } else {
1.160.6.22 raeburn 1413: $datatable .= '<td> </td><td class="LC_left_item">'.
1414: &mt('Upload:').'<br />';
1.6 raeburn 1415: }
1416: } else {
1.160.6.22 raeburn 1417: $datatable .= '<td> </td><td class="LC_left_item">'.
1418: &mt('Upload:').'<br />';
1.6 raeburn 1419: }
1.9 raeburn 1420: if ($switchserver) {
1421: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1422: } else {
1.135 bisitz 1423: if ($img ne 'login') { # suppress file selection for Log-in header
1424: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1425: }
1.9 raeburn 1426: }
1427: $datatable .= '</td></tr>';
1.6 raeburn 1428: }
1429: $itemcount ++;
1430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1431: $datatable .= '<tr'.$css_class.'>'.
1432: '<td>'.$choices->{'bgs'}.'</td>';
1433: my $bgs_def;
1434: foreach my $item (@{$bgs}) {
1435: if (!$is_custom->{$item}) {
1.70 raeburn 1436: $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 1437: }
1438: }
1439: if ($bgs_def) {
1.8 raeburn 1440: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1441: } else {
1442: $datatable .= '<td> </td>';
1443: }
1444: $datatable .= '<td class="LC_right_item">'.
1445: '<table border="0"><tr>';
1.160.6.13 raeburn 1446:
1.6 raeburn 1447: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1448: $datatable .= '<td align="center">'.$choices->{$item};
1449: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1450: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1451: $datatable .= ' ';
1.6 raeburn 1452: }
1.160.6.9 raeburn 1453: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1454: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1455: }
1456: $datatable .= '</tr></table></td></tr>';
1457: $itemcount ++;
1458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1459: $datatable .= '<tr'.$css_class.'>'.
1460: '<td>'.$choices->{'links'}.'</td>';
1461: my $links_def;
1462: foreach my $item (@{$links}) {
1463: if (!$is_custom->{$item}) {
1.30 raeburn 1464: $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 1465: }
1466: }
1467: if ($links_def) {
1.8 raeburn 1468: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1469: } else {
1470: $datatable .= '<td> </td>';
1471: }
1472: $datatable .= '<td class="LC_right_item">'.
1473: '<table border="0"><tr>';
1474: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1475: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1476: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1477: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1478: $datatable.=' ';
1.6 raeburn 1479: }
1.160.6.9 raeburn 1480: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1481: '" /></td>';
1482: }
1.30 raeburn 1483: $$rowtotal += $itemcount;
1.3 raeburn 1484: return $datatable;
1485: }
1486:
1.70 raeburn 1487: sub logo_display_options {
1488: my ($img,$defaults,$designs) = @_;
1489: my $checkedon;
1490: if (ref($defaults) eq 'HASH') {
1491: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1492: if ($defaults->{'showlogo'}{$img}) {
1493: $checkedon = 'checked="checked" ';
1494: }
1495: }
1496: }
1497: if (ref($designs) eq 'HASH') {
1498: if (ref($designs->{'showlogo'}) eq 'HASH') {
1499: if (defined($designs->{'showlogo'}{$img})) {
1500: if ($designs->{'showlogo'}{$img} == 0) {
1501: $checkedon = '';
1502: } elsif ($designs->{'showlogo'}{$img} == 1) {
1503: $checkedon = 'checked="checked" ';
1504: }
1505: }
1506: }
1507: }
1508: return '<br /><label> <input type="checkbox" name="'.
1509: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1510: &mt('show').'</label>'."\n";
1511: }
1512:
1.41 raeburn 1513: sub login_header_options {
1.135 bisitz 1514: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1515: my $output = '';
1.41 raeburn 1516: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1517: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1518: if (!$is_custom->{'textcol'}) {
1519: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1520: ' ';
1521: }
1522: if (!$is_custom->{'bgcol'}) {
1523: $output .= $choices->{'bgcol'}.': '.
1524: '<span id="css_'.$role.'_font" style="background-color: '.
1525: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1526: }
1527: $output .= '<br />';
1528: }
1529: $output .='<br />';
1530: return $output;
1531: }
1532:
1533: sub login_text_colors {
1.160.6.22 raeburn 1534: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1535: my $color_menu = '<table border="0"><tr>';
1536: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1537: $color_menu .= '<td align="center">'.$choices->{$item};
1538: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1539: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1540: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1541: }
1542: $color_menu .= '</tr></table><br />';
1543: return $color_menu;
1544: }
1545:
1546: sub image_changes {
1547: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1548: my $output;
1.135 bisitz 1549: if ($img eq 'login') {
1550: # suppress image for Log-in header
1551: } elsif (!$is_custom) {
1.70 raeburn 1552: if ($img ne 'domlogo') {
1.41 raeburn 1553: $output .= &mt('Default image:').'<br />';
1554: } else {
1555: $output .= &mt('Default in use:').'<br />';
1556: }
1557: }
1.135 bisitz 1558: if ($img eq 'login') { # suppress image for Log-in header
1559: $output .= '<td>'.$logincolors;
1.41 raeburn 1560: } else {
1.135 bisitz 1561: if ($img_import) {
1562: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1563: }
1564: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1565: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1566: if ($is_custom) {
1567: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1568: '<input type="checkbox" name="'.
1569: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1570: '</label> '.&mt('Replace:').'</span><br />';
1571: } else {
1.160.6.22 raeburn 1572: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1573: }
1.41 raeburn 1574: }
1575: return $output;
1576: }
1577:
1.3 raeburn 1578: sub print_quotas {
1.86 raeburn 1579: my ($dom,$settings,$rowtotal,$action) = @_;
1580: my $context;
1581: if ($action eq 'quotas') {
1582: $context = 'tools';
1583: } else {
1584: $context = $action;
1585: }
1.160.6.20 raeburn 1586: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1587: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1588: my $typecount = 0;
1.101 raeburn 1589: my ($css_class,%titles);
1.86 raeburn 1590: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1591: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1592: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1593: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1594: %titles = &courserequest_titles();
1.160.6.5 raeburn 1595: } elsif ($context eq 'requestauthor') {
1596: @usertools = ('author');
1597: @options = ('norequest','approval','automatic');
1598: %titles = &authorrequest_titles();
1.86 raeburn 1599: } else {
1.160.6.4 raeburn 1600: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1601: %titles = &tool_titles();
1.86 raeburn 1602: }
1.26 raeburn 1603: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1604: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1605: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1606: unless (($context eq 'requestcourses') ||
1607: ($context eq 'requestauthor')) {
1.86 raeburn 1608: if (ref($settings) eq 'HASH') {
1609: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1610: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1611: } else {
1612: $currdefquota = $settings->{$type};
1613: }
1.160.6.20 raeburn 1614: if (ref($settings->{authorquota}) eq 'HASH') {
1615: $currauthorquota = $settings->{authorquota}->{$type};
1616: }
1.78 raeburn 1617: }
1.72 raeburn 1618: }
1.3 raeburn 1619: if (defined($usertypes->{$type})) {
1620: $typecount ++;
1621: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1622: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1623: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1624: '<td class="LC_left_item">';
1.101 raeburn 1625: if ($context eq 'requestcourses') {
1626: $datatable .= '<table><tr>';
1627: }
1628: my %cell;
1.72 raeburn 1629: foreach my $item (@usertools) {
1.101 raeburn 1630: if ($context eq 'requestcourses') {
1631: my ($curroption,$currlimit);
1632: if (ref($settings) eq 'HASH') {
1633: if (ref($settings->{$item}) eq 'HASH') {
1634: $curroption = $settings->{$item}->{$type};
1635: if ($curroption =~ /^autolimit=(\d*)$/) {
1636: $currlimit = $1;
1637: }
1638: }
1639: }
1640: if (!$curroption) {
1641: $curroption = 'norequest';
1642: }
1643: $datatable .= '<th>'.$titles{$item}.'</th>';
1644: foreach my $option (@options) {
1645: my $val = $option;
1646: if ($option eq 'norequest') {
1647: $val = 0;
1648: }
1649: if ($option eq 'validate') {
1650: my $canvalidate = 0;
1651: if (ref($validations{$item}) eq 'HASH') {
1652: if ($validations{$item}{$type}) {
1653: $canvalidate = 1;
1654: }
1655: }
1656: next if (!$canvalidate);
1657: }
1658: my $checked = '';
1659: if ($option eq $curroption) {
1660: $checked = ' checked="checked"';
1661: } elsif ($option eq 'autolimit') {
1662: if ($curroption =~ /^autolimit/) {
1663: $checked = ' checked="checked"';
1664: }
1665: }
1666: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1667: '<input type="radio" name="crsreq_'.$item.
1668: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1669: $titles{$option}.'</label>';
1.101 raeburn 1670: if ($option eq 'autolimit') {
1.127 raeburn 1671: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1672: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1673: 'value="'.$currlimit.'" />';
1.101 raeburn 1674: }
1.127 raeburn 1675: $cell{$item} .= '</span> ';
1.103 raeburn 1676: if ($option eq 'autolimit') {
1.127 raeburn 1677: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1678: }
1.101 raeburn 1679: }
1.160.6.5 raeburn 1680: } elsif ($context eq 'requestauthor') {
1681: my $curroption;
1682: if (ref($settings) eq 'HASH') {
1683: $curroption = $settings->{$type};
1684: }
1685: if (!$curroption) {
1686: $curroption = 'norequest';
1687: }
1688: foreach my $option (@options) {
1689: my $val = $option;
1690: if ($option eq 'norequest') {
1691: $val = 0;
1692: }
1693: my $checked = '';
1694: if ($option eq $curroption) {
1695: $checked = ' checked="checked"';
1696: }
1697: $datatable .= '<span class="LC_nobreak"><label>'.
1698: '<input type="radio" name="authorreq_'.$type.
1699: '" value="'.$val.'"'.$checked.' />'.
1700: $titles{$option}.'</label></span> ';
1701: }
1.101 raeburn 1702: } else {
1703: my $checked = 'checked="checked" ';
1704: if (ref($settings) eq 'HASH') {
1705: if (ref($settings->{$item}) eq 'HASH') {
1706: if ($settings->{$item}->{$type} == 0) {
1707: $checked = '';
1708: } elsif ($settings->{$item}->{$type} == 1) {
1709: $checked = 'checked="checked" ';
1710: }
1.78 raeburn 1711: }
1.72 raeburn 1712: }
1.101 raeburn 1713: $datatable .= '<span class="LC_nobreak"><label>'.
1714: '<input type="checkbox" name="'.$context.'_'.$item.
1715: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1716: '</label></span> ';
1.72 raeburn 1717: }
1.101 raeburn 1718: }
1719: if ($context eq 'requestcourses') {
1720: $datatable .= '</tr><tr>';
1721: foreach my $item (@usertools) {
1.106 raeburn 1722: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1723: }
1724: $datatable .= '</tr></table>';
1.72 raeburn 1725: }
1.86 raeburn 1726: $datatable .= '</td>';
1.160.6.5 raeburn 1727: unless (($context eq 'requestcourses') ||
1728: ($context eq 'requestauthor')) {
1.86 raeburn 1729: $datatable .=
1.160.6.20 raeburn 1730: '<td class="LC_right_item">'.
1731: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1732: '<input type="text" name="quota_'.$type.
1.72 raeburn 1733: '" value="'.$currdefquota.
1.160.6.20 raeburn 1734: '" size="5" /></span>'.(' ' x 2).
1735: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1736: '<input type="text" name="authorquota_'.$type.
1737: '" value="'.$currauthorquota.
1738: '" size="5" /></span></td>';
1.86 raeburn 1739: }
1740: $datatable .= '</tr>';
1.3 raeburn 1741: }
1742: }
1743: }
1.160.6.5 raeburn 1744: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1745: $defaultquota = '20';
1.160.6.20 raeburn 1746: $authorquota = '500';
1.86 raeburn 1747: if (ref($settings) eq 'HASH') {
1748: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1749: $defaultquota = $settings->{'defaultquota'}->{'default'};
1750: } elsif (defined($settings->{'default'})) {
1751: $defaultquota = $settings->{'default'};
1752: }
1.160.6.20 raeburn 1753: if (ref($settings->{'authorquota'}) eq 'HASH') {
1754: $authorquota = $settings->{'authorquota'}->{'default'};
1755: }
1.3 raeburn 1756: }
1757: }
1758: $typecount ++;
1759: $css_class = $typecount%2?' class="LC_odd_row"':'';
1760: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1761: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1762: '<td class="LC_left_item">';
1.101 raeburn 1763: if ($context eq 'requestcourses') {
1764: $datatable .= '<table><tr>';
1765: }
1766: my %defcell;
1.72 raeburn 1767: foreach my $item (@usertools) {
1.101 raeburn 1768: if ($context eq 'requestcourses') {
1769: my ($curroption,$currlimit);
1770: if (ref($settings) eq 'HASH') {
1771: if (ref($settings->{$item}) eq 'HASH') {
1772: $curroption = $settings->{$item}->{'default'};
1773: if ($curroption =~ /^autolimit=(\d*)$/) {
1774: $currlimit = $1;
1775: }
1776: }
1777: }
1778: if (!$curroption) {
1779: $curroption = 'norequest';
1780: }
1781: $datatable .= '<th>'.$titles{$item}.'</th>';
1782: foreach my $option (@options) {
1783: my $val = $option;
1784: if ($option eq 'norequest') {
1785: $val = 0;
1786: }
1787: if ($option eq 'validate') {
1788: my $canvalidate = 0;
1789: if (ref($validations{$item}) eq 'HASH') {
1790: if ($validations{$item}{'default'}) {
1791: $canvalidate = 1;
1792: }
1793: }
1794: next if (!$canvalidate);
1795: }
1796: my $checked = '';
1797: if ($option eq $curroption) {
1798: $checked = ' checked="checked"';
1799: } elsif ($option eq 'autolimit') {
1800: if ($curroption =~ /^autolimit/) {
1801: $checked = ' checked="checked"';
1802: }
1803: }
1804: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1805: '<input type="radio" name="crsreq_'.$item.
1806: '_default" value="'.$val.'"'.$checked.' />'.
1807: $titles{$option}.'</label>';
1808: if ($option eq 'autolimit') {
1.127 raeburn 1809: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1810: $item.'_limit_default" size="1" '.
1811: 'value="'.$currlimit.'" />';
1812: }
1.127 raeburn 1813: $defcell{$item} .= '</span> ';
1.104 raeburn 1814: if ($option eq 'autolimit') {
1.127 raeburn 1815: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1816: }
1.101 raeburn 1817: }
1.160.6.5 raeburn 1818: } elsif ($context eq 'requestauthor') {
1819: my $curroption;
1820: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1821: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1822: }
1823: if (!$curroption) {
1824: $curroption = 'norequest';
1825: }
1826: foreach my $option (@options) {
1827: my $val = $option;
1828: if ($option eq 'norequest') {
1829: $val = 0;
1830: }
1831: my $checked = '';
1832: if ($option eq $curroption) {
1833: $checked = ' checked="checked"';
1834: }
1835: $datatable .= '<span class="LC_nobreak"><label>'.
1836: '<input type="radio" name="authorreq_default"'.
1837: ' value="'.$val.'"'.$checked.' />'.
1838: $titles{$option}.'</label></span> ';
1839: }
1.101 raeburn 1840: } else {
1841: my $checked = 'checked="checked" ';
1842: if (ref($settings) eq 'HASH') {
1843: if (ref($settings->{$item}) eq 'HASH') {
1844: if ($settings->{$item}->{'default'} == 0) {
1845: $checked = '';
1846: } elsif ($settings->{$item}->{'default'} == 1) {
1847: $checked = 'checked="checked" ';
1848: }
1.78 raeburn 1849: }
1.72 raeburn 1850: }
1.101 raeburn 1851: $datatable .= '<span class="LC_nobreak"><label>'.
1852: '<input type="checkbox" name="'.$context.'_'.$item.
1853: '" value="default" '.$checked.'/>'.$titles{$item}.
1854: '</label></span> ';
1855: }
1856: }
1857: if ($context eq 'requestcourses') {
1858: $datatable .= '</tr><tr>';
1859: foreach my $item (@usertools) {
1.106 raeburn 1860: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1861: }
1.101 raeburn 1862: $datatable .= '</tr></table>';
1.72 raeburn 1863: }
1.86 raeburn 1864: $datatable .= '</td>';
1.160.6.5 raeburn 1865: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1866: $datatable .= '<td class="LC_right_item">'.
1867: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1868: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1869: $defaultquota.'" size="5" /></span>'.(' ' x2).
1870: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1871: '<input type="text" name="authorquota" value="'.
1872: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1873: }
1874: $datatable .= '</tr>';
1.72 raeburn 1875: $typecount ++;
1876: $css_class = $typecount%2?' class="LC_odd_row"':'';
1877: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1878: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1879: if ($context eq 'requestcourses') {
1.109 raeburn 1880: $datatable .= &mt('(overrides affiliation, if set)').
1881: '</td>'.
1882: '<td class="LC_left_item">'.
1883: '<table><tr>';
1.101 raeburn 1884: } else {
1.109 raeburn 1885: $datatable .= &mt('(overrides affiliation, if checked)').
1886: '</td>'.
1887: '<td class="LC_left_item" colspan="2">'.
1888: '<br />';
1.101 raeburn 1889: }
1890: my %advcell;
1.72 raeburn 1891: foreach my $item (@usertools) {
1.101 raeburn 1892: if ($context eq 'requestcourses') {
1893: my ($curroption,$currlimit);
1894: if (ref($settings) eq 'HASH') {
1895: if (ref($settings->{$item}) eq 'HASH') {
1896: $curroption = $settings->{$item}->{'_LC_adv'};
1897: if ($curroption =~ /^autolimit=(\d*)$/) {
1898: $currlimit = $1;
1899: }
1900: }
1901: }
1902: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1903: my $checked = '';
1904: if ($curroption eq '') {
1905: $checked = ' checked="checked"';
1906: }
1907: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1908: '<input type="radio" name="crsreq_'.$item.
1909: '__LC_adv" value=""'.$checked.' />'.
1910: &mt('No override set').'</label></span> ';
1.101 raeburn 1911: foreach my $option (@options) {
1912: my $val = $option;
1913: if ($option eq 'norequest') {
1914: $val = 0;
1915: }
1916: if ($option eq 'validate') {
1917: my $canvalidate = 0;
1918: if (ref($validations{$item}) eq 'HASH') {
1919: if ($validations{$item}{'_LC_adv'}) {
1920: $canvalidate = 1;
1921: }
1922: }
1923: next if (!$canvalidate);
1924: }
1925: my $checked = '';
1.104 raeburn 1926: if ($val eq $curroption) {
1.101 raeburn 1927: $checked = ' checked="checked"';
1928: } elsif ($option eq 'autolimit') {
1929: if ($curroption =~ /^autolimit/) {
1930: $checked = ' checked="checked"';
1931: }
1932: }
1933: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1934: '<input type="radio" name="crsreq_'.$item.
1935: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1936: $titles{$option}.'</label>';
1937: if ($option eq 'autolimit') {
1.127 raeburn 1938: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1939: $item.'_limit__LC_adv" size="1" '.
1940: 'value="'.$currlimit.'" />';
1941: }
1.127 raeburn 1942: $advcell{$item} .= '</span> ';
1.104 raeburn 1943: if ($option eq 'autolimit') {
1.127 raeburn 1944: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1945: }
1.101 raeburn 1946: }
1.160.6.5 raeburn 1947: } elsif ($context eq 'requestauthor') {
1948: my $curroption;
1949: if (ref($settings) eq 'HASH') {
1950: $curroption = $settings->{'_LC_adv'};
1951: }
1952: my $checked = '';
1953: if ($curroption eq '') {
1954: $checked = ' checked="checked"';
1955: }
1956: $datatable .= '<span class="LC_nobreak"><label>'.
1957: '<input type="radio" name="authorreq__LC_adv"'.
1958: ' value=""'.$checked.' />'.
1959: &mt('No override set').'</label></span> ';
1960: foreach my $option (@options) {
1961: my $val = $option;
1962: if ($option eq 'norequest') {
1963: $val = 0;
1964: }
1965: my $checked = '';
1966: if ($val eq $curroption) {
1967: $checked = ' checked="checked"';
1968: }
1969: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1970: '<input type="radio" name="authorreq__LC_adv"'.
1971: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1972: $titles{$option}.'</label></span> ';
1973: }
1.101 raeburn 1974: } else {
1975: my $checked = 'checked="checked" ';
1976: if (ref($settings) eq 'HASH') {
1977: if (ref($settings->{$item}) eq 'HASH') {
1978: if ($settings->{$item}->{'_LC_adv'} == 0) {
1979: $checked = '';
1980: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1981: $checked = 'checked="checked" ';
1982: }
1.79 raeburn 1983: }
1.72 raeburn 1984: }
1.101 raeburn 1985: $datatable .= '<span class="LC_nobreak"><label>'.
1986: '<input type="checkbox" name="'.$context.'_'.$item.
1987: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1988: '</label></span> ';
1989: }
1990: }
1991: if ($context eq 'requestcourses') {
1992: $datatable .= '</tr><tr>';
1993: foreach my $item (@usertools) {
1.106 raeburn 1994: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1995: }
1.101 raeburn 1996: $datatable .= '</tr></table>';
1.72 raeburn 1997: }
1.98 raeburn 1998: $datatable .= '</td></tr>';
1.30 raeburn 1999: $$rowtotal += $typecount;
1.3 raeburn 2000: return $datatable;
2001: }
2002:
1.160.6.5 raeburn 2003: sub print_requestmail {
2004: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2005: my ($now,$datatable,%currapp);
1.102 raeburn 2006: $now = time;
2007: if (ref($settings) eq 'HASH') {
2008: if (ref($settings->{'notify'}) eq 'HASH') {
2009: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2010: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2011: }
2012: }
2013: }
1.160.6.16 raeburn 2014: my $numinrow = 2;
1.160.6.34 raeburn 2015: my $css_class;
2016: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2017: my $text;
2018: if ($action eq 'requestcourses') {
2019: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2020: } elsif ($action eq 'requestauthor') {
2021: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2022: } else {
1.160.6.34 raeburn 2023: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2024: }
1.160.6.34 raeburn 2025: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2026: ' <td>'.$text.'</td>'.
1.102 raeburn 2027: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2028: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2029: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2030: if ($numdc > 0) {
2031: $datatable .= $table;
1.102 raeburn 2032: } else {
2033: $datatable .= &mt('There are no active Domain Coordinators');
2034: }
2035: $datatable .='</td></tr>';
2036: $$rowtotal += $rows;
2037: return $datatable;
2038: }
2039:
1.160.6.30 raeburn 2040: sub print_studentcode {
2041: my ($settings,$rowtotal) = @_;
2042: my $rownum = 0;
2043: my ($output,%current);
2044: my @crstypes = ('official','unofficial','community','textbook');
2045: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2046: foreach my $type (@crstypes) {
2047: $current{$type} = $settings->{'uniquecode'}{$type};
2048: }
2049: }
2050: $output .= '<tr>'.
2051: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2052: '<td class="LC_left_item">';
2053: foreach my $type (@crstypes) {
2054: my $check = ' ';
2055: if ($current{$type}) {
2056: $check = ' checked="checked" ';
2057: }
2058: $output .= '<span class="LC_nobreak"><label>'.
2059: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2060: &mt($type).'</label></span>'.(' 'x2).' ';
2061: }
2062: $output .= '</td></tr>';
2063: $$rowtotal ++;
2064: return $output;
2065: }
2066:
2067: sub print_textbookcourses {
2068: my ($dom,$settings,$rowtotal) = @_;
2069: my $rownum = 0;
2070: my $css_class;
2071: my $itemcount = 1;
2072: my $maxnum = 0;
2073: my $bookshash;
2074: if (ref($settings) eq 'HASH') {
2075: $bookshash = $settings->{'textbooks'};
2076: }
2077: my %ordered;
2078: if (ref($bookshash) eq 'HASH') {
2079: foreach my $item (keys(%{$bookshash})) {
2080: if (ref($bookshash->{$item}) eq 'HASH') {
2081: my $num = $bookshash->{$item}{'order'};
2082: $ordered{$num} = $item;
2083: }
2084: }
2085: }
2086: my $confname = $dom.'-domainconfig';
2087: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.40 raeburn 2088: $maxnum = scalar(keys(%ordered));
1.160.6.30 raeburn 2089: my $datatable = &textbookcourses_javascript(\%ordered);
2090: if (keys(%ordered)) {
2091: my @items = sort { $a <=> $b } keys(%ordered);
2092: for (my $i=0; $i<@items; $i++) {
2093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2094: my $key = $ordered{$items[$i]};
2095: my %coursehash=&Apache::lonnet::coursedescription($key);
2096: my $coursetitle = $coursehash{'description'};
2097: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2098: if (ref($bookshash->{$key}) eq 'HASH') {
2099: $subject = $bookshash->{$key}->{'subject'};
2100: $title = $bookshash->{$key}->{'title'};
2101: $author = $bookshash->{$key}->{'author'};
2102: $image = $bookshash->{$key}->{'image'};
2103: if ($image ne '') {
2104: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2105: my $imagethumb = "$path/tn-".$imagefile;
2106: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2107: }
2108: }
2109: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
2110: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2111: .'<select name="'.$key.'"'.$chgstr.'>';
2112: for (my $k=0; $k<=$maxnum; $k++) {
2113: my $vpos = $k+1;
2114: my $selstr;
2115: if ($k == $i) {
2116: $selstr = ' selected="selected" ';
2117: }
2118: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2119: }
2120: $datatable .= '</select>'.(' 'x2).
2121: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2122: &mt('Delete?').'</label></span></td>'.
2123: '<td colspan="2">'.
2124: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2125: (' 'x2).
2126: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2127: (' 'x2).
2128: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2129: (' 'x2).
2130: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2131: if ($image) {
2132: $datatable .= '<span class="LC_nobreak">'.
2133: $imgsrc.
2134: '<label><input type="checkbox" name="book_image_del"'.
2135: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2136: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2137: }
2138: if ($switchserver) {
2139: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2140: } else {
2141: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2142: }
2143: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2144: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2145: $coursetitle.'</span></td></tr>'."\n";
2146: $itemcount ++;
2147: }
2148: }
2149: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2150: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
2151: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2152: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2153: '<select name="addbook_pos"'.$chgstr.'>';
2154: for (my $k=0; $k<$maxnum+1; $k++) {
2155: my $vpos = $k+1;
2156: my $selstr;
2157: if ($k == $maxnum) {
2158: $selstr = ' selected="selected" ';
2159: }
2160: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2161: }
2162: $datatable .= '</select> '."\n".
2163: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2164: '<td colspan="2">'.
2165: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2166: (' 'x2).
2167: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2168: (' 'x2).
2169: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2170: (' 'x2).
2171: '<span class="LC_nobreak">'.&mt('Image:').' ';
2172: if ($switchserver) {
2173: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2174: } else {
2175: $datatable .= '<input type="file" name="addbook_image" value="" />';
2176: }
2177: $datatable .= '</span>'."\n".
2178: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2179: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2180: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2181: &Apache::loncommon::selectcourse_link
2182: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2183: '</span></td>'."\n".
2184: '</tr>'."\n";
2185: $itemcount ++;
2186: return $datatable;
2187: }
2188:
2189: sub textbookcourses_javascript {
2190: my ($textbooks) = @_;
2191: return unless(ref($textbooks) eq 'HASH');
2192: my $num = scalar(keys(%{$textbooks}));
2193: my @jsarray;
2194: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2195: push(@jsarray,$textbooks->{$item});
2196: }
2197: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2198: return <<"ENDSCRIPT";
2199: <script type="text/javascript">
2200: // <![CDATA[
2201: function reorderBooks(form,item) {
2202: var changedVal;
2203: $jstext
2204: var newpos = 'addbook_pos';
2205: var current = new Array;
2206: var maxh = 1 + $num;
2207: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2208: if (item == newpos) {
2209: changedVal = newitemVal;
2210: } else {
2211: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2212: current[newitemVal] = newpos;
2213: }
2214: for (var i=0; i<textbooks.length; i++) {
2215: var elementName = textbooks[i];
2216: if (elementName != item) {
2217: if (form.elements[elementName]) {
2218: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2219: current[currVal] = elementName;
2220: }
2221: }
2222: }
2223: var oldVal;
2224: for (var j=0; j<maxh; j++) {
2225: if (current[j] == undefined) {
2226: oldVal = j;
2227: }
2228: }
2229: if (oldVal < changedVal) {
2230: for (var k=oldVal+1; k<=changedVal ; k++) {
2231: var elementName = current[k];
2232: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2233: }
2234: } else {
2235: for (var k=changedVal; k<oldVal; k++) {
2236: var elementName = current[k];
2237: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2238: }
2239: }
2240: return;
2241: }
2242:
2243: // ]]>
2244: </script>
2245:
2246: ENDSCRIPT
2247: }
2248:
1.3 raeburn 2249: sub print_autoenroll {
1.30 raeburn 2250: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2251: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2252: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2253: if (ref($settings) eq 'HASH') {
2254: if (exists($settings->{'run'})) {
2255: if ($settings->{'run'} eq '0') {
2256: $runoff = ' checked="checked" ';
2257: $runon = ' ';
2258: } else {
2259: $runon = ' checked="checked" ';
2260: $runoff = ' ';
2261: }
2262: } else {
2263: if ($autorun) {
2264: $runon = ' checked="checked" ';
2265: $runoff = ' ';
2266: } else {
2267: $runoff = ' checked="checked" ';
2268: $runon = ' ';
2269: }
2270: }
1.129 raeburn 2271: if (exists($settings->{'co-owners'})) {
2272: if ($settings->{'co-owners'} eq '0') {
2273: $coownersoff = ' checked="checked" ';
2274: $coownerson = ' ';
2275: } else {
2276: $coownerson = ' checked="checked" ';
2277: $coownersoff = ' ';
2278: }
2279: } else {
2280: $coownersoff = ' checked="checked" ';
2281: $coownerson = ' ';
2282: }
1.3 raeburn 2283: if (exists($settings->{'sender_domain'})) {
2284: $defdom = $settings->{'sender_domain'};
2285: }
1.14 raeburn 2286: } else {
2287: if ($autorun) {
2288: $runon = ' checked="checked" ';
2289: $runoff = ' ';
2290: } else {
2291: $runoff = ' checked="checked" ';
2292: $runon = ' ';
2293: }
1.3 raeburn 2294: }
2295: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2296: my $notif_sender;
2297: if (ref($settings) eq 'HASH') {
2298: $notif_sender = $settings->{'sender_uname'};
2299: }
1.3 raeburn 2300: my $datatable='<tr class="LC_odd_row">'.
2301: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2302: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2303: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2304: $runon.' value="1" />'.&mt('Yes').'</label> '.
2305: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2306: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2307: '</tr><tr>'.
2308: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2309: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2310: &mt('username').': '.
2311: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2312: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2313: ': '.$domform.'</span></td></tr>'.
2314: '<tr class="LC_odd_row">'.
2315: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2316: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2317: '<input type="radio" name="autoassign_coowners"'.
2318: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2319: '<label><input type="radio" name="autoassign_coowners"'.
2320: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2321: '</tr>';
2322: $$rowtotal += 3;
1.3 raeburn 2323: return $datatable;
2324: }
2325:
2326: sub print_autoupdate {
1.30 raeburn 2327: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2328: my $datatable;
2329: if ($position eq 'top') {
2330: my $updateon = ' ';
2331: my $updateoff = ' checked="checked" ';
2332: my $classlistson = ' ';
2333: my $classlistsoff = ' checked="checked" ';
2334: if (ref($settings) eq 'HASH') {
2335: if ($settings->{'run'} eq '1') {
2336: $updateon = $updateoff;
2337: $updateoff = ' ';
2338: }
2339: if ($settings->{'classlists'} eq '1') {
2340: $classlistson = $classlistsoff;
2341: $classlistsoff = ' ';
2342: }
2343: }
2344: my %title = (
2345: run => 'Auto-update active?',
2346: classlists => 'Update information in classlists?',
2347: );
2348: $datatable = '<tr class="LC_odd_row">'.
2349: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2350: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2351: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2352: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2353: '<label><input type="radio" name="autoupdate_run"'.
2354: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2355: '</tr><tr>'.
2356: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2357: '<td class="LC_right_item"><span class="LC_nobreak">'.
2358: '<label><input type="radio" name="classlists"'.
2359: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2360: '<label><input type="radio" name="classlists"'.
2361: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2362: '</tr>';
1.30 raeburn 2363: $$rowtotal += 2;
1.131 raeburn 2364: } elsif ($position eq 'middle') {
2365: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2366: my $numinrow = 3;
2367: my $locknamesettings;
2368: $datatable .= &insttypes_row($settings,$types,$usertypes,
2369: $dom,$numinrow,$othertitle,
2370: 'lockablenames');
2371: $$rowtotal ++;
1.3 raeburn 2372: } else {
1.44 raeburn 2373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2374: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2375: 'permanentemail','id');
1.33 raeburn 2376: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2377: my $numrows = 0;
1.26 raeburn 2378: if (ref($types) eq 'ARRAY') {
2379: if (@{$types} > 0) {
2380: $datatable =
2381: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2382: \@fields,$types,\$numrows);
1.30 raeburn 2383: $$rowtotal += @{$types};
1.26 raeburn 2384: }
1.3 raeburn 2385: }
2386: $datatable .=
2387: &usertype_update_row($settings,{'default' => $othertitle},
2388: \%fieldtitles,\@fields,['default'],
2389: \$numrows);
1.30 raeburn 2390: $$rowtotal ++;
1.3 raeburn 2391: }
2392: return $datatable;
2393: }
2394:
1.125 raeburn 2395: sub print_autocreate {
2396: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2397: my (%createon,%createoff,%currhash);
1.125 raeburn 2398: my @types = ('xml','req');
2399: if (ref($settings) eq 'HASH') {
2400: foreach my $item (@types) {
2401: $createoff{$item} = ' checked="checked" ';
2402: $createon{$item} = ' ';
2403: if (exists($settings->{$item})) {
2404: if ($settings->{$item}) {
2405: $createon{$item} = ' checked="checked" ';
2406: $createoff{$item} = ' ';
2407: }
2408: }
2409: }
1.160.6.16 raeburn 2410: if ($settings->{'xmldc'} ne '') {
2411: $currhash{$settings->{'xmldc'}} = 1;
2412: }
1.125 raeburn 2413: } else {
2414: foreach my $item (@types) {
2415: $createoff{$item} = ' checked="checked" ';
2416: $createon{$item} = ' ';
2417: }
2418: }
2419: $$rowtotal += 2;
1.160.6.16 raeburn 2420: my $numinrow = 2;
1.125 raeburn 2421: my $datatable='<tr class="LC_odd_row">'.
2422: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2423: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2424: '<input type="radio" name="autocreate_xml"'.
2425: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2426: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2427: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2428: '</td></tr><tr>'.
2429: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2430: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2431: '<input type="radio" name="autocreate_req"'.
2432: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2433: '<label><input type="radio" name="autocreate_req"'.
2434: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2435: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2436: 'autocreate_xmldc',%currhash);
1.125 raeburn 2437: if ($numdc > 1) {
1.143 raeburn 2438: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2439: &mt('Course creation processed as: (choose Dom. Coord.)').
2440: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2441: } else {
1.143 raeburn 2442: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2443: }
1.160.6.16 raeburn 2444: $$rowtotal += $rows;
1.125 raeburn 2445: return $datatable;
2446: }
2447:
1.23 raeburn 2448: sub print_directorysrch {
1.30 raeburn 2449: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2450: my $srchon = ' ';
2451: my $srchoff = ' checked="checked" ';
1.25 raeburn 2452: my ($exacton,$containson,$beginson);
1.24 raeburn 2453: my $localon = ' ';
2454: my $localoff = ' checked="checked" ';
1.23 raeburn 2455: if (ref($settings) eq 'HASH') {
2456: if ($settings->{'available'} eq '1') {
2457: $srchon = $srchoff;
2458: $srchoff = ' ';
2459: }
1.24 raeburn 2460: if ($settings->{'localonly'} eq '1') {
2461: $localon = $localoff;
2462: $localoff = ' ';
2463: }
1.25 raeburn 2464: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2465: foreach my $type (@{$settings->{'searchtypes'}}) {
2466: if ($type eq 'exact') {
2467: $exacton = ' checked="checked" ';
2468: } elsif ($type eq 'contains') {
2469: $containson = ' checked="checked" ';
2470: } elsif ($type eq 'begins') {
2471: $beginson = ' checked="checked" ';
2472: }
2473: }
2474: } else {
2475: if ($settings->{'searchtypes'} eq 'exact') {
2476: $exacton = ' checked="checked" ';
2477: } elsif ($settings->{'searchtypes'} eq 'contains') {
2478: $containson = ' checked="checked" ';
2479: } elsif ($settings->{'searchtypes'} eq 'specify') {
2480: $exacton = ' checked="checked" ';
2481: $containson = ' checked="checked" ';
2482: }
1.23 raeburn 2483: }
2484: }
2485: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2487:
2488: my $numinrow = 4;
1.26 raeburn 2489: my $cansrchrow = 0;
1.23 raeburn 2490: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2491: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2492: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2493: '<input type="radio" name="dirsrch_available"'.
2494: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2495: '<label><input type="radio" name="dirsrch_available"'.
2496: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2497: '</tr><tr>'.
1.30 raeburn 2498: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2499: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2500: '<input type="radio" name="dirsrch_localonly"'.
2501: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2502: '<label><input type="radio" name="dirsrch_localonly"'.
2503: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2504: '</tr>';
1.30 raeburn 2505: $$rowtotal += 2;
1.26 raeburn 2506: if (ref($usertypes) eq 'HASH') {
2507: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2508: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2509: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2510: $cansrchrow = 1;
2511: }
2512: }
2513: if ($cansrchrow) {
1.30 raeburn 2514: $$rowtotal ++;
1.26 raeburn 2515: $datatable .= '<tr>';
2516: } else {
2517: $datatable .= '<tr class="LC_odd_row">';
2518: }
1.30 raeburn 2519: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2520: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2521: foreach my $title (@{$titleorder}) {
2522: if (defined($searchtitles->{$title})) {
2523: my $check = ' ';
1.93 raeburn 2524: if (ref($settings) eq 'HASH') {
1.39 raeburn 2525: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2526: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2527: $check = ' checked="checked" ';
2528: }
1.25 raeburn 2529: }
2530: }
2531: $datatable .= '<td class="LC_left_item">'.
2532: '<span class="LC_nobreak"><label>'.
2533: '<input type="checkbox" name="searchby" '.
2534: 'value="'.$title.'"'.$check.'/>'.
2535: $searchtitles->{$title}.'</label></span></td>';
2536: }
2537: }
1.26 raeburn 2538: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2539: $$rowtotal ++;
1.26 raeburn 2540: if ($cansrchrow) {
2541: $datatable .= '<tr class="LC_odd_row">';
2542: } else {
2543: $datatable .= '<tr>';
2544: }
1.30 raeburn 2545: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2546: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2547: '<span class="LC_nobreak"><label>'.
2548: '<input type="checkbox" name="searchtypes" '.
2549: $exacton.' value="exact" />'.&mt('Exact match').
2550: '</label> '.
2551: '<label><input type="checkbox" name="searchtypes" '.
2552: $beginson.' value="begins" />'.&mt('Begins with').
2553: '</label> '.
2554: '<label><input type="checkbox" name="searchtypes" '.
2555: $containson.' value="contains" />'.&mt('Contains').
2556: '</label></span></td></tr>';
1.30 raeburn 2557: $$rowtotal ++;
1.25 raeburn 2558: return $datatable;
2559: }
2560:
1.28 raeburn 2561: sub print_contacts {
1.30 raeburn 2562: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2563: my $datatable;
2564: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2565: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2566: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2567: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2568: foreach my $type (@mailings) {
2569: $otheremails{$type} = '';
2570: }
1.134 raeburn 2571: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2572: if (ref($settings) eq 'HASH') {
2573: foreach my $item (@contacts) {
2574: if (exists($settings->{$item})) {
2575: $to{$item} = $settings->{$item};
2576: }
2577: }
2578: foreach my $type (@mailings) {
2579: if (exists($settings->{$type})) {
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (@contacts) {
2582: if ($settings->{$type}{$item}) {
2583: $checked{$type}{$item} = ' checked="checked" ';
2584: }
2585: }
2586: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2587: if ($type eq 'helpdeskmail') {
2588: $bccemails{$type} = $settings->{$type}{'bcc'};
2589: }
1.28 raeburn 2590: }
1.89 raeburn 2591: } elsif ($type eq 'lonstatusmail') {
2592: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2593: }
2594: }
2595: } else {
2596: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2597: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2598: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2599: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2600: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2601: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2602: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2603: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2604: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2605: }
2606: my ($titles,$short_titles) = &contact_titles();
2607: my $rownum = 0;
2608: my $css_class;
2609: foreach my $item (@contacts) {
1.69 raeburn 2610: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2611: $datatable .= '<tr'.$css_class.'>'.
2612: '<td><span class="LC_nobreak">'.$titles->{$item}.
2613: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2614: '<input type="text" name="'.$item.'" value="'.
2615: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2616: $rownum ++;
1.28 raeburn 2617: }
2618: foreach my $type (@mailings) {
1.69 raeburn 2619: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2620: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2621: '<td><span class="LC_nobreak">'.
2622: $titles->{$type}.': </span></td>'.
1.28 raeburn 2623: '<td class="LC_left_item">'.
2624: '<span class="LC_nobreak">';
2625: foreach my $item (@contacts) {
2626: $datatable .= '<label>'.
2627: '<input type="checkbox" name="'.$type.'"'.
2628: $checked{$type}{$item}.
2629: ' value="'.$item.'" />'.$short_titles->{$item}.
2630: '</label> ';
2631: }
2632: $datatable .= '</span><br />'.&mt('Others').': '.
2633: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2634: 'value="'.$otheremails{$type}.'" />';
2635: if ($type eq 'helpdeskmail') {
1.136 raeburn 2636: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2637: '<input type="text" name="'.$type.'_bcc" '.
2638: 'value="'.$bccemails{$type}.'" />';
2639: }
2640: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2641: $rownum ++;
1.28 raeburn 2642: }
1.160.6.23 raeburn 2643: my %choices;
2644: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2645: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2646: &mt('LON-CAPA core group - MSU'),600,500));
2647: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2648: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2649: &mt('LON-CAPA core group - MSU'),600,500));
2650: my @toggles = ('reporterrors','reportupdates');
2651: my %defaultchecked = ('reporterrors' => 'on',
2652: 'reportupdates' => 'on');
2653: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2654: \%choices,$rownum);
2655: $datatable .= $reports;
1.30 raeburn 2656: $$rowtotal += $rownum;
1.28 raeburn 2657: return $datatable;
2658: }
2659:
1.118 jms 2660: sub print_helpsettings {
1.160.6.5 raeburn 2661: my ($dom,$confname,$settings,$rowtotal) = @_;
2662: my ($datatable,$itemcount);
2663: $itemcount = 1;
2664: my (%choices,%defaultchecked,@toggles);
2665: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2666: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2667: &mt('LON-CAPA bug tracker'),600,500));
2668: %defaultchecked = ('submitbugs' => 'on');
2669: @toggles = ('submitbugs',);
1.122 jms 2670:
1.160.6.5 raeburn 2671: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2672: \%choices,$itemcount);
2673: return $datatable;
1.121 raeburn 2674: }
2675:
2676: sub radiobutton_prefs {
1.160.6.16 raeburn 2677: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2678: $additional) = @_;
1.121 raeburn 2679: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2680: (ref($choices) eq 'HASH'));
2681:
2682: my (%checkedon,%checkedoff,$datatable,$css_class);
2683:
2684: foreach my $item (@{$toggles}) {
2685: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2686: $checkedon{$item} = ' checked="checked" ';
2687: $checkedoff{$item} = ' ';
1.121 raeburn 2688: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2689: $checkedoff{$item} = ' checked="checked" ';
2690: $checkedon{$item} = ' ';
2691: }
2692: }
2693: if (ref($settings) eq 'HASH') {
1.121 raeburn 2694: foreach my $item (@{$toggles}) {
1.118 jms 2695: if ($settings->{$item} eq '1') {
2696: $checkedon{$item} = ' checked="checked" ';
2697: $checkedoff{$item} = ' ';
2698: } elsif ($settings->{$item} eq '0') {
2699: $checkedoff{$item} = ' checked="checked" ';
2700: $checkedon{$item} = ' ';
2701: }
2702: }
1.121 raeburn 2703: }
1.160.6.16 raeburn 2704: if ($onclick) {
2705: $onclick = ' onclick="'.$onclick.'"';
2706: }
1.121 raeburn 2707: foreach my $item (@{$toggles}) {
1.118 jms 2708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2709: $datatable .=
1.160.6.16 raeburn 2710: '<tr'.$css_class.'><td valign="top">'.
2711: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2712: '</span></td>'.
2713: '<td class="LC_right_item"><span class="LC_nobreak">'.
2714: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2715: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2716: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2717: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2718: '</span>'.$additional.
2719: '</td>'.
1.118 jms 2720: '</tr>';
2721: $itemcount ++;
1.121 raeburn 2722: }
2723: return ($datatable,$itemcount);
2724: }
2725:
2726: sub print_coursedefaults {
1.139 raeburn 2727: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2728: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2729: my $itemcount = 1;
1.160.6.16 raeburn 2730: my %choices = &Apache::lonlocal::texthash (
2731: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2732: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2733: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2734: coursecredits => 'Credits can be specified for courses',
2735: );
1.160.6.21 raeburn 2736: my %staticdefaults = (
2737: anonsurvey_threshold => 10,
2738: uploadquota => 500,
2739: );
1.139 raeburn 2740: if ($position eq 'top') {
2741: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2742: @toggles = ('canuse_pdfforms');
1.139 raeburn 2743: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2744: \%choices,$itemcount);
1.139 raeburn 2745: } else {
2746: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2747: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2748: %curruploadquota);
1.160.6.16 raeburn 2749: my $currusecredits = 0;
1.160.6.30 raeburn 2750: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2751: if (ref($settings) eq 'HASH') {
2752: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2753: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2754: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2755: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2756: }
2757: }
1.160.6.16 raeburn 2758: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2759: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2760: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2761: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2762: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2763: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2764: $currusecredits = 1;
2765: }
2766: }
1.139 raeburn 2767: }
2768: if (!$currdefresponder) {
1.160.6.21 raeburn 2769: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2770: } elsif ($currdefresponder < 1) {
2771: $currdefresponder = 1;
2772: }
1.160.6.21 raeburn 2773: foreach my $type (@types) {
2774: if ($curruploadquota{$type} eq '') {
2775: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2776: }
2777: }
1.139 raeburn 2778: $datatable .=
1.160.6.16 raeburn 2779: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2780: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2781: '</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak">'.
2783: '<input type="text" name="anonsurvey_threshold"'.
2784: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2785: '</td></tr>'."\n";
2786: $itemcount ++;
2787: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2788: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2789: $choices{'uploadquota'}.
2790: '</span></td>'.
2791: '<td align="right" class="LC_right_item">'.
2792: '<table><tr>';
1.160.6.21 raeburn 2793: foreach my $type (@types) {
2794: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2795: '<input type="text" name="uploadquota_'.$type.'"'.
2796: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2797: }
2798: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2799: $itemcount ++;
1.160.6.40 raeburn 2800: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2801: my $display = 'none';
2802: if ($currusecredits) {
2803: $display = 'block';
2804: }
2805: my $additional = '<div id="credits" style="display: '.$display.'">'.
2806: '<span class="LC_nobreak">'.
2807: &mt('Default credits for official courses [_1]',
2808: '<input type="text" name="official_credits" value="'.
2809: $def_official_credits.'" size="3" />').
2810: '</span><br />'.
2811: '<span class="LC_nobreak">'.
2812: &mt('Default credits for unofficial courses [_1]',
2813: '<input type="text" name="unofficial_credits" value="'.
2814: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2815: '</span><br />'.
2816: '<span class="LC_nobreak">'.
2817: &mt('Default credits for textbook courses [_1]',
2818: '<input type="text" name="textbook_credits" value="'.
2819: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2820: '</span></div>'."\n";
2821: %defaultchecked = ('coursecredits' => 'off');
2822: @toggles = ('coursecredits');
2823: my $current = {
2824: 'coursecredits' => $currusecredits,
2825: };
2826: (my $table,$itemcount) =
2827: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2828: \%choices,$itemcount,$onclick,$additional);
2829: $datatable .= $table;
1.160.6.37 raeburn 2830: $itemcount ++;
2831: }
2832: $$rowtotal += $itemcount;
2833: return $datatable;
2834: }
2835:
2836: sub print_selfenrollment {
2837: my ($position,$dom,$settings,$rowtotal) = @_;
2838: my ($css_class,$datatable);
2839: my $itemcount = 1;
2840: my @types = ('official','unofficial','community','textbook');
2841: if (($position eq 'top') || ($position eq 'middle')) {
2842: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2843: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2844: my @rows;
2845: my $key;
2846: if ($position eq 'top') {
2847: $key = 'admin';
2848: if (ref($rowsref) eq 'ARRAY') {
2849: @rows = @{$rowsref};
2850: }
2851: } elsif ($position eq 'middle') {
2852: $key = 'default';
2853: @rows = ('types','registered','approval','limit');
2854: }
2855: foreach my $row (@rows) {
2856: if (defined($titlesref->{$row})) {
2857: $itemcount ++;
2858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2859: $datatable .= '<tr'.$css_class.'>'.
2860: '<td>'.$titlesref->{$row}.'</td>'.
2861: '<td class="LC_left_item">'.
2862: '<table><tr>';
2863: my (%current,%currentcap);
2864: if (ref($settings) eq 'HASH') {
2865: if (ref($settings->{$key}) eq 'HASH') {
2866: foreach my $type (@types) {
2867: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2868: $current{$type} = $settings->{$key}->{$type}->{$row};
2869: }
2870: if (($row eq 'limit') && ($key eq 'default')) {
2871: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2872: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2873: }
2874: }
2875: }
2876: }
2877: }
2878: my %roles = (
2879: '0' => &Apache::lonnet::plaintext('dc'),
2880: );
2881:
2882: foreach my $type (@types) {
2883: unless (($row eq 'registered') && ($key eq 'default')) {
2884: $datatable .= '<th>'.&mt($type).'</th>';
2885: }
2886: }
2887: unless (($row eq 'registered') && ($key eq 'default')) {
2888: $datatable .= '</tr><tr>';
2889: }
2890: foreach my $type (@types) {
2891: if ($type eq 'community') {
2892: $roles{'1'} = &mt('Community personnel');
2893: } else {
2894: $roles{'1'} = &mt('Course personnel');
2895: }
2896: $datatable .= '<td style="vertical-align: top">';
2897: if ($position eq 'top') {
2898: my %checked;
2899: if ($current{$type} eq '0') {
2900: $checked{'0'} = ' checked="checked"';
2901: } else {
2902: $checked{'1'} = ' checked="checked"';
2903: }
2904: foreach my $role ('1','0') {
2905: $datatable .= '<span class="LC_nobreak"><label>'.
2906: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2907: 'value="'.$role.'"'.$checked{$role}.' />'.
2908: $roles{$role}.'</label></span> ';
2909: }
2910: } else {
2911: if ($row eq 'types') {
2912: my %checked;
2913: if ($current{$type} =~ /^(all|dom)$/) {
2914: $checked{$1} = ' checked="checked"';
2915: } else {
2916: $checked{''} = ' checked="checked"';
2917: }
2918: foreach my $val ('','dom','all') {
2919: $datatable .= '<span class="LC_nobreak"><label>'.
2920: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2921: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2922: }
2923: } elsif ($row eq 'registered') {
2924: my %checked;
2925: if ($current{$type} eq '1') {
2926: $checked{'1'} = ' checked="checked"';
2927: } else {
2928: $checked{'0'} = ' checked="checked"';
2929: }
2930: foreach my $val ('0','1') {
2931: $datatable .= '<span class="LC_nobreak"><label>'.
2932: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2933: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2934: }
2935: } elsif ($row eq 'approval') {
2936: my %checked;
2937: if ($current{$type} =~ /^([12])$/) {
2938: $checked{$1} = ' checked="checked"';
2939: } else {
2940: $checked{'0'} = ' checked="checked"';
2941: }
2942: for my $val (0..2) {
2943: $datatable .= '<span class="LC_nobreak"><label>'.
2944: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2945: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2946: }
2947: } elsif ($row eq 'limit') {
2948: my %checked;
2949: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2950: $checked{$1} = ' checked="checked"';
2951: } else {
2952: $checked{'none'} = ' checked="checked"';
2953: }
2954: my $cap;
2955: if ($currentcap{$type} =~ /^\d+$/) {
2956: $cap = $currentcap{$type};
2957: }
2958: foreach my $val ('none','allstudents','selfenrolled') {
2959: $datatable .= '<span class="LC_nobreak"><label>'.
2960: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2961: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2962: }
2963: $datatable .= '<br />'.
2964: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2965: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2966: '</span>';
2967: }
2968: }
2969: $datatable .= '</td>';
2970: }
2971: $datatable .= '</tr>';
2972: }
2973: $datatable .= '</table></td></tr>';
2974: }
2975: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 2976: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
2977: }
2978: $$rowtotal += $itemcount;
2979: return $datatable;
2980: }
2981:
2982: sub print_validation_rows {
2983: my ($caller,$dom,$settings,$rowtotal) = @_;
2984: my ($itemsref,$namesref,$fieldsref);
2985: if ($caller eq 'selfenroll') {
2986: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
2987: } elsif ($caller eq 'requestcourses') {
2988: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
2989: }
2990: my %currvalidation;
2991: if (ref($settings) eq 'HASH') {
2992: if (ref($settings->{'validation'}) eq 'HASH') {
2993: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 2994: }
1.160.6.39 raeburn 2995: }
2996: my $datatable;
2997: my $itemcount = 0;
2998: foreach my $item (@{$itemsref}) {
2999: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3000: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3001: $namesref->{$item}.
3002: '</span></td>'.
3003: '<td class="LC_left_item">';
3004: if (($item eq 'url') || ($item eq 'button')) {
3005: $datatable .= '<span class="LC_nobreak">'.
3006: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3007: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3008: } elsif ($item eq 'fields') {
3009: my @currfields;
3010: if (ref($currvalidation{$item}) eq 'ARRAY') {
3011: @currfields = @{$currvalidation{$item}};
3012: }
3013: foreach my $field (@{$fieldsref}) {
3014: my $check = '';
3015: if (grep(/^\Q$field\E$/,@currfields)) {
3016: $check = ' checked="checked"';
3017: }
3018: $datatable .= '<span class="LC_nobreak"><label>'.
3019: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3020: ' value="'.$field.'"'.$check.' />'.$field.
3021: '</label></span> ';
3022: }
3023: } elsif ($item eq 'markup') {
3024: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3025: $currvalidation{$item}.
1.160.6.37 raeburn 3026: '</textarea>';
1.160.6.39 raeburn 3027: }
3028: $datatable .= '</td></tr>'."\n";
3029: if (ref($rowtotal)) {
1.160.6.37 raeburn 3030: $itemcount ++;
3031: }
1.139 raeburn 3032: }
1.160.6.39 raeburn 3033: if ($caller eq 'requestcourses') {
3034: my %currhash;
3035: if (ref($settings->{'validation'}) eq 'HASH') {
3036: if ($settings->{'validation'}{'dc'} ne '') {
3037: $currhash{$settings->{'validation'}{'dc'}} = 1;
3038: }
3039: }
3040: my $numinrow = 2;
3041: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3042: 'validationdc',%currhash);
3043: if ($numdc > 1) {
3044: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3045: &mt('Course creation processed as: (choose Dom. Coord.)').
3046: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3047: } else {
3048: $datatable .= $dctable.'</td></tr>';
3049: }
3050: $itemcount ++;
3051: }
3052: if (ref($rowtotal)) {
3053: $$rowtotal += $itemcount;
3054: }
1.121 raeburn 3055: return $datatable;
1.118 jms 3056: }
3057:
1.137 raeburn 3058: sub print_usersessions {
3059: my ($position,$dom,$settings,$rowtotal) = @_;
3060: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3061: my (%by_ip,%by_location,@intdoms);
3062: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3063:
3064: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3065: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3066: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3067: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3068: my $itemcount = 1;
3069: if ($position eq 'top') {
1.152 raeburn 3070: if (keys(%serverhomes) > 1) {
1.145 raeburn 3071: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3072: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3073: } else {
1.140 raeburn 3074: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3075: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3076: }
1.137 raeburn 3077: } else {
1.145 raeburn 3078: if (keys(%by_location) == 0) {
3079: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3080: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3081: } else {
3082: my %lt = &usersession_titles();
3083: my $numinrow = 5;
3084: my $prefix;
3085: my @types;
3086: if ($position eq 'bottom') {
3087: $prefix = 'remote';
3088: @types = ('version','excludedomain','includedomain');
3089: } else {
3090: $prefix = 'hosted';
3091: @types = ('excludedomain','includedomain');
3092: }
3093: my (%current,%checkedon,%checkedoff);
3094: my @lcversions = &Apache::lonnet::all_loncaparevs();
3095: my @locations = sort(keys(%by_location));
3096: foreach my $type (@types) {
3097: $checkedon{$type} = '';
3098: $checkedoff{$type} = ' checked="checked"';
3099: }
3100: if (ref($settings) eq 'HASH') {
3101: if (ref($settings->{$prefix}) eq 'HASH') {
3102: foreach my $key (keys(%{$settings->{$prefix}})) {
3103: $current{$key} = $settings->{$prefix}{$key};
3104: if ($key eq 'version') {
3105: if ($current{$key} ne '') {
3106: $checkedon{$key} = ' checked="checked"';
3107: $checkedoff{$key} = '';
3108: }
3109: } elsif (ref($current{$key}) eq 'ARRAY') {
3110: $checkedon{$key} = ' checked="checked"';
3111: $checkedoff{$key} = '';
3112: }
1.137 raeburn 3113: }
3114: }
3115: }
1.145 raeburn 3116: foreach my $type (@types) {
3117: next if ($type ne 'version' && !@locations);
3118: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3119: $datatable .= '<tr'.$css_class.'>
3120: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3121: <span class="LC_nobreak">
3122: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3123: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3124: if ($type eq 'version') {
3125: my $selector = '<select name="'.$prefix.'_version">';
3126: foreach my $version (@lcversions) {
3127: my $selected = '';
3128: if ($current{'version'} eq $version) {
3129: $selected = ' selected="selected"';
3130: }
3131: $selector .= ' <option value="'.$version.'"'.
3132: $selected.'>'.$version.'</option>';
3133: }
3134: $selector .= '</select> ';
3135: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3136: } else {
3137: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3138: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3139: ' />'.(' 'x2).
3140: '<input type="button" value="'.&mt('uncheck all').'" '.
3141: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3142: "\n".
3143: '</div><div><table>';
3144: my $rem;
3145: for (my $i=0; $i<@locations; $i++) {
3146: my ($showloc,$value,$checkedtype);
3147: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3148: my $ip = $by_location{$locations[$i]}->[0];
3149: if (ref($by_ip{$ip}) eq 'ARRAY') {
3150: $value = join(':',@{$by_ip{$ip}});
3151: $showloc = join(', ',@{$by_ip{$ip}});
3152: if (ref($current{$type}) eq 'ARRAY') {
3153: foreach my $loc (@{$by_ip{$ip}}) {
3154: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3155: $checkedtype = ' checked="checked"';
3156: last;
3157: }
3158: }
1.138 raeburn 3159: }
3160: }
3161: }
1.145 raeburn 3162: $rem = $i%($numinrow);
3163: if ($rem == 0) {
3164: if ($i > 0) {
3165: $datatable .= '</tr>';
3166: }
3167: $datatable .= '<tr>';
3168: }
3169: $datatable .= '<td class="LC_left_item">'.
3170: '<span class="LC_nobreak"><label>'.
3171: '<input type="checkbox" name="'.$prefix.'_'.$type.
3172: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3173: '</label></span></td>';
1.137 raeburn 3174: }
1.145 raeburn 3175: $rem = @locations%($numinrow);
3176: my $colsleft = $numinrow - $rem;
3177: if ($colsleft > 1 ) {
3178: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3179: ' </td>';
3180: } elsif ($colsleft == 1) {
3181: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3182: }
1.145 raeburn 3183: $datatable .= '</tr></table>';
1.137 raeburn 3184: }
1.145 raeburn 3185: $datatable .= '</td></tr>';
3186: $itemcount ++;
1.137 raeburn 3187: }
3188: }
3189: }
3190: $$rowtotal += $itemcount;
3191: return $datatable;
3192: }
3193:
1.138 raeburn 3194: sub build_location_hashes {
3195: my ($intdoms,$by_ip,$by_location) = @_;
3196: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3197: (ref($by_location) eq 'HASH'));
3198: my %iphost = &Apache::lonnet::get_iphost();
3199: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3200: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3201: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3202: foreach my $id (@{$iphost{$primary_ip}}) {
3203: my $intdom = &Apache::lonnet::internet_dom($id);
3204: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3205: push(@{$intdoms},$intdom);
3206: }
3207: }
3208: }
3209: foreach my $ip (keys(%iphost)) {
3210: if (ref($iphost{$ip}) eq 'ARRAY') {
3211: foreach my $id (@{$iphost{$ip}}) {
3212: my $location = &Apache::lonnet::internet_dom($id);
3213: if ($location) {
3214: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3215: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3216: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3217: push(@{$by_ip->{$ip}},$location);
3218: }
3219: } else {
3220: $by_ip->{$ip} = [$location];
3221: }
3222: }
3223: }
3224: }
3225: }
3226: foreach my $ip (sort(keys(%{$by_ip}))) {
3227: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3228: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3229: my $first = $by_ip->{$ip}->[0];
3230: if (ref($by_location->{$first}) eq 'ARRAY') {
3231: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3232: push(@{$by_location->{$first}},$ip);
3233: }
3234: } else {
3235: $by_location->{$first} = [$ip];
3236: }
3237: }
3238: }
3239: return;
3240: }
3241:
1.145 raeburn 3242: sub current_offloads_to {
3243: my ($dom,$settings,$servers) = @_;
3244: my (%spareid,%otherdomconfigs);
1.152 raeburn 3245: if (ref($servers) eq 'HASH') {
1.145 raeburn 3246: foreach my $lonhost (sort(keys(%{$servers}))) {
3247: my $gotspares;
1.152 raeburn 3248: if (ref($settings) eq 'HASH') {
3249: if (ref($settings->{'spares'}) eq 'HASH') {
3250: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3251: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3252: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3253: $gotspares = 1;
3254: }
1.145 raeburn 3255: }
3256: }
3257: unless ($gotspares) {
3258: my $gotspares;
3259: my $serverhomeID =
3260: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3261: my $serverhomedom =
3262: &Apache::lonnet::host_domain($serverhomeID);
3263: if ($serverhomedom ne $dom) {
3264: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3265: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3266: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3267: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3268: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3269: $gotspares = 1;
3270: }
3271: }
3272: } else {
3273: $otherdomconfigs{$serverhomedom} =
3274: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3275: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3276: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3277: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3278: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3279: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3280: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3281: $gotspares = 1;
3282: }
3283: }
3284: }
3285: }
3286: }
3287: }
3288: }
3289: unless ($gotspares) {
3290: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3291: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3292: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3293: } else {
3294: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3295: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3296: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3297: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3298: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3299: } else {
1.150 raeburn 3300: my %what = (
3301: spareid => 1,
3302: );
3303: my ($result,$returnhash) =
3304: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3305: if ($result eq 'ok') {
3306: if (ref($returnhash) eq 'HASH') {
3307: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3308: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3309: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3310: }
3311: }
1.145 raeburn 3312: }
3313: }
3314: }
3315: }
3316: }
3317: }
3318: return %spareid;
3319: }
3320:
3321: sub spares_row {
1.152 raeburn 3322: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3323: my $css_class;
3324: my $numinrow = 4;
3325: my $itemcount = 1;
3326: my $datatable;
1.152 raeburn 3327: my %typetitles = &sparestype_titles();
3328: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3329: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3330: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3331: my ($othercontrol,$serverdom);
3332: if ($serverhome ne $server) {
3333: $serverdom = &Apache::lonnet::host_domain($serverhome);
3334: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3335: } else {
3336: $serverdom = &Apache::lonnet::host_domain($server);
3337: if ($serverdom ne $dom) {
3338: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3339: }
3340: }
3341: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3342: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3343: $datatable .= '<tr'.$css_class.'>
3344: <td rowspan="2">
1.160.6.13 raeburn 3345: <span class="LC_nobreak">'.
3346: &mt('[_1] when busy, offloads to:'
3347: ,'<b>'.$server.'</b>').
3348: "\n";
1.145 raeburn 3349: my (%current,%canselect);
1.152 raeburn 3350: my @choices =
3351: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3352: foreach my $type ('primary','default') {
3353: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3354: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3355: my @spares = @{$spareid->{$server}{$type}};
3356: if (@spares > 0) {
1.152 raeburn 3357: if ($othercontrol) {
3358: $current{$type} = join(', ',@spares);
3359: } else {
3360: $current{$type} .= '<table>';
3361: my $numspares = scalar(@spares);
3362: for (my $i=0; $i<@spares; $i++) {
3363: my $rem = $i%($numinrow);
3364: if ($rem == 0) {
3365: if ($i > 0) {
3366: $current{$type} .= '</tr>';
3367: }
3368: $current{$type} .= '<tr>';
1.145 raeburn 3369: }
1.152 raeburn 3370: $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'".');" /> '.
3371: $spareid->{$server}{$type}[$i].
3372: '</label></td>'."\n";
3373: }
3374: my $rem = @spares%($numinrow);
3375: my $colsleft = $numinrow - $rem;
3376: if ($colsleft > 1 ) {
3377: $current{$type} .= '<td colspan="'.$colsleft.
3378: '" class="LC_left_item">'.
3379: ' </td>';
3380: } elsif ($colsleft == 1) {
3381: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3382: }
1.152 raeburn 3383: $current{$type} .= '</tr></table>';
1.150 raeburn 3384: }
1.145 raeburn 3385: }
3386: }
3387: if ($current{$type} eq '') {
3388: $current{$type} = &mt('None specified');
3389: }
1.152 raeburn 3390: if ($othercontrol) {
3391: if ($type eq 'primary') {
3392: $canselect{$type} = $othercontrol;
3393: }
3394: } else {
3395: $canselect{$type} =
3396: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3397: '<select name="newspare_'.$type.'_'.$server.'" '.
3398: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3399: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3400: if (@choices > 0) {
3401: foreach my $lonhost (@choices) {
3402: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3403: }
3404: }
3405: $canselect{$type} .= '</select>'."\n";
3406: }
3407: } else {
3408: $current{$type} = &mt('Could not be determined');
3409: if ($type eq 'primary') {
3410: $canselect{$type} = $othercontrol;
3411: }
1.145 raeburn 3412: }
1.152 raeburn 3413: if ($type eq 'default') {
3414: $datatable .= '<tr'.$css_class.'>';
3415: }
3416: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3417: '<td>'.$current{$type}.'</td>'."\n".
3418: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3419: }
3420: $itemcount ++;
3421: }
3422: }
3423: $$rowtotal += $itemcount;
3424: return $datatable;
3425: }
3426:
1.152 raeburn 3427: sub possible_newspares {
3428: my ($server,$currspares,$serverhomes,$altids) = @_;
3429: my $serverhostname = &Apache::lonnet::hostname($server);
3430: my %excluded;
3431: if ($serverhostname ne '') {
3432: %excluded = (
3433: $serverhostname => 1,
3434: );
3435: }
3436: if (ref($currspares) eq 'HASH') {
3437: foreach my $type (keys(%{$currspares})) {
3438: if (ref($currspares->{$type}) eq 'ARRAY') {
3439: if (@{$currspares->{$type}} > 0) {
3440: foreach my $curr (@{$currspares->{$type}}) {
3441: my $hostname = &Apache::lonnet::hostname($curr);
3442: $excluded{$hostname} = 1;
3443: }
3444: }
3445: }
3446: }
3447: }
3448: my @choices;
3449: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3450: if (keys(%{$serverhomes}) > 1) {
3451: foreach my $name (sort(keys(%{$serverhomes}))) {
3452: unless ($excluded{$name}) {
3453: if (exists($altids->{$serverhomes->{$name}})) {
3454: push(@choices,$altids->{$serverhomes->{$name}});
3455: } else {
3456: push(@choices,$serverhomes->{$name});
1.145 raeburn 3457: }
3458: }
3459: }
3460: }
3461: }
1.152 raeburn 3462: return sort(@choices);
1.145 raeburn 3463: }
3464:
1.150 raeburn 3465: sub print_loadbalancing {
3466: my ($dom,$settings,$rowtotal) = @_;
3467: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3468: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3469: my $numinrow = 1;
3470: my $datatable;
3471: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3472: my (%currbalancer,%currtargets,%currrules,%existing);
3473: if (ref($settings) eq 'HASH') {
3474: %existing = %{$settings};
3475: }
3476: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3477: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3478: \%currtargets,\%currrules);
1.150 raeburn 3479: } else {
3480: return;
3481: }
3482: my ($othertitle,$usertypes,$types) =
3483: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3484: my $rownum = 8;
1.150 raeburn 3485: if (ref($types) eq 'ARRAY') {
3486: $rownum += scalar(@{$types});
3487: }
1.160.6.7 raeburn 3488: my @css_class = ('LC_odd_row','LC_even_row');
3489: my $balnum = 0;
3490: my $islast;
3491: my (@toshow,$disabledtext);
3492: if (keys(%currbalancer) > 0) {
3493: @toshow = sort(keys(%currbalancer));
3494: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3495: push(@toshow,'');
3496: }
3497: } else {
3498: @toshow = ('');
3499: $disabledtext = &mt('No existing load balancer');
3500: }
3501: foreach my $lonhost (@toshow) {
3502: if ($balnum == scalar(@toshow)-1) {
3503: $islast = 1;
3504: } else {
3505: $islast = 0;
3506: }
3507: my $cssidx = $balnum%2;
3508: my $targets_div_style = 'display: none';
3509: my $disabled_div_style = 'display: block';
3510: my $homedom_div_style = 'display: none';
3511: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3512: '<td rowspan="'.$rownum.'" valign="top">'.
3513: '<p>';
3514: if ($lonhost eq '') {
3515: $datatable .= '<span class="LC_nobreak">';
3516: if (keys(%currbalancer) > 0) {
3517: $datatable .= &mt('Add balancer:');
3518: } else {
3519: $datatable .= &mt('Enable balancer:');
3520: }
3521: $datatable .= ' '.
3522: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3523: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3524: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3525: '<option value="" selected="selected">'.&mt('None').
3526: '</option>'."\n";
3527: foreach my $server (sort(keys(%servers))) {
3528: next if ($currbalancer{$server});
3529: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3530: }
3531: $datatable .=
3532: '</select>'."\n".
3533: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3534: } else {
3535: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3536: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3537: &mt('Stop balancing').'</label>'.
3538: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3539: $targets_div_style = 'display: block';
3540: $disabled_div_style = 'display: none';
3541: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3542: $homedom_div_style = 'display: block';
3543: }
3544: }
3545: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3546: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3547: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3548: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3549: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3550: my @sparestypes = ('primary','default');
3551: my %typetitles = &sparestype_titles();
3552: foreach my $sparetype (@sparestypes) {
3553: my $targettable;
3554: for (my $i=0; $i<$numspares; $i++) {
3555: my $checked;
3556: if (ref($currtargets{$lonhost}) eq 'HASH') {
3557: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3558: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3559: $checked = ' checked="checked"';
3560: }
3561: }
3562: }
3563: my ($chkboxval,$disabled);
3564: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3565: $chkboxval = $spares[$i];
3566: }
3567: if (exists($currbalancer{$spares[$i]})) {
3568: $disabled = ' disabled="disabled"';
3569: }
3570: $targettable .=
3571: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3572: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3573: '</span></label></td>';
3574: my $rem = $i%($numinrow);
3575: if ($rem == 0) {
3576: if (($i > 0) && ($i < $numspares-1)) {
3577: $targettable .= '</tr>';
3578: }
3579: if ($i < $numspares-1) {
3580: $targettable .= '<tr>';
1.150 raeburn 3581: }
3582: }
3583: }
1.160.6.7 raeburn 3584: if ($targettable ne '') {
3585: my $rem = $numspares%($numinrow);
3586: my $colsleft = $numinrow - $rem;
3587: if ($colsleft > 1 ) {
3588: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3589: ' </td>';
3590: } elsif ($colsleft == 1) {
3591: $targettable .= '<td class="LC_left_item"> </td>';
3592: }
3593: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3594: '<table><tr>'.$targettable.'</tr></table><br />';
3595: }
3596: }
3597: $datatable .= '</div></td></tr>'.
3598: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3599: $othertitle,$usertypes,$types,\%servers,
3600: \%currbalancer,$lonhost,
3601: $targets_div_style,$homedom_div_style,
3602: $css_class[$cssidx],$balnum,$islast);
3603: $$rowtotal += $rownum;
3604: $balnum ++;
3605: }
3606: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3607: return $datatable;
3608: }
3609:
3610: sub get_loadbalancers_config {
3611: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3612: return unless ((ref($servers) eq 'HASH') &&
3613: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3614: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3615: if (keys(%{$existing}) > 0) {
3616: my $oldlonhost;
3617: foreach my $key (sort(keys(%{$existing}))) {
3618: if ($key eq 'lonhost') {
3619: $oldlonhost = $existing->{'lonhost'};
3620: $currbalancer->{$oldlonhost} = 1;
3621: } elsif ($key eq 'targets') {
3622: if ($oldlonhost) {
3623: $currtargets->{$oldlonhost} = $existing->{'targets'};
3624: }
3625: } elsif ($key eq 'rules') {
3626: if ($oldlonhost) {
3627: $currrules->{$oldlonhost} = $existing->{'rules'};
3628: }
3629: } elsif (ref($existing->{$key}) eq 'HASH') {
3630: $currbalancer->{$key} = 1;
3631: $currtargets->{$key} = $existing->{$key}{'targets'};
3632: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3633: }
3634: }
1.160.6.7 raeburn 3635: } else {
3636: my ($balancerref,$targetsref) =
3637: &Apache::lonnet::get_lonbalancer_config($servers);
3638: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3639: foreach my $server (sort(keys(%{$balancerref}))) {
3640: $currbalancer->{$server} = 1;
3641: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3642: }
3643: }
3644: }
1.160.6.7 raeburn 3645: return;
1.150 raeburn 3646: }
3647:
3648: sub loadbalancing_rules {
3649: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3650: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3651: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3652: my $output;
1.160.6.7 raeburn 3653: my $num = 0;
3654: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3655: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3656: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3657: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3658: $num ++;
1.150 raeburn 3659: my $current;
3660: if (ref($currrules) eq 'HASH') {
3661: $current = $currrules->{$type};
3662: }
1.160.6.26 raeburn 3663: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3664: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3665: $current = '';
3666: }
3667: }
3668: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3669: $servers,$currbalancer,$lonhost,$dom,
3670: $targets_div_style,$homedom_div_style,
3671: $css_class,$balnum,$num,$islast);
1.150 raeburn 3672: }
3673: }
3674: return $output;
3675: }
3676:
3677: sub loadbalancing_titles {
3678: my ($dom,$intdom,$usertypes,$types) = @_;
3679: my %othertypes = (
3680: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3681: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3682: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3683: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3684: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3685: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3686: );
1.160.6.26 raeburn 3687: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3688: if (ref($types) eq 'ARRAY') {
3689: unshift(@alltypes,@{$types},'default');
3690: }
3691: my %titles;
3692: foreach my $type (@alltypes) {
3693: if ($type =~ /^_LC_/) {
3694: $titles{$type} = $othertypes{$type};
3695: } elsif ($type eq 'default') {
3696: $titles{$type} = &mt('All users from [_1]',$dom);
3697: if (ref($types) eq 'ARRAY') {
3698: if (@{$types} > 0) {
3699: $titles{$type} = &mt('Other users from [_1]',$dom);
3700: }
3701: }
3702: } elsif (ref($usertypes) eq 'HASH') {
3703: $titles{$type} = $usertypes->{$type};
3704: }
3705: }
3706: return (\@alltypes,\%othertypes,\%titles);
3707: }
3708:
3709: sub loadbalance_rule_row {
1.160.6.7 raeburn 3710: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3711: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3712: my @rulenames;
1.150 raeburn 3713: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3714: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3715: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3716: } else {
1.160.6.26 raeburn 3717: @rulenames = ('default','homeserver');
3718: if ($type eq '_LC_external') {
3719: push(@rulenames,'externalbalancer');
3720: } else {
3721: push(@rulenames,'specific');
3722: }
3723: push(@rulenames,'none');
1.150 raeburn 3724: }
3725: my $style = $targets_div_style;
1.160.6.26 raeburn 3726: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3727: $style = $homedom_div_style;
3728: }
1.160.6.7 raeburn 3729: my $space;
3730: if ($islast && $num == 1) {
3731: $space = '<div display="inline-block"> </div>';
3732: }
3733: my $output =
3734: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3735: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3736: '<td valaign="top">'.$space.
3737: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3738: for (my $i=0; $i<@rulenames; $i++) {
3739: my $rule = $rulenames[$i];
3740: my ($checked,$extra);
3741: if ($rulenames[$i] eq 'default') {
3742: $rule = '';
3743: }
3744: if ($rulenames[$i] eq 'specific') {
3745: if (ref($servers) eq 'HASH') {
3746: my $default;
3747: if (($current ne '') && (exists($servers->{$current}))) {
3748: $checked = ' checked="checked"';
3749: }
3750: unless ($checked) {
3751: $default = ' selected="selected"';
3752: }
1.160.6.7 raeburn 3753: $extra =
3754: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3755: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3756: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3757: '<option value=""'.$default.'></option>'."\n";
3758: foreach my $server (sort(keys(%{$servers}))) {
3759: if (ref($currbalancer) eq 'HASH') {
3760: next if (exists($currbalancer->{$server}));
3761: }
1.150 raeburn 3762: my $selected;
1.160.6.7 raeburn 3763: if ($server eq $current) {
1.150 raeburn 3764: $selected = ' selected="selected"';
3765: }
1.160.6.7 raeburn 3766: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3767: }
3768: $extra .= '</select>';
3769: }
3770: } elsif ($rule eq $current) {
3771: $checked = ' checked="checked"';
3772: }
3773: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3774: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3775: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3776: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3777: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3778: '</label>'.$extra.'</span><br />'."\n";
3779: }
3780: $output .= '</div></td></tr>'."\n";
3781: return $output;
3782: }
3783:
3784: sub offloadtype_text {
3785: my %ruletitles = &Apache::lonlocal::texthash (
3786: 'default' => 'Offloads to default destinations',
3787: 'homeserver' => "Offloads to user's home server",
3788: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3789: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3790: 'none' => 'No offload',
1.160.6.26 raeburn 3791: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3792: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3793: );
3794: return %ruletitles;
3795: }
3796:
3797: sub sparestype_titles {
3798: my %typestitles = &Apache::lonlocal::texthash (
3799: 'primary' => 'primary',
3800: 'default' => 'default',
3801: );
3802: return %typestitles;
3803: }
3804:
1.28 raeburn 3805: sub contact_titles {
3806: my %titles = &Apache::lonlocal::texthash (
3807: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3808: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3809: 'errormail' => 'Error reports to be e-mailed to',
3810: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3811: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3812: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3813: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3814: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3815: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3816: );
3817: my %short_titles = &Apache::lonlocal::texthash (
3818: adminemail => 'Admin E-mail address',
3819: supportemail => 'Support E-mail',
3820: );
3821: return (\%titles,\%short_titles);
3822: }
3823:
1.72 raeburn 3824: sub tool_titles {
3825: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3826: aboutme => 'Personal web page',
1.86 raeburn 3827: blog => 'Blog',
1.160.6.4 raeburn 3828: webdav => 'WebDAV',
1.86 raeburn 3829: portfolio => 'Portfolio',
1.88 bisitz 3830: official => 'Official courses (with institutional codes)',
3831: unofficial => 'Unofficial courses',
1.98 raeburn 3832: community => 'Communities',
1.160.6.30 raeburn 3833: textbook => 'Textbook courses',
1.86 raeburn 3834: );
1.72 raeburn 3835: return %titles;
3836: }
3837:
1.101 raeburn 3838: sub courserequest_titles {
3839: my %titles = &Apache::lonlocal::texthash (
3840: official => 'Official',
3841: unofficial => 'Unofficial',
3842: community => 'Communities',
1.160.6.30 raeburn 3843: textbook => 'Textbook',
1.101 raeburn 3844: norequest => 'Not allowed',
1.104 raeburn 3845: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3846: validate => 'With validation',
3847: autolimit => 'Numerical limit',
1.103 raeburn 3848: unlimited => '(blank for unlimited)',
1.101 raeburn 3849: );
3850: return %titles;
3851: }
3852:
1.160.6.5 raeburn 3853: sub authorrequest_titles {
3854: my %titles = &Apache::lonlocal::texthash (
3855: norequest => 'Not allowed',
3856: approval => 'Approval by Dom. Coord.',
3857: automatic => 'Automatic approval',
3858: );
3859: return %titles;
3860: }
3861:
1.101 raeburn 3862: sub courserequest_conditions {
3863: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3864: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3865: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3866: );
3867: return %conditions;
3868: }
3869:
3870:
1.27 raeburn 3871: sub print_usercreation {
1.30 raeburn 3872: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3873: my $numinrow = 4;
1.28 raeburn 3874: my $datatable;
3875: if ($position eq 'top') {
1.30 raeburn 3876: $$rowtotal ++;
1.34 raeburn 3877: my $rowcount = 0;
1.32 raeburn 3878: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3879: if (ref($rules) eq 'HASH') {
3880: if (keys(%{$rules}) > 0) {
1.32 raeburn 3881: $datatable .= &user_formats_row('username',$settings,$rules,
3882: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3883: $$rowtotal ++;
1.32 raeburn 3884: $rowcount ++;
3885: }
3886: }
3887: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3888: if (ref($idrules) eq 'HASH') {
3889: if (keys(%{$idrules}) > 0) {
3890: $datatable .= &user_formats_row('id',$settings,$idrules,
3891: $idruleorder,$numinrow,$rowcount);
3892: $$rowtotal ++;
3893: $rowcount ++;
1.28 raeburn 3894: }
3895: }
1.39 raeburn 3896: if ($rowcount == 0) {
3897: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3898: $$rowtotal ++;
3899: $rowcount ++;
3900: }
1.34 raeburn 3901: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3902: my @creators = ('author','course','requestcrs');
1.37 raeburn 3903: my ($rules,$ruleorder) =
3904: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3905: my %lt = &usercreation_types();
3906: my %checked;
3907: if (ref($settings) eq 'HASH') {
3908: if (ref($settings->{'cancreate'}) eq 'HASH') {
3909: foreach my $item (@creators) {
3910: $checked{$item} = $settings->{'cancreate'}{$item};
3911: }
3912: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3913: foreach my $item (@creators) {
3914: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3915: $checked{$item} = 'none';
3916: }
3917: }
3918: }
3919: }
3920: my $rownum = 0;
3921: foreach my $item (@creators) {
3922: $rownum ++;
1.160.6.34 raeburn 3923: if ($checked{$item} eq '') {
3924: $checked{$item} = 'any';
1.34 raeburn 3925: }
3926: my $css_class;
3927: if ($rownum%2) {
3928: $css_class = '';
3929: } else {
3930: $css_class = ' class="LC_odd_row" ';
3931: }
3932: $datatable .= '<tr'.$css_class.'>'.
3933: '<td><span class="LC_nobreak">'.$lt{$item}.
3934: '</span></td><td align="right">';
1.160.6.34 raeburn 3935: my @options = ('any');
3936: if (ref($rules) eq 'HASH') {
3937: if (keys(%{$rules}) > 0) {
3938: push(@options,('official','unofficial'));
1.37 raeburn 3939: }
3940: }
1.160.6.34 raeburn 3941: push(@options,'none');
1.37 raeburn 3942: foreach my $option (@options) {
1.50 raeburn 3943: my $type = 'radio';
1.34 raeburn 3944: my $check = ' ';
1.160.6.34 raeburn 3945: if ($checked{$item} eq $option) {
3946: $check = ' checked="checked" ';
1.34 raeburn 3947: }
3948: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3949: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3950: $item.'" value="'.$option.'"'.$check.'/> '.
3951: $lt{$option}.'</label> </span>';
3952: }
3953: $datatable .= '</td></tr>';
3954: }
1.28 raeburn 3955: } else {
3956: my @contexts = ('author','course','domain');
3957: my @authtypes = ('int','krb4','krb5','loc');
3958: my %checked;
3959: if (ref($settings) eq 'HASH') {
3960: if (ref($settings->{'authtypes'}) eq 'HASH') {
3961: foreach my $item (@contexts) {
3962: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3963: foreach my $auth (@authtypes) {
3964: if ($settings->{'authtypes'}{$item}{$auth}) {
3965: $checked{$item}{$auth} = ' checked="checked" ';
3966: }
3967: }
3968: }
3969: }
1.27 raeburn 3970: }
1.35 raeburn 3971: } else {
3972: foreach my $item (@contexts) {
1.36 raeburn 3973: foreach my $auth (@authtypes) {
1.35 raeburn 3974: $checked{$item}{$auth} = ' checked="checked" ';
3975: }
3976: }
1.27 raeburn 3977: }
1.28 raeburn 3978: my %title = &context_names();
3979: my %authname = &authtype_names();
3980: my $rownum = 0;
3981: my $css_class;
3982: foreach my $item (@contexts) {
3983: if ($rownum%2) {
3984: $css_class = '';
3985: } else {
3986: $css_class = ' class="LC_odd_row" ';
3987: }
1.30 raeburn 3988: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3989: '<td>'.$title{$item}.
3990: '</td><td class="LC_left_item">'.
3991: '<span class="LC_nobreak">';
3992: foreach my $auth (@authtypes) {
3993: $datatable .= '<label>'.
3994: '<input type="checkbox" name="'.$item.'_auth" '.
3995: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3996: $authname{$auth}.'</label> ';
3997: }
3998: $datatable .= '</span></td></tr>';
3999: $rownum ++;
1.27 raeburn 4000: }
1.30 raeburn 4001: $$rowtotal += $rownum;
1.27 raeburn 4002: }
4003: return $datatable;
4004: }
4005:
1.160.6.34 raeburn 4006: sub print_selfcreation {
4007: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4008: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4009: if (ref($settings) eq 'HASH') {
4010: if (ref($settings->{'cancreate'}) eq 'HASH') {
4011: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4012: if (ref($createsettings) eq 'HASH') {
4013: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4014: @selfcreate = @{$createsettings->{'selfcreate'}};
4015: } elsif ($createsettings->{'selfcreate'} ne '') {
4016: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4017: @selfcreate = ('email','login','sso');
4018: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4019: @selfcreate = ($createsettings->{'selfcreate'});
4020: }
4021: }
4022: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4023: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4024: }
4025: }
4026: }
4027: }
4028: my %radiohash;
4029: my $numinrow = 4;
4030: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4031: if ($position eq 'top') {
4032: my %choices = &Apache::lonlocal::texthash (
4033: cancreate_login => 'Institutional Login',
4034: cancreate_sso => 'Institutional Single Sign On',
4035: );
4036: my @toggles = sort(keys(%choices));
4037: my %defaultchecked = (
4038: 'cancreate_login' => 'off',
4039: 'cancreate_sso' => 'off',
4040: );
1.160.6.35 raeburn 4041: my ($onclick,$itemcount);
1.160.6.34 raeburn 4042: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4043: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4044: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4045:
1.160.6.34 raeburn 4046: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4047:
4048: if (ref($usertypes) eq 'HASH') {
4049: if (keys(%{$usertypes}) > 0) {
4050: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4051: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4052: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4053: $$rowtotal ++;
4054: }
4055: }
4056: } elsif ($position eq 'middle') {
4057: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4058: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4059: $usertypes->{'default'} = $othertitle;
4060: if (ref($types) eq 'ARRAY') {
4061: push(@{$types},'default');
4062: $usertypes->{'default'} = $othertitle;
4063: foreach my $status (@{$types}) {
4064: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4065: $numinrow,$$rowtotal,$usertypes);
1.160.6.40 raeburn 4066: $$rowtotal ++;
1.160.6.34 raeburn 4067: }
4068: }
4069: } else {
1.160.6.40 raeburn 4070: my %choices = &Apache::lonlocal::texthash (
4071: cancreate_email => 'E-mail address as username',
4072: );
4073: my @toggles = sort(keys(%choices));
4074: my %defaultchecked = (
4075: 'cancreate_email' => 'off',
4076: );
4077: my $itemcount = 0;
4078: my $display = 'none';
4079: if (grep(/^\Qemail\E$/,@selfcreate)) {
4080: $display = 'block';
4081: }
4082: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4083: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4084: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4085: my $usertypes = {};
4086: my $order = [];
4087: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4088: $usertypes = $domdefaults{'inststatustypes'};
4089: $order = $domdefaults{'inststatusguest'};
4090: }
4091: if (ref($order) eq 'ARRAY') {
4092: push(@{$order},'default');
4093: if (@{$order} > 1) {
4094: $usertypes->{'default'} = &mt('Other users');
4095: $additional .= '<table><tr>';
4096: foreach my $status (@{$order}) {
4097: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4098: }
4099: $additional .= '</tr><tr>';
4100: foreach my $status (@{$order}) {
4101: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4102: }
1.160.6.40 raeburn 4103: $additional .= '</tr></table>';
1.160.6.34 raeburn 4104: } else {
1.160.6.40 raeburn 4105: $usertypes->{'default'} = &mt('All users');
4106: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4107: }
4108: }
1.160.6.40 raeburn 4109: $additional .= '</div>'."\n";
4110:
4111: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4112: \%choices,$itemcount,$onclick,$additional);
4113: $$rowtotal += $itemcount;
4114: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4115: $$rowtotal ++;
1.160.6.35 raeburn 4116: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4117: $numinrow = 1;
1.160.6.40 raeburn 4118: if (ref($order) eq 'ARRAY') {
4119: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4120: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4121: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4122: $$rowtotal ++;
4123: }
4124: }
1.160.6.34 raeburn 4125: my ($emailrules,$emailruleorder) =
4126: &Apache::lonnet::inst_userrules($dom,'email');
4127: if (ref($emailrules) eq 'HASH') {
4128: if (keys(%{$emailrules}) > 0) {
4129: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4130: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4131: $$rowtotal ++;
4132: }
4133: }
1.160.6.35 raeburn 4134: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4135: }
4136: return $datatable;
4137: }
4138:
1.160.6.40 raeburn 4139: sub email_as_username {
4140: my ($rowtotal,$processing,$type) = @_;
4141: my %choices =
4142: &Apache::lonlocal::texthash (
4143: automatic => 'Automatic approval',
4144: approval => 'Queued for approval',
4145: );
4146: my $output;
4147: foreach my $option ('automatic','approval') {
4148: my $checked;
4149: if (ref($processing) eq 'HASH') {
4150: if ($type eq '') {
4151: if (!exists($processing->{'default'})) {
4152: if ($option eq 'automatic') {
4153: $checked = ' checked="checked"';
4154: }
4155: } else {
4156: if ($processing->{'default'} eq $option) {
4157: $checked = ' checked="checked"';
4158: }
4159: }
4160: } else {
4161: if (!exists($processing->{$type})) {
4162: if ($option eq 'automatic') {
4163: $checked = ' checked="checked"';
4164: }
4165: } else {
4166: if ($processing->{$type} eq $option) {
4167: $checked = ' checked="checked"';
4168: }
4169: }
4170: }
4171: } elsif ($option eq 'automatic') {
4172: $checked = ' checked="checked"';
4173: }
4174: my $name = 'cancreate_emailprocess';
4175: if (($type ne '') && ($type ne 'default')) {
4176: $name .= '_'.$type;
4177: }
4178: $output .= '<span class="LC_nobreak"><label>'.
4179: '<input type="radio" name="'.$name.'"'.
4180: $checked.' value="'.$option.'" />'.
4181: $choices{$option}.'</label></span>';
4182: if ($type eq '') {
4183: $output .= ' ';
4184: } else {
4185: $output .= '<br />';
4186: }
4187: }
4188: $$rowtotal ++;
4189: return $output;
4190: }
4191:
1.160.6.5 raeburn 4192: sub captcha_choice {
4193: my ($context,$settings,$itemcount) = @_;
4194: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4195: my %lt = &captcha_phrases();
4196: $keyentry = 'hidden';
4197: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4198: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4199: } elsif ($context eq 'login') {
4200: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4201: }
4202: if (ref($settings) eq 'HASH') {
4203: if ($settings->{'captcha'}) {
4204: $checked{$settings->{'captcha'}} = ' checked="checked"';
4205: } else {
4206: $checked{'original'} = ' checked="checked"';
4207: }
4208: if ($settings->{'captcha'} eq 'recaptcha') {
4209: $pubtext = $lt{'pub'};
4210: $privtext = $lt{'priv'};
4211: $keyentry = 'text';
4212: }
4213: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4214: $currpub = $settings->{'recaptchakeys'}{'public'};
4215: $currpriv = $settings->{'recaptchakeys'}{'private'};
4216: }
4217: } else {
4218: $checked{'original'} = ' checked="checked"';
4219: }
4220: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4221: my $output = '<tr'.$css_class.'>'.
4222: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4223: '<table><tr><td>'."\n";
4224: foreach my $option ('original','recaptcha','notused') {
4225: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4226: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4227: $lt{$option}.'</label></span>';
4228: unless ($option eq 'notused') {
4229: $output .= (' 'x2)."\n";
4230: }
4231: }
4232: #
4233: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4234: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4235: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4236: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4237: #
4238: $output .= '</td></tr>'."\n".
4239: '<tr><td>'."\n".
4240: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4241: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4242: $currpub.'" size="40" /></span><br />'."\n".
4243: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4244: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4245: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4246: '</td></tr>';
4247: return $output;
4248: }
4249:
1.32 raeburn 4250: sub user_formats_row {
4251: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4252: my $output;
4253: my %text = (
4254: 'username' => 'new usernames',
4255: 'id' => 'IDs',
1.45 raeburn 4256: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4257: );
4258: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4259: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4260: '<td><span class="LC_nobreak">';
4261: if ($type eq 'email') {
4262: $output .= &mt("Formats disallowed for $text{$type}: ");
4263: } else {
4264: $output .= &mt("Format rules to check for $text{$type}: ");
4265: }
4266: $output .= '</span></td>'.
4267: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4268: my $rem;
4269: if (ref($ruleorder) eq 'ARRAY') {
4270: for (my $i=0; $i<@{$ruleorder}; $i++) {
4271: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4272: my $rem = $i%($numinrow);
4273: if ($rem == 0) {
4274: if ($i > 0) {
4275: $output .= '</tr>';
4276: }
4277: $output .= '<tr>';
4278: }
4279: my $check = ' ';
1.39 raeburn 4280: if (ref($settings) eq 'HASH') {
4281: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4282: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4283: $check = ' checked="checked" ';
4284: }
1.27 raeburn 4285: }
4286: }
4287: $output .= '<td class="LC_left_item">'.
4288: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4289: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4290: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4291: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4292: }
4293: }
4294: $rem = @{$ruleorder}%($numinrow);
4295: }
4296: my $colsleft = $numinrow - $rem;
4297: if ($colsleft > 1 ) {
4298: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4299: ' </td>';
4300: } elsif ($colsleft == 1) {
4301: $output .= '<td class="LC_left_item"> </td>';
4302: }
4303: $output .= '</tr></table></td></tr>';
4304: return $output;
4305: }
4306:
1.34 raeburn 4307: sub usercreation_types {
4308: my %lt = &Apache::lonlocal::texthash (
4309: author => 'When adding a co-author',
4310: course => 'When adding a user to a course',
1.100 raeburn 4311: requestcrs => 'When requesting a course',
1.34 raeburn 4312: any => 'Any',
4313: official => 'Institutional only ',
4314: unofficial => 'Non-institutional only',
4315: none => 'None',
4316: );
4317: return %lt;
1.48 raeburn 4318: }
1.34 raeburn 4319:
1.160.6.34 raeburn 4320: sub selfcreation_types {
4321: my %lt = &Apache::lonlocal::texthash (
4322: selfcreate => 'User creates own account',
4323: any => 'Any',
4324: official => 'Institutional only ',
4325: unofficial => 'Non-institutional only',
4326: email => 'E-mail address',
4327: login => 'Institutional Login',
4328: sso => 'SSO',
4329: );
4330: }
4331:
1.28 raeburn 4332: sub authtype_names {
4333: my %lt = &Apache::lonlocal::texthash(
4334: int => 'Internal',
4335: krb4 => 'Kerberos 4',
4336: krb5 => 'Kerberos 5',
4337: loc => 'Local',
4338: );
4339: return %lt;
4340: }
4341:
4342: sub context_names {
4343: my %context_title = &Apache::lonlocal::texthash(
4344: author => 'Creating users when an Author',
4345: course => 'Creating users when in a course',
4346: domain => 'Creating users when a Domain Coordinator',
4347: );
4348: return %context_title;
4349: }
4350:
1.33 raeburn 4351: sub print_usermodification {
4352: my ($position,$dom,$settings,$rowtotal) = @_;
4353: my $numinrow = 4;
4354: my ($context,$datatable,$rowcount);
4355: if ($position eq 'top') {
4356: $rowcount = 0;
4357: $context = 'author';
4358: foreach my $role ('ca','aa') {
4359: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4360: $numinrow,$rowcount);
4361: $$rowtotal ++;
4362: $rowcount ++;
4363: }
1.160.6.37 raeburn 4364: } elsif ($position eq 'bottom') {
1.33 raeburn 4365: $context = 'course';
4366: $rowcount = 0;
4367: foreach my $role ('st','ep','ta','in','cr') {
4368: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4369: $numinrow,$rowcount);
4370: $$rowtotal ++;
4371: $rowcount ++;
4372: }
4373: }
4374: return $datatable;
4375: }
4376:
1.43 raeburn 4377: sub print_defaults {
1.160.6.40 raeburn 4378: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4379: my $rownum = 0;
4380: my ($datatable,$css_class);
1.160.6.40 raeburn 4381: if ($position eq 'top') {
4382: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4383: 'datelocale_def','portal_def');
4384: my %defaults;
4385: if (ref($settings) eq 'HASH') {
4386: %defaults = %{$settings};
1.43 raeburn 4387: } else {
1.160.6.40 raeburn 4388: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4389: foreach my $item (@items) {
4390: $defaults{$item} = $domdefaults{$item};
4391: }
1.43 raeburn 4392: }
1.160.6.40 raeburn 4393: my $titles = &defaults_titles($dom);
4394: foreach my $item (@items) {
4395: if ($rownum%2) {
4396: $css_class = '';
4397: } else {
4398: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4399: }
1.160.6.40 raeburn 4400: $datatable .= '<tr'.$css_class.'>'.
4401: '<td><span class="LC_nobreak">'.$titles->{$item}.
4402: '</span></td><td class="LC_right_item" colspan="3">';
4403: if ($item eq 'auth_def') {
4404: my @authtypes = ('internal','krb4','krb5','localauth');
4405: my %shortauth = (
4406: internal => 'int',
4407: krb4 => 'krb4',
4408: krb5 => 'krb5',
4409: localauth => 'loc'
4410: );
4411: my %authnames = &authtype_names();
4412: foreach my $auth (@authtypes) {
4413: my $checked = ' ';
4414: if ($defaults{$item} eq $auth) {
4415: $checked = ' checked="checked" ';
4416: }
4417: $datatable .= '<label><input type="radio" name="'.$item.
4418: '" value="'.$auth.'"'.$checked.'/>'.
4419: $authnames{$shortauth{$auth}}.'</label> ';
4420: }
4421: } elsif ($item eq 'timezone_def') {
4422: my $includeempty = 1;
4423: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4424: } elsif ($item eq 'datelocale_def') {
4425: my $includeempty = 1;
4426: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4427: } elsif ($item eq 'lang_def') {
4428: my %langchoices = &get_languages_hash();
4429: $langchoices{''} = 'No language preference';
4430: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4431: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4432: \%langchoices);
4433: } else {
4434: my $size;
4435: if ($item eq 'portal_def') {
4436: $size = ' size="25"';
4437: }
4438: $datatable .= '<input type="text" name="'.$item.'" value="'.
4439: $defaults{$item}.'"'.$size.' />';
4440: }
4441: $datatable .= '</td></tr>';
4442: $rownum ++;
4443: }
4444: } else {
4445: my (%defaults);
4446: if (ref($settings) eq 'HASH') {
4447: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4448: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4449: my $maxnum = @{$settings->{'inststatusorder'}};
4450: for (my $i=0; $i<$maxnum; $i++) {
4451: $css_class = $rownum%2?' class="LC_odd_row"':'';
4452: my $item = $settings->{'inststatusorder'}->[$i];
4453: my $title = $settings->{'inststatustypes'}->{$item};
4454: my $guestok;
4455: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4456: $guestok = 1;
4457: }
4458: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4459: $datatable .= '<tr'.$css_class.'>'.
4460: '<td><span class="LC_nobreak">'.
4461: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4462: for (my $k=0; $k<=$maxnum; $k++) {
4463: my $vpos = $k+1;
4464: my $selstr;
4465: if ($k == $i) {
4466: $selstr = ' selected="selected" ';
4467: }
4468: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4469: }
4470: my ($checkedon,$checkedoff);
4471: $checkedoff = ' checked="checked"';
4472: if ($guestok) {
4473: $checkedon = $checkedoff;
4474: $checkedoff = '';
4475: }
4476: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4477: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4478: &mt('delete').'</span></td>'.
4479: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4480: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4481: '</span></td>'.
4482: '<td class="LC_right_item"><span class="LC_nobreak">'.
4483: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4484: &mt('Yes').'</label>'.(' 'x2).
4485: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4486: &mt('No').'</label></span></td></tr>';
4487: }
4488: $css_class = $rownum%2?' class="LC_odd_row"':'';
4489: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4490: $datatable .= '<tr '.$css_class.'>'.
4491: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4492: for (my $k=0; $k<=$maxnum; $k++) {
4493: my $vpos = $k+1;
4494: my $selstr;
4495: if ($k == $maxnum) {
4496: $selstr = ' selected="selected" ';
4497: }
4498: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4499: }
4500: $datatable .= '</select> '.&mt('Internal ID:').
4501: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4502: ' '.&mt('(new)').
4503: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4504: &mt('Name displayed:').
4505: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4506: '<td class="LC_right_item"><span class="LC_nobreak">'.
4507: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4508: &mt('Yes').'</label>'.(' 'x2).
4509: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4510: &mt('No').'</label></span></td></tr>';
4511: '</tr>'."\n";
4512: $rownum ++;
1.141 raeburn 4513: }
1.43 raeburn 4514: }
4515: }
4516: $$rowtotal += $rownum;
4517: return $datatable;
4518: }
4519:
1.160.6.5 raeburn 4520: sub get_languages_hash {
4521: my %langchoices;
4522: foreach my $id (&Apache::loncommon::languageids()) {
4523: my $code = &Apache::loncommon::supportedlanguagecode($id);
4524: if ($code ne '') {
4525: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4526: }
4527: }
4528: return %langchoices;
4529: }
4530:
1.43 raeburn 4531: sub defaults_titles {
1.141 raeburn 4532: my ($dom) = @_;
1.43 raeburn 4533: my %titles = &Apache::lonlocal::texthash (
4534: 'auth_def' => 'Default authentication type',
4535: 'auth_arg_def' => 'Default authentication argument',
4536: 'lang_def' => 'Default language',
1.54 raeburn 4537: 'timezone_def' => 'Default timezone',
1.68 raeburn 4538: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4539: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4540: );
1.141 raeburn 4541: if ($dom) {
4542: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4543: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4544: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4545: $protocol = 'http' if ($protocol ne 'https');
4546: if ($uint_dom) {
4547: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4548: $uint_dom);
4549: }
4550: }
1.43 raeburn 4551: return (\%titles);
4552: }
4553:
1.46 raeburn 4554: sub print_scantronformat {
4555: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4556: my $itemcount = 1;
1.60 raeburn 4557: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4558: %confhash);
1.46 raeburn 4559: my $switchserver = &check_switchserver($dom,$confname);
4560: my %lt = &Apache::lonlocal::texthash (
1.95 www 4561: default => 'Default bubblesheet format file error',
4562: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4563: );
4564: my %scantronfiles = (
4565: default => 'default.tab',
4566: custom => 'custom.tab',
4567: );
4568: foreach my $key (keys(%scantronfiles)) {
4569: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4570: .$scantronfiles{$key};
4571: }
4572: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4573: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4574: if (!$switchserver) {
4575: my $servadm = $r->dir_config('lonAdmEMail');
4576: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4577: if ($configuserok eq 'ok') {
4578: if ($author_ok eq 'ok') {
4579: my %legacyfile = (
4580: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4581: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4582: );
4583: my %md5chk;
4584: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4585: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4586: chomp($md5chk{$type});
1.46 raeburn 4587: }
4588: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4589: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4590: ($scantronurls{$type},my $error) =
1.46 raeburn 4591: &legacy_scantronformat($r,$dom,$confname,
4592: $type,$legacyfile{$type},
4593: $scantronurls{$type},
4594: $scantronfiles{$type});
1.60 raeburn 4595: if ($error ne '') {
4596: $error{$type} = $error;
4597: }
4598: }
4599: if (keys(%error) == 0) {
4600: $is_custom = 1;
4601: $confhash{'scantron'}{'scantronformat'} =
4602: $scantronurls{'custom'};
4603: my $putresult =
4604: &Apache::lonnet::put_dom('configuration',
4605: \%confhash,$dom);
4606: if ($putresult ne 'ok') {
4607: $error{'custom'} =
4608: '<span class="LC_error">'.
4609: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4610: }
1.46 raeburn 4611: }
4612: } else {
1.60 raeburn 4613: ($scantronurls{'default'},my $error) =
1.46 raeburn 4614: &legacy_scantronformat($r,$dom,$confname,
4615: 'default',$legacyfile{'default'},
4616: $scantronurls{'default'},
4617: $scantronfiles{'default'});
1.60 raeburn 4618: if ($error eq '') {
4619: $confhash{'scantron'}{'scantronformat'} = '';
4620: my $putresult =
4621: &Apache::lonnet::put_dom('configuration',
4622: \%confhash,$dom);
4623: if ($putresult ne 'ok') {
4624: $error{'default'} =
4625: '<span class="LC_error">'.
4626: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4627: }
4628: } else {
4629: $error{'default'} = $error;
4630: }
1.46 raeburn 4631: }
4632: }
4633: }
4634: } else {
1.95 www 4635: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4636: }
4637: }
4638: if (ref($settings) eq 'HASH') {
4639: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4640: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4641: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4642: $scantronurl = '';
4643: } else {
4644: $scantronurl = $settings->{'scantronformat'};
4645: }
4646: $is_custom = 1;
4647: } else {
4648: $scantronurl = $scantronurls{'default'};
4649: }
4650: } else {
1.60 raeburn 4651: if ($is_custom) {
4652: $scantronurl = $scantronurls{'custom'};
4653: } else {
4654: $scantronurl = $scantronurls{'default'};
4655: }
1.46 raeburn 4656: }
4657: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4658: $datatable .= '<tr'.$css_class.'>';
4659: if (!$is_custom) {
1.65 raeburn 4660: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4661: '<span class="LC_nobreak">';
1.46 raeburn 4662: if ($scantronurl) {
1.160.6.21 raeburn 4663: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4664: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4665: } else {
4666: $datatable = &mt('File unavailable for display');
4667: }
1.65 raeburn 4668: $datatable .= '</span></td>';
1.60 raeburn 4669: if (keys(%error) == 0) {
4670: $datatable .= '<td valign="bottom">';
4671: if (!$switchserver) {
4672: $datatable .= &mt('Upload:').'<br />';
4673: }
4674: } else {
4675: my $errorstr;
4676: foreach my $key (sort(keys(%error))) {
4677: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4678: }
4679: $datatable .= '<td>'.$errorstr;
4680: }
1.46 raeburn 4681: } else {
4682: if (keys(%error) > 0) {
4683: my $errorstr;
4684: foreach my $key (sort(keys(%error))) {
4685: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4686: }
1.60 raeburn 4687: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4688: } elsif ($scantronurl) {
1.160.6.26 raeburn 4689: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4690: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4691: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4692: $link.
4693: '<label><input type="checkbox" name="scantronformat_del"'.
4694: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4695: '<td><span class="LC_nobreak"> '.
4696: &mt('Replace:').'</span><br />';
1.46 raeburn 4697: }
4698: }
4699: if (keys(%error) == 0) {
4700: if ($switchserver) {
4701: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4702: } else {
1.65 raeburn 4703: $datatable .='<span class="LC_nobreak"> '.
4704: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4705: }
4706: }
4707: $datatable .= '</td></tr>';
4708: $$rowtotal ++;
4709: return $datatable;
4710: }
4711:
4712: sub legacy_scantronformat {
4713: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4714: my ($url,$error);
4715: my @statinfo = &Apache::lonnet::stat_file($newurl);
4716: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4717: (my $result,$url) =
4718: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4719: '','',$newfile);
4720: if ($result ne 'ok') {
1.130 raeburn 4721: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4722: }
4723: }
4724: return ($url,$error);
4725: }
1.43 raeburn 4726:
1.49 raeburn 4727: sub print_coursecategories {
1.57 raeburn 4728: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4729: my $datatable;
4730: if ($position eq 'top') {
4731: my $toggle_cats_crs = ' ';
4732: my $toggle_cats_dom = ' checked="checked" ';
4733: my $can_cat_crs = ' ';
4734: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4735: my $toggle_catscomm_comm = ' ';
4736: my $toggle_catscomm_dom = ' checked="checked" ';
4737: my $can_catcomm_comm = ' ';
4738: my $can_catcomm_dom = ' checked="checked" ';
4739:
1.57 raeburn 4740: if (ref($settings) eq 'HASH') {
4741: if ($settings->{'togglecats'} eq 'crs') {
4742: $toggle_cats_crs = $toggle_cats_dom;
4743: $toggle_cats_dom = ' ';
4744: }
4745: if ($settings->{'categorize'} eq 'crs') {
4746: $can_cat_crs = $can_cat_dom;
4747: $can_cat_dom = ' ';
4748: }
1.120 raeburn 4749: if ($settings->{'togglecatscomm'} eq 'comm') {
4750: $toggle_catscomm_comm = $toggle_catscomm_dom;
4751: $toggle_catscomm_dom = ' ';
4752: }
4753: if ($settings->{'categorizecomm'} eq 'comm') {
4754: $can_catcomm_comm = $can_catcomm_dom;
4755: $can_catcomm_dom = ' ';
4756: }
1.57 raeburn 4757: }
4758: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4759: togglecats => 'Show/Hide a course in catalog',
4760: togglecatscomm => 'Show/Hide a community in catalog',
4761: categorize => 'Assign a category to a course',
4762: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4763: );
4764: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4765: dom => 'Set in Domain',
4766: crs => 'Set in Course',
4767: comm => 'Set in Community',
1.57 raeburn 4768: );
4769: $datatable = '<tr class="LC_odd_row">'.
4770: '<td>'.$title{'togglecats'}.'</td>'.
4771: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4772: '<input type="radio" name="togglecats"'.
4773: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4774: '<label><input type="radio" name="togglecats"'.
4775: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4776: '</tr><tr>'.
4777: '<td>'.$title{'categorize'}.'</td>'.
4778: '<td class="LC_right_item"><span class="LC_nobreak">'.
4779: '<label><input type="radio" name="categorize"'.
4780: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4781: '<label><input type="radio" name="categorize"'.
4782: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4783: '</tr><tr class="LC_odd_row">'.
4784: '<td>'.$title{'togglecatscomm'}.'</td>'.
4785: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4786: '<input type="radio" name="togglecatscomm"'.
4787: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4788: '<label><input type="radio" name="togglecatscomm"'.
4789: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4790: '</tr><tr>'.
4791: '<td>'.$title{'categorizecomm'}.'</td>'.
4792: '<td class="LC_right_item"><span class="LC_nobreak">'.
4793: '<label><input type="radio" name="categorizecomm"'.
4794: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4795: '<label><input type="radio" name="categorizecomm"'.
4796: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4797: '</tr>';
1.120 raeburn 4798: $$rowtotal += 4;
1.57 raeburn 4799: } else {
4800: my $css_class;
4801: my $itemcount = 1;
4802: my $cathash;
4803: if (ref($settings) eq 'HASH') {
4804: $cathash = $settings->{'cats'};
4805: }
4806: if (ref($cathash) eq 'HASH') {
4807: my (@cats,@trails,%allitems,%idx,@jsarray);
4808: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4809: \%allitems,\%idx,\@jsarray);
4810: my $maxdepth = scalar(@cats);
4811: my $colattrib = '';
4812: if ($maxdepth > 2) {
4813: $colattrib = ' colspan="2" ';
4814: }
4815: my @path;
4816: if (@cats > 0) {
4817: if (ref($cats[0]) eq 'ARRAY') {
4818: my $numtop = @{$cats[0]};
4819: my $maxnum = $numtop;
1.120 raeburn 4820: my %default_names = (
4821: instcode => &mt('Official courses'),
4822: communities => &mt('Communities'),
4823: );
4824:
4825: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4826: ($cathash->{'instcode::0'} eq '') ||
4827: (!grep(/^communities$/,@{$cats[0]})) ||
4828: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4829: $maxnum ++;
4830: }
4831: my $lastidx;
4832: for (my $i=0; $i<$numtop; $i++) {
4833: my $parent = $cats[0][$i];
4834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4835: my $item = &escape($parent).'::0';
4836: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4837: $lastidx = $idx{$item};
4838: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4839: .'<select name="'.$item.'"'.$chgstr.'>';
4840: for (my $k=0; $k<=$maxnum; $k++) {
4841: my $vpos = $k+1;
4842: my $selstr;
4843: if ($k == $i) {
4844: $selstr = ' selected="selected" ';
4845: }
4846: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4847: }
1.160.6.29 raeburn 4848: $datatable .= '</select></span></td><td>';
1.120 raeburn 4849: if ($parent eq 'instcode' || $parent eq 'communities') {
4850: $datatable .= '<span class="LC_nobreak">'
4851: .$default_names{$parent}.'</span>';
4852: if ($parent eq 'instcode') {
4853: $datatable .= '<br /><span class="LC_nobreak">('
4854: .&mt('with institutional codes')
4855: .')</span></td><td'.$colattrib.'>';
4856: } else {
4857: $datatable .= '<table><tr><td>';
4858: }
4859: $datatable .= '<span class="LC_nobreak">'
4860: .'<label><input type="radio" name="'
4861: .$parent.'" value="1" checked="checked" />'
4862: .&mt('Display').'</label>';
4863: if ($parent eq 'instcode') {
4864: $datatable .= ' ';
4865: } else {
4866: $datatable .= '</span></td></tr><tr><td>'
4867: .'<span class="LC_nobreak">';
4868: }
4869: $datatable .= '<label><input type="radio" name="'
4870: .$parent.'" value="0" />'
4871: .&mt('Do not display').'</label></span>';
4872: if ($parent eq 'communities') {
4873: $datatable .= '</td></tr></table>';
4874: }
4875: $datatable .= '</td>';
1.57 raeburn 4876: } else {
4877: $datatable .= $parent
1.160.6.29 raeburn 4878: .' <span class="LC_nobreak"><label>'
4879: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4880: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4881: }
4882: my $depth = 1;
4883: push(@path,$parent);
4884: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4885: pop(@path);
4886: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4887: $itemcount ++;
4888: }
1.48 raeburn 4889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4890: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4891: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4892: for (my $k=0; $k<=$maxnum; $k++) {
4893: my $vpos = $k+1;
4894: my $selstr;
1.57 raeburn 4895: if ($k == $numtop) {
1.48 raeburn 4896: $selstr = ' selected="selected" ';
4897: }
4898: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4899: }
1.59 bisitz 4900: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4901: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4902: .'</tr>'."\n";
1.48 raeburn 4903: $itemcount ++;
1.120 raeburn 4904: foreach my $default ('instcode','communities') {
4905: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4906: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4907: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4908: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4909: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4910: for (my $k=0; $k<=$maxnum; $k++) {
4911: my $vpos = $k+1;
4912: my $selstr;
4913: if ($k == $maxnum) {
4914: $selstr = ' selected="selected" ';
4915: }
4916: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4917: }
1.120 raeburn 4918: $datatable .= '</select></span></td>'.
4919: '<td><span class="LC_nobreak">'.
4920: $default_names{$default}.'</span>';
4921: if ($default eq 'instcode') {
4922: $datatable .= '<br /><span class="LC_nobreak">('
4923: .&mt('with institutional codes').')</span>';
4924: }
4925: $datatable .= '</td>'
4926: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4927: .&mt('Display').'</label> '
4928: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4929: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4930: }
4931: }
4932: }
1.57 raeburn 4933: } else {
4934: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4935: }
4936: } else {
1.57 raeburn 4937: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4938: .&initialize_categories($itemcount);
1.48 raeburn 4939: }
1.57 raeburn 4940: $$rowtotal += $itemcount;
1.48 raeburn 4941: }
4942: return $datatable;
4943: }
4944:
1.69 raeburn 4945: sub print_serverstatuses {
4946: my ($dom,$settings,$rowtotal) = @_;
4947: my $datatable;
4948: my @pages = &serverstatus_pages();
4949: my (%namedaccess,%machineaccess);
4950: foreach my $type (@pages) {
4951: $namedaccess{$type} = '';
4952: $machineaccess{$type}= '';
4953: }
4954: if (ref($settings) eq 'HASH') {
4955: foreach my $type (@pages) {
4956: if (exists($settings->{$type})) {
4957: if (ref($settings->{$type}) eq 'HASH') {
4958: foreach my $key (keys(%{$settings->{$type}})) {
4959: if ($key eq 'namedusers') {
4960: $namedaccess{$type} = $settings->{$type}->{$key};
4961: } elsif ($key eq 'machines') {
4962: $machineaccess{$type} = $settings->{$type}->{$key};
4963: }
4964: }
4965: }
4966: }
4967: }
4968: }
1.81 raeburn 4969: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4970: my $rownum = 0;
4971: my $css_class;
4972: foreach my $type (@pages) {
4973: $rownum ++;
4974: $css_class = $rownum%2?' class="LC_odd_row"':'';
4975: $datatable .= '<tr'.$css_class.'>'.
4976: '<td><span class="LC_nobreak">'.
4977: $titles->{$type}.'</span></td>'.
4978: '<td class="LC_left_item">'.
4979: '<input type="text" name="'.$type.'_namedusers" '.
4980: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4981: '<td class="LC_right_item">'.
4982: '<span class="LC_nobreak">'.
4983: '<input type="text" name="'.$type.'_machines" '.
4984: 'value="'.$machineaccess{$type}.'" size="10" />'.
4985: '</td></tr>'."\n";
4986: }
4987: $$rowtotal += $rownum;
4988: return $datatable;
4989: }
4990:
4991: sub serverstatus_pages {
4992: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 4993: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 4994: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 4995: 'uniquecodes','diskusage');
1.69 raeburn 4996: }
4997:
1.160.6.40 raeburn 4998: sub defaults_javascript {
4999: my ($settings) = @_;
5000: my ($output,$jstext);
5001: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5002: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5003: if ($maxnum eq '') {
5004: $maxnum = 0;
5005: }
5006: $maxnum ++;
5007: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5008: return <<"ENDSCRIPT";
5009: <script type="text/javascript">
5010: // <![CDATA[
5011: function reorderTypes(form,caller) {
5012: var changedVal;
5013: $jstext
5014: var newpos = 'addinststatus_pos';
5015: var current = new Array;
5016: var maxh = $maxnum;
5017: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5018: var oldVal;
5019: if (caller == newpos) {
5020: changedVal = newitemVal;
5021: } else {
5022: var curritem = 'inststatus_pos_'+caller;
5023: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5024: current[newitemVal] = newpos;
5025: }
5026: for (var i=0; i<inststatuses.length; i++) {
5027: if (inststatuses[i] != caller) {
5028: var elementName = 'inststatus_pos_'+inststatuses[i];
5029: if (form.elements[elementName]) {
5030: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5031: current[currVal] = elementName;
5032: }
5033: }
5034: }
5035: for (var j=0; j<maxh; j++) {
5036: if (current[j] == undefined) {
5037: oldVal = j;
5038: }
5039: }
5040: if (oldVal < changedVal) {
5041: for (var k=oldVal+1; k<=changedVal ; k++) {
5042: var elementName = current[k];
5043: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5044: }
5045: } else {
5046: for (var k=changedVal; k<oldVal; k++) {
5047: var elementName = current[k];
5048: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5049: }
5050: }
5051: return;
5052: }
5053:
5054: // ]]>
5055: </script>
5056:
5057: ENDSCRIPT
5058: }
5059: }
5060:
1.49 raeburn 5061: sub coursecategories_javascript {
5062: my ($settings) = @_;
1.57 raeburn 5063: my ($output,$jstext,$cathash);
1.49 raeburn 5064: if (ref($settings) eq 'HASH') {
1.57 raeburn 5065: $cathash = $settings->{'cats'};
5066: }
5067: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5068: my (@cats,@jsarray,%idx);
1.57 raeburn 5069: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5070: if (@jsarray > 0) {
5071: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5072: for (my $i=0; $i<@jsarray; $i++) {
5073: if (ref($jsarray[$i]) eq 'ARRAY') {
5074: my $catstr = join('","',@{$jsarray[$i]});
5075: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5076: }
5077: }
5078: }
5079: } else {
5080: $jstext = ' var categories = Array(1);'."\n".
5081: ' categories[0] = Array("instcode_pos");'."\n";
5082: }
1.120 raeburn 5083: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
5084: my $communities_reserved = &mt('The name: "communities" is a reserved category');
5085: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 5086: $output = <<"ENDSCRIPT";
5087: <script type="text/javascript">
1.109 raeburn 5088: // <![CDATA[
1.49 raeburn 5089: function reorderCats(form,parent,item,idx) {
5090: var changedVal;
5091: $jstext
5092: var newpos = 'addcategory_pos';
5093: if (parent == '') {
5094: var has_instcode = 0;
5095: var maxtop = categories[idx].length;
5096: for (var j=0; j<maxtop; j++) {
5097: if (categories[idx][j] == 'instcode::0') {
5098: has_instcode == 1;
5099: }
5100: }
5101: if (has_instcode == 0) {
5102: categories[idx][maxtop] = 'instcode_pos';
5103: }
5104: } else {
5105: newpos += '_'+parent;
5106: }
5107: var maxh = 1 + categories[idx].length;
5108: var current = new Array;
5109: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5110: if (item == newpos) {
5111: changedVal = newitemVal;
5112: } else {
5113: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5114: current[newitemVal] = newpos;
5115: }
5116: for (var i=0; i<categories[idx].length; i++) {
5117: var elementName = categories[idx][i];
5118: if (elementName != item) {
5119: if (form.elements[elementName]) {
5120: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5121: current[currVal] = elementName;
5122: }
5123: }
5124: }
5125: var oldVal;
5126: for (var j=0; j<maxh; j++) {
5127: if (current[j] == undefined) {
5128: oldVal = j;
5129: }
5130: }
5131: if (oldVal < changedVal) {
5132: for (var k=oldVal+1; k<=changedVal ; k++) {
5133: var elementName = current[k];
5134: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5135: }
5136: } else {
5137: for (var k=changedVal; k<oldVal; k++) {
5138: var elementName = current[k];
5139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5140: }
5141: }
5142: return;
5143: }
1.120 raeburn 5144:
5145: function categoryCheck(form) {
5146: if (form.elements['addcategory_name'].value == 'instcode') {
5147: alert('$instcode_reserved\\n$choose_again');
5148: return false;
5149: }
5150: if (form.elements['addcategory_name'].value == 'communities') {
5151: alert('$communities_reserved\\n$choose_again');
5152: return false;
5153: }
5154: return true;
5155: }
5156:
1.109 raeburn 5157: // ]]>
1.49 raeburn 5158: </script>
5159:
5160: ENDSCRIPT
5161: return $output;
5162: }
5163:
1.48 raeburn 5164: sub initialize_categories {
5165: my ($itemcount) = @_;
1.120 raeburn 5166: my ($datatable,$css_class,$chgstr);
5167: my %default_names = (
5168: instcode => 'Official courses (with institutional codes)',
5169: communities => 'Communities',
5170: );
5171: my $select0 = ' selected="selected"';
5172: my $select1 = '';
5173: foreach my $default ('instcode','communities') {
5174: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5175: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5176: if ($default eq 'communities') {
5177: $select1 = $select0;
5178: $select0 = '';
5179: }
5180: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5181: .'<select name="'.$default.'_pos">'
5182: .'<option value="0"'.$select0.'>1</option>'
5183: .'<option value="1"'.$select1.'>2</option>'
5184: .'<option value="2">3</option></select> '
5185: .$default_names{$default}
5186: .'</span></td><td><span class="LC_nobreak">'
5187: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5188: .&mt('Display').'</label> <label>'
5189: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5190: .'</label></span></td></tr>';
1.120 raeburn 5191: $itemcount ++;
5192: }
1.48 raeburn 5193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5194: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5195: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5196: .'<select name="addcategory_pos"'.$chgstr.'>'
5197: .'<option value="0">1</option>'
5198: .'<option value="1">2</option>'
5199: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5200: .&mt('Add category').'</td><td>'.&mt('Name:')
5201: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5202: return $datatable;
5203: }
5204:
5205: sub build_category_rows {
1.49 raeburn 5206: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5207: my ($text,$name,$item,$chgstr);
1.48 raeburn 5208: if (ref($cats) eq 'ARRAY') {
5209: my $maxdepth = scalar(@{$cats});
5210: if (ref($cats->[$depth]) eq 'HASH') {
5211: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5212: my $numchildren = @{$cats->[$depth]{$parent}};
5213: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5214: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5215: my ($idxnum,$parent_name,$parent_item);
5216: my $higher = $depth - 1;
5217: if ($higher == 0) {
5218: $parent_name = &escape($parent).'::'.$higher;
5219: } else {
5220: if (ref($path) eq 'ARRAY') {
5221: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5222: }
5223: }
5224: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5225: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5226: if ($j < $numchildren) {
1.48 raeburn 5227: $name = $cats->[$depth]{$parent}[$j];
5228: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5229: $idxnum = $idx->{$item};
5230: } else {
5231: $name = $parent_name;
5232: $item = $parent_item;
1.48 raeburn 5233: }
1.49 raeburn 5234: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5235: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5236: for (my $i=0; $i<=$numchildren; $i++) {
5237: my $vpos = $i+1;
5238: my $selstr;
5239: if ($j == $i) {
5240: $selstr = ' selected="selected" ';
5241: }
5242: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5243: }
5244: $text .= '</select> ';
5245: if ($j < $numchildren) {
5246: my $deeper = $depth+1;
5247: $text .= $name.' '
5248: .'<label><input type="checkbox" name="deletecategory" value="'
5249: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5250: if(ref($path) eq 'ARRAY') {
5251: push(@{$path},$name);
1.49 raeburn 5252: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5253: pop(@{$path});
5254: }
5255: } else {
1.59 bisitz 5256: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5257: if ($j == $numchildren) {
5258: $text .= $name;
5259: } else {
5260: $text .= $item;
5261: }
5262: $text .= '" value="" />';
5263: }
5264: $text .= '</td></tr>';
5265: }
5266: $text .= '</table></td>';
5267: } else {
5268: my $higher = $depth-1;
5269: if ($higher == 0) {
5270: $name = &escape($parent).'::'.$higher;
5271: } else {
5272: if (ref($path) eq 'ARRAY') {
5273: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5274: }
5275: }
5276: my $colspan;
5277: if ($parent ne 'instcode') {
5278: $colspan = $maxdepth - $depth - 1;
5279: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5280: }
5281: }
5282: }
5283: }
5284: return $text;
5285: }
5286:
1.33 raeburn 5287: sub modifiable_userdata_row {
1.160.6.35 raeburn 5288: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5289: my ($role,$rolename,$statustype);
5290: $role = $item;
1.160.6.34 raeburn 5291: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5292: if ($item =~ /^emailusername_(.+)$/) {
5293: $statustype = $1;
5294: $role = 'emailusername';
5295: if (ref($usertypes) eq 'HASH') {
5296: if ($usertypes->{$statustype}) {
5297: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5298: } else {
5299: $rolename = &mt('Data provided by user');
5300: }
5301: }
1.160.6.34 raeburn 5302: }
5303: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5304: if (ref($usertypes) eq 'HASH') {
5305: $rolename = $usertypes->{$role};
5306: } else {
5307: $rolename = $role;
5308: }
1.33 raeburn 5309: } else {
1.63 raeburn 5310: if ($role eq 'cr') {
5311: $rolename = &mt('Custom role');
5312: } else {
5313: $rolename = &Apache::lonnet::plaintext($role);
5314: }
1.33 raeburn 5315: }
1.160.6.34 raeburn 5316: my (@fields,%fieldtitles);
5317: if (ref($fieldsref) eq 'ARRAY') {
5318: @fields = @{$fieldsref};
5319: } else {
5320: @fields = ('lastname','firstname','middlename','generation',
5321: 'permanentemail','id');
5322: }
5323: if ((ref($titlesref) eq 'HASH')) {
5324: %fieldtitles = %{$titlesref};
5325: } else {
5326: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5327: }
1.33 raeburn 5328: my $output;
5329: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5330: $output = '<tr '.$css_class.'>'.
5331: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5332: '<td class="LC_left_item" colspan="2"><table>';
5333: my $rem;
5334: my %checks;
5335: if (ref($settings) eq 'HASH') {
5336: if (ref($settings->{$context}) eq 'HASH') {
5337: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5338: my $hashref = $settings->{$context}->{$role};
5339: if ($role eq 'emailusername') {
5340: if ($statustype) {
5341: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5342: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5343: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5344: foreach my $field (@fields) {
5345: if ($hashref->{$field}) {
5346: $checks{$field} = $hashref->{$field};
5347: }
5348: }
5349: }
5350: }
5351: }
5352: } else {
5353: if (ref($hashref) eq 'HASH') {
5354: foreach my $field (@fields) {
5355: if ($hashref->{$field}) {
5356: $checks{$field} = ' checked="checked" ';
5357: }
5358: }
1.33 raeburn 5359: }
5360: }
5361: }
5362: }
5363: }
1.160.6.39 raeburn 5364:
1.33 raeburn 5365: for (my $i=0; $i<@fields; $i++) {
5366: my $rem = $i%($numinrow);
5367: if ($rem == 0) {
5368: if ($i > 0) {
5369: $output .= '</tr>';
5370: }
5371: $output .= '<tr>';
5372: }
5373: my $check = ' ';
1.160.6.35 raeburn 5374: unless ($role eq 'emailusername') {
5375: if (exists($checks{$fields[$i]})) {
5376: $check = $checks{$fields[$i]}
5377: } else {
5378: if ($role eq 'st') {
5379: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5380: $check = ' checked="checked" ';
1.160.6.35 raeburn 5381: }
1.33 raeburn 5382: }
5383: }
5384: }
5385: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5386: '<span class="LC_nobreak">';
5387: if ($role eq 'emailusername') {
5388: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5389: $checks{$fields[$i]} = 'omit';
5390: }
5391: foreach my $option ('required','optional','omit') {
5392: my $checked='';
5393: if ($checks{$fields[$i]} eq $option) {
5394: $checked='checked="checked" ';
5395: }
5396: $output .= '<label>'.
5397: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5398: &mt($option).'</label>'.(' ' x2);
5399: }
5400: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5401: } else {
5402: $output .= '<label>'.
5403: '<input type="checkbox" name="canmodify_'.$role.'" '.
5404: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5405: '</label>';
5406: }
5407: $output .= '</span></td>';
1.33 raeburn 5408: $rem = @fields%($numinrow);
5409: }
5410: my $colsleft = $numinrow - $rem;
5411: if ($colsleft > 1 ) {
5412: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5413: ' </td>';
5414: } elsif ($colsleft == 1) {
5415: $output .= '<td class="LC_left_item"> </td>';
5416: }
5417: $output .= '</tr></table></td></tr>';
5418: return $output;
5419: }
1.28 raeburn 5420:
1.93 raeburn 5421: sub insttypes_row {
1.160.6.34 raeburn 5422: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5423: my %lt = &Apache::lonlocal::texthash (
5424: cansearch => 'Users allowed to search',
5425: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5426: lockablenames => 'User preference to lock name',
1.93 raeburn 5427: );
5428: my $showdom;
5429: if ($context eq 'cansearch') {
5430: $showdom = ' ('.$dom.')';
5431: }
1.160.6.5 raeburn 5432: my $class = 'LC_left_item';
5433: if ($context eq 'statustocreate') {
5434: $class = 'LC_right_item';
5435: }
1.160.6.34 raeburn 5436: my $css_class = ' class="LC_odd_row"';
5437: if ($rownum ne '') {
5438: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5439: }
5440: my $output = '<tr'.$css_class.'>'.
5441: '<td>'.$lt{$context}.$showdom.
5442: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5443: my $rem;
5444: if (ref($types) eq 'ARRAY') {
5445: for (my $i=0; $i<@{$types}; $i++) {
5446: if (defined($usertypes->{$types->[$i]})) {
5447: my $rem = $i%($numinrow);
5448: if ($rem == 0) {
5449: if ($i > 0) {
5450: $output .= '</tr>';
5451: }
5452: $output .= '<tr>';
1.23 raeburn 5453: }
1.26 raeburn 5454: my $check = ' ';
1.99 raeburn 5455: if (ref($settings) eq 'HASH') {
5456: if (ref($settings->{$context}) eq 'ARRAY') {
5457: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5458: $check = ' checked="checked" ';
5459: }
5460: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5461: $check = ' checked="checked" ';
5462: }
1.23 raeburn 5463: }
1.26 raeburn 5464: $output .= '<td class="LC_left_item">'.
5465: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5466: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5467: 'value="'.$types->[$i].'"'.$check.'/>'.
5468: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5469: }
5470: }
1.26 raeburn 5471: $rem = @{$types}%($numinrow);
1.23 raeburn 5472: }
5473: my $colsleft = $numinrow - $rem;
1.131 raeburn 5474: if (($rem == 0) && (@{$types} > 0)) {
5475: $output .= '<tr>';
5476: }
1.23 raeburn 5477: if ($colsleft > 1) {
1.25 raeburn 5478: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5479: } else {
1.25 raeburn 5480: $output .= '<td class="LC_left_item">';
1.23 raeburn 5481: }
5482: my $defcheck = ' ';
1.99 raeburn 5483: if (ref($settings) eq 'HASH') {
5484: if (ref($settings->{$context}) eq 'ARRAY') {
5485: if (grep(/^default$/,@{$settings->{$context}})) {
5486: $defcheck = ' checked="checked" ';
5487: }
5488: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5489: $defcheck = ' checked="checked" ';
5490: }
1.23 raeburn 5491: }
1.25 raeburn 5492: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5493: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5494: 'value="default"'.$defcheck.'/>'.
5495: $othertitle.'</label></span></td>'.
5496: '</tr></table></td></tr>';
5497: return $output;
1.23 raeburn 5498: }
5499:
5500: sub sorted_searchtitles {
5501: my %searchtitles = &Apache::lonlocal::texthash(
5502: 'uname' => 'username',
5503: 'lastname' => 'last name',
5504: 'lastfirst' => 'last name, first name',
5505: );
5506: my @titleorder = ('uname','lastname','lastfirst');
5507: return (\%searchtitles,\@titleorder);
5508: }
5509:
1.25 raeburn 5510: sub sorted_searchtypes {
5511: my %srchtypes_desc = (
5512: exact => 'is exact match',
5513: contains => 'contains ..',
5514: begins => 'begins with ..',
5515: );
5516: my @srchtypeorder = ('exact','begins','contains');
5517: return (\%srchtypes_desc,\@srchtypeorder);
5518: }
5519:
1.3 raeburn 5520: sub usertype_update_row {
5521: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5522: my $datatable;
5523: my $numinrow = 4;
5524: foreach my $type (@{$types}) {
5525: if (defined($usertypes->{$type})) {
5526: $$rownums ++;
5527: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5528: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5529: '</td><td class="LC_left_item"><table>';
5530: for (my $i=0; $i<@{$fields}; $i++) {
5531: my $rem = $i%($numinrow);
5532: if ($rem == 0) {
5533: if ($i > 0) {
5534: $datatable .= '</tr>';
5535: }
5536: $datatable .= '<tr>';
5537: }
5538: my $check = ' ';
1.39 raeburn 5539: if (ref($settings) eq 'HASH') {
5540: if (ref($settings->{'fields'}) eq 'HASH') {
5541: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5542: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5543: $check = ' checked="checked" ';
5544: }
1.3 raeburn 5545: }
5546: }
5547: }
5548:
5549: if ($i == @{$fields}-1) {
5550: my $colsleft = $numinrow - $rem;
5551: if ($colsleft > 1) {
5552: $datatable .= '<td colspan="'.$colsleft.'">';
5553: } else {
5554: $datatable .= '<td>';
5555: }
5556: } else {
5557: $datatable .= '<td>';
5558: }
1.8 raeburn 5559: $datatable .= '<span class="LC_nobreak"><label>'.
5560: '<input type="checkbox" name="updateable_'.$type.
5561: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5562: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5563: }
5564: $datatable .= '</tr></table></td></tr>';
5565: }
5566: }
5567: return $datatable;
1.1 raeburn 5568: }
5569:
5570: sub modify_login {
1.160.6.24 raeburn 5571: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5572: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5573: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5574: %title = ( coursecatalog => 'Display course catalog',
5575: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5576: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5577: newuser => 'Link for visitors to create a user account',
5578: loginheader => 'Log-in box header');
5579: @offon = ('off','on');
1.112 raeburn 5580: if (ref($domconfig{login}) eq 'HASH') {
5581: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5582: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5583: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5584: }
5585: }
5586: }
1.9 raeburn 5587: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5588: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5589: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5590: foreach my $item (@toggles) {
5591: $loginhash{login}{$item} = $env{'form.'.$item};
5592: }
1.41 raeburn 5593: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5594: if (ref($colchanges{'login'}) eq 'HASH') {
5595: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5596: \%loginhash);
5597: }
1.110 raeburn 5598:
1.149 raeburn 5599: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5600: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5601: if (keys(%servers) > 1) {
5602: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5603: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5604: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5605: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5606: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5607: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5608: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5609: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5610: $changes{'loginvia'}{$lonhost} = 1;
5611: } else {
5612: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5613: $changes{'loginvia'}{$lonhost} = 1;
5614: }
5615: } else {
5616: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5617: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5618: $changes{'loginvia'}{$lonhost} = 1;
5619: }
5620: }
5621: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5622: foreach my $item (@loginvia_attribs) {
5623: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5624: }
5625: } else {
5626: foreach my $item (@loginvia_attribs) {
5627: my $new = $env{'form.'.$lonhost.'_'.$item};
5628: if (($item eq 'serverpath') && ($new eq 'custom')) {
5629: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5630: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5631: $new = '/';
5632: }
5633: }
5634: if (($item eq 'custompath') &&
5635: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5636: $new = '';
5637: }
5638: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5639: $changes{'loginvia'}{$lonhost} = 1;
5640: }
5641: if ($item eq 'exempt') {
5642: $new =~ s/^\s+//;
5643: $new =~ s/\s+$//;
5644: my @poss_ips = split(/\s*[,:]\s*/,$new);
5645: my @okips;
5646: foreach my $ip (@poss_ips) {
5647: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5648: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5649: push(@okips,$ip);
5650: }
5651: }
5652: }
5653: if (@okips > 0) {
5654: $new = join(',',@okips);
5655: } else {
5656: $new = '';
5657: }
5658: }
5659: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5660: }
5661: }
1.112 raeburn 5662: } else {
1.128 raeburn 5663: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5664: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5665: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5666: foreach my $item (@loginvia_attribs) {
5667: my $new = $env{'form.'.$lonhost.'_'.$item};
5668: if (($item eq 'serverpath') && ($new eq 'custom')) {
5669: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5670: $new = '/';
5671: }
5672: }
5673: if (($item eq 'custompath') &&
5674: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5675: $new = '';
5676: }
5677: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5678: }
1.110 raeburn 5679: }
5680: }
5681: }
5682: }
1.119 raeburn 5683:
1.160.6.5 raeburn 5684: my $servadm = $r->dir_config('lonAdmEMail');
5685: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5686: if (ref($domconfig{'login'}) eq 'HASH') {
5687: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5688: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5689: if ($lang eq 'nolang') {
5690: push(@currlangs,$lang);
5691: } elsif (defined($langchoices{$lang})) {
5692: push(@currlangs,$lang);
5693: } else {
5694: next;
5695: }
5696: }
5697: }
5698: }
5699: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5700: if (@currlangs > 0) {
5701: foreach my $lang (@currlangs) {
5702: if (grep(/^\Q$lang\E$/,@delurls)) {
5703: $changes{'helpurl'}{$lang} = 1;
5704: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5705: $changes{'helpurl'}{$lang} = 1;
5706: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5707: push(@newlangs,$lang);
5708: } else {
5709: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5710: }
5711: }
5712: }
5713: unless (grep(/^nolang$/,@currlangs)) {
5714: if ($env{'form.loginhelpurl_nolang.filename'}) {
5715: $changes{'helpurl'}{'nolang'} = 1;
5716: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5717: push(@newlangs,'nolang');
5718: }
5719: }
5720: if ($env{'form.loginhelpurl_add_lang'}) {
5721: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5722: ($env{'form.loginhelpurl_add_file.filename'})) {
5723: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5724: $addedfile = $env{'form.loginhelpurl_add_lang'};
5725: }
5726: }
5727: if ((@newlangs > 0) || ($addedfile)) {
5728: my $error;
5729: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5730: if ($configuserok eq 'ok') {
5731: if ($switchserver) {
5732: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5733: } elsif ($author_ok eq 'ok') {
5734: my @allnew = @newlangs;
5735: if ($addedfile ne '') {
5736: push(@allnew,$addedfile);
5737: }
5738: foreach my $lang (@allnew) {
5739: my $formelem = 'loginhelpurl_'.$lang;
5740: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5741: $formelem = 'loginhelpurl_add_file';
5742: }
5743: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5744: "help/$lang",'','',$newfile{$lang});
5745: if ($result eq 'ok') {
5746: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5747: $changes{'helpurl'}{$lang} = 1;
5748: } else {
5749: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5750: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5751: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5752: (!grep(/^\Q$lang\E$/,@delurls))) {
5753:
5754: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5755: }
5756: }
5757: }
5758: } else {
5759: $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);
5760: }
5761: } else {
5762: $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);
5763: }
5764: if ($error) {
5765: &Apache::lonnet::logthis($error);
5766: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5767: }
5768: }
5769: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5770:
5771: my $defaulthelpfile = '/adm/loginproblems.html';
5772: my $defaulttext = &mt('Default in use');
5773:
1.1 raeburn 5774: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5775: $dom);
5776: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5777: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5778: my %defaultchecked = (
5779: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5780: 'helpdesk' => 'on',
1.42 raeburn 5781: 'adminmail' => 'off',
1.43 raeburn 5782: 'newuser' => 'off',
1.42 raeburn 5783: );
1.55 raeburn 5784: if (ref($domconfig{'login'}) eq 'HASH') {
5785: foreach my $item (@toggles) {
5786: if ($defaultchecked{$item} eq 'on') {
5787: if (($domconfig{'login'}{$item} eq '0') &&
5788: ($env{'form.'.$item} eq '1')) {
5789: $changes{$item} = 1;
5790: } elsif (($domconfig{'login'}{$item} eq '' ||
5791: $domconfig{'login'}{$item} eq '1') &&
5792: ($env{'form.'.$item} eq '0')) {
5793: $changes{$item} = 1;
5794: }
5795: } elsif ($defaultchecked{$item} eq 'off') {
5796: if (($domconfig{'login'}{$item} eq '1') &&
5797: ($env{'form.'.$item} eq '0')) {
5798: $changes{$item} = 1;
5799: } elsif (($domconfig{'login'}{$item} eq '' ||
5800: $domconfig{'login'}{$item} eq '0') &&
5801: ($env{'form.'.$item} eq '1')) {
5802: $changes{$item} = 1;
5803: }
1.42 raeburn 5804: }
5805: }
1.41 raeburn 5806: }
1.6 raeburn 5807: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5808: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5809: if (ref($lastactref) eq 'HASH') {
5810: $lastactref->{'domainconfig'} = 1;
5811: }
1.1 raeburn 5812: $resulttext = &mt('Changes made:').'<ul>';
5813: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5814: if ($item eq 'loginvia') {
1.112 raeburn 5815: if (ref($changes{$item}) eq 'HASH') {
5816: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5817: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5818: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5819: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5820: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5821: $protocol = 'http' if ($protocol ne 'https');
5822: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5823:
5824: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5825: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5826: } else {
5827: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5828: }
5829: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5830: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5831: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5832: }
5833: $resulttext .= '</li>';
5834: } else {
5835: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5836: }
1.112 raeburn 5837: } else {
1.128 raeburn 5838: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5839: }
5840: }
1.128 raeburn 5841: $resulttext .= '</ul></li>';
1.112 raeburn 5842: }
1.160.6.5 raeburn 5843: } elsif ($item eq 'helpurl') {
5844: if (ref($changes{$item}) eq 'HASH') {
5845: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5846: if (grep(/^\Q$lang\E$/,@delurls)) {
5847: my ($chg,$link);
5848: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5849: if ($lang eq 'nolang') {
5850: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5851: } else {
5852: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5853: }
5854: $resulttext .= '<li>'.$chg.'</li>';
5855: } else {
5856: my $chg;
5857: if ($lang eq 'nolang') {
5858: $chg = &mt('custom log-in help file for no preferred language');
5859: } else {
5860: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5861: }
5862: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5863: $loginhash{'login'}{'helpurl'}{$lang}.
5864: '?inhibitmenu=yes',$chg,600,500).
5865: '</li>';
5866: }
5867: }
5868: }
5869: } elsif ($item eq 'captcha') {
5870: if (ref($loginhash{'login'}) eq 'HASH') {
5871: my $chgtxt;
5872: if ($loginhash{'login'}{$item} eq 'notused') {
5873: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5874: } else {
5875: my %captchas = &captcha_phrases();
5876: if ($captchas{$loginhash{'login'}{$item}}) {
5877: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5878: } else {
5879: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5880: }
5881: }
5882: $resulttext .= '<li>'.$chgtxt.'</li>';
5883: }
5884: } elsif ($item eq 'recaptchakeys') {
5885: if (ref($loginhash{'login'}) eq 'HASH') {
5886: my ($privkey,$pubkey);
5887: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5888: $pubkey = $loginhash{'login'}{$item}{'public'};
5889: $privkey = $loginhash{'login'}{$item}{'private'};
5890: }
5891: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5892: if (!$pubkey) {
5893: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5894: } else {
5895: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5896: }
5897: if (!$privkey) {
5898: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5899: } else {
5900: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5901: }
5902: $chgtxt .= '</ul>';
5903: $resulttext .= '<li>'.$chgtxt.'</li>';
5904: }
1.41 raeburn 5905: } else {
5906: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5907: }
1.1 raeburn 5908: }
1.6 raeburn 5909: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5910: } else {
5911: $resulttext = &mt('No changes made to log-in page settings');
5912: }
5913: } else {
1.11 albertel 5914: $resulttext = '<span class="LC_error">'.
5915: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5916: }
1.6 raeburn 5917: if ($errors) {
1.9 raeburn 5918: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5919: $errors.'</ul>';
5920: }
5921: return $resulttext;
5922: }
5923:
5924: sub color_font_choices {
5925: my %choices =
5926: &Apache::lonlocal::texthash (
5927: img => "Header",
5928: bgs => "Background colors",
5929: links => "Link colors",
1.55 raeburn 5930: images => "Images",
1.6 raeburn 5931: font => "Font color",
1.160.6.22 raeburn 5932: fontmenu => "Font menu",
1.76 raeburn 5933: pgbg => "Page",
1.6 raeburn 5934: tabbg => "Header",
5935: sidebg => "Border",
5936: link => "Link",
5937: alink => "Active link",
5938: vlink => "Visited link",
5939: );
5940: return %choices;
5941: }
5942:
5943: sub modify_rolecolors {
1.160.6.24 raeburn 5944: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5945: my ($resulttext,%rolehash);
5946: $rolehash{'rolecolors'} = {};
1.55 raeburn 5947: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5948: if ($domconfig{'rolecolors'} eq '') {
5949: $domconfig{'rolecolors'} = {};
5950: }
5951: }
1.9 raeburn 5952: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5953: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5954: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5955: $dom);
5956: if ($putresult eq 'ok') {
5957: if (keys(%changes) > 0) {
1.41 raeburn 5958: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5959: if (ref($lastactref) eq 'HASH') {
5960: $lastactref->{'domainconfig'} = 1;
5961: }
1.6 raeburn 5962: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5963: $rolehash{'rolecolors'});
5964: } else {
5965: $resulttext = &mt('No changes made to default color schemes');
5966: }
5967: } else {
1.11 albertel 5968: $resulttext = '<span class="LC_error">'.
5969: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5970: }
5971: if ($errors) {
5972: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5973: $errors.'</ul>';
5974: }
5975: return $resulttext;
5976: }
5977:
5978: sub modify_colors {
1.9 raeburn 5979: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5980: my (%changes,%choices);
1.51 raeburn 5981: my @bgs;
1.6 raeburn 5982: my @links = ('link','alink','vlink');
1.41 raeburn 5983: my @logintext;
1.6 raeburn 5984: my @images;
5985: my $servadm = $r->dir_config('lonAdmEMail');
5986: my $errors;
1.160.6.22 raeburn 5987: my %defaults;
1.6 raeburn 5988: foreach my $role (@{$roles}) {
5989: if ($role eq 'login') {
1.12 raeburn 5990: %choices = &login_choices();
1.41 raeburn 5991: @logintext = ('textcol','bgcol');
1.12 raeburn 5992: } else {
5993: %choices = &color_font_choices();
5994: }
5995: if ($role eq 'login') {
1.41 raeburn 5996: @images = ('img','logo','domlogo','login');
1.51 raeburn 5997: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5998: } else {
5999: @images = ('img');
1.160.6.22 raeburn 6000: @bgs = ('pgbg','tabbg','sidebg');
6001: }
6002: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6003: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6004: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6005: }
6006: if ($role eq 'login') {
6007: foreach my $item (@logintext) {
1.160.6.39 raeburn 6008: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6009: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6010: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6011: }
6012: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6013: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6014: }
6015: }
6016: } else {
1.160.6.39 raeburn 6017: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6018: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6019: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6020: }
6021: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6022: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6023: }
1.6 raeburn 6024: }
1.160.6.22 raeburn 6025: foreach my $item (@bgs) {
1.160.6.39 raeburn 6026: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6027: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6028: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6029: }
6030: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6031: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6032: }
6033: }
6034: foreach my $item (@links) {
1.160.6.39 raeburn 6035: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6036: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6037: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6038: }
6039: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6040: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6041: }
1.6 raeburn 6042: }
1.46 raeburn 6043: my ($configuserok,$author_ok,$switchserver) =
6044: &config_check($dom,$confname,$servadm);
1.9 raeburn 6045: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6046: if (ref($domconfig->{$role}) ne 'HASH') {
6047: $domconfig->{$role} = {};
6048: }
1.8 raeburn 6049: foreach my $img (@images) {
1.70 raeburn 6050: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6051: if (defined($env{'form.login_showlogo_'.$img})) {
6052: $confhash->{$role}{'showlogo'}{$img} = 1;
6053: } else {
6054: $confhash->{$role}{'showlogo'}{$img} = 0;
6055: }
6056: }
1.18 albertel 6057: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6058: && !defined($domconfig->{$role}{$img})
6059: && !$env{'form.'.$role.'_del_'.$img}
6060: && $env{'form.'.$role.'_import_'.$img}) {
6061: # import the old configured image from the .tab setting
6062: # if they haven't provided a new one
6063: $domconfig->{$role}{$img} =
6064: $env{'form.'.$role.'_import_'.$img};
6065: }
1.6 raeburn 6066: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6067: my $error;
1.6 raeburn 6068: if ($configuserok eq 'ok') {
1.9 raeburn 6069: if ($switchserver) {
1.12 raeburn 6070: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6071: } else {
6072: if ($author_ok eq 'ok') {
6073: my ($result,$logourl) =
6074: &publishlogo($r,'upload',$role.'_'.$img,
6075: $dom,$confname,$img,$width,$height);
6076: if ($result eq 'ok') {
6077: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6078: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6079: } else {
1.12 raeburn 6080: $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 6081: }
6082: } else {
1.46 raeburn 6083: $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 6084: }
6085: }
6086: } else {
1.46 raeburn 6087: $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 6088: }
6089: if ($error) {
1.8 raeburn 6090: &Apache::lonnet::logthis($error);
1.11 albertel 6091: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6092: }
6093: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6094: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6095: my $error;
6096: if ($configuserok eq 'ok') {
6097: # is confname an author?
6098: if ($switchserver eq '') {
6099: if ($author_ok eq 'ok') {
6100: my ($result,$logourl) =
6101: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6102: $dom,$confname,$img,$width,$height);
6103: if ($result eq 'ok') {
6104: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6105: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6106: }
6107: }
6108: }
6109: }
1.6 raeburn 6110: }
6111: }
6112: }
6113: if (ref($domconfig) eq 'HASH') {
6114: if (ref($domconfig->{$role}) eq 'HASH') {
6115: foreach my $img (@images) {
6116: if ($domconfig->{$role}{$img} ne '') {
6117: if ($env{'form.'.$role.'_del_'.$img}) {
6118: $confhash->{$role}{$img} = '';
1.12 raeburn 6119: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6120: } else {
1.9 raeburn 6121: if ($confhash->{$role}{$img} eq '') {
6122: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6123: }
1.6 raeburn 6124: }
6125: } else {
6126: if ($env{'form.'.$role.'_del_'.$img}) {
6127: $confhash->{$role}{$img} = '';
1.12 raeburn 6128: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6129: }
6130: }
1.70 raeburn 6131: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6132: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6133: if ($confhash->{$role}{'showlogo'}{$img} ne
6134: $domconfig->{$role}{'showlogo'}{$img}) {
6135: $changes{$role}{'showlogo'}{$img} = 1;
6136: }
6137: } else {
6138: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6139: $changes{$role}{'showlogo'}{$img} = 1;
6140: }
6141: }
6142: }
6143: }
1.6 raeburn 6144: if ($domconfig->{$role}{'font'} ne '') {
6145: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6146: $changes{$role}{'font'} = 1;
6147: }
6148: } else {
6149: if ($confhash->{$role}{'font'}) {
6150: $changes{$role}{'font'} = 1;
6151: }
6152: }
1.107 raeburn 6153: if ($role ne 'login') {
6154: if ($domconfig->{$role}{'fontmenu'} ne '') {
6155: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6156: $changes{$role}{'fontmenu'} = 1;
6157: }
6158: } else {
6159: if ($confhash->{$role}{'fontmenu'}) {
6160: $changes{$role}{'fontmenu'} = 1;
6161: }
1.97 tempelho 6162: }
6163: }
1.6 raeburn 6164: foreach my $item (@bgs) {
6165: if ($domconfig->{$role}{$item} ne '') {
6166: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6167: $changes{$role}{'bgs'}{$item} = 1;
6168: }
6169: } else {
6170: if ($confhash->{$role}{$item}) {
6171: $changes{$role}{'bgs'}{$item} = 1;
6172: }
6173: }
6174: }
6175: foreach my $item (@links) {
6176: if ($domconfig->{$role}{$item} ne '') {
6177: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6178: $changes{$role}{'links'}{$item} = 1;
6179: }
6180: } else {
6181: if ($confhash->{$role}{$item}) {
6182: $changes{$role}{'links'}{$item} = 1;
6183: }
6184: }
6185: }
1.41 raeburn 6186: foreach my $item (@logintext) {
6187: if ($domconfig->{$role}{$item} ne '') {
6188: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6189: $changes{$role}{'logintext'}{$item} = 1;
6190: }
6191: } else {
6192: if ($confhash->{$role}{$item}) {
6193: $changes{$role}{'logintext'}{$item} = 1;
6194: }
6195: }
6196: }
1.6 raeburn 6197: } else {
6198: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6199: \@logintext,$confhash,\%changes);
1.6 raeburn 6200: }
6201: } else {
6202: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6203: \@logintext,$confhash,\%changes);
1.6 raeburn 6204: }
6205: }
6206: return ($errors,%changes);
6207: }
6208:
1.46 raeburn 6209: sub config_check {
6210: my ($dom,$confname,$servadm) = @_;
6211: my ($configuserok,$author_ok,$switchserver,%currroles);
6212: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6213: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6214: $confname,$servadm);
6215: if ($configuserok eq 'ok') {
6216: $switchserver = &check_switchserver($dom,$confname);
6217: if ($switchserver eq '') {
6218: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6219: }
6220: }
6221: return ($configuserok,$author_ok,$switchserver);
6222: }
6223:
1.6 raeburn 6224: sub default_change_checker {
1.41 raeburn 6225: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6226: foreach my $item (@{$links}) {
6227: if ($confhash->{$role}{$item}) {
6228: $changes->{$role}{'links'}{$item} = 1;
6229: }
6230: }
6231: foreach my $item (@{$bgs}) {
6232: if ($confhash->{$role}{$item}) {
6233: $changes->{$role}{'bgs'}{$item} = 1;
6234: }
6235: }
1.41 raeburn 6236: foreach my $item (@{$logintext}) {
6237: if ($confhash->{$role}{$item}) {
6238: $changes->{$role}{'logintext'}{$item} = 1;
6239: }
6240: }
1.6 raeburn 6241: foreach my $img (@{$images}) {
6242: if ($env{'form.'.$role.'_del_'.$img}) {
6243: $confhash->{$role}{$img} = '';
1.12 raeburn 6244: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6245: }
1.70 raeburn 6246: if ($role eq 'login') {
6247: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6248: $changes->{$role}{'showlogo'}{$img} = 1;
6249: }
6250: }
1.6 raeburn 6251: }
6252: if ($confhash->{$role}{'font'}) {
6253: $changes->{$role}{'font'} = 1;
6254: }
1.48 raeburn 6255: }
1.6 raeburn 6256:
6257: sub display_colorchgs {
6258: my ($dom,$changes,$roles,$confhash) = @_;
6259: my (%choices,$resulttext);
6260: if (!grep(/^login$/,@{$roles})) {
6261: $resulttext = &mt('Changes made:').'<br />';
6262: }
6263: foreach my $role (@{$roles}) {
6264: if ($role eq 'login') {
6265: %choices = &login_choices();
6266: } else {
6267: %choices = &color_font_choices();
6268: }
6269: if (ref($changes->{$role}) eq 'HASH') {
6270: if ($role ne 'login') {
6271: $resulttext .= '<h4>'.&mt($role).'</h4>';
6272: }
6273: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6274: if ($role ne 'login') {
6275: $resulttext .= '<ul>';
6276: }
6277: if (ref($changes->{$role}{$key}) eq 'HASH') {
6278: if ($role ne 'login') {
6279: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6280: }
6281: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6282: if (($role eq 'login') && ($key eq 'showlogo')) {
6283: if ($confhash->{$role}{$key}{$item}) {
6284: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6285: } else {
6286: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6287: }
6288: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6289: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6290: } else {
1.12 raeburn 6291: my $newitem = $confhash->{$role}{$item};
6292: if ($key eq 'images') {
6293: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6294: }
6295: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6296: }
6297: }
6298: if ($role ne 'login') {
6299: $resulttext .= '</ul></li>';
6300: }
6301: } else {
6302: if ($confhash->{$role}{$key} eq '') {
6303: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6304: } else {
6305: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6306: }
6307: }
6308: if ($role ne 'login') {
6309: $resulttext .= '</ul>';
6310: }
6311: }
6312: }
6313: }
1.3 raeburn 6314: return $resulttext;
1.1 raeburn 6315: }
6316:
1.9 raeburn 6317: sub thumb_dimensions {
6318: return ('200','50');
6319: }
6320:
1.16 raeburn 6321: sub check_dimensions {
6322: my ($inputfile) = @_;
6323: my ($fullwidth,$fullheight);
6324: if ($inputfile =~ m|^[/\w.\-]+$|) {
6325: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6326: my $imageinfo = <PIPE>;
6327: if (!close(PIPE)) {
6328: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6329: }
6330: chomp($imageinfo);
6331: my ($fullsize) =
1.21 raeburn 6332: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6333: if ($fullsize) {
6334: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6335: }
6336: }
6337: }
6338: return ($fullwidth,$fullheight);
6339: }
6340:
1.9 raeburn 6341: sub check_configuser {
6342: my ($uhome,$dom,$confname,$servadm) = @_;
6343: my ($configuserok,%currroles);
6344: if ($uhome eq 'no_host') {
6345: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6346: my $configpass = &LONCAPA::Enrollment::create_password();
6347: $configuserok =
6348: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6349: $configpass,'','','','','',undef,$servadm);
6350: } else {
6351: $configuserok = 'ok';
6352: %currroles =
6353: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6354: }
6355: return ($configuserok,%currroles);
6356: }
6357:
6358: sub check_authorstatus {
6359: my ($dom,$confname,%currroles) = @_;
6360: my $author_ok;
1.40 raeburn 6361: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6362: my $start = time;
6363: my $end = 0;
6364: $author_ok =
6365: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6366: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6367: } else {
6368: $author_ok = 'ok';
6369: }
6370: return $author_ok;
6371: }
6372:
6373: sub publishlogo {
1.46 raeburn 6374: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6375: my ($output,$fname,$logourl);
6376: if ($action eq 'upload') {
6377: $fname=$env{'form.'.$formname.'.filename'};
6378: chop($env{'form.'.$formname});
6379: } else {
6380: ($fname) = ($formname =~ /([^\/]+)$/);
6381: }
1.46 raeburn 6382: if ($savefileas ne '') {
6383: $fname = $savefileas;
6384: }
1.9 raeburn 6385: $fname=&Apache::lonnet::clean_filename($fname);
6386: # See if there is anything left
6387: unless ($fname) { return ('error: no uploaded file'); }
6388: $fname="$subdir/$fname";
1.160.6.5 raeburn 6389: my $docroot=$r->dir_config('lonDocRoot');
6390: my $filepath="$docroot/priv";
6391: my $relpath = "$dom/$confname";
1.9 raeburn 6392: my ($fnamepath,$file,$fetchthumb);
6393: $file=$fname;
6394: if ($fname=~m|/|) {
6395: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6396: }
1.160.6.26 raeburn 6397: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6398: my $count;
1.160.6.5 raeburn 6399: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6400: $filepath.="/$parts[$count]";
6401: if ((-e $filepath)!=1) {
6402: mkdir($filepath,02770);
6403: }
6404: }
6405: # Check for bad extension and disallow upload
6406: if ($file=~/\.(\w+)$/ &&
6407: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6408: $output =
1.160.6.25 raeburn 6409: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6410: } elsif ($file=~/\.(\w+)$/ &&
6411: !defined(&Apache::loncommon::fileembstyle($1))) {
6412: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6413: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6414: $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 6415: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6416: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6417: } else {
6418: my $source = $filepath.'/'.$file;
6419: my $logfile;
6420: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6421: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6422: }
6423: print $logfile
6424: "\n================= Publish ".localtime()." ================\n".
6425: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6426: # Save the file
6427: if (!open(FH,'>'.$source)) {
6428: &Apache::lonnet::logthis('Failed to create '.$source);
6429: return (&mt('Failed to create file'));
6430: }
6431: if ($action eq 'upload') {
6432: if (!print FH ($env{'form.'.$formname})) {
6433: &Apache::lonnet::logthis('Failed to write to '.$source);
6434: return (&mt('Failed to write file'));
6435: }
6436: } else {
6437: my $original = &Apache::lonnet::filelocation('',$formname);
6438: if(!copy($original,$source)) {
6439: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6440: return (&mt('Failed to write file'));
6441: }
6442: }
6443: close(FH);
6444: chmod(0660, $source); # Permissions to rw-rw---.
6445:
6446: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6447: my $copyfile=$targetdir.'/'.$file;
6448:
6449: my @parts=split(/\//,$targetdir);
6450: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6451: for (my $count=5;$count<=$#parts;$count++) {
6452: $path.="/$parts[$count]";
6453: if (!-e $path) {
6454: print $logfile "\nCreating directory ".$path;
6455: mkdir($path,02770);
6456: }
6457: }
6458: my $versionresult;
6459: if (-e $copyfile) {
6460: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6461: } else {
6462: $versionresult = 'ok';
6463: }
6464: if ($versionresult eq 'ok') {
6465: if (copy($source,$copyfile)) {
6466: print $logfile "\nCopied original source to ".$copyfile."\n";
6467: $output = 'ok';
6468: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6469: push(@{$modified_urls},[$copyfile,$source]);
6470: my $metaoutput =
6471: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6472: unless ($registered_cleanup) {
6473: my $handlers = $r->get_handlers('PerlCleanupHandler');
6474: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6475: $registered_cleanup=1;
6476: }
1.9 raeburn 6477: } else {
6478: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6479: $output = &mt('Failed to copy file to RES space').", $!";
6480: }
6481: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6482: my $inputfile = $filepath.'/'.$file;
6483: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6484: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6485: if ($fullwidth ne '' && $fullheight ne '') {
6486: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6487: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6488: system("convert -sample $thumbsize $inputfile $outfile");
6489: chmod(0660, $filepath.'/tn-'.$file);
6490: if (-e $outfile) {
6491: my $copyfile=$targetdir.'/tn-'.$file;
6492: if (copy($outfile,$copyfile)) {
6493: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6494: my $thumb_metaoutput =
6495: &write_metadata($dom,$confname,$formname,
6496: $targetdir,'tn-'.$file,$logfile);
6497: push(@{$modified_urls},[$copyfile,$outfile]);
6498: unless ($registered_cleanup) {
6499: my $handlers = $r->get_handlers('PerlCleanupHandler');
6500: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6501: $registered_cleanup=1;
6502: }
1.16 raeburn 6503: } else {
6504: print $logfile "\nUnable to write ".$copyfile.
6505: ':'.$!."\n";
6506: }
6507: }
1.9 raeburn 6508: }
6509: }
6510: }
6511: } else {
6512: $output = $versionresult;
6513: }
6514: }
6515: return ($output,$logourl);
6516: }
6517:
6518: sub logo_versioning {
6519: my ($targetdir,$file,$logfile) = @_;
6520: my $target = $targetdir.'/'.$file;
6521: my ($maxversion,$fn,$extn,$output);
6522: $maxversion = 0;
6523: if ($file =~ /^(.+)\.(\w+)$/) {
6524: $fn=$1;
6525: $extn=$2;
6526: }
6527: opendir(DIR,$targetdir);
6528: while (my $filename=readdir(DIR)) {
6529: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6530: $maxversion=($1>$maxversion)?$1:$maxversion;
6531: }
6532: }
6533: $maxversion++;
6534: print $logfile "\nCreating old version ".$maxversion."\n";
6535: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6536: if (copy($target,$copyfile)) {
6537: print $logfile "Copied old target to ".$copyfile."\n";
6538: $copyfile=$copyfile.'.meta';
6539: if (copy($target.'.meta',$copyfile)) {
6540: print $logfile "Copied old target metadata to ".$copyfile."\n";
6541: $output = 'ok';
6542: } else {
6543: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6544: $output = &mt('Failed to copy old meta').", $!, ";
6545: }
6546: } else {
6547: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6548: $output = &mt('Failed to copy old target').", $!, ";
6549: }
6550: return $output;
6551: }
6552:
6553: sub write_metadata {
6554: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6555: my (%metadatafields,%metadatakeys,$output);
6556: $metadatafields{'title'}=$formname;
6557: $metadatafields{'creationdate'}=time;
6558: $metadatafields{'lastrevisiondate'}=time;
6559: $metadatafields{'copyright'}='public';
6560: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6561: $env{'user.domain'};
6562: $metadatafields{'authorspace'}=$confname.':'.$dom;
6563: $metadatafields{'domain'}=$dom;
6564: {
6565: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6566: my $mfh;
1.155 raeburn 6567: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6568: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6569: unless ($_=~/\./) {
6570: my $unikey=$_;
6571: $unikey=~/^([A-Za-z]+)/;
6572: my $tag=$1;
6573: $tag=~tr/A-Z/a-z/;
6574: print $mfh "\n\<$tag";
6575: foreach (split(/\,/,$metadatakeys{$unikey})) {
6576: my $value=$metadatafields{$unikey.'.'.$_};
6577: $value=~s/\"/\'\'/g;
6578: print $mfh ' '.$_.'="'.$value.'"';
6579: }
6580: print $mfh '>'.
6581: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6582: .'</'.$tag.'>';
6583: }
6584: }
6585: $output = 'ok';
6586: print $logfile "\nWrote metadata";
6587: close($mfh);
6588: } else {
6589: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6590: $output = &mt('Could not write metadata');
6591: }
6592: }
1.155 raeburn 6593: return $output;
6594: }
6595:
6596: sub notifysubscribed {
6597: foreach my $targetsource (@{$modified_urls}){
6598: next unless (ref($targetsource) eq 'ARRAY');
6599: my ($target,$source)=@{$targetsource};
6600: if ($source ne '') {
6601: if (open(my $logfh,'>>'.$source.'.log')) {
6602: print $logfh "\nCleanup phase: Notifications\n";
6603: my @subscribed=&subscribed_hosts($target);
6604: foreach my $subhost (@subscribed) {
6605: print $logfh "\nNotifying host ".$subhost.':';
6606: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6607: print $logfh $reply;
6608: }
6609: my @subscribedmeta=&subscribed_hosts("$target.meta");
6610: foreach my $subhost (@subscribedmeta) {
6611: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6612: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6613: $subhost);
6614: print $logfh $reply;
6615: }
6616: print $logfh "\n============ Done ============\n";
1.160 raeburn 6617: close($logfh);
1.155 raeburn 6618: }
6619: }
6620: }
6621: return OK;
6622: }
6623:
6624: sub subscribed_hosts {
6625: my ($target) = @_;
6626: my @subscribed;
6627: if (open(my $fh,"<$target.subscription")) {
6628: while (my $subline=<$fh>) {
6629: if ($subline =~ /^($match_lonid):/) {
6630: my $host = $1;
6631: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6632: unless (grep(/^\Q$host\E$/,@subscribed)) {
6633: push(@subscribed,$host);
6634: }
6635: }
6636: }
6637: }
6638: }
6639: return @subscribed;
1.9 raeburn 6640: }
6641:
6642: sub check_switchserver {
6643: my ($dom,$confname) = @_;
6644: my ($allowed,$switchserver);
6645: my $home = &Apache::lonnet::homeserver($confname,$dom);
6646: if ($home eq 'no_host') {
6647: $home = &Apache::lonnet::domain($dom,'primary');
6648: }
6649: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6650: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6651: if (!$allowed) {
1.160.6.11 raeburn 6652: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6653: }
6654: return $switchserver;
6655: }
6656:
1.1 raeburn 6657: sub modify_quotas {
1.160.6.30 raeburn 6658: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6659: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6660: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6661: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6662: $validationfieldsref);
1.86 raeburn 6663: if ($action eq 'quotas') {
6664: $context = 'tools';
1.160.6.26 raeburn 6665: } else {
1.86 raeburn 6666: $context = $action;
6667: }
6668: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6669: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6670: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6671: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6672: %titles = &courserequest_titles();
6673: $toolregexp = join('|',@usertools);
6674: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6675: $confname = $dom.'-domainconfig';
6676: my $servadm = $r->dir_config('lonAdmEMail');
6677: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6678: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6679: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6680: } elsif ($context eq 'requestauthor') {
6681: @usertools = ('author');
6682: %titles = &authorrequest_titles();
1.86 raeburn 6683: } else {
1.160.6.4 raeburn 6684: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6685: %titles = &tool_titles();
1.86 raeburn 6686: }
1.160.6.27 raeburn 6687: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6688: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6689: foreach my $key (keys(%env)) {
1.101 raeburn 6690: if ($context eq 'requestcourses') {
6691: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6692: my $item = $1;
6693: my $type = $2;
6694: if ($type =~ /^limit_(.+)/) {
6695: $limithash{$item}{$1} = $env{$key};
6696: } else {
6697: $confhash{$item}{$type} = $env{$key};
6698: }
6699: }
1.160.6.5 raeburn 6700: } elsif ($context eq 'requestauthor') {
6701: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6702: $confhash{$1} = $env{$key};
6703: }
1.101 raeburn 6704: } else {
1.86 raeburn 6705: if ($key =~ /^form\.quota_(.+)$/) {
6706: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6707: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6708: $confhash{'authorquota'}{$1} = $env{$key};
6709: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6710: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6711: }
1.72 raeburn 6712: }
6713: }
1.160.6.5 raeburn 6714: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6715: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6716: @approvalnotify = sort(@approvalnotify);
6717: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6718: my @crstypes = ('official','unofficial','community','textbook');
6719: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6720: foreach my $type (@hasuniquecode) {
6721: if (grep(/^\Q$type\E$/,@crstypes)) {
6722: $confhash{'uniquecode'}{$type} = 1;
6723: }
6724: }
6725: my ($newbook,@allpos);
6726: if ($context eq 'requestcourses') {
6727: if ($env{'form.addbook'}) {
6728: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6729: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6730: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6731: $env{'form.addbook_cdom'}) eq 'no_host') {
6732: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6733: '</span></li>';
6734: } else {
6735: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6736: my $position = $env{'form.addbook_pos'};
6737: $position =~ s/\D+//g;
6738: if ($position ne '') {
6739: $allpos[$position] = $newbook;
6740: }
6741: }
6742: } else {
6743: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6744: '</span></li>';
6745: }
6746: }
1.160.6.39 raeburn 6747:
1.160.6.30 raeburn 6748: }
1.102 raeburn 6749: if (ref($domconfig{$action}) eq 'HASH') {
6750: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6751: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6752: $changes{'notify'}{'approval'} = 1;
6753: }
6754: } else {
1.144 raeburn 6755: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6756: $changes{'notify'}{'approval'} = 1;
6757: }
6758: }
1.160.6.30 raeburn 6759: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6760: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6761: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6762: unless ($confhash{'uniquecode'}{$crstype}) {
6763: $changes{'uniquecode'} = 1;
6764: }
6765: }
6766: unless ($changes{'uniquecode'}) {
6767: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6768: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6769: $changes{'uniquecode'} = 1;
6770: }
6771: }
6772: }
6773: } else {
6774: $changes{'uniquecode'} = 1;
6775: }
6776: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6777: $changes{'uniquecode'} = 1;
6778: }
6779: if ($context eq 'requestcourses') {
6780: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6781: my %deletions;
6782: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6783: if (@todelete) {
6784: map { $deletions{$_} = 1; } @todelete;
6785: }
6786: my %imgdeletions;
6787: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6788: if (@todeleteimages) {
6789: map { $imgdeletions{$_} = 1; } @todeleteimages;
6790: }
6791: my $maxnum = $env{'form.book_maxnum'};
6792: for (my $i=0; $i<=$maxnum; $i++) {
6793: my $key = $env{'form.book_id_'.$i};
6794: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6795: if ($deletions{$key}) {
6796: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6797: #FIXME need to obsolete item in RES space
6798: }
6799: next;
6800: } else {
6801: my $newpos = $env{'form.'.$key};
6802: $newpos =~ s/\D+//g;
6803: foreach my $item ('subject','title','author') {
6804: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6805: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6806: $changes{'textbooks'}{$key} = 1;
6807: }
6808: }
6809: $allpos[$newpos] = $key;
6810: }
6811: if ($imgdeletions{$key}) {
6812: $changes{'textbooks'}{$key} = 1;
6813: #FIXME need to obsolete item in RES space
6814: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6815: my ($cdom,$cnum) = split(/_/,$key);
6816: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6817: $cdom,$cnum,$configuserok,
6818: $switchserver,$author_ok);
6819: if ($imgurl) {
6820: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6821: $changes{'textbooks'}{$key} = 1;
6822: }
6823: if ($error) {
6824: &Apache::lonnet::logthis($error);
6825: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6826: }
6827: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6828: $confhash{'textbooks'}{$key}{'image'} =
6829: $domconfig{$action}{'textbooks'}{$key}{'image'};
6830: }
6831: }
6832: }
6833: }
6834: }
1.102 raeburn 6835: } else {
1.144 raeburn 6836: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6837: $changes{'notify'}{'approval'} = 1;
6838: }
1.160.6.30 raeburn 6839: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6840: $changes{'uniquecode'} = 1;
6841: }
6842: }
6843: if ($context eq 'requestcourses') {
6844: if ($newbook) {
6845: $changes{'textbooks'}{$newbook} = 1;
6846: foreach my $item ('subject','title','author') {
6847: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6848: if ($env{'form.addbook_'.$item}) {
6849: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6850: }
6851: }
6852: if ($env{'form.addbook_image.filename'} ne '') {
6853: my ($cdom,$cnum) = split(/_/,$newbook);
1.160.6.39 raeburn 6854: my ($imageurl,$error) =
1.160.6.30 raeburn 6855: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6856: $switchserver,$author_ok);
6857: if ($imageurl) {
6858: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6859: }
6860: if ($error) {
6861: &Apache::lonnet::logthis($error);
6862: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6863: }
6864: }
6865: }
6866: if (@allpos > 0) {
6867: my $idx = 0;
6868: foreach my $item (@allpos) {
6869: if ($item ne '') {
6870: $confhash{'textbooks'}{$item}{'order'} = $idx;
6871: if (ref($domconfig{$action}) eq 'HASH') {
6872: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6873: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6874: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6875: $changes{'textbooks'}{$item} = 1;
6876: }
6877: }
6878: }
6879: }
6880: $idx ++;
6881: }
6882: }
6883: }
1.160.6.39 raeburn 6884: if (ref($validationitemsref) eq 'ARRAY') {
6885: foreach my $item (@{$validationitemsref}) {
6886: if ($item eq 'fields') {
6887: my @changed;
6888: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
6889: if (@{$confhash{'validation'}{$item}} > 0) {
6890: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
6891: }
6892: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6893: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
6894: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
6895: $domconfig{'requestcourses'}{'validation'}{$item});
6896: } else {
6897: @changed = @{$confhash{'validation'}{$item}};
6898: }
6899: } else {
6900: @changed = @{$confhash{'validation'}{$item}};
6901: }
6902: if (@changed) {
6903: if ($confhash{'validation'}{$item}) {
6904: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
6905: } else {
6906: $changes{'validation'}{$item} = &mt('None');
6907: }
6908: }
6909: } else {
6910: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
6911: if ($item eq 'markup') {
6912: if ($env{'form.requestcourses_validation_'.$item}) {
6913: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
6914: }
6915: }
6916: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6917: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
6918: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6919: }
6920: } else {
6921: if ($confhash{'validation'}{$item} ne '') {
6922: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6923: }
6924: }
6925: }
6926: }
6927: }
6928: if ($env{'form.validationdc'}) {
6929: my $newval = $env{'form.validationdc'};
6930: my %domcoords = &get_active_dcs($dom);
6931: if (exists($domcoords{$newval})) {
6932: $confhash{'validation'}{'dc'} = $newval;
6933: }
6934: }
6935: if (ref($confhash{'validation'}) eq 'HASH') {
6936: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6937: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
6938: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
6939: if ($confhash{'validation'}{'dc'} eq '') {
6940: $changes{'validation'}{'dc'} = &mt('None');
6941: } else {
6942: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6943: }
6944: }
6945: } elsif ($confhash{'validation'}{'dc'} ne '') {
6946: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6947: }
6948: } elsif ($confhash{'validation'}{'dc'} ne '') {
6949: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6950: }
6951: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6952: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
6953: $changes{'validation'}{'dc'} = &mt('None');
6954: }
6955: }
1.102 raeburn 6956: }
6957: } else {
1.86 raeburn 6958: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 6959: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 6960: }
1.72 raeburn 6961: foreach my $item (@usertools) {
6962: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 6963: my $unset;
1.101 raeburn 6964: if ($context eq 'requestcourses') {
1.104 raeburn 6965: $unset = '0';
6966: if ($type eq '_LC_adv') {
6967: $unset = '';
6968: }
1.101 raeburn 6969: if ($confhash{$item}{$type} eq 'autolimit') {
6970: $confhash{$item}{$type} .= '=';
6971: unless ($limithash{$item}{$type} =~ /\D/) {
6972: $confhash{$item}{$type} .= $limithash{$item}{$type};
6973: }
6974: }
1.160.6.5 raeburn 6975: } elsif ($context eq 'requestauthor') {
6976: $unset = '0';
6977: if ($type eq '_LC_adv') {
6978: $unset = '';
6979: }
1.72 raeburn 6980: } else {
1.101 raeburn 6981: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
6982: $confhash{$item}{$type} = 1;
6983: } else {
6984: $confhash{$item}{$type} = 0;
6985: }
1.72 raeburn 6986: }
1.86 raeburn 6987: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 6988: if ($action eq 'requestauthor') {
6989: if ($domconfig{$action}{$type} ne $confhash{$type}) {
6990: $changes{$type} = 1;
6991: }
6992: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 6993: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
6994: $changes{$item}{$type} = 1;
6995: }
6996: } else {
6997: if ($context eq 'requestcourses') {
1.104 raeburn 6998: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 6999: $changes{$item}{$type} = 1;
7000: }
7001: } else {
7002: if (!$confhash{$item}{$type}) {
7003: $changes{$item}{$type} = 1;
7004: }
7005: }
7006: }
7007: } else {
7008: if ($context eq 'requestcourses') {
1.104 raeburn 7009: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7010: $changes{$item}{$type} = 1;
7011: }
1.160.6.5 raeburn 7012: } elsif ($context eq 'requestauthor') {
7013: if ($confhash{$type} ne $unset) {
7014: $changes{$type} = 1;
7015: }
1.72 raeburn 7016: } else {
7017: if (!$confhash{$item}{$type}) {
7018: $changes{$item}{$type} = 1;
7019: }
7020: }
7021: }
1.1 raeburn 7022: }
7023: }
1.160.6.5 raeburn 7024: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7025: if (ref($domconfig{'quotas'}) eq 'HASH') {
7026: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7027: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7028: if (exists($confhash{'defaultquota'}{$key})) {
7029: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7030: $changes{'defaultquota'}{$key} = 1;
7031: }
7032: } else {
7033: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7034: }
7035: }
1.86 raeburn 7036: } else {
7037: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7038: if (exists($confhash{'defaultquota'}{$key})) {
7039: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7040: $changes{'defaultquota'}{$key} = 1;
7041: }
7042: } else {
7043: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7044: }
1.1 raeburn 7045: }
7046: }
1.160.6.20 raeburn 7047: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7048: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7049: if (exists($confhash{'authorquota'}{$key})) {
7050: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7051: $changes{'authorquota'}{$key} = 1;
7052: }
7053: } else {
7054: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7055: }
7056: }
7057: }
1.1 raeburn 7058: }
1.86 raeburn 7059: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7060: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7061: if (ref($domconfig{'quotas'}) eq 'HASH') {
7062: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7063: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7064: $changes{'defaultquota'}{$key} = 1;
7065: }
7066: } else {
7067: if (!exists($domconfig{'quotas'}{$key})) {
7068: $changes{'defaultquota'}{$key} = 1;
7069: }
1.72 raeburn 7070: }
7071: } else {
1.86 raeburn 7072: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7073: }
1.1 raeburn 7074: }
7075: }
1.160.6.20 raeburn 7076: if (ref($confhash{'authorquota'}) eq 'HASH') {
7077: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7078: if (ref($domconfig{'quotas'}) eq 'HASH') {
7079: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7080: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7081: $changes{'authorquota'}{$key} = 1;
7082: }
7083: } else {
7084: $changes{'authorquota'}{$key} = 1;
7085: }
7086: } else {
7087: $changes{'authorquota'}{$key} = 1;
7088: }
7089: }
7090: }
1.1 raeburn 7091: }
1.72 raeburn 7092:
1.160.6.5 raeburn 7093: if ($context eq 'requestauthor') {
7094: $domdefaults{'requestauthor'} = \%confhash;
7095: } else {
7096: foreach my $key (keys(%confhash)) {
1.160.6.30 raeburn 7097: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
7098: $domdefaults{$key} = $confhash{$key};
7099: }
1.160.6.5 raeburn 7100: }
1.72 raeburn 7101: }
1.160.6.5 raeburn 7102:
1.1 raeburn 7103: my %quotahash = (
1.86 raeburn 7104: $action => { %confhash }
1.1 raeburn 7105: );
7106: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7107: $dom);
7108: if ($putresult eq 'ok') {
7109: if (keys(%changes) > 0) {
1.72 raeburn 7110: my $cachetime = 24*60*60;
7111: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7112: if (ref($lastactref) eq 'HASH') {
7113: $lastactref->{'domdefaults'} = 1;
7114: }
1.1 raeburn 7115: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7116: unless (($context eq 'requestcourses') ||
7117: ($context eq 'requestauthor')) {
1.86 raeburn 7118: if (ref($changes{'defaultquota'}) eq 'HASH') {
7119: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7120: foreach my $type (@{$types},'default') {
7121: if (defined($changes{'defaultquota'}{$type})) {
7122: my $typetitle = $usertypes->{$type};
7123: if ($type eq 'default') {
7124: $typetitle = $othertitle;
7125: }
1.160.6.28 raeburn 7126: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7127: }
7128: }
1.86 raeburn 7129: $resulttext .= '</ul></li>';
1.72 raeburn 7130: }
1.160.6.20 raeburn 7131: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7132: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7133: foreach my $type (@{$types},'default') {
7134: if (defined($changes{'authorquota'}{$type})) {
7135: my $typetitle = $usertypes->{$type};
7136: if ($type eq 'default') {
7137: $typetitle = $othertitle;
7138: }
1.160.6.28 raeburn 7139: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7140: }
7141: }
7142: $resulttext .= '</ul></li>';
7143: }
1.72 raeburn 7144: }
1.80 raeburn 7145: my %newenv;
1.72 raeburn 7146: foreach my $item (@usertools) {
1.160.6.5 raeburn 7147: my (%haschgs,%inconf);
7148: if ($context eq 'requestauthor') {
7149: %haschgs = %changes;
7150: %inconf = %confhash;
7151: } else {
7152: if (ref($changes{$item}) eq 'HASH') {
7153: %haschgs = %{$changes{$item}};
7154: }
7155: if (ref($confhash{$item}) eq 'HASH') {
7156: %inconf = %{$confhash{$item}};
7157: }
7158: }
7159: if (keys(%haschgs) > 0) {
1.80 raeburn 7160: my $newacc =
7161: &Apache::lonnet::usertools_access($env{'user.name'},
7162: $env{'user.domain'},
1.86 raeburn 7163: $item,'reload',$context);
1.160.6.5 raeburn 7164: if (($context eq 'requestcourses') ||
7165: ($context eq 'requestauthor')) {
1.108 raeburn 7166: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7167: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7168: }
7169: } else {
7170: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7171: $newenv{'environment.availabletools.'.$item} = $newacc;
7172: }
1.80 raeburn 7173: }
1.160.6.5 raeburn 7174: unless ($context eq 'requestauthor') {
7175: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7176: }
1.72 raeburn 7177: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7178: if ($haschgs{$type}) {
1.72 raeburn 7179: my $typetitle = $usertypes->{$type};
7180: if ($type eq 'default') {
7181: $typetitle = $othertitle;
7182: } elsif ($type eq '_LC_adv') {
7183: $typetitle = 'LON-CAPA Advanced Users';
7184: }
1.160.6.5 raeburn 7185: if ($inconf{$type}) {
1.101 raeburn 7186: if ($context eq 'requestcourses') {
7187: my $cond;
1.160.6.5 raeburn 7188: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7189: if ($1 eq '') {
7190: $cond = &mt('(Automatic processing of any request).');
7191: } else {
7192: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7193: }
7194: } else {
1.160.6.5 raeburn 7195: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7196: }
7197: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7198: } elsif ($context eq 'requestauthor') {
7199: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7200: $titles{$inconf{$type}},$typetitle);
7201:
1.101 raeburn 7202: } else {
7203: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7204: }
1.72 raeburn 7205: } else {
1.104 raeburn 7206: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7207: if ($inconf{$type} eq '0') {
1.104 raeburn 7208: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7209: } else {
7210: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7211: }
7212: } else {
7213: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7214: }
1.72 raeburn 7215: }
7216: }
1.26 raeburn 7217: }
1.160.6.5 raeburn 7218: unless ($context eq 'requestauthor') {
7219: $resulttext .= '</ul></li>';
7220: }
1.26 raeburn 7221: }
1.1 raeburn 7222: }
1.160.6.5 raeburn 7223: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7224: if (ref($changes{'notify'}) eq 'HASH') {
7225: if ($changes{'notify'}{'approval'}) {
7226: if (ref($confhash{'notify'}) eq 'HASH') {
7227: if ($confhash{'notify'}{'approval'}) {
7228: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7229: } else {
1.160.6.5 raeburn 7230: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7231: }
7232: }
7233: }
7234: }
7235: }
1.160.6.30 raeburn 7236: if ($action eq 'requestcourses') {
7237: my @offon = ('off','on');
7238: if ($changes{'uniquecode'}) {
7239: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7240: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7241: $resulttext .= '<li>'.
7242: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7243: '</li>';
7244: } else {
7245: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7246: '</li>';
7247: }
7248: }
7249: if (ref($changes{'textbooks'}) eq 'HASH') {
7250: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
7251: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
7252: my %coursehash = &Apache::lonnet::coursedescription($key);
7253: my $coursetitle = $coursehash{'description'};
7254: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
7255: $resulttext .= '<li>';
7256: foreach my $item ('subject','title','author') {
7257: my $name = $item.':';
7258: $name =~ s/^(\w)/\U$1/;
7259: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
7260: }
7261: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7262: if ($confhash{'textbooks'}{$key}{'image'}) {
7263: $resulttext .= ' '.&mt('Image: [_1]',
7264: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
7265: ' alt="Textbook cover" />').'<br />';
7266: }
7267: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7268: }
7269: $resulttext .= '</ul></li>';
7270: }
1.160.6.39 raeburn 7271: if (ref($changes{'validation'}) eq 'HASH') {
7272: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7273: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7274: foreach my $item (@{$validationitemsref}) {
7275: if (exists($changes{'validation'}{$item})) {
7276: if ($item eq 'markup') {
7277: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7278: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7279: } else {
7280: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7281: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7282: }
7283: }
7284: }
7285: if (exists($changes{'validation'}{'dc'})) {
7286: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7287: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7288: }
7289: }
7290: }
1.160.6.30 raeburn 7291: }
1.1 raeburn 7292: $resulttext .= '</ul>';
1.80 raeburn 7293: if (keys(%newenv)) {
7294: &Apache::lonnet::appenv(\%newenv);
7295: }
1.1 raeburn 7296: } else {
1.86 raeburn 7297: if ($context eq 'requestcourses') {
7298: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7299: } elsif ($context eq 'requestauthor') {
7300: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7301: } else {
1.90 weissno 7302: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7303: }
1.1 raeburn 7304: }
7305: } else {
1.11 albertel 7306: $resulttext = '<span class="LC_error">'.
7307: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7308: }
1.160.6.30 raeburn 7309: if ($errors) {
7310: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7311: '<ul>'.$errors.'</ul></p>';
7312: }
1.3 raeburn 7313: return $resulttext;
1.1 raeburn 7314: }
7315:
1.160.6.30 raeburn 7316: sub process_textbook_image {
7317: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
7318: my $filename = $env{'form.'.$caller.'.filename'};
7319: my ($error,$url);
7320: my ($width,$height) = (50,50);
7321: if ($configuserok eq 'ok') {
7322: if ($switchserver) {
7323: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7324: $switchserver);
7325: } elsif ($author_ok eq 'ok') {
7326: my ($result,$imageurl) =
7327: &publishlogo($r,'upload',$caller,$dom,$confname,
7328: "textbooks/$dom/$cnum/cover",$width,$height);
7329: if ($result eq 'ok') {
7330: $url = $imageurl;
7331: } else {
7332: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7333: }
7334: } else {
7335: $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);
7336: }
7337: } else {
7338: $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);
7339: }
7340: return ($url,$error);
7341: }
7342:
1.3 raeburn 7343: sub modify_autoenroll {
1.160.6.24 raeburn 7344: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7345: my ($resulttext,%changes);
7346: my %currautoenroll;
7347: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7348: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7349: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7350: }
7351: }
7352: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7353: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7354: sender => 'Sender for notification messages',
7355: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7356: my @offon = ('off','on');
1.17 raeburn 7357: my $sender_uname = $env{'form.sender_uname'};
7358: my $sender_domain = $env{'form.sender_domain'};
7359: if ($sender_domain eq '') {
7360: $sender_uname = '';
7361: } elsif ($sender_uname eq '') {
7362: $sender_domain = '';
7363: }
1.129 raeburn 7364: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7365: my %autoenrollhash = (
1.129 raeburn 7366: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7367: 'sender_uname' => $sender_uname,
7368: 'sender_domain' => $sender_domain,
7369: 'co-owners' => $coowners,
1.1 raeburn 7370: }
7371: );
1.4 raeburn 7372: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7373: $dom);
1.1 raeburn 7374: if ($putresult eq 'ok') {
7375: if (exists($currautoenroll{'run'})) {
7376: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7377: $changes{'run'} = 1;
7378: }
7379: } elsif ($autorun) {
7380: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7381: $changes{'run'} = 1;
1.1 raeburn 7382: }
7383: }
1.17 raeburn 7384: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7385: $changes{'sender'} = 1;
7386: }
1.17 raeburn 7387: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7388: $changes{'sender'} = 1;
7389: }
1.129 raeburn 7390: if ($currautoenroll{'co-owners'} ne '') {
7391: if ($currautoenroll{'co-owners'} ne $coowners) {
7392: $changes{'coowners'} = 1;
7393: }
7394: } elsif ($coowners) {
7395: $changes{'coowners'} = 1;
7396: }
1.1 raeburn 7397: if (keys(%changes) > 0) {
7398: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7399: if ($changes{'run'}) {
1.1 raeburn 7400: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7401: }
7402: if ($changes{'sender'}) {
1.17 raeburn 7403: if ($sender_uname eq '' || $sender_domain eq '') {
7404: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7405: } else {
7406: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7407: }
1.1 raeburn 7408: }
1.129 raeburn 7409: if ($changes{'coowners'}) {
7410: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7411: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7412: if (ref($lastactref) eq 'HASH') {
7413: $lastactref->{'domainconfig'} = 1;
7414: }
1.129 raeburn 7415: }
1.1 raeburn 7416: $resulttext .= '</ul>';
7417: } else {
7418: $resulttext = &mt('No changes made to auto-enrollment settings');
7419: }
7420: } else {
1.11 albertel 7421: $resulttext = '<span class="LC_error">'.
7422: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7423: }
1.3 raeburn 7424: return $resulttext;
1.1 raeburn 7425: }
7426:
7427: sub modify_autoupdate {
1.3 raeburn 7428: my ($dom,%domconfig) = @_;
1.1 raeburn 7429: my ($resulttext,%currautoupdate,%fields,%changes);
7430: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7431: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7432: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7433: }
7434: }
7435: my @offon = ('off','on');
7436: my %title = &Apache::lonlocal::texthash (
7437: run => 'Auto-update:',
7438: classlists => 'Updates to user information in classlists?'
7439: );
1.44 raeburn 7440: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7441: my %fieldtitles = &Apache::lonlocal::texthash (
7442: id => 'Student/Employee ID',
1.20 raeburn 7443: permanentemail => 'E-mail address',
1.1 raeburn 7444: lastname => 'Last Name',
7445: firstname => 'First Name',
7446: middlename => 'Middle Name',
1.132 raeburn 7447: generation => 'Generation',
1.1 raeburn 7448: );
1.142 raeburn 7449: $othertitle = &mt('All users');
1.1 raeburn 7450: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7451: $othertitle = &mt('Other users');
1.1 raeburn 7452: }
7453: foreach my $key (keys(%env)) {
7454: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7455: my ($usertype,$item) = ($1,$2);
7456: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7457: if ($usertype eq 'default') {
7458: push(@{$fields{$1}},$2);
7459: } elsif (ref($types) eq 'ARRAY') {
7460: if (grep(/^\Q$usertype\E$/,@{$types})) {
7461: push(@{$fields{$1}},$2);
7462: }
7463: }
7464: }
1.1 raeburn 7465: }
7466: }
1.131 raeburn 7467: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7468: @lockablenames = sort(@lockablenames);
7469: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7470: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7471: if (@changed) {
7472: $changes{'lockablenames'} = 1;
7473: }
7474: } else {
7475: if (@lockablenames) {
7476: $changes{'lockablenames'} = 1;
7477: }
7478: }
1.1 raeburn 7479: my %updatehash = (
7480: autoupdate => { run => $env{'form.autoupdate_run'},
7481: classlists => $env{'form.classlists'},
7482: fields => {%fields},
1.131 raeburn 7483: lockablenames => \@lockablenames,
1.1 raeburn 7484: }
7485: );
7486: foreach my $key (keys(%currautoupdate)) {
7487: if (($key eq 'run') || ($key eq 'classlists')) {
7488: if (exists($updatehash{autoupdate}{$key})) {
7489: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7490: $changes{$key} = 1;
7491: }
7492: }
7493: } elsif ($key eq 'fields') {
7494: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7495: foreach my $item (@{$types},'default') {
1.1 raeburn 7496: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7497: my $change = 0;
7498: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7499: if (!exists($fields{$item})) {
7500: $change = 1;
1.132 raeburn 7501: last;
1.1 raeburn 7502: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7503: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7504: $change = 1;
1.132 raeburn 7505: last;
1.1 raeburn 7506: }
7507: }
7508: }
7509: if ($change) {
7510: push(@{$changes{$key}},$item);
7511: }
1.26 raeburn 7512: }
1.1 raeburn 7513: }
7514: }
1.131 raeburn 7515: } elsif ($key eq 'lockablenames') {
7516: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7517: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7518: if (@changed) {
7519: $changes{'lockablenames'} = 1;
7520: }
7521: } else {
7522: if (@lockablenames) {
7523: $changes{'lockablenames'} = 1;
7524: }
7525: }
7526: }
7527: }
7528: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7529: if (@lockablenames) {
7530: $changes{'lockablenames'} = 1;
1.1 raeburn 7531: }
7532: }
1.26 raeburn 7533: foreach my $item (@{$types},'default') {
7534: if (defined($fields{$item})) {
7535: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7536: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7537: my $change = 0;
7538: if (ref($fields{$item}) eq 'ARRAY') {
7539: foreach my $type (@{$fields{$item}}) {
7540: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7541: $change = 1;
7542: last;
7543: }
7544: }
7545: }
7546: if ($change) {
7547: push(@{$changes{'fields'}},$item);
7548: }
7549: } else {
1.26 raeburn 7550: push(@{$changes{'fields'}},$item);
7551: }
7552: } else {
7553: push(@{$changes{'fields'}},$item);
1.1 raeburn 7554: }
7555: }
7556: }
7557: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7558: $dom);
7559: if ($putresult eq 'ok') {
7560: if (keys(%changes) > 0) {
7561: $resulttext = &mt('Changes made:').'<ul>';
7562: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7563: if ($key eq 'lockablenames') {
7564: $resulttext .= '<li>';
7565: if (@lockablenames) {
7566: $usertypes->{'default'} = $othertitle;
7567: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7568: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7569: } else {
7570: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7571: }
7572: $resulttext .= '</li>';
7573: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7574: foreach my $item (@{$changes{$key}}) {
7575: my @newvalues;
7576: foreach my $type (@{$fields{$item}}) {
7577: push(@newvalues,$fieldtitles{$type});
7578: }
1.3 raeburn 7579: my $newvaluestr;
7580: if (@newvalues > 0) {
7581: $newvaluestr = join(', ',@newvalues);
7582: } else {
7583: $newvaluestr = &mt('none');
1.6 raeburn 7584: }
1.1 raeburn 7585: if ($item eq 'default') {
1.26 raeburn 7586: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7587: } else {
1.26 raeburn 7588: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7589: }
7590: }
7591: } else {
7592: my $newvalue;
7593: if ($key eq 'run') {
7594: $newvalue = $offon[$env{'form.autoupdate_run'}];
7595: } else {
7596: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7597: }
1.1 raeburn 7598: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7599: }
7600: }
7601: $resulttext .= '</ul>';
7602: } else {
1.3 raeburn 7603: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7604: }
7605: } else {
1.11 albertel 7606: $resulttext = '<span class="LC_error">'.
7607: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7608: }
1.3 raeburn 7609: return $resulttext;
1.1 raeburn 7610: }
7611:
1.125 raeburn 7612: sub modify_autocreate {
7613: my ($dom,%domconfig) = @_;
7614: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7615: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7616: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7617: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7618: }
7619: }
7620: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7621: req => 'Auto-creation of validated requests for official courses',
7622: xmldc => 'Identity of course creator of courses from XML files',
7623: );
7624: my @types = ('xml','req');
7625: foreach my $item (@types) {
7626: $newvals{$item} = $env{'form.autocreate_'.$item};
7627: $newvals{$item} =~ s/\D//g;
7628: $newvals{$item} = 0 if ($newvals{$item} eq '');
7629: }
7630: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7631: my %domcoords = &get_active_dcs($dom);
7632: unless (exists($domcoords{$newvals{'xmldc'}})) {
7633: $newvals{'xmldc'} = '';
7634: }
7635: %autocreatehash = (
7636: autocreate => { xml => $newvals{'xml'},
7637: req => $newvals{'req'},
7638: }
7639: );
7640: if ($newvals{'xmldc'} ne '') {
7641: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7642: }
7643: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7644: $dom);
7645: if ($putresult eq 'ok') {
7646: my @items = @types;
7647: if ($newvals{'xml'}) {
7648: push(@items,'xmldc');
7649: }
7650: foreach my $item (@items) {
7651: if (exists($currautocreate{$item})) {
7652: if ($currautocreate{$item} ne $newvals{$item}) {
7653: $changes{$item} = 1;
7654: }
7655: } elsif ($newvals{$item}) {
7656: $changes{$item} = 1;
7657: }
7658: }
7659: if (keys(%changes) > 0) {
7660: my @offon = ('off','on');
7661: $resulttext = &mt('Changes made:').'<ul>';
7662: foreach my $item (@types) {
7663: if ($changes{$item}) {
7664: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7665: $resulttext .= '<li>'.
7666: &mt("$title{$item} set to [_1]$newtxt [_2]",
7667: '<b>','</b>').
7668: '</li>';
1.125 raeburn 7669: }
7670: }
7671: if ($changes{'xmldc'}) {
7672: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7673: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7674: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7675: }
7676: $resulttext .= '</ul>';
7677: } else {
7678: $resulttext = &mt('No changes made to auto-creation settings');
7679: }
7680: } else {
7681: $resulttext = '<span class="LC_error">'.
7682: &mt('An error occurred: [_1]',$putresult).'</span>';
7683: }
7684: return $resulttext;
7685: }
7686:
1.23 raeburn 7687: sub modify_directorysrch {
7688: my ($dom,%domconfig) = @_;
7689: my ($resulttext,%changes);
7690: my %currdirsrch;
7691: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7692: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7693: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7694: }
7695: }
7696: my %title = ( available => 'Directory search available',
1.24 raeburn 7697: localonly => 'Other domains can search',
1.23 raeburn 7698: searchby => 'Search types',
7699: searchtypes => 'Search latitude');
7700: my @offon = ('off','on');
1.24 raeburn 7701: my @otherdoms = ('Yes','No');
1.23 raeburn 7702:
1.25 raeburn 7703: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7704: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7705: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7706:
1.44 raeburn 7707: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7708: if (keys(%{$usertypes}) == 0) {
7709: @cansearch = ('default');
7710: } else {
7711: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7712: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7713: if (!grep(/^\Q$type\E$/,@cansearch)) {
7714: push(@{$changes{'cansearch'}},$type);
7715: }
1.23 raeburn 7716: }
1.26 raeburn 7717: foreach my $type (@cansearch) {
7718: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7719: push(@{$changes{'cansearch'}},$type);
7720: }
1.23 raeburn 7721: }
1.26 raeburn 7722: } else {
7723: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7724: }
7725: }
7726:
7727: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7728: foreach my $by (@{$currdirsrch{'searchby'}}) {
7729: if (!grep(/^\Q$by\E$/,@searchby)) {
7730: push(@{$changes{'searchby'}},$by);
7731: }
7732: }
7733: foreach my $by (@searchby) {
7734: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7735: push(@{$changes{'searchby'}},$by);
7736: }
7737: }
7738: } else {
7739: push(@{$changes{'searchby'}},@searchby);
7740: }
1.25 raeburn 7741:
7742: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7743: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7744: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7745: push(@{$changes{'searchtypes'}},$type);
7746: }
7747: }
7748: foreach my $type (@searchtypes) {
7749: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7750: push(@{$changes{'searchtypes'}},$type);
7751: }
7752: }
7753: } else {
7754: if (exists($currdirsrch{'searchtypes'})) {
7755: foreach my $type (@searchtypes) {
7756: if ($type ne $currdirsrch{'searchtypes'}) {
7757: push(@{$changes{'searchtypes'}},$type);
7758: }
7759: }
7760: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7761: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7762: }
7763: } else {
7764: push(@{$changes{'searchtypes'}},@searchtypes);
7765: }
7766: }
7767:
1.23 raeburn 7768: my %dirsrch_hash = (
7769: directorysrch => { available => $env{'form.dirsrch_available'},
7770: cansearch => \@cansearch,
1.24 raeburn 7771: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7772: searchby => \@searchby,
1.25 raeburn 7773: searchtypes => \@searchtypes,
1.23 raeburn 7774: }
7775: );
7776: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7777: $dom);
7778: if ($putresult eq 'ok') {
7779: if (exists($currdirsrch{'available'})) {
7780: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7781: $changes{'available'} = 1;
7782: }
7783: } else {
7784: if ($env{'form.dirsrch_available'} eq '1') {
7785: $changes{'available'} = 1;
7786: }
7787: }
1.24 raeburn 7788: if (exists($currdirsrch{'localonly'})) {
7789: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7790: $changes{'localonly'} = 1;
7791: }
7792: } else {
7793: if ($env{'form.dirsrch_localonly'} eq '1') {
7794: $changes{'localonly'} = 1;
7795: }
7796: }
1.23 raeburn 7797: if (keys(%changes) > 0) {
7798: $resulttext = &mt('Changes made:').'<ul>';
7799: if ($changes{'available'}) {
7800: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7801: }
1.24 raeburn 7802: if ($changes{'localonly'}) {
7803: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7804: }
7805:
1.23 raeburn 7806: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7807: my $chgtext;
1.26 raeburn 7808: if (ref($usertypes) eq 'HASH') {
7809: if (keys(%{$usertypes}) > 0) {
7810: foreach my $type (@{$types}) {
7811: if (grep(/^\Q$type\E$/,@cansearch)) {
7812: $chgtext .= $usertypes->{$type}.'; ';
7813: }
7814: }
7815: if (grep(/^default$/,@cansearch)) {
7816: $chgtext .= $othertitle;
7817: } else {
7818: $chgtext =~ s/\; $//;
7819: }
1.160.6.13 raeburn 7820: $resulttext .=
7821: '<li>'.
7822: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7823: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7824: '</li>';
1.23 raeburn 7825: }
7826: }
7827: }
7828: if (ref($changes{'searchby'}) eq 'ARRAY') {
7829: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7830: my $chgtext;
7831: foreach my $type (@{$titleorder}) {
7832: if (grep(/^\Q$type\E$/,@searchby)) {
7833: if (defined($searchtitles->{$type})) {
7834: $chgtext .= $searchtitles->{$type}.'; ';
7835: }
7836: }
7837: }
7838: $chgtext =~ s/\; $//;
7839: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7840: }
1.25 raeburn 7841: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7842: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7843: my $chgtext;
7844: foreach my $type (@{$srchtypeorder}) {
7845: if (grep(/^\Q$type\E$/,@searchtypes)) {
7846: if (defined($srchtypes_desc->{$type})) {
7847: $chgtext .= $srchtypes_desc->{$type}.'; ';
7848: }
7849: }
7850: }
7851: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 7852: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7853: }
7854: $resulttext .= '</ul>';
7855: } else {
7856: $resulttext = &mt('No changes made to institution directory search settings');
7857: }
7858: } else {
7859: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7860: &mt('An error occurred: [_1]',$putresult).'</span>';
7861: }
7862: return $resulttext;
7863: }
7864:
1.28 raeburn 7865: sub modify_contacts {
1.160.6.24 raeburn 7866: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7867: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7868: if (ref($domconfig{'contacts'}) eq 'HASH') {
7869: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7870: $currsetting{$key} = $domconfig{'contacts'}{$key};
7871: }
7872: }
1.134 raeburn 7873: my (%others,%to,%bcc);
1.28 raeburn 7874: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7875: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 7876: 'requestsmail','updatesmail','idconflictsmail');
7877: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7878: foreach my $type (@mailings) {
7879: @{$newsetting{$type}} =
7880: &Apache::loncommon::get_env_multiple('form.'.$type);
7881: foreach my $item (@contacts) {
7882: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7883: $contacts_hash{contacts}{$type}{$item} = 1;
7884: } else {
7885: $contacts_hash{contacts}{$type}{$item} = 0;
7886: }
7887: }
7888: $others{$type} = $env{'form.'.$type.'_others'};
7889: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7890: if ($type eq 'helpdeskmail') {
7891: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7892: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7893: }
1.28 raeburn 7894: }
7895: foreach my $item (@contacts) {
7896: $to{$item} = $env{'form.'.$item};
7897: $contacts_hash{'contacts'}{$item} = $to{$item};
7898: }
1.160.6.23 raeburn 7899: foreach my $item (@toggles) {
7900: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7901: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7902: }
7903: }
1.28 raeburn 7904: if (keys(%currsetting) > 0) {
7905: foreach my $item (@contacts) {
7906: if ($to{$item} ne $currsetting{$item}) {
7907: $changes{$item} = 1;
7908: }
7909: }
7910: foreach my $type (@mailings) {
7911: foreach my $item (@contacts) {
7912: if (ref($currsetting{$type}) eq 'HASH') {
7913: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7914: push(@{$changes{$type}},$item);
7915: }
7916: } else {
7917: push(@{$changes{$type}},@{$newsetting{$type}});
7918: }
7919: }
7920: if ($others{$type} ne $currsetting{$type}{'others'}) {
7921: push(@{$changes{$type}},'others');
7922: }
1.134 raeburn 7923: if ($type eq 'helpdeskmail') {
7924: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7925: push(@{$changes{$type}},'bcc');
7926: }
7927: }
1.28 raeburn 7928: }
7929: } else {
7930: my %default;
7931: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7932: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7933: $default{'errormail'} = 'adminemail';
7934: $default{'packagesmail'} = 'adminemail';
7935: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7936: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7937: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 7938: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7939: foreach my $item (@contacts) {
7940: if ($to{$item} ne $default{$item}) {
7941: $changes{$item} = 1;
1.160.6.23 raeburn 7942: }
1.28 raeburn 7943: }
7944: foreach my $type (@mailings) {
7945: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7946:
7947: push(@{$changes{$type}},@{$newsetting{$type}});
7948: }
7949: if ($others{$type} ne '') {
7950: push(@{$changes{$type}},'others');
1.134 raeburn 7951: }
7952: if ($type eq 'helpdeskmail') {
7953: if ($bcc{$type} ne '') {
7954: push(@{$changes{$type}},'bcc');
7955: }
7956: }
1.28 raeburn 7957: }
7958: }
1.160.6.23 raeburn 7959: foreach my $item (@toggles) {
7960: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
7961: $changes{$item} = 1;
7962: } elsif ((!$env{'form.'.$item}) &&
7963: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
7964: $changes{$item} = 1;
7965: }
7966: }
1.28 raeburn 7967: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
7968: $dom);
7969: if ($putresult eq 'ok') {
7970: if (keys(%changes) > 0) {
1.160.6.24 raeburn 7971: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7972: if (ref($lastactref) eq 'HASH') {
7973: $lastactref->{'domainconfig'} = 1;
7974: }
1.28 raeburn 7975: my ($titles,$short_titles) = &contact_titles();
7976: $resulttext = &mt('Changes made:').'<ul>';
7977: foreach my $item (@contacts) {
7978: if ($changes{$item}) {
7979: $resulttext .= '<li>'.$titles->{$item}.
7980: &mt(' set to: ').
7981: '<span class="LC_cusr_emph">'.
7982: $to{$item}.'</span></li>';
7983: }
7984: }
7985: foreach my $type (@mailings) {
7986: if (ref($changes{$type}) eq 'ARRAY') {
7987: $resulttext .= '<li>'.$titles->{$type}.': ';
7988: my @text;
7989: foreach my $item (@{$newsetting{$type}}) {
7990: push(@text,$short_titles->{$item});
7991: }
7992: if ($others{$type} ne '') {
7993: push(@text,$others{$type});
7994: }
7995: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 7996: join(', ',@text).'</span>';
7997: if ($type eq 'helpdeskmail') {
7998: if ($bcc{$type} ne '') {
7999: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8000: }
8001: }
8002: $resulttext .= '</li>';
1.28 raeburn 8003: }
8004: }
1.160.6.23 raeburn 8005: my @offon = ('off','on');
8006: if ($changes{'reporterrors'}) {
8007: $resulttext .= '<li>'.
8008: &mt('E-mail error reports to [_1] set to "'.
8009: $offon[$env{'form.reporterrors'}].'".',
8010: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8011: &mt('LON-CAPA core group - MSU'),600,500)).
8012: '</li>';
8013: }
8014: if ($changes{'reportupdates'}) {
8015: $resulttext .= '<li>'.
8016: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8017: $offon[$env{'form.reportupdates'}].'".',
8018: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8019: &mt('LON-CAPA core group - MSU'),600,500)).
8020: '</li>';
8021: }
1.28 raeburn 8022: $resulttext .= '</ul>';
8023: } else {
1.34 raeburn 8024: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8025: }
8026: } else {
8027: $resulttext = '<span class="LC_error">'.
8028: &mt('An error occurred: [_1].',$putresult).'</span>';
8029: }
8030: return $resulttext;
8031: }
8032:
8033: sub modify_usercreation {
1.27 raeburn 8034: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8035: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8036: my $warningmsg;
1.27 raeburn 8037: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8038: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8039: if ($key eq 'cancreate') {
8040: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8041: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8042: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8043: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8044: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8045: } else {
8046: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8047: }
1.50 raeburn 8048: }
1.43 raeburn 8049: }
1.160.6.34 raeburn 8050: } elsif ($key eq 'email_rule') {
8051: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8052: } else {
8053: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8054: }
8055: }
1.34 raeburn 8056: }
1.160.6.34 raeburn 8057: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8058: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8059: my @contexts = ('author','course','requestcrs');
8060: foreach my $item(@contexts) {
8061: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8062: }
1.34 raeburn 8063: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8064: foreach my $item (@contexts) {
1.160.6.34 raeburn 8065: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8066: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8067: }
1.27 raeburn 8068: }
1.34 raeburn 8069: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8070: foreach my $item (@contexts) {
1.43 raeburn 8071: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8072: if ($cancreate{$item} ne 'any') {
8073: push(@{$changes{'cancreate'}},$item);
8074: }
8075: } else {
8076: if ($cancreate{$item} ne 'none') {
8077: push(@{$changes{'cancreate'}},$item);
8078: }
1.27 raeburn 8079: }
8080: }
8081: } else {
1.43 raeburn 8082: foreach my $item (@contexts) {
1.34 raeburn 8083: push(@{$changes{'cancreate'}},$item);
8084: }
1.27 raeburn 8085: }
1.34 raeburn 8086:
1.27 raeburn 8087: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8088: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8089: if (!grep(/^\Q$type\E$/,@username_rule)) {
8090: push(@{$changes{'username_rule'}},$type);
8091: }
8092: }
8093: foreach my $type (@username_rule) {
8094: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8095: push(@{$changes{'username_rule'}},$type);
8096: }
8097: }
8098: } else {
8099: push(@{$changes{'username_rule'}},@username_rule);
8100: }
8101:
1.32 raeburn 8102: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8103: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8104: if (!grep(/^\Q$type\E$/,@id_rule)) {
8105: push(@{$changes{'id_rule'}},$type);
8106: }
8107: }
8108: foreach my $type (@id_rule) {
8109: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8110: push(@{$changes{'id_rule'}},$type);
8111: }
8112: }
8113: } else {
8114: push(@{$changes{'id_rule'}},@id_rule);
8115: }
8116:
1.43 raeburn 8117: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8118: my @authtypes = ('int','krb4','krb5','loc');
8119: my %authhash;
1.43 raeburn 8120: foreach my $item (@authen_contexts) {
1.28 raeburn 8121: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8122: foreach my $auth (@authtypes) {
8123: if (grep(/^\Q$auth\E$/,@authallowed)) {
8124: $authhash{$item}{$auth} = 1;
8125: } else {
8126: $authhash{$item}{$auth} = 0;
8127: }
8128: }
8129: }
8130: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8131: foreach my $item (@authen_contexts) {
1.28 raeburn 8132: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8133: foreach my $auth (@authtypes) {
8134: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8135: push(@{$changes{'authtypes'}},$item);
8136: last;
8137: }
8138: }
8139: }
8140: }
8141: } else {
1.43 raeburn 8142: foreach my $item (@authen_contexts) {
1.28 raeburn 8143: push(@{$changes{'authtypes'}},$item);
8144: }
8145: }
8146:
1.160.6.34 raeburn 8147: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8148: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8149: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8150: $save_usercreate{'id_rule'} = \@id_rule;
8151: $save_usercreate{'username_rule'} = \@username_rule,
8152: $save_usercreate{'authtypes'} = \%authhash;
8153:
1.27 raeburn 8154: my %usercreation_hash = (
1.160.6.34 raeburn 8155: usercreation => \%save_usercreate,
8156: );
1.27 raeburn 8157:
8158: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8159: $dom);
1.50 raeburn 8160:
1.160.6.34 raeburn 8161: if ($putresult eq 'ok') {
8162: if (keys(%changes) > 0) {
8163: $resulttext = &mt('Changes made:').'<ul>';
8164: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8165: my %lt = &usercreation_types();
8166: foreach my $type (@{$changes{'cancreate'}}) {
8167: my $chgtext = $lt{$type}.', ';
8168: if ($cancreate{$type} eq 'none') {
8169: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8170: } elsif ($cancreate{$type} eq 'any') {
8171: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8172: } elsif ($cancreate{$type} eq 'official') {
8173: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8174: } elsif ($cancreate{$type} eq 'unofficial') {
8175: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8176: }
8177: $resulttext .= '<li>'.$chgtext.'</li>';
8178: }
8179: }
8180: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8181: my ($rules,$ruleorder) =
8182: &Apache::lonnet::inst_userrules($dom,'username');
8183: my $chgtext = '<ul>';
8184: foreach my $type (@username_rule) {
8185: if (ref($rules->{$type}) eq 'HASH') {
8186: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8187: }
8188: }
8189: $chgtext .= '</ul>';
8190: if (@username_rule > 0) {
8191: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8192: } else {
8193: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8194: }
8195: }
8196: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8197: my ($idrules,$idruleorder) =
8198: &Apache::lonnet::inst_userrules($dom,'id');
8199: my $chgtext = '<ul>';
8200: foreach my $type (@id_rule) {
8201: if (ref($idrules->{$type}) eq 'HASH') {
8202: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8203: }
8204: }
8205: $chgtext .= '</ul>';
8206: if (@id_rule > 0) {
8207: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8208: } else {
8209: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8210: }
8211: }
8212: my %authname = &authtype_names();
8213: my %context_title = &context_names();
8214: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8215: my $chgtext = '<ul>';
8216: foreach my $type (@{$changes{'authtypes'}}) {
8217: my @allowed;
8218: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8219: foreach my $auth (@authtypes) {
8220: if ($authhash{$type}{$auth}) {
8221: push(@allowed,$authname{$auth});
8222: }
8223: }
8224: if (@allowed > 0) {
8225: $chgtext .= join(', ',@allowed).'</li>';
8226: } else {
8227: $chgtext .= &mt('none').'</li>';
8228: }
8229: }
8230: $chgtext .= '</ul>';
8231: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8232: $resulttext .= '</li>';
8233: }
8234: $resulttext .= '</ul>';
8235: } else {
8236: $resulttext = &mt('No changes made to user creation settings');
8237: }
8238: } else {
8239: $resulttext = '<span class="LC_error">'.
8240: &mt('An error occurred: [_1]',$putresult).'</span>';
8241: }
8242: if ($warningmsg ne '') {
8243: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8244: }
8245: return $resulttext;
8246: }
8247:
8248: sub modify_selfcreation {
8249: my ($dom,%domconfig) = @_;
8250: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8251: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8252: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8253: if (ref($types) eq 'ARRAY') {
8254: $usertypes->{'default'} = $othertitle;
8255: push(@{$types},'default');
8256: }
1.160.6.34 raeburn 8257: #
8258: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8259: #
8260: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8261: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8262: if ($key eq 'cancreate') {
8263: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8264: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8265: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8266: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8267: ($item eq 'emailusername') || ($item eq 'notify') ||
8268: ($item eq 'selfcreateprocessing')) {
1.160.6.34 raeburn 8269: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8270: } else {
8271: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8272: }
8273: }
8274: }
8275: } elsif ($key eq 'email_rule') {
8276: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8277: } else {
8278: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8279: }
8280: }
8281: }
8282: #
8283: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8284: #
8285: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8286: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8287: if ($key eq 'selfcreate') {
8288: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8289: } else {
8290: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8291: }
8292: }
8293: }
8294:
8295: my @contexts = ('selfcreate');
8296: @{$cancreate{'selfcreate'}} = ();
8297: %{$cancreate{'emailusername'}} = ();
8298: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8299: %{$cancreate{'selfcreateprocessing'}} = ();
1.50 raeburn 8300: my %selfcreatetypes = (
8301: sso => 'users authenticated by institutional single sign on',
8302: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8303: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8304: );
1.160.6.34 raeburn 8305: #
8306: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8307: # is permitted.
8308: #
1.160.6.40 raeburn 8309:
8310: my @statuses;
8311: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8312: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8313: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8314: }
8315: }
8316: push(@statuses,'default');
8317:
1.160.6.35 raeburn 8318: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8319: if ($item eq 'email') {
1.160.6.40 raeburn 8320: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8321: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8322: push(@contexts,'selfcreateprocessing');
8323: foreach my $type (@statuses) {
8324: if ($type eq 'default') {
8325: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8326: } else {
8327: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8328: }
8329: }
1.160.6.34 raeburn 8330: }
8331: } else {
8332: if ($env{'form.cancreate_'.$item}) {
8333: push(@{$cancreate{'selfcreate'}},$item);
8334: }
8335: }
8336: }
8337: my (@email_rule,%userinfo,%savecaptcha);
8338: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8339: #
1.160.6.35 raeburn 8340: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8341: # 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 8342: #
1.160.6.40 raeburn 8343:
8344: if ($env{'form.cancreate_email'} eq 'email') {
1.160.6.37 raeburn 8345: push(@contexts,'emailusername');
1.160.6.35 raeburn 8346: if (ref($types) eq 'ARRAY') {
8347: foreach my $type (@{$types}) {
8348: if (ref($infofields) eq 'ARRAY') {
8349: foreach my $field (@{$infofields}) {
8350: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8351: $cancreate{'emailusername'}{$type}{$field} = $1;
8352: }
8353: }
1.160.6.34 raeburn 8354: }
8355: }
8356: }
8357: #
8358: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8359: # queued requests for self-creation of account using e-mail address as username
8360: #
8361:
8362: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8363: @approvalnotify = sort(@approvalnotify);
8364: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8365: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8366: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8367: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8368: push(@{$changes{'cancreate'}},'notify');
8369: }
8370: } else {
8371: if ($cancreate{'notify'}{'approval'}) {
8372: push(@{$changes{'cancreate'}},'notify');
8373: }
8374: }
8375: } elsif ($cancreate{'notify'}{'approval'}) {
8376: push(@{$changes{'cancreate'}},'notify');
8377: }
8378:
8379: #
8380: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8381: #
8382: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8383: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8384: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8385: if (@{$curr_usercreation{'email_rule'}} > 0) {
8386: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8387: if (!grep(/^\Q$type\E$/,@email_rule)) {
8388: push(@{$changes{'email_rule'}},$type);
8389: }
8390: }
8391: }
8392: if (@email_rule > 0) {
8393: foreach my $type (@email_rule) {
8394: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8395: push(@{$changes{'email_rule'}},$type);
8396: }
8397: }
8398: }
8399: } elsif (@email_rule > 0) {
8400: push(@{$changes{'email_rule'}},@email_rule);
8401: }
8402: }
8403: #
1.160.6.40 raeburn 8404: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8405: # institutional log-in.
8406: #
8407: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8408: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8409: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8410: ($domdefaults{'auth_def'} eq 'localauth'))) {
8411: $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.').' '.
8412: &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.');
8413: }
8414: }
8415: my @fields = ('lastname','firstname','middlename','generation',
8416: 'permanentemail','id');
8417: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8418: #
8419: # Where usernames may created for institutional log-in and/or institutional single sign on:
8420: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8421: # may self-create accounts
8422: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8423: # which the user may supply, if institutional data is unavailable.
8424: #
8425: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8426: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8427: if (@{$types} > 1) {
1.160.6.34 raeburn 8428: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8429: push(@contexts,'statustocreate');
8430: } else {
8431: undef($cancreate{'statustocreate'});
8432: }
8433: foreach my $type (@{$types}) {
8434: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8435: foreach my $field (@fields) {
8436: if (grep(/^\Q$field\E$/,@modifiable)) {
8437: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8438: } else {
8439: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8440: }
8441: }
8442: }
8443: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8444: foreach my $type (@{$types}) {
8445: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8446: foreach my $field (@fields) {
8447: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8448: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8449: push(@{$changes{'selfcreate'}},$type);
8450: last;
8451: }
8452: }
8453: }
8454: }
8455: } else {
8456: foreach my $type (@{$types}) {
8457: push(@{$changes{'selfcreate'}},$type);
8458: }
8459: }
8460: }
8461: }
8462: foreach my $item (@contexts) {
8463: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8464: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8465: if (ref($cancreate{$item}) eq 'ARRAY') {
8466: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8467: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8468: push(@{$changes{'cancreate'}},$item);
8469: }
8470: }
8471: }
8472: }
8473: if (ref($cancreate{$item}) eq 'ARRAY') {
8474: foreach my $type (@{$cancreate{$item}}) {
8475: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8476: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8477: push(@{$changes{'cancreate'}},$item);
8478: }
8479: }
8480: }
8481: }
8482: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8483: if (ref($cancreate{$item}) eq 'HASH') {
8484: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8485: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8486: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8487: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8488: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8489: push(@{$changes{'cancreate'}},$item);
8490: }
8491: }
8492: }
1.160.6.40 raeburn 8493: } elsif ($item eq 'selfcreateprocessing') {
8494: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8495: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8496: push(@{$changes{'cancreate'}},$item);
8497: }
8498: }
1.160.6.35 raeburn 8499: } else {
8500: if (!$cancreate{$item}{$curr}) {
8501: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8502: push(@{$changes{'cancreate'}},$item);
8503: }
1.160.6.34 raeburn 8504: }
8505: }
8506: }
8507: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8508: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8509: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8510: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8511: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8512: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8513: push(@{$changes{'cancreate'}},$item);
8514: }
8515: }
8516: } else {
8517: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8518: push(@{$changes{'cancreate'}},$item);
8519: }
8520: }
8521: }
1.160.6.40 raeburn 8522: } elsif ($item eq 'selfcreateprocessing') {
8523: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8524: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8525: push(@{$changes{'cancreate'}},$item);
8526: }
8527: }
1.160.6.35 raeburn 8528: } else {
8529: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8530: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8531: push(@{$changes{'cancreate'}},$item);
8532: }
1.160.6.34 raeburn 8533: }
8534: }
8535: }
8536: }
8537: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8538: if (ref($cancreate{$item}) eq 'ARRAY') {
8539: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8540: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8541: push(@{$changes{'cancreate'}},$item);
8542: }
8543: }
8544: } elsif (ref($cancreate{$item}) eq 'HASH') {
8545: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8546: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8547: push(@{$changes{'cancreate'}},$item);
8548: }
8549: }
8550: }
8551: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8552: if (ref($cancreate{$item}) eq 'HASH') {
8553: foreach my $type (keys(%{$cancreate{$item}})) {
8554: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8555: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8556: if ($cancreate{$item}{$type}{$field}) {
8557: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8558: push(@{$changes{'cancreate'}},$item);
8559: }
8560: last;
8561: }
8562: }
8563: }
8564: }
1.160.6.34 raeburn 8565: }
8566: }
8567: }
8568: #
8569: # Populate %save_usercreate hash with updates to self-creation configuration.
8570: #
8571: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8572: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8573: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8574: if (ref($cancreate{'notify'}) eq 'HASH') {
8575: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8576: }
1.160.6.40 raeburn 8577: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8578: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8579: }
1.160.6.34 raeburn 8580: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8581: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8582: }
8583: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8584: $save_usercreate{'emailrule'} = \@email_rule;
8585:
8586: my %userconfig_hash = (
8587: usercreation => \%save_usercreate,
8588: usermodification => \%save_usermodify,
8589: );
8590: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8591: $dom);
8592: #
8593: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8594: #
1.27 raeburn 8595: if ($putresult eq 'ok') {
8596: if (keys(%changes) > 0) {
8597: $resulttext = &mt('Changes made:').'<ul>';
8598: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8599: my %lt = &selfcreation_types();
1.34 raeburn 8600: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8601: my $chgtext;
1.45 raeburn 8602: if ($type eq 'selfcreate') {
1.50 raeburn 8603: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8604: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8605: } else {
1.160.6.34 raeburn 8606: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8607: '<ul>';
1.50 raeburn 8608: foreach my $case (@{$cancreate{$type}}) {
8609: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8610: }
8611: $chgtext .= '</ul>';
1.100 raeburn 8612: if (ref($cancreate{$type}) eq 'ARRAY') {
8613: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8614: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8615: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8616: $chgtext .= '<br />'.
8617: '<span class="LC_warning">'.
8618: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8619: '</span>';
1.100 raeburn 8620: }
8621: }
8622: }
8623: }
1.43 raeburn 8624: }
1.93 raeburn 8625: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8626: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8627: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8628: if (@{$cancreate{'selfcreate'}} > 0) {
8629: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8630: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8631: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8632: $chgtext .= '<br />'.
8633: '<span class="LC_warning">'.
8634: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8635: '</span>';
8636: }
1.96 raeburn 8637: } elsif (ref($usertypes) eq 'HASH') {
8638: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8639: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8640: } else {
8641: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8642: }
8643: $chgtext .= '<ul>';
8644: foreach my $case (@{$cancreate{$type}}) {
8645: if ($case eq 'default') {
8646: $chgtext .= '<li>'.$othertitle.'</li>';
8647: } else {
8648: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8649: }
8650: }
1.100 raeburn 8651: $chgtext .= '</ul>';
8652: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8653: $chgtext .= '<br /><span class="LC_warning">'.
8654: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8655: '</span>';
1.100 raeburn 8656: }
8657: }
8658: } else {
8659: if (@{$cancreate{$type}} == 0) {
8660: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8661: } else {
8662: $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 8663: }
8664: }
8665: }
1.160.6.40 raeburn 8666: } elsif ($type eq 'selfcreateprocessing') {
8667: my %choices = &Apache::lonlocal::texthash (
8668: automatic => 'Automatic approval',
8669: approval => 'Queued for approval',
8670: );
8671: if (@statuses > 1) {
8672: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8673: '<ul>';
8674: foreach my $type (@statuses) {
8675: if ($type eq 'default') {
8676: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8677: } else {
8678: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8679: }
8680: }
8681: $chgtext .= '</ul>';
8682: } else {
8683: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8684: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8685: }
1.160.6.5 raeburn 8686: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8687: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8688: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8689: } else {
8690: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8691: if ($captchas{$savecaptcha{$type}}) {
8692: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8693: } else {
8694: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8695: }
8696: }
8697: } elsif ($type eq 'recaptchakeys') {
8698: my ($privkey,$pubkey);
1.160.6.34 raeburn 8699: if (ref($savecaptcha{$type}) eq 'HASH') {
8700: $pubkey = $savecaptcha{$type}{'public'};
8701: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8702: }
8703: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8704: if (!$pubkey) {
8705: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8706: } else {
8707: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8708: }
8709: if (!$privkey) {
8710: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8711: } else {
8712: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8713: }
8714: $chgtext .= '</ul>';
1.160.6.34 raeburn 8715: } elsif ($type eq 'emailusername') {
8716: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8717: if (ref($types) eq 'ARRAY') {
8718: foreach my $type (@{$types}) {
8719: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8720: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8721: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8722: '<ul>';
8723: foreach my $field (@{$infofields}) {
8724: if ($cancreate{'emailusername'}{$type}{$field}) {
8725: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8726: }
8727: }
8728: }
8729: $chgtext .= '</ul>';
8730: } else {
8731: $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 8732: }
8733: }
8734: }
8735: }
8736: } elsif ($type eq 'notify') {
8737: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8738: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8739: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8740: if ($cancreate{'notify'}{'approval'}) {
8741: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8742: }
8743: }
1.43 raeburn 8744: }
1.34 raeburn 8745: }
1.160.6.34 raeburn 8746: if ($chgtext) {
8747: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8748: }
8749: }
8750: }
1.43 raeburn 8751: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8752: my ($emailrules,$emailruleorder) =
8753: &Apache::lonnet::inst_userrules($dom,'email');
8754: my $chgtext = '<ul>';
8755: foreach my $type (@email_rule) {
8756: if (ref($emailrules->{$type}) eq 'HASH') {
8757: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8758: }
8759: }
8760: $chgtext .= '</ul>';
8761: if (@email_rule > 0) {
1.160.6.34 raeburn 8762: $resulttext .= '<li>'.
8763: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8764: $chgtext.
8765: '</li>';
1.43 raeburn 8766: } else {
1.160.6.34 raeburn 8767: $resulttext .= '<li>'.
8768: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8769: '</li>';
1.43 raeburn 8770: }
8771: }
1.160.6.34 raeburn 8772: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8773: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8774: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8775: foreach my $type (@{$changes{'selfcreate'}}) {
8776: my $typename = $type;
8777: if (ref($usertypes) eq 'HASH') {
8778: if ($usertypes->{$type} ne '') {
8779: $typename = $usertypes->{$type};
1.28 raeburn 8780: }
8781: }
1.160.6.34 raeburn 8782: my @modifiable;
8783: $resulttext .= '<li>'.
8784: &mt('Self-creation of account by users with status: [_1]',
8785: '<span class="LC_cusr_emph">'.$typename.'</span>').
8786: ' - '.&mt('modifiable fields (if institutional data blank): ');
8787: foreach my $field (@fields) {
8788: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8789: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
8790: }
8791: }
8792: if (@modifiable > 0) {
8793: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8794: } else {
1.160.6.34 raeburn 8795: $resulttext .= &mt('none');
1.43 raeburn 8796: }
1.160.6.34 raeburn 8797: $resulttext .= '</li>';
1.28 raeburn 8798: }
1.160.6.34 raeburn 8799: $resulttext .= '</ul></li>';
1.28 raeburn 8800: }
1.27 raeburn 8801: $resulttext .= '</ul>';
8802: } else {
1.160.6.34 raeburn 8803: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8804: }
8805: } else {
8806: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8807: &mt('An error occurred: [_1]',$putresult).'</span>';
8808: }
1.43 raeburn 8809: if ($warningmsg ne '') {
8810: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8811: }
1.23 raeburn 8812: return $resulttext;
8813: }
8814:
1.160.6.5 raeburn 8815: sub process_captcha {
8816: my ($container,$changes,$newsettings,$current) = @_;
8817: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8818: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8819: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8820: $newsettings->{'captcha'} = 'original';
8821: }
8822: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
8823: if ($container eq 'cancreate') {
8824: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8825: push(@{$changes->{'cancreate'}},'captcha');
8826: } elsif (!defined($changes->{'cancreate'})) {
8827: $changes->{'cancreate'} = ['captcha'];
8828: }
8829: } else {
8830: $changes->{'captcha'} = 1;
8831: }
8832: }
8833: my ($newpub,$newpriv,$currpub,$currpriv);
8834: if ($newsettings->{'captcha'} eq 'recaptcha') {
8835: $newpub = $env{'form.'.$container.'_recaptchapub'};
8836: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
8837: $newpub =~ s/\W//g;
8838: $newpriv =~ s/\W//g;
8839: $newsettings->{'recaptchakeys'} = {
8840: public => $newpub,
8841: private => $newpriv,
8842: };
8843: }
8844: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8845: $currpub = $current->{'recaptchakeys'}{'public'};
8846: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 8847: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8848: $newsettings->{'recaptchakeys'} = {
8849: public => '',
8850: private => '',
8851: }
8852: }
1.160.6.5 raeburn 8853: }
8854: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
8855: if ($container eq 'cancreate') {
8856: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8857: push(@{$changes->{'cancreate'}},'recaptchakeys');
8858: } elsif (!defined($changes->{'cancreate'})) {
8859: $changes->{'cancreate'} = ['recaptchakeys'];
8860: }
8861: } else {
8862: $changes->{'recaptchakeys'} = 1;
8863: }
8864: }
8865: return;
8866: }
8867:
1.33 raeburn 8868: sub modify_usermodification {
8869: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8870: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8871: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8872: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 8873: if ($key eq 'selfcreate') {
8874: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8875: } else {
8876: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8877: }
1.33 raeburn 8878: }
8879: }
1.160.6.34 raeburn 8880: my @contexts = ('author','course');
1.33 raeburn 8881: my %context_title = (
8882: author => 'In author context',
8883: course => 'In course context',
8884: );
8885: my @fields = ('lastname','firstname','middlename','generation',
8886: 'permanentemail','id');
8887: my %roles = (
8888: author => ['ca','aa'],
8889: course => ['st','ep','ta','in','cr'],
8890: );
8891: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8892: foreach my $context (@contexts) {
8893: foreach my $role (@{$roles{$context}}) {
8894: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8895: foreach my $item (@fields) {
8896: if (grep(/^\Q$item\E$/,@modifiable)) {
8897: $modifyhash{$context}{$role}{$item} = 1;
8898: } else {
8899: $modifyhash{$context}{$role}{$item} = 0;
8900: }
8901: }
8902: }
8903: if (ref($curr_usermodification{$context}) eq 'HASH') {
8904: foreach my $role (@{$roles{$context}}) {
8905: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8906: foreach my $field (@fields) {
8907: if ($modifyhash{$context}{$role}{$field} ne
8908: $curr_usermodification{$context}{$role}{$field}) {
8909: push(@{$changes{$context}},$role);
8910: last;
8911: }
8912: }
8913: }
8914: }
8915: } else {
8916: foreach my $context (@contexts) {
8917: foreach my $role (@{$roles{$context}}) {
8918: push(@{$changes{$context}},$role);
8919: }
8920: }
8921: }
8922: }
8923: my %usermodification_hash = (
8924: usermodification => \%modifyhash,
8925: );
8926: my $putresult = &Apache::lonnet::put_dom('configuration',
8927: \%usermodification_hash,$dom);
8928: if ($putresult eq 'ok') {
8929: if (keys(%changes) > 0) {
8930: $resulttext = &mt('Changes made: ').'<ul>';
8931: foreach my $context (@contexts) {
8932: if (ref($changes{$context}) eq 'ARRAY') {
8933: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8934: if (ref($changes{$context}) eq 'ARRAY') {
8935: foreach my $role (@{$changes{$context}}) {
8936: my $rolename;
1.160.6.34 raeburn 8937: if ($role eq 'cr') {
8938: $rolename = &mt('Custom');
1.33 raeburn 8939: } else {
1.160.6.34 raeburn 8940: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8941: }
8942: my @modifiable;
1.160.6.34 raeburn 8943: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8944: foreach my $field (@fields) {
8945: if ($modifyhash{$context}{$role}{$field}) {
8946: push(@modifiable,$fieldtitles{$field});
8947: }
8948: }
8949: if (@modifiable > 0) {
8950: $resulttext .= join(', ',@modifiable);
8951: } else {
8952: $resulttext .= &mt('none');
8953: }
8954: $resulttext .= '</li>';
8955: }
8956: $resulttext .= '</ul></li>';
8957: }
8958: }
8959: }
8960: $resulttext .= '</ul>';
8961: } else {
8962: $resulttext = &mt('No changes made to user modification settings');
8963: }
8964: } else {
8965: $resulttext = '<span class="LC_error">'.
8966: &mt('An error occurred: [_1]',$putresult).'</span>';
8967: }
8968: return $resulttext;
8969: }
8970:
1.43 raeburn 8971: sub modify_defaults {
1.160.6.27 raeburn 8972: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 8973: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 8974: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 8975: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 8976: my @authtypes = ('internal','krb4','krb5','localauth');
8977: foreach my $item (@items) {
8978: $newvalues{$item} = $env{'form.'.$item};
8979: if ($item eq 'auth_def') {
8980: if ($newvalues{$item} ne '') {
8981: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
8982: push(@errors,$item);
8983: }
8984: }
8985: } elsif ($item eq 'lang_def') {
8986: if ($newvalues{$item} ne '') {
8987: if ($newvalues{$item} =~ /^(\w+)/) {
8988: my $langcode = $1;
1.103 raeburn 8989: if ($langcode ne 'x_chef') {
8990: if (code2language($langcode) eq '') {
8991: push(@errors,$item);
8992: }
1.43 raeburn 8993: }
8994: } else {
8995: push(@errors,$item);
8996: }
8997: }
1.54 raeburn 8998: } elsif ($item eq 'timezone_def') {
8999: if ($newvalues{$item} ne '') {
1.62 raeburn 9000: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9001: push(@errors,$item);
9002: }
9003: }
1.68 raeburn 9004: } elsif ($item eq 'datelocale_def') {
9005: if ($newvalues{$item} ne '') {
9006: my @datelocale_ids = DateTime::Locale->ids();
9007: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9008: push(@errors,$item);
9009: }
9010: }
1.141 raeburn 9011: } elsif ($item eq 'portal_def') {
9012: if ($newvalues{$item} ne '') {
9013: 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])\/?$/) {
9014: push(@errors,$item);
9015: }
9016: }
1.43 raeburn 9017: }
9018: if (grep(/^\Q$item\E$/,@errors)) {
9019: $newvalues{$item} = $domdefaults{$item};
9020: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9021: $changes{$item} = 1;
9022: }
1.72 raeburn 9023: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9024: }
9025: my %defaults_hash = (
1.72 raeburn 9026: defaults => \%newvalues,
9027: );
1.43 raeburn 9028: my $title = &defaults_titles();
1.160.6.40 raeburn 9029:
9030: my $currinststatus;
9031: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9032: $currinststatus = $domconfig{'inststatus'};
9033: } else {
9034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9035: $currinststatus = {
9036: inststatustypes => $usertypes,
9037: inststatusorder => $types,
9038: inststatusguest => [],
9039: };
9040: }
9041: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9042: my @allpos;
9043: my %guests;
9044: my %alltypes;
9045: my ($currtitles,$currguests,$currorder);
9046: if (ref($currinststatus) eq 'HASH') {
9047: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9048: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9049: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9050: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9051: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9052: }
9053: }
9054: unless (grep(/^\Q$type\E$/,@todelete)) {
9055: my $position = $env{'form.inststatus_pos_'.$type};
9056: $position =~ s/\D+//g;
9057: $allpos[$position] = $type;
9058: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9059: $alltypes{$type} =~ s/`//g;
9060: if ($env{'form.inststatus_guest_'.$type}) {
9061: $guests{$type} = 1;
9062: }
9063: }
9064: }
9065: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9066: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9067: }
9068: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9069: $currtitles =~ s/,$//;
9070: }
9071: }
9072: if ($env{'form.addinststatus'}) {
9073: my $newtype = $env{'form.addinststatus'};
9074: $newtype =~ s/\W//g;
9075: unless (exists($alltypes{$newtype})) {
9076: if ($env{'form.addinststatus_guest'}) {
9077: $guests{$newtype} = 1;
9078: }
9079: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9080: $alltypes{$newtype} =~ s/`//g;
9081: my $position = $env{'form.addinststatus_pos'};
9082: $position =~ s/\D+//g;
9083: if ($position ne '') {
9084: $allpos[$position] = $newtype;
9085: }
9086: }
9087: }
9088: my (@orderedstatus,@orderedguests);
9089: foreach my $type (@allpos) {
9090: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9091: push(@orderedstatus,$type);
9092: if ($guests{$type}) {
9093: push(@orderedguests,$type);
9094: }
9095: }
9096: }
9097: foreach my $type (keys(%alltypes)) {
9098: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9099: delete($alltypes{$type});
9100: }
9101: }
9102: $defaults_hash{'inststatus'} = {
9103: inststatustypes => \%alltypes,
9104: inststatusorder => \@orderedstatus,
9105: inststatusguest => \@orderedguests,
9106: };
9107: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9108: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9109: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9110: }
9111: }
9112: if ($currorder ne join(',',@orderedstatus)) {
9113: $changes{'inststatus'}{'inststatusorder'} = 1;
9114: }
9115: if ($currguests ne join(',',@orderedguests)) {
9116: $changes{'inststatus'}{'inststatusguest'} = 1;
9117: }
9118: my $newtitles;
9119: foreach my $item (@orderedstatus) {
9120: $newtitles .= $alltypes{$item}.',';
9121: }
9122: $newtitles =~ s/,$//;
9123: if ($currtitles ne $newtitles) {
9124: $changes{'inststatus'}{'inststatustypes'} = 1;
9125: }
1.43 raeburn 9126: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9127: $dom);
9128: if ($putresult eq 'ok') {
9129: if (keys(%changes) > 0) {
9130: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9131: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9132: 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";
9133: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9134: if ($item eq 'inststatus') {
9135: if (ref($changes{'inststatus'}) eq 'HASH') {
9136: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9137: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9138: foreach my $type (@orderedstatus) {
9139: $resulttext .= $alltypes{$type}.', ';
9140: }
9141: $resulttext =~ s/, $//;
9142: $resulttext .= '</li>';
9143: }
9144: if ($changes{'inststatus'}{'inststatusguest'}) {
9145: $resulttext .= '<li>';
9146: if (@orderedguests) {
9147: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9148: foreach my $type (@orderedguests) {
9149: $resulttext .= $alltypes{$type}.', ';
9150: }
9151: $resulttext =~ s/, $//;
9152: } else {
9153: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9154: }
9155: $resulttext .= '</li>';
9156: }
9157: }
9158: } else {
9159: my $value = $env{'form.'.$item};
9160: if ($value eq '') {
9161: $value = &mt('none');
9162: } elsif ($item eq 'auth_def') {
9163: my %authnames = &authtype_names();
9164: my %shortauth = (
9165: internal => 'int',
9166: krb4 => 'krb4',
9167: krb5 => 'krb5',
9168: localauth => 'loc',
9169: );
9170: $value = $authnames{$shortauth{$value}};
9171: }
9172: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9173: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9174: }
9175: }
9176: $resulttext .= '</ul>';
9177: $mailmsgtext .= "\n";
9178: my $cachetime = 24*60*60;
1.72 raeburn 9179: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9180: if (ref($lastactref) eq 'HASH') {
9181: $lastactref->{'domdefaults'} = 1;
9182: }
1.68 raeburn 9183: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9184: my $notify = 1;
9185: if (ref($domconfig{'contacts'}) eq 'HASH') {
9186: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9187: $notify = 0;
9188: }
9189: }
9190: if ($notify) {
9191: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9192: "LON-CAPA Domain Settings Change - $dom",
9193: $mailmsgtext);
9194: }
1.54 raeburn 9195: }
1.43 raeburn 9196: } else {
1.54 raeburn 9197: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9198: }
9199: } else {
9200: $resulttext = '<span class="LC_error">'.
9201: &mt('An error occurred: [_1]',$putresult).'</span>';
9202: }
9203: if (@errors > 0) {
9204: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9205: foreach my $item (@errors) {
9206: $resulttext .= ' "'.$title->{$item}.'",';
9207: }
9208: $resulttext =~ s/,$//;
9209: }
9210: return $resulttext;
9211: }
9212:
1.46 raeburn 9213: sub modify_scantron {
1.160.6.24 raeburn 9214: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9215: my ($resulttext,%confhash,%changes,$errors);
9216: my $custom = 'custom.tab';
9217: my $default = 'default.tab';
9218: my $servadm = $r->dir_config('lonAdmEMail');
9219: my ($configuserok,$author_ok,$switchserver) =
9220: &config_check($dom,$confname,$servadm);
9221: if ($env{'form.scantronformat.filename'} ne '') {
9222: my $error;
9223: if ($configuserok eq 'ok') {
9224: if ($switchserver) {
1.130 raeburn 9225: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9226: } else {
9227: if ($author_ok eq 'ok') {
9228: my ($result,$scantronurl) =
9229: &publishlogo($r,'upload','scantronformat',$dom,
9230: $confname,'scantron','','',$custom);
9231: if ($result eq 'ok') {
9232: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9233: $changes{'scantronformat'} = 1;
1.46 raeburn 9234: } else {
9235: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9236: }
9237: } else {
9238: $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);
9239: }
9240: }
9241: } else {
9242: $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);
9243: }
9244: if ($error) {
9245: &Apache::lonnet::logthis($error);
9246: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9247: }
9248: }
1.48 raeburn 9249: if (ref($domconfig{'scantron'}) eq 'HASH') {
9250: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9251: if ($env{'form.scantronformat_del'}) {
9252: $confhash{'scantron'}{'scantronformat'} = '';
9253: $changes{'scantronformat'} = 1;
1.46 raeburn 9254: }
9255: }
9256: }
9257: if (keys(%confhash) > 0) {
9258: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9259: $dom);
9260: if ($putresult eq 'ok') {
9261: if (keys(%changes) > 0) {
1.48 raeburn 9262: if (ref($confhash{'scantron'}) eq 'HASH') {
9263: $resulttext = &mt('Changes made:').'<ul>';
9264: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9265: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9266: } else {
1.130 raeburn 9267: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9268: }
1.48 raeburn 9269: $resulttext .= '</ul>';
9270: } else {
1.130 raeburn 9271: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9272: }
9273: $resulttext .= '</ul>';
9274: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9275: if (ref($lastactref) eq 'HASH') {
9276: $lastactref->{'domainconfig'} = 1;
9277: }
1.46 raeburn 9278: } else {
1.130 raeburn 9279: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9280: }
9281: } else {
9282: $resulttext = '<span class="LC_error">'.
9283: &mt('An error occurred: [_1]',$putresult).'</span>';
9284: }
9285: } else {
1.130 raeburn 9286: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9287: }
9288: if ($errors) {
9289: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9290: $errors.'</ul>';
9291: }
9292: return $resulttext;
9293: }
9294:
1.48 raeburn 9295: sub modify_coursecategories {
9296: my ($dom,%domconfig) = @_;
1.57 raeburn 9297: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9298: $cathash);
1.48 raeburn 9299: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 9300: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9301: $cathash = $domconfig{'coursecategories'}{'cats'};
9302: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9303: $changes{'togglecats'} = 1;
9304: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9305: }
9306: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9307: $changes{'categorize'} = 1;
9308: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9309: }
1.120 raeburn 9310: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9311: $changes{'togglecatscomm'} = 1;
9312: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9313: }
9314: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9315: $changes{'categorizecomm'} = 1;
9316: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9317: }
1.57 raeburn 9318: } else {
9319: $changes{'togglecats'} = 1;
9320: $changes{'categorize'} = 1;
1.124 raeburn 9321: $changes{'togglecatscomm'} = 1;
9322: $changes{'categorizecomm'} = 1;
1.87 raeburn 9323: $domconfig{'coursecategories'} = {
9324: togglecats => $env{'form.togglecats'},
9325: categorize => $env{'form.categorize'},
1.124 raeburn 9326: togglecatscomm => $env{'form.togglecatscomm'},
9327: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9328: };
1.57 raeburn 9329: }
9330: if (ref($cathash) eq 'HASH') {
9331: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9332: push (@deletecategory,'instcode::0');
9333: }
1.120 raeburn 9334: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9335: push(@deletecategory,'communities::0');
9336: }
1.48 raeburn 9337: }
1.57 raeburn 9338: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9339: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9340: if (@deletecategory > 0) {
9341: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9342: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9343: foreach my $item (@deletecategory) {
1.57 raeburn 9344: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9345: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9346: $deletions{$item} = 1;
1.57 raeburn 9347: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9348: }
9349: }
9350: }
1.57 raeburn 9351: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9352: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9353: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9354: $reorderings{$item} = 1;
1.57 raeburn 9355: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9356: }
9357: if ($env{'form.addcategory_name_'.$item} ne '') {
9358: my $newcat = $env{'form.addcategory_name_'.$item};
9359: my $newdepth = $depth+1;
9360: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9361: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9362: $adds{$newitem} = 1;
9363: }
9364: if ($env{'form.subcat_'.$item} ne '') {
9365: my $newcat = $env{'form.subcat_'.$item};
9366: my $newdepth = $depth+1;
9367: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9368: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9369: $adds{$newitem} = 1;
9370: }
9371: }
9372: }
9373: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9374: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9375: my $newitem = 'instcode::0';
1.57 raeburn 9376: if ($cathash->{$newitem} eq '') {
9377: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9378: $adds{$newitem} = 1;
9379: }
9380: } else {
9381: my $newitem = 'instcode::0';
1.57 raeburn 9382: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9383: $adds{$newitem} = 1;
9384: }
9385: }
1.120 raeburn 9386: if ($env{'form.communities'} eq '1') {
9387: if (ref($cathash) eq 'HASH') {
9388: my $newitem = 'communities::0';
9389: if ($cathash->{$newitem} eq '') {
9390: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9391: $adds{$newitem} = 1;
9392: }
9393: } else {
9394: my $newitem = 'communities::0';
9395: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9396: $adds{$newitem} = 1;
9397: }
9398: }
1.48 raeburn 9399: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9400: if (($env{'form.addcategory_name'} ne 'instcode') &&
9401: ($env{'form.addcategory_name'} ne 'communities')) {
9402: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9403: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9404: $adds{$newitem} = 1;
9405: }
1.48 raeburn 9406: }
1.57 raeburn 9407: my $putresult;
1.48 raeburn 9408: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9409: if (keys(%deletions) > 0) {
9410: foreach my $key (keys(%deletions)) {
9411: if ($predelallitems{$key} ne '') {
9412: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9413: }
9414: }
9415: }
9416: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9417: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9418: if (ref($chkcats[0]) eq 'ARRAY') {
9419: my $depth = 0;
9420: my $chg = 0;
9421: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9422: my $name = $chkcats[0][$i];
9423: my $item;
9424: if ($name eq '') {
9425: $chg ++;
9426: } else {
9427: $item = &escape($name).'::0';
9428: if ($chg) {
1.57 raeburn 9429: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9430: }
9431: $depth ++;
1.57 raeburn 9432: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9433: $depth --;
9434: }
9435: }
9436: }
1.57 raeburn 9437: }
9438: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9439: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9440: if ($putresult eq 'ok') {
1.57 raeburn 9441: my %title = (
1.120 raeburn 9442: togglecats => 'Show/Hide a course in catalog',
9443: categorize => 'Assign a category to a course',
9444: togglecatscomm => 'Show/Hide a community in catalog',
9445: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9446: );
9447: my %level = (
1.120 raeburn 9448: dom => 'set in Domain ("Modify Course/Community")',
9449: crs => 'set in Course ("Course Configuration")',
9450: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 9451: );
1.48 raeburn 9452: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9453: if ($changes{'togglecats'}) {
9454: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9455: }
9456: if ($changes{'categorize'}) {
9457: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9458: }
1.120 raeburn 9459: if ($changes{'togglecatscomm'}) {
9460: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9461: }
9462: if ($changes{'categorizecomm'}) {
9463: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9464: }
1.57 raeburn 9465: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9466: my $cathash;
9467: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9468: $cathash = $domconfig{'coursecategories'}{'cats'};
9469: } else {
9470: $cathash = {};
9471: }
9472: my (@cats,@trails,%allitems);
9473: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9474: if (keys(%deletions) > 0) {
9475: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9476: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9477: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9478: }
9479: $resulttext .= '</ul></li>';
9480: }
9481: if (keys(%reorderings) > 0) {
9482: my %sort_by_trail;
9483: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9484: foreach my $key (keys(%reorderings)) {
9485: if ($allitems{$key} ne '') {
9486: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9487: }
1.48 raeburn 9488: }
1.57 raeburn 9489: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9490: $resulttext .= '<li>'.$trails[$trail].'</li>';
9491: }
9492: $resulttext .= '</ul></li>';
1.48 raeburn 9493: }
1.57 raeburn 9494: if (keys(%adds) > 0) {
9495: my %sort_by_trail;
9496: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9497: foreach my $key (keys(%adds)) {
9498: if ($allitems{$key} ne '') {
9499: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9500: }
9501: }
9502: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9503: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9504: }
1.57 raeburn 9505: $resulttext .= '</ul></li>';
1.48 raeburn 9506: }
9507: }
9508: $resulttext .= '</ul>';
9509: } else {
9510: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9511: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9512: }
9513: } else {
1.120 raeburn 9514: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9515: }
9516: return $resulttext;
9517: }
9518:
1.69 raeburn 9519: sub modify_serverstatuses {
9520: my ($dom,%domconfig) = @_;
9521: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9522: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9523: %currserverstatus = %{$domconfig{'serverstatuses'}};
9524: }
9525: my @pages = &serverstatus_pages();
9526: foreach my $type (@pages) {
9527: $newserverstatus{$type}{'namedusers'} = '';
9528: $newserverstatus{$type}{'machines'} = '';
9529: if (defined($env{'form.'.$type.'_namedusers'})) {
9530: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9531: my @okusers;
9532: foreach my $user (@users) {
9533: my ($uname,$udom) = split(/:/,$user);
9534: if (($udom =~ /^$match_domain$/) &&
9535: (&Apache::lonnet::domain($udom)) &&
9536: ($uname =~ /^$match_username$/)) {
9537: if (!grep(/^\Q$user\E/,@okusers)) {
9538: push(@okusers,$user);
9539: }
9540: }
9541: }
9542: if (@okusers > 0) {
9543: @okusers = sort(@okusers);
9544: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9545: }
9546: }
9547: if (defined($env{'form.'.$type.'_machines'})) {
9548: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9549: my @okmachines;
9550: foreach my $ip (@machines) {
9551: my @parts = split(/\./,$ip);
9552: next if (@parts < 4);
9553: my $badip = 0;
9554: for (my $i=0; $i<4; $i++) {
9555: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9556: $badip = 1;
9557: last;
9558: }
9559: }
9560: if (!$badip) {
9561: push(@okmachines,$ip);
9562: }
9563: }
9564: @okmachines = sort(@okmachines);
9565: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9566: }
9567: }
9568: my %serverstatushash = (
9569: serverstatuses => \%newserverstatus,
9570: );
9571: foreach my $type (@pages) {
1.83 raeburn 9572: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9573: my (@current,@new);
1.83 raeburn 9574: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9575: if ($currserverstatus{$type}{$setting} ne '') {
9576: @current = split(/,/,$currserverstatus{$type}{$setting});
9577: }
9578: }
9579: if ($newserverstatus{$type}{$setting} ne '') {
9580: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9581: }
9582: if (@current > 0) {
9583: if (@new > 0) {
9584: foreach my $item (@current) {
9585: if (!grep(/^\Q$item\E$/,@new)) {
9586: $changes{$type}{$setting} = 1;
1.82 raeburn 9587: last;
9588: }
9589: }
1.84 raeburn 9590: foreach my $item (@new) {
9591: if (!grep(/^\Q$item\E$/,@current)) {
9592: $changes{$type}{$setting} = 1;
9593: last;
1.82 raeburn 9594: }
9595: }
9596: } else {
1.83 raeburn 9597: $changes{$type}{$setting} = 1;
1.69 raeburn 9598: }
1.83 raeburn 9599: } elsif (@new > 0) {
9600: $changes{$type}{$setting} = 1;
1.69 raeburn 9601: }
9602: }
9603: }
9604: if (keys(%changes) > 0) {
1.81 raeburn 9605: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9606: my $putresult = &Apache::lonnet::put_dom('configuration',
9607: \%serverstatushash,$dom);
9608: if ($putresult eq 'ok') {
9609: $resulttext .= &mt('Changes made:').'<ul>';
9610: foreach my $type (@pages) {
1.84 raeburn 9611: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9612: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9613: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9614: if ($newserverstatus{$type}{'namedusers'} eq '') {
9615: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9616: } else {
9617: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9618: }
1.84 raeburn 9619: }
9620: if ($changes{$type}{'machines'}) {
1.69 raeburn 9621: if ($newserverstatus{$type}{'machines'} eq '') {
9622: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9623: } else {
9624: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9625: }
9626:
9627: }
9628: $resulttext .= '</ul></li>';
9629: }
9630: }
9631: $resulttext .= '</ul>';
9632: } else {
9633: $resulttext = '<span class="LC_error">'.
9634: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9635:
9636: }
9637: } else {
9638: $resulttext = &mt('No changes made to access to server status pages');
9639: }
9640: return $resulttext;
9641: }
9642:
1.118 jms 9643: sub modify_helpsettings {
1.122 jms 9644: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9645: my ($resulttext,$errors,%changes,%helphash);
9646: my %defaultchecked = ('submitbugs' => 'on');
9647: my @offon = ('off','on');
1.118 jms 9648: my @toggles = ('submitbugs');
9649: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9650: foreach my $item (@toggles) {
1.160.6.5 raeburn 9651: if ($defaultchecked{$item} eq 'on') {
9652: if ($domconfig{'helpsettings'}{$item} eq '') {
9653: if ($env{'form.'.$item} eq '0') {
9654: $changes{$item} = 1;
9655: }
9656: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9657: $changes{$item} = 1;
9658: }
9659: } elsif ($defaultchecked{$item} eq 'off') {
9660: if ($domconfig{'helpsettings'}{$item} eq '') {
9661: if ($env{'form.'.$item} eq '1') {
9662: $changes{$item} = 1;
9663: }
9664: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9665: $changes{$item} = 1;
9666: }
1.160.6.26 raeburn 9667: }
1.160.6.5 raeburn 9668: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9669: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9670: }
9671: }
1.118 jms 9672: }
1.123 jms 9673: my $putresult;
9674: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9675: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9676: if ($putresult eq 'ok') {
9677: $resulttext = &mt('Changes made:').'<ul>';
9678: foreach my $item (sort(keys(%changes))) {
9679: if ($item eq 'submitbugs') {
9680: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9681: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9682: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9683: }
9684: }
9685: $resulttext .= '</ul>';
9686: } else {
9687: $resulttext = &mt('No changes made to help settings');
9688: $errors .= '<li><span class="LC_error">'.
9689: &mt('An error occurred storing the settings: [_1]',
9690: $putresult).'</span></li>';
9691: }
1.118 jms 9692: }
9693: if ($errors) {
1.160.6.5 raeburn 9694: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9695: $errors.'</ul>';
9696: }
9697: return $resulttext;
9698: }
9699:
1.121 raeburn 9700: sub modify_coursedefaults {
1.160.6.27 raeburn 9701: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9702: my ($resulttext,$errors,%changes,%defaultshash);
9703: my %defaultchecked = ('canuse_pdfforms' => 'off');
9704: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9705: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9706: 'uploadquota_community','uploadquota_textbook');
9707: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9708: my %staticdefaults = (
9709: anonsurvey_threshold => 10,
9710: uploadquota => 500,
9711: );
1.121 raeburn 9712:
9713: $defaultshash{'coursedefaults'} = {};
9714:
9715: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9716: if ($domconfig{'coursedefaults'} eq '') {
9717: $domconfig{'coursedefaults'} = {};
9718: }
9719: }
9720:
9721: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9722: foreach my $item (@toggles) {
9723: if ($defaultchecked{$item} eq 'on') {
9724: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9725: ($env{'form.'.$item} eq '0')) {
9726: $changes{$item} = 1;
1.160.6.16 raeburn 9727: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9728: $changes{$item} = 1;
9729: }
9730: } elsif ($defaultchecked{$item} eq 'off') {
9731: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9732: ($env{'form.'.$item} eq '1')) {
9733: $changes{$item} = 1;
9734: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9735: $changes{$item} = 1;
9736: }
9737: }
9738: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9739: }
1.160.6.21 raeburn 9740: foreach my $item (@numbers) {
9741: my ($currdef,$newdef);
1.160.6.26 raeburn 9742: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 9743: if ($item eq 'anonsurvey_threshold') {
9744: $currdef = $domconfig{'coursedefaults'}{$item};
9745: $newdef =~ s/\D//g;
9746: if ($newdef eq '' || $newdef < 1) {
9747: $newdef = 1;
9748: }
9749: $defaultshash{'coursedefaults'}{$item} = $newdef;
9750: } else {
9751: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9752: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9753: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9754: }
9755: $newdef =~ s/[^\w.\-]//g;
9756: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9757: }
9758: if ($currdef ne $newdef) {
9759: my $staticdef;
9760: if ($item eq 'anonsurvey_threshold') {
9761: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9762: $changes{$item} = 1;
9763: }
9764: } else {
9765: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9766: $changes{'uploadquota'} = 1;
9767: }
9768: }
1.139 raeburn 9769: }
9770: }
1.160.6.37 raeburn 9771:
1.160.6.16 raeburn 9772: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 9773: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 9774: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 9775: $unofficialcreds =~ s/[^\d.]+//g;
9776: my $textbookcreds = $env{'form.textbook_credits'};
9777: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 9778: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9779: ($env{'form.coursecredits'} eq '1')) {
9780: $changes{'coursecredits'} = 1;
9781: } else {
9782: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 9783: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9784: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 9785: $changes{'coursecredits'} = 1;
9786: }
9787: }
9788: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9789: official => $officialcreds,
9790: unofficial => $unofficialcreds,
1.160.6.30 raeburn 9791: textbook => $textbookcreds,
1.160.6.16 raeburn 9792: }
1.121 raeburn 9793: }
9794: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9795: $dom);
9796: if ($putresult eq 'ok') {
9797: if (keys(%changes) > 0) {
1.160.6.27 raeburn 9798: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 9799: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
9800: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 9801: if ($changes{'canuse_pdfforms'}) {
9802: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9803: }
9804: if ($changes{'coursecredits'}) {
9805: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9806: $domdefaults{'officialcredits'} =
9807: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9808: $domdefaults{'unofficialcredits'} =
9809: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 9810: $domdefaults{'textbookcredits'} =
9811: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 9812: }
9813: }
1.160.6.21 raeburn 9814: if ($changes{'uploadquota'}) {
9815: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9816: foreach my $type (@types) {
9817: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9818: }
9819: }
9820: }
1.121 raeburn 9821: my $cachetime = 24*60*60;
9822: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9823: if (ref($lastactref) eq 'HASH') {
9824: $lastactref->{'domdefaults'} = 1;
9825: }
1.121 raeburn 9826: }
9827: $resulttext = &mt('Changes made:').'<ul>';
9828: foreach my $item (sort(keys(%changes))) {
9829: if ($item eq 'canuse_pdfforms') {
9830: if ($env{'form.'.$item} eq '1') {
9831: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9832: } else {
9833: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9834: }
1.139 raeburn 9835: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 9836: $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 9837: } elsif ($item eq 'uploadquota') {
9838: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9839: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9840: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9841: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 9842: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9843:
1.160.6.21 raeburn 9844: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9845: '</ul>'.
9846: '</li>';
9847: } else {
9848: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9849: }
1.160.6.16 raeburn 9850: } elsif ($item eq 'coursecredits') {
9851: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9852: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 9853: ($domdefaults{'unofficialcredits'} eq '') &&
9854: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 9855: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9856: } else {
9857: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9858: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9859: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 9860: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 9861: '</ul>'.
9862: '</li>';
9863: }
9864: } else {
9865: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9866: }
1.140 raeburn 9867: }
1.121 raeburn 9868: }
9869: $resulttext .= '</ul>';
9870: } else {
9871: $resulttext = &mt('No changes made to course defaults');
9872: }
9873: } else {
9874: $resulttext = '<span class="LC_error">'.
9875: &mt('An error occurred: [_1]',$putresult).'</span>';
9876: }
9877: return $resulttext;
9878: }
9879:
1.160.6.37 raeburn 9880: sub modify_selfenrollment {
9881: my ($dom,$lastactref,%domconfig) = @_;
9882: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9883: my @types = ('official','unofficial','community','textbook');
9884: my %titles = &tool_titles();
9885: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
9886: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
9887: $ordered{'default'} = ['types','registered','approval','limit'];
9888:
9889: my (%roles,%shown,%toplevel);
9890: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9891:
9892: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9893: if ($domconfig{'selfenrollment'} eq '') {
9894: $domconfig{'selfenrollment'} = {};
9895: }
9896: }
9897: %toplevel = (
9898: admin => 'Configuration Rights',
9899: default => 'Default settings',
9900: validation => 'Validation of self-enrollment requests',
9901: );
9902: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
9903:
9904: if (ref($ordered{'admin'}) eq 'ARRAY') {
9905: foreach my $item (@{$ordered{'admin'}}) {
9906: foreach my $type (@types) {
9907: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
9908: $selfenrollhash{'admin'}{$type}{$item} = 1;
9909: } else {
9910: $selfenrollhash{'admin'}{$type}{$item} = 0;
9911: }
9912: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
9913: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
9914: if ($selfenrollhash{'admin'}{$type}{$item} ne
9915: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
9916: push(@{$changes{'admin'}{$type}},$item);
9917: }
9918: } else {
9919: if (!$selfenrollhash{'admin'}{$type}{$item}) {
9920: push(@{$changes{'admin'}{$type}},$item);
9921: }
9922: }
9923: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
9924: push(@{$changes{'admin'}{$type}},$item);
9925: }
9926: }
9927: }
9928: }
9929:
9930: foreach my $item (@{$ordered{'default'}}) {
9931: foreach my $type (@types) {
9932: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
9933: if ($item eq 'types') {
9934: unless (($value eq 'all') || ($value eq 'dom')) {
9935: $value = '';
9936: }
9937: } elsif ($item eq 'registered') {
9938: unless ($value eq '1') {
9939: $value = 0;
9940: }
9941: } elsif ($item eq 'approval') {
9942: unless ($value =~ /^[012]$/) {
9943: $value = 0;
9944: }
9945: } else {
9946: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9947: $value = 'none';
9948: }
9949: }
9950: $selfenrollhash{'default'}{$type}{$item} = $value;
9951: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
9952: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9953: if ($selfenrollhash{'default'}{$type}{$item} ne
9954: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
9955: push(@{$changes{'default'}{$type}},$item);
9956: }
9957: } else {
9958: push(@{$changes{'default'}{$type}},$item);
9959: }
9960: } else {
9961: push(@{$changes{'default'}{$type}},$item);
9962: }
9963: if ($item eq 'limit') {
9964: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
9965: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
9966: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
9967: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
9968: }
9969: } else {
9970: $selfenrollhash{'default'}{$type}{'cap'} = '';
9971: }
9972: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
9973: if ($selfenrollhash{'default'}{$type}{'cap'} ne
9974: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
9975: push(@{$changes{'default'}{$type}},'cap');
9976: }
9977: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
9978: push(@{$changes{'default'}{$type}},'cap');
9979: }
9980: }
9981: }
9982: }
9983:
9984: foreach my $item (@{$itemsref}) {
9985: if ($item eq 'fields') {
9986: my @changed;
9987: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
9988: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
9989: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
9990: }
9991: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
9992: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
9993: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
9994: $domconfig{'selfenrollment'}{'validation'}{$item});
9995: } else {
9996: @changed = @{$selfenrollhash{'validation'}{$item}};
9997: }
9998: } else {
9999: @changed = @{$selfenrollhash{'validation'}{$item}};
10000: }
10001: if (@changed) {
10002: if ($selfenrollhash{'validation'}{$item}) {
10003: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10004: } else {
10005: $changes{'validation'}{$item} = &mt('None');
10006: }
10007: }
10008: } else {
10009: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10010: if ($item eq 'markup') {
10011: if ($env{'form.selfenroll_validation_'.$item}) {
10012: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10013: }
10014: }
10015: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10016: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10017: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10018: }
10019: }
10020: }
10021: }
10022:
10023: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10024: $dom);
10025: if ($putresult eq 'ok') {
10026: if (keys(%changes) > 0) {
10027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10028: $resulttext = &mt('Changes made:').'<ul>';
10029: foreach my $key ('admin','default','validation') {
10030: if (ref($changes{$key}) eq 'HASH') {
10031: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10032: if ($key eq 'validation') {
10033: foreach my $item (@{$itemsref}) {
10034: if (exists($changes{$key}{$item})) {
10035: if ($item eq 'markup') {
10036: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10037: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10038: } else {
10039: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10040: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10041: }
10042: }
10043: }
10044: } else {
10045: foreach my $type (@types) {
10046: if ($type eq 'community') {
10047: $roles{'1'} = &mt('Community personnel');
10048: } else {
10049: $roles{'1'} = &mt('Course personnel');
10050: }
10051: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10052: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10053: if ($key eq 'admin') {
10054: my @mgrdc = ();
10055: if (ref($ordered{$key}) eq 'ARRAY') {
10056: foreach my $item (@{$ordered{'admin'}}) {
10057: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10058: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10059: push(@mgrdc,$item);
10060: }
10061: }
10062: }
10063: if (@mgrdc) {
10064: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10065: } else {
10066: delete($domdefaults{$type.'selfenrolladmdc'});
10067: }
10068: }
10069: } else {
10070: if (ref($ordered{$key}) eq 'ARRAY') {
10071: foreach my $item (@{$ordered{$key}}) {
10072: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10073: $domdefaults{$type.'selfenroll'.$item} =
10074: $selfenrollhash{$key}{$type}{$item};
10075: }
10076: }
10077: }
10078: }
10079: }
10080: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10081: foreach my $item (@{$ordered{$key}}) {
10082: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10083: $resulttext .= '<li>';
10084: if ($key eq 'admin') {
10085: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10086: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10087: } else {
10088: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10089: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10090: }
10091: $resulttext .= '</li>';
10092: }
10093: }
10094: $resulttext .= '</ul></li>';
10095: }
10096: }
10097: $resulttext .= '</ul></li>';
10098: }
10099: }
10100: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10101: my $cachetime = 24*60*60;
10102: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10103: if (ref($lastactref) eq 'HASH') {
10104: $lastactref->{'domdefaults'} = 1;
10105: }
10106: }
10107: }
10108: $resulttext .= '</ul>';
10109: } else {
10110: $resulttext = &mt('No changes made to self-enrollment settings');
10111: }
10112: } else {
10113: $resulttext = '<span class="LC_error">'.
10114: &mt('An error occurred: [_1]',$putresult).'</span>';
10115: }
10116: return $resulttext;
10117: }
10118:
1.137 raeburn 10119: sub modify_usersessions {
1.160.6.27 raeburn 10120: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10121: my @hostingtypes = ('version','excludedomain','includedomain');
10122: my @offloadtypes = ('primary','default');
10123: my %types = (
10124: remote => \@hostingtypes,
10125: hosted => \@hostingtypes,
10126: spares => \@offloadtypes,
10127: );
10128: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10129: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10130: my (%by_ip,%by_location,@intdoms);
10131: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10132: my @locations = sort(keys(%by_location));
1.137 raeburn 10133: my (%defaultshash,%changes);
10134: foreach my $prefix (@prefixes) {
10135: $defaultshash{'usersessions'}{$prefix} = {};
10136: }
1.160.6.27 raeburn 10137: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10138: my $resulttext;
1.138 raeburn 10139: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10140: foreach my $prefix (@prefixes) {
1.145 raeburn 10141: next if ($prefix eq 'spares');
10142: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10143: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10144: if ($type eq 'version') {
10145: my $value = $env{'form.'.$prefix.'_'.$type};
10146: my $okvalue;
10147: if ($value ne '') {
10148: if (grep(/^\Q$value\E$/,@lcversions)) {
10149: $okvalue = $value;
10150: }
10151: }
10152: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10153: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10154: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10155: if ($inuse == 0) {
10156: $changes{$prefix}{$type} = 1;
10157: } else {
10158: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10159: $changes{$prefix}{$type} = 1;
10160: }
10161: if ($okvalue ne '') {
10162: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10163: }
10164: }
10165: } else {
10166: if (($inuse == 1) && ($okvalue ne '')) {
10167: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10168: $changes{$prefix}{$type} = 1;
10169: }
10170: }
10171: } else {
10172: if (($inuse == 1) && ($okvalue ne '')) {
10173: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10174: $changes{$prefix}{$type} = 1;
10175: }
10176: }
10177: } else {
10178: if (($inuse == 1) && ($okvalue ne '')) {
10179: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10180: $changes{$prefix}{$type} = 1;
10181: }
10182: }
10183: } else {
10184: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10185: my @okvals;
10186: foreach my $val (@vals) {
1.138 raeburn 10187: if ($val =~ /:/) {
10188: my @items = split(/:/,$val);
10189: foreach my $item (@items) {
10190: if (ref($by_location{$item}) eq 'ARRAY') {
10191: push(@okvals,$item);
10192: }
10193: }
10194: } else {
10195: if (ref($by_location{$val}) eq 'ARRAY') {
10196: push(@okvals,$val);
10197: }
1.137 raeburn 10198: }
10199: }
10200: @okvals = sort(@okvals);
10201: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10202: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10203: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10204: if ($inuse == 0) {
10205: $changes{$prefix}{$type} = 1;
10206: } else {
10207: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10208: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10209: if (@changed > 0) {
10210: $changes{$prefix}{$type} = 1;
10211: }
10212: }
10213: } else {
10214: if ($inuse == 1) {
10215: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10216: $changes{$prefix}{$type} = 1;
10217: }
10218: }
10219: } else {
10220: if ($inuse == 1) {
10221: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10222: $changes{$prefix}{$type} = 1;
10223: }
10224: }
10225: } else {
10226: if ($inuse == 1) {
10227: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10228: $changes{$prefix}{$type} = 1;
10229: }
10230: }
10231: }
10232: }
10233: }
1.145 raeburn 10234:
10235: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10236: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10237: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10238: my $savespares;
10239:
10240: foreach my $lonhost (sort(keys(%servers))) {
10241: my $serverhomeID =
10242: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10243: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10244: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10245: my %spareschg;
10246: foreach my $type (@{$types{'spares'}}) {
10247: my @okspares;
10248: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10249: foreach my $server (@checked) {
1.152 raeburn 10250: if (&Apache::lonnet::hostname($server) ne '') {
10251: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10252: unless (grep(/^\Q$server\E$/,@okspares)) {
10253: push(@okspares,$server);
10254: }
1.145 raeburn 10255: }
10256: }
10257: }
10258: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10259: my $newspare;
1.152 raeburn 10260: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10261: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10262: $newspare = $new;
10263: }
10264: }
1.152 raeburn 10265: my @spares;
10266: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10267: @spares = sort(@okspares,$newspare);
10268: } else {
10269: @spares = sort(@okspares);
10270: }
10271: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10272: if (ref($spareid{$lonhost}) eq 'HASH') {
10273: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10274: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10275: if (@diffs > 0) {
10276: $spareschg{$type} = 1;
10277: }
10278: }
10279: }
10280: }
10281: if (keys(%spareschg) > 0) {
10282: $changes{'spares'}{$lonhost} = \%spareschg;
10283: }
10284: }
10285:
10286: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10287: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10288: if (ref($changes{'spares'}) eq 'HASH') {
10289: if (keys(%{$changes{'spares'}}) > 0) {
10290: $savespares = 1;
10291: }
10292: }
10293: } else {
10294: $savespares = 1;
10295: }
10296: }
10297:
1.147 raeburn 10298: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10299: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10300: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10301: $dom);
10302: if ($putresult eq 'ok') {
10303: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10304: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10305: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10306: }
10307: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10308: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10309: }
10310: }
10311: my $cachetime = 24*60*60;
10312: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10313: if (ref($lastactref) eq 'HASH') {
10314: $lastactref->{'domdefaults'} = 1;
10315: }
1.147 raeburn 10316: if (keys(%changes) > 0) {
10317: my %lt = &usersession_titles();
10318: $resulttext = &mt('Changes made:').'<ul>';
10319: foreach my $prefix (@prefixes) {
10320: if (ref($changes{$prefix}) eq 'HASH') {
10321: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10322: if ($prefix eq 'spares') {
10323: if (ref($changes{$prefix}) eq 'HASH') {
10324: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10325: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10326: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10327: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10328: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10329: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10330: foreach my $type (@{$types{$prefix}}) {
10331: if ($changes{$prefix}{$lonhost}{$type}) {
10332: my $offloadto = &mt('None');
10333: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10334: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10335: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10336: }
1.145 raeburn 10337: }
1.147 raeburn 10338: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10339: }
1.137 raeburn 10340: }
10341: }
1.147 raeburn 10342: $resulttext .= '</li>';
1.137 raeburn 10343: }
10344: }
1.147 raeburn 10345: } else {
10346: foreach my $type (@{$types{$prefix}}) {
10347: if (defined($changes{$prefix}{$type})) {
10348: my $newvalue;
10349: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10350: if (ref($defaultshash{'usersessions'}{$prefix})) {
10351: if ($type eq 'version') {
10352: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10353: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10354: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10355: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10356: }
1.145 raeburn 10357: }
10358: }
10359: }
1.147 raeburn 10360: if ($newvalue eq '') {
10361: if ($type eq 'version') {
10362: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10363: } else {
10364: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10365: }
1.145 raeburn 10366: } else {
1.147 raeburn 10367: if ($type eq 'version') {
10368: $newvalue .= ' '.&mt('(or later)');
10369: }
10370: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10371: }
1.137 raeburn 10372: }
10373: }
10374: }
1.147 raeburn 10375: $resulttext .= '</ul>';
1.137 raeburn 10376: }
10377: }
1.147 raeburn 10378: $resulttext .= '</ul>';
10379: } else {
10380: $resulttext = $nochgmsg;
1.137 raeburn 10381: }
10382: } else {
10383: $resulttext = '<span class="LC_error">'.
10384: &mt('An error occurred: [_1]',$putresult).'</span>';
10385: }
10386: } else {
1.147 raeburn 10387: $resulttext = $nochgmsg;
1.137 raeburn 10388: }
10389: return $resulttext;
10390: }
10391:
1.150 raeburn 10392: sub modify_loadbalancing {
10393: my ($dom,%domconfig) = @_;
10394: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10395: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10396: my ($othertitle,$usertypes,$types) =
10397: &Apache::loncommon::sorted_inst_types($dom);
10398: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10399: my @sparestypes = ('primary','default');
10400: my %typetitles = &sparestype_titles();
10401: my $resulttext;
1.160.6.7 raeburn 10402: my (%currbalancer,%currtargets,%currrules,%existing);
10403: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10404: %existing = %{$domconfig{'loadbalancing'}};
10405: }
10406: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10407: \%currtargets,\%currrules);
10408: my ($saveloadbalancing,%defaultshash,%changes);
10409: my ($alltypes,$othertypes,$titles) =
10410: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10411: my %ruletitles = &offloadtype_text();
10412: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10413: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10414: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10415: if ($balancer eq '') {
10416: next;
10417: }
10418: if (!exists($servers{$balancer})) {
10419: if (exists($currbalancer{$balancer})) {
10420: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10421: }
1.160.6.7 raeburn 10422: next;
10423: }
10424: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10425: push(@{$changes{'delete'}},$balancer);
10426: next;
10427: }
10428: if (!exists($currbalancer{$balancer})) {
10429: push(@{$changes{'add'}},$balancer);
10430: }
10431: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10432: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10433: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10434: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10435: $saveloadbalancing = 1;
10436: }
10437: foreach my $sparetype (@sparestypes) {
10438: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10439: my @offloadto;
10440: foreach my $target (@targets) {
10441: if (($servers{$target}) && ($target ne $balancer)) {
10442: if ($sparetype eq 'default') {
10443: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10444: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10445: }
10446: }
1.160.6.7 raeburn 10447: unless(grep(/^\Q$target\E$/,@offloadto)) {
10448: push(@offloadto,$target);
10449: }
1.150 raeburn 10450: }
1.160.6.7 raeburn 10451: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10452: }
10453: }
1.160.6.7 raeburn 10454: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10455: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10456: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10457: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10458: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10459: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10460: }
1.160.6.7 raeburn 10461: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10462: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10463: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10464: }
10465: }
10466: }
10467: } else {
1.160.6.7 raeburn 10468: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10469: foreach my $sparetype (@sparestypes) {
10470: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10471: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10472: $changes{'curr'}{$balancer}{'targets'} = 1;
10473: }
1.150 raeburn 10474: }
10475: }
1.160.6.7 raeburn 10476: }
1.150 raeburn 10477: }
10478: my $ishomedom;
1.160.6.7 raeburn 10479: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10480: $ishomedom = 1;
1.150 raeburn 10481: }
10482: if (ref($alltypes) eq 'ARRAY') {
10483: foreach my $type (@{$alltypes}) {
10484: my $rule;
1.160.6.7 raeburn 10485: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10486: (!$ishomedom)) {
1.160.6.7 raeburn 10487: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10488: }
10489: if ($rule eq 'specific') {
10490: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10491: }
1.160.6.7 raeburn 10492: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10493: if (ref($currrules{$balancer}) eq 'HASH') {
10494: if ($rule ne $currrules{$balancer}{$type}) {
10495: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10496: }
10497: } elsif ($rule ne '') {
1.160.6.7 raeburn 10498: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10499: }
10500: }
10501: }
1.160.6.7 raeburn 10502: }
10503: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10504: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10505: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10506: $defaultshash{'loadbalancing'} = {};
10507: }
10508: my $putresult = &Apache::lonnet::put_dom('configuration',
10509: \%defaultshash,$dom);
10510: if ($putresult eq 'ok') {
10511: if (keys(%changes) > 0) {
10512: if (ref($changes{'delete'}) eq 'ARRAY') {
10513: foreach my $balancer (sort(@{$changes{'delete'}})) {
10514: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10515: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10516: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10517: }
1.160.6.7 raeburn 10518: }
10519: if (ref($changes{'add'}) eq 'ARRAY') {
10520: foreach my $balancer (sort(@{$changes{'add'}})) {
10521: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10522: }
10523: }
10524: if (ref($changes{'curr'}) eq 'HASH') {
10525: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10526: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10527: if ($changes{'curr'}{$balancer}{'targets'}) {
10528: my %offloadstr;
10529: foreach my $sparetype (@sparestypes) {
10530: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10531: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10532: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10533: }
10534: }
1.150 raeburn 10535: }
1.160.6.7 raeburn 10536: if (keys(%offloadstr) == 0) {
10537: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10538: } else {
1.160.6.7 raeburn 10539: my $showoffload;
10540: foreach my $sparetype (@sparestypes) {
10541: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10542: if (defined($offloadstr{$sparetype})) {
10543: $showoffload .= $offloadstr{$sparetype};
10544: } else {
10545: $showoffload .= &mt('None');
10546: }
10547: $showoffload .= (' 'x3);
10548: }
10549: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10550: }
10551: }
10552: }
1.160.6.7 raeburn 10553: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10554: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10555: foreach my $type (@{$alltypes}) {
10556: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10557: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10558: my $balancetext;
10559: if ($rule eq '') {
10560: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10561: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10562: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10563: $balancetext = $ruletitles{$rule};
10564: } else {
10565: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10566: }
1.160.6.26 raeburn 10567: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10568: }
10569: }
10570: }
10571: }
1.160.6.29 raeburn 10572: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10573: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10574: }
1.160.6.7 raeburn 10575: }
10576: if ($resulttext ne '') {
10577: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10578: } else {
10579: $resulttext = $nochgmsg;
10580: }
10581: } else {
1.160.6.7 raeburn 10582: $resulttext = $nochgmsg;
1.150 raeburn 10583: }
10584: } else {
1.160.6.7 raeburn 10585: $resulttext = '<span class="LC_error">'.
10586: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10587: }
10588: } else {
1.160.6.7 raeburn 10589: $resulttext = $nochgmsg;
1.150 raeburn 10590: }
10591: return $resulttext;
10592: }
10593:
1.48 raeburn 10594: sub recurse_check {
10595: my ($chkcats,$categories,$depth,$name) = @_;
10596: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10597: my $chg = 0;
10598: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10599: my $category = $chkcats->[$depth]{$name}[$j];
10600: my $item;
10601: if ($category eq '') {
10602: $chg ++;
10603: } else {
10604: my $deeper = $depth + 1;
10605: $item = &escape($category).':'.&escape($name).':'.$depth;
10606: if ($chg) {
10607: $categories->{$item} -= $chg;
10608: }
10609: &recurse_check($chkcats,$categories,$deeper,$category);
10610: $deeper --;
10611: }
10612: }
10613: }
10614: return;
10615: }
10616:
10617: sub recurse_cat_deletes {
10618: my ($item,$coursecategories,$deletions) = @_;
10619: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10620: my $subdepth = $depth + 1;
10621: if (ref($coursecategories) eq 'HASH') {
10622: foreach my $subitem (keys(%{$coursecategories})) {
10623: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10624: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10625: delete($coursecategories->{$subitem});
10626: $deletions->{$subitem} = 1;
10627: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10628: }
1.48 raeburn 10629: }
10630: }
10631: return;
10632: }
10633:
1.125 raeburn 10634: sub get_active_dcs {
10635: my ($dom) = @_;
1.160.6.16 raeburn 10636: my $now = time;
10637: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10638: my %domcoords;
10639: my $numdcs = 0;
10640: foreach my $server (keys(%dompersonnel)) {
10641: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10642: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10643: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10644: }
10645: }
10646: return %domcoords;
10647: }
10648:
10649: sub active_dc_picker {
1.160.6.16 raeburn 10650: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10651: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10652: my @domcoord = keys(%domcoords);
10653: if (keys(%currhash)) {
10654: foreach my $dc (keys(%currhash)) {
10655: unless (exists($domcoords{$dc})) {
10656: push(@domcoord,$dc);
10657: }
10658: }
10659: }
10660: @domcoord = sort(@domcoord);
10661: my $numdcs = scalar(@domcoord);
10662: my $rows = 0;
10663: my $table;
1.125 raeburn 10664: if ($numdcs > 1) {
1.160.6.16 raeburn 10665: $table = '<table>';
10666: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10667: my $rem = $i%($numinrow);
10668: if ($rem == 0) {
10669: if ($i > 0) {
1.160.6.16 raeburn 10670: $table .= '</tr>';
1.125 raeburn 10671: }
1.160.6.16 raeburn 10672: $table .= '<tr>';
10673: $rows ++;
1.125 raeburn 10674: }
1.160.6.16 raeburn 10675: my $check = '';
10676: if ($inputtype eq 'radio') {
10677: if (keys(%currhash) == 0) {
10678: if (!$i) {
10679: $check = ' checked="checked"';
10680: }
10681: } elsif (exists($currhash{$domcoord[$i]})) {
10682: $check = ' checked="checked"';
10683: }
10684: } else {
10685: if (exists($currhash{$domcoord[$i]})) {
10686: $check = ' checked="checked"';
1.125 raeburn 10687: }
10688: }
1.160.6.16 raeburn 10689: if ($i == @domcoord - 1) {
1.125 raeburn 10690: my $colsleft = $numinrow - $rem;
10691: if ($colsleft > 1) {
1.160.6.16 raeburn 10692: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10693: } else {
1.160.6.16 raeburn 10694: $table .= '<td class="LC_left_item">';
1.125 raeburn 10695: }
10696: } else {
1.160.6.16 raeburn 10697: $table .= '<td class="LC_left_item">';
10698: }
10699: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10700: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10701: $table .= '<span class="LC_nobreak"><label>'.
10702: '<input type="'.$inputtype.'" name="'.$name.'"'.
10703: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10704: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10705: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10706: }
1.160.6.33 raeburn 10707: $table .= '</label></span></td>';
1.125 raeburn 10708: }
1.160.6.16 raeburn 10709: $table .= '</tr></table>';
10710: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10711: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10712: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10713: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 10714: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10715: if ($user ne $dcname.':'.$dcdom) {
10716: $table .= ' ('.$dcname.':'.$dcdom.')';
10717: }
1.160.6.16 raeburn 10718: } else {
10719: my $check;
10720: if (exists($currhash{$domcoord[0]})) {
10721: $check = ' checked="checked"';
10722: }
1.160.6.31 raeburn 10723: $table .= '<span class="LC_nobreak"><label>'.
10724: '<input type="checkbox" name="'.$name.'" '.
10725: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10726: if ($user ne $dcname.':'.$dcdom) {
10727: $table .= ' ('.$dcname.':'.$dcdom.')';
10728: }
10729: $table .= '</label></span>';
1.160.6.16 raeburn 10730: $rows ++;
10731: }
1.125 raeburn 10732: }
1.160.6.16 raeburn 10733: return ($numdcs,$table,$rows);
1.125 raeburn 10734: }
10735:
1.137 raeburn 10736: sub usersession_titles {
10737: return &Apache::lonlocal::texthash(
10738: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10739: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10740: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10741: version => 'LON-CAPA version requirement',
1.138 raeburn 10742: excludedomain => 'Allow all, but exclude specific domains',
10743: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10744: primary => 'Primary (checked first)',
1.154 raeburn 10745: default => 'Default',
1.137 raeburn 10746: );
10747: }
10748:
1.152 raeburn 10749: sub id_for_thisdom {
10750: my (%servers) = @_;
10751: my %altids;
10752: foreach my $server (keys(%servers)) {
10753: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10754: if ($serverhome ne $server) {
10755: $altids{$serverhome} = $server;
10756: }
10757: }
10758: return %altids;
10759: }
10760:
1.150 raeburn 10761: sub count_servers {
10762: my ($currbalancer,%servers) = @_;
10763: my (@spares,$numspares);
10764: foreach my $lonhost (sort(keys(%servers))) {
10765: next if ($currbalancer eq $lonhost);
10766: push(@spares,$lonhost);
10767: }
10768: if ($currbalancer) {
10769: $numspares = scalar(@spares);
10770: } else {
10771: $numspares = scalar(@spares) - 1;
10772: }
10773: return ($numspares,@spares);
10774: }
10775:
10776: sub lonbalance_targets_js {
1.160.6.7 raeburn 10777: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 10778: my $select = &mt('Select');
10779: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10780: if (ref($servers) eq 'HASH') {
10781: $alltargets = join("','",sort(keys(%{$servers})));
10782: my @homedoms;
10783: foreach my $server (sort(keys(%{$servers}))) {
10784: if (&Apache::lonnet::host_domain($server) eq $dom) {
10785: push(@homedoms,'1');
10786: } else {
10787: push(@homedoms,'0');
10788: }
10789: }
10790: $allishome = join("','",@homedoms);
10791: }
10792: if (ref($types) eq 'ARRAY') {
10793: if (@{$types} > 0) {
10794: @alltypes = @{$types};
10795: }
10796: }
10797: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10798: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 10799: my (%currbalancer,%currtargets,%currrules,%existing);
10800: if (ref($settings) eq 'HASH') {
10801: %existing = %{$settings};
10802: }
10803: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10804: \%currtargets,\%currrules);
10805: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 10806: return <<"END";
10807:
10808: <script type="text/javascript">
10809: // <![CDATA[
10810:
1.160.6.7 raeburn 10811: currBalancers = new Array('$balancers');
10812:
10813: function toggleTargets(balnum) {
10814: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10815: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10816: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10817: var prevbalancer = prevhostitem.value;
10818: var baltotal = document.getElementById('loadbalancing_total').value;
10819: prevhostitem.value = balancer;
10820: if (prevbalancer != '') {
10821: var prevIdx = currBalancers.indexOf(prevbalancer);
10822: if (prevIdx != -1) {
10823: currBalancers.splice(prevIdx,1);
10824: }
10825: }
1.150 raeburn 10826: if (balancer == '') {
1.160.6.7 raeburn 10827: hideSpares(balnum);
1.150 raeburn 10828: } else {
1.160.6.7 raeburn 10829: var currIdx = currBalancers.indexOf(balancer);
10830: if (currIdx == -1) {
10831: currBalancers.push(balancer);
10832: }
1.150 raeburn 10833: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 10834: var ishomedom = homedoms[lonhostitem.selectedIndex];
10835: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 10836: }
1.160.6.7 raeburn 10837: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 10838: return;
10839: }
10840:
1.160.6.7 raeburn 10841: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 10842: var alltargets = new Array('$alltargets');
10843: var insttypes = new Array('$allinsttypes');
1.151 raeburn 10844: var offloadtypes = new Array('primary','default');
10845:
1.160.6.7 raeburn 10846: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10847: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 10848:
1.151 raeburn 10849: for (var i=0; i<offloadtypes.length; i++) {
10850: var count = 0;
10851: for (var j=0; j<alltargets.length; j++) {
10852: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 10853: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10854: item.value = alltargets[j];
10855: item.style.textAlign='left';
10856: item.style.textFace='normal';
10857: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10858: if (currBalancers.indexOf(alltargets[j]) == -1) {
10859: item.disabled = '';
10860: } else {
10861: item.disabled = 'disabled';
10862: item.checked = false;
10863: }
1.151 raeburn 10864: count ++;
10865: }
1.150 raeburn 10866: }
10867: }
1.151 raeburn 10868: for (var k=0; k<insttypes.length; k++) {
10869: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 10870: if (ishomedom == 1) {
1.160.6.7 raeburn 10871: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10872: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10873: } else {
1.160.6.7 raeburn 10874: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10875: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 10876: }
10877: } else {
1.160.6.7 raeburn 10878: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10879: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10880: }
1.151 raeburn 10881: if ((insttypes[k] != '_LC_external') &&
10882: ((insttypes[k] != '_LC_internetdom') ||
10883: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 10884: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10885: item.options.length = 0;
10886: item.options[0] = new Option("","",true,true);
10887: var idx = 0;
1.151 raeburn 10888: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 10889: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10890: idx ++;
10891: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 10892: }
10893: }
10894: }
10895: }
10896: return;
10897: }
10898:
1.160.6.7 raeburn 10899: function hideSpares(balnum) {
1.150 raeburn 10900: var alltargets = new Array('$alltargets');
10901: var insttypes = new Array('$allinsttypes');
10902: var offloadtypes = new Array('primary','default');
10903:
1.160.6.7 raeburn 10904: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
10905: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 10906:
10907: var total = alltargets.length - 1;
10908: for (var i=0; i<offloadtypes; i++) {
10909: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 10910: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
10911: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
10912: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 10913: }
1.150 raeburn 10914: }
10915: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 10916: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10917: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 10918: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 10919: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
10920: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 10921: }
10922: }
10923: return;
10924: }
10925:
1.160.6.7 raeburn 10926: function checkOffloads(item,balnum,type) {
1.150 raeburn 10927: var alltargets = new Array('$alltargets');
10928: var offloadtypes = new Array('primary','default');
10929: if (item.checked) {
10930: var total = alltargets.length - 1;
10931: var other;
10932: if (type == offloadtypes[0]) {
1.151 raeburn 10933: other = offloadtypes[1];
1.150 raeburn 10934: } else {
1.151 raeburn 10935: other = offloadtypes[0];
1.150 raeburn 10936: }
10937: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 10938: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 10939: if (server == item.value) {
1.160.6.7 raeburn 10940: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
10941: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 10942: }
10943: }
10944: }
10945: }
10946: return;
10947: }
10948:
1.160.6.7 raeburn 10949: function singleServerToggle(balnum,type) {
10950: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 10951: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 10952: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
10953: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10954:
10955: } else {
1.160.6.7 raeburn 10956: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
10957: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 10958: }
10959: return;
10960: }
10961:
1.160.6.7 raeburn 10962: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 10963: if (type == '_LC_external') {
1.160.6.26 raeburn 10964: return;
1.150 raeburn 10965: }
1.160.6.7 raeburn 10966: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 10967: for (var i=0; i<typesRules.length; i++) {
10968: if (formname.elements[typesRules[i]].checked) {
10969: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 10970: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
10971: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 10972: } else {
1.160.6.7 raeburn 10973: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
10974: }
10975: }
10976: }
10977: return;
10978: }
10979:
10980: function balancerDeleteChange(balnum) {
10981: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10982: var baltotal = document.getElementById('loadbalancing_total').value;
10983: var addtarget;
10984: var removetarget;
10985: var action = 'delete';
10986: if (document.getElementById('loadbalancing_delete_'+balnum)) {
10987: var lonhost = hostitem.value;
10988: var currIdx = currBalancers.indexOf(lonhost);
10989: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
10990: if (currIdx != -1) {
10991: currBalancers.splice(currIdx,1);
10992: }
10993: addtarget = lonhost;
10994: } else {
10995: if (currIdx == -1) {
10996: currBalancers.push(lonhost);
10997: }
10998: removetarget = lonhost;
10999: action = 'undelete';
11000: }
11001: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11002: }
11003: return;
11004: }
11005:
11006: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11007: if (baltotal > 1) {
11008: var offloadtypes = new Array('primary','default');
11009: var alltargets = new Array('$alltargets');
11010: var insttypes = new Array('$allinsttypes');
11011: for (var i=0; i<baltotal; i++) {
11012: if (i != balnum) {
11013: for (var j=0; j<offloadtypes.length; j++) {
11014: var total = alltargets.length - 1;
11015: for (var k=0; k<total; k++) {
11016: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11017: var server = serveritem.value;
11018: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11019: if (server == addtarget) {
11020: serveritem.disabled = '';
11021: }
11022: }
11023: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11024: if (server == removetarget) {
11025: serveritem.disabled = 'disabled';
11026: serveritem.checked = false;
11027: }
11028: }
11029: }
11030: }
11031: for (var j=0; j<insttypes.length; j++) {
11032: if (insttypes[j] != '_LC_external') {
11033: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11034: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11035: var currSel = singleserver.selectedIndex;
11036: var currVal = singleserver.options[currSel].value;
11037: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11038: var numoptions = singleserver.options.length;
11039: var needsnew = 1;
11040: for (var k=0; k<numoptions; k++) {
11041: if (singleserver.options[k] == addtarget) {
11042: needsnew = 0;
11043: break;
11044: }
11045: }
11046: if (needsnew == 1) {
11047: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11048: }
11049: }
11050: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11051: singleserver.options.length = 0;
11052: if ((currVal) && (currVal != removetarget)) {
11053: singleserver.options[0] = new Option("","",false,false);
11054: } else {
11055: singleserver.options[0] = new Option("","",true,true);
11056: }
11057: var idx = 0;
11058: for (var m=0; m<alltargets.length; m++) {
11059: if (currBalancers.indexOf(alltargets[m]) == -1) {
11060: idx ++;
11061: if (currVal == alltargets[m]) {
11062: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11063: } else {
11064: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11065: }
11066: }
11067: }
11068: }
11069: }
11070: }
11071: }
1.150 raeburn 11072: }
11073: }
11074: }
11075: return;
11076: }
11077:
1.152 raeburn 11078: // ]]>
11079: </script>
11080:
11081: END
11082: }
11083:
11084: sub new_spares_js {
11085: my @sparestypes = ('primary','default');
11086: my $types = join("','",@sparestypes);
11087: my $select = &mt('Select');
11088: return <<"END";
11089:
11090: <script type="text/javascript">
11091: // <![CDATA[
11092:
11093: function updateNewSpares(formname,lonhost) {
11094: var types = new Array('$types');
11095: var include = new Array();
11096: var exclude = new Array();
11097: for (var i=0; i<types.length; i++) {
11098: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11099: for (var j=0; j<spareboxes.length; j++) {
11100: if (formname.elements[spareboxes[j]].checked) {
11101: exclude.push(formname.elements[spareboxes[j]].value);
11102: } else {
11103: include.push(formname.elements[spareboxes[j]].value);
11104: }
11105: }
11106: }
11107: for (var i=0; i<types.length; i++) {
11108: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11109: var selIdx = newSpare.selectedIndex;
11110: var currnew = newSpare.options[selIdx].value;
11111: var okSpares = new Array();
11112: for (var j=0; j<newSpare.options.length; j++) {
11113: var possible = newSpare.options[j].value;
11114: if (possible != '') {
11115: if (exclude.indexOf(possible) == -1) {
11116: okSpares.push(possible);
11117: } else {
11118: if (currnew == possible) {
11119: selIdx = 0;
11120: }
11121: }
11122: }
11123: }
11124: for (var k=0; k<include.length; k++) {
11125: if (okSpares.indexOf(include[k]) == -1) {
11126: okSpares.push(include[k]);
11127: }
11128: }
11129: okSpares.sort();
11130: newSpare.options.length = 0;
11131: if (selIdx == 0) {
11132: newSpare.options[0] = new Option("$select","",true,true);
11133: } else {
11134: newSpare.options[0] = new Option("$select","",false,false);
11135: }
11136: for (var m=0; m<okSpares.length; m++) {
11137: var idx = m+1;
11138: var selThis = 0;
11139: if (selIdx != 0) {
11140: if (okSpares[m] == currnew) {
11141: selThis = 1;
11142: }
11143: }
11144: if (selThis == 1) {
11145: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11146: } else {
11147: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11148: }
11149: }
11150: }
11151: return;
11152: }
11153:
11154: function checkNewSpares(lonhost,type) {
11155: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11156: var chosen = newSpare.options[newSpare.selectedIndex].value;
11157: if (chosen != '') {
11158: var othertype;
11159: var othernewSpare;
11160: if (type == 'primary') {
11161: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11162: }
11163: if (type == 'default') {
11164: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11165: }
11166: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11167: othernewSpare.selectedIndex = 0;
11168: }
11169: }
11170: return;
11171: }
11172:
11173: // ]]>
11174: </script>
11175:
11176: END
11177:
11178: }
11179:
11180: sub common_domprefs_js {
11181: return <<"END";
11182:
11183: <script type="text/javascript">
11184: // <![CDATA[
11185:
1.150 raeburn 11186: function getIndicesByName(formname,item) {
1.152 raeburn 11187: var group = new Array();
1.150 raeburn 11188: for (var i=0;i<formname.elements.length;i++) {
11189: if (formname.elements[i].name == item) {
1.152 raeburn 11190: group.push(formname.elements[i].id);
1.150 raeburn 11191: }
11192: }
1.152 raeburn 11193: return group;
1.150 raeburn 11194: }
11195:
11196: // ]]>
11197: </script>
11198:
11199: END
1.152 raeburn 11200:
1.150 raeburn 11201: }
11202:
1.160.6.5 raeburn 11203: sub recaptcha_js {
11204: my %lt = &captcha_phrases();
11205: return <<"END";
11206:
11207: <script type="text/javascript">
11208: // <![CDATA[
11209:
11210: function updateCaptcha(caller,context) {
11211: var privitem;
11212: var pubitem;
11213: var privtext;
11214: var pubtext;
11215: if (document.getElementById(context+'_recaptchapub')) {
11216: pubitem = document.getElementById(context+'_recaptchapub');
11217: } else {
11218: return;
11219: }
11220: if (document.getElementById(context+'_recaptchapriv')) {
11221: privitem = document.getElementById(context+'_recaptchapriv');
11222: } else {
11223: return;
11224: }
11225: if (document.getElementById(context+'_recaptchapubtxt')) {
11226: pubtext = document.getElementById(context+'_recaptchapubtxt');
11227: } else {
11228: return;
11229: }
11230: if (document.getElementById(context+'_recaptchaprivtxt')) {
11231: privtext = document.getElementById(context+'_recaptchaprivtxt');
11232: } else {
11233: return;
11234: }
11235: if (caller.checked) {
11236: if (caller.value == 'recaptcha') {
11237: pubitem.type = 'text';
11238: privitem.type = 'text';
11239: pubitem.size = '40';
11240: privitem.size = '40';
11241: pubtext.innerHTML = "$lt{'pub'}";
11242: privtext.innerHTML = "$lt{'priv'}";
11243: } else {
11244: pubitem.type = 'hidden';
11245: privitem.type = 'hidden';
11246: pubtext.innerHTML = '';
11247: privtext.innerHTML = '';
11248: }
11249: }
11250: return;
11251: }
11252:
11253: // ]]>
11254: </script>
11255:
11256: END
11257:
11258: }
11259:
1.160.6.40 raeburn 11260: sub toggle_display_js {
1.160.6.16 raeburn 11261: return <<"END";
11262:
11263: <script type="text/javascript">
11264: // <![CDATA[
11265:
1.160.6.40 raeburn 11266: function toggleDisplay(domForm,caller) {
11267: if (document.getElementById(caller)) {
11268: var divitem = document.getElementById(caller);
11269: var optionsElement = domForm.coursecredits;
11270: if (caller == 'emailoptions') {
11271: optionsElement = domForm.cancreate_email;
11272: }
11273: if (optionsElement.length) {
1.160.6.16 raeburn 11274: var currval;
1.160.6.40 raeburn 11275: for (var i=0; i<optionsElement.length; i++) {
11276: if (optionsElement[i].checked) {
11277: currval = optionsElement[i].value;
1.160.6.16 raeburn 11278: }
11279: }
11280: if (currval == 1) {
1.160.6.40 raeburn 11281: divitem.style.display = 'block';
1.160.6.16 raeburn 11282: } else {
1.160.6.40 raeburn 11283: divitem.style.display = 'none';
1.160.6.16 raeburn 11284: }
11285: }
11286: }
11287: return;
11288: }
11289:
11290: // ]]>
11291: </script>
11292:
11293: END
11294:
11295: }
11296:
1.160.6.5 raeburn 11297: sub captcha_phrases {
11298: return &Apache::lonlocal::texthash (
11299: priv => 'Private key',
11300: pub => 'Public key',
11301: original => 'original (CAPTCHA)',
11302: recaptcha => 'successor (ReCAPTCHA)',
11303: notused => 'unused',
11304: );
11305: }
11306:
1.160.6.24 raeburn 11307: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11308: my ($dom,$cachekeys) = @_;
11309: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11310: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11311: my %thismachine;
11312: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11313: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11314: if (keys(%servers) > 1) {
11315: foreach my $server (keys(%servers)) {
11316: next if ($thismachine{$server});
1.160.6.27 raeburn 11317: my @cached;
11318: foreach my $name (@posscached) {
11319: if ($cachekeys->{$name}) {
11320: push(@cached,&escape($name).':'.&escape($dom));
11321: }
11322: }
11323: if (@cached) {
11324: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11325: }
1.160.6.24 raeburn 11326: }
11327: }
11328: return;
11329: }
11330:
1.3 raeburn 11331: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>