Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.43
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.43! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.42 2014/04/28 04:12:41 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.160.6.42 raeburn 390: header => [{col1 => 'Catalog type/availability',
391: col2 => '',},
392: {col1 => 'Category settings for standard catalog',
1.57 raeburn 393: col2 => '',},
394: {col1 => 'Categories',
395: col2 => '',
396: }],
1.160.6.37 raeburn 397: print => \&print_coursecategories,
398: modify => \&modify_coursecategories,
1.69 raeburn 399: },
400: 'serverstatuses' =>
1.77 raeburn 401: {text => 'Access to server status pages',
1.69 raeburn 402: help => 'Domain_Configuration_Server_Status',
403: header => [{col1 => 'Status Page',
404: col2 => 'Other named users',
405: col3 => 'Specific IPs',
406: }],
1.160.6.37 raeburn 407: print => \&print_serverstatuses,
408: modify => \&modify_serverstatuses,
1.69 raeburn 409: },
1.160.6.39 raeburn 410: 'coursedefaults' =>
1.160.6.16 raeburn 411: {text => 'Course/Community defaults',
412: help => 'Domain_Configuration_Course_Defaults',
1.160.6.37 raeburn 413: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
414: col2 => 'Value',},
415: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 416: col2 => 'Value',},],
1.160.6.37 raeburn 417: print => \&print_coursedefaults,
418: modify => \&modify_coursedefaults,
419: },
1.160.6.39 raeburn 420: 'selfenrollment' =>
1.160.6.37 raeburn 421: {text => 'Self-enrollment in Course/Community',
422: help => 'Domain_Configuration_Selfenrollment',
423: header => [{col1 => 'Configuration Rights',
424: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
425: {col1 => 'Defaults',
426: col2 => 'Value'},
427: {col1 => 'Self-enrollment validation (optional)',
428: col2 => 'Value'},],
429: print => \&print_selfenrollment,
430: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 431: },
1.141 raeburn 432: 'usersessions' =>
1.145 raeburn 433: {text => 'User session hosting/offloading',
1.137 raeburn 434: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 435: header => [{col1 => 'Domain server',
436: col2 => 'Servers to offload sessions to when busy'},
437: {col1 => 'Hosting of users from other domains',
1.137 raeburn 438: col2 => 'Rules'},
439: {col1 => "Hosting domain's own users elsewhere",
440: col2 => 'Rules'}],
1.160.6.37 raeburn 441: print => \&print_usersessions,
442: modify => \&modify_usersessions,
1.137 raeburn 443: },
1.150 raeburn 444: 'loadbalancing' =>
1.160.6.7 raeburn 445: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 446: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 447: header => [{col1 => 'Balancers',
1.150 raeburn 448: col2 => 'Default destinations',
1.160.6.13 raeburn 449: col3 => 'User affiliation',
1.150 raeburn 450: col4 => 'Overrides'},
451: ],
1.160.6.37 raeburn 452: print => \&print_loadbalancing,
453: modify => \&modify_loadbalancing,
1.150 raeburn 454: },
1.3 raeburn 455: );
1.110 raeburn 456: if (keys(%servers) > 1) {
457: $prefs{'login'} = { text => 'Log-in page options',
458: help => 'Domain_Configuration_Login_Page',
459: header => [{col1 => 'Log-in Service',
460: col2 => 'Server Setting',},
461: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 462: col2 => ''},
463: {col1 => 'Log-in Help',
464: col2 => 'Value'}],
1.160.6.37 raeburn 465: print => \&print_login,
466: modify => \&modify_login,
1.110 raeburn 467: };
468: }
1.160.6.13 raeburn 469:
1.6 raeburn 470: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 471: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 472: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 473: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 474: text=>"Settings to display/modify"});
1.9 raeburn 475: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 476:
1.3 raeburn 477: if ($phase eq 'process') {
1.160.6.27 raeburn 478: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
479: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 480: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 481: $r->rflush();
1.160.6.27 raeburn 482: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 483: }
1.30 raeburn 484: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 485: my $js = &recaptcha_js().
1.160.6.40 raeburn 486: &toggle_display_js();
1.160.6.7 raeburn 487: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 488: my ($othertitle,$usertypes,$types) =
489: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 490: $js .= &lonbalance_targets_js($dom,$types,\%servers,
491: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 492: &new_spares_js().
493: &common_domprefs_js().
494: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 495: }
1.160.6.30 raeburn 496: if (grep(/^requestcourses$/,@actions)) {
497: my $javascript_validations;
498: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
499: $js .= <<END;
500: <script type="text/javascript">
501: $javascript_validations
502: </script>
503: $coursebrowserjs
504: END
505: }
1.150 raeburn 506: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 507: } else {
1.160.6.11 raeburn 508: # check if domconfig user exists for the domain.
509: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 510: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 511: &config_check($dom,$confname,$servadm);
512: unless ($configuserok eq 'ok') {
513: &Apache::lonconfigsettings::print_header($r,$phase,$context);
514: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
515: $confname).
516: '<br />'
517: );
518: if ($switchserver) {
519: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
520: '<br />'.
521: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
522: '<br />'.
523: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
524: '<br />'.
525: &mt('To do that now, use the following link: [_1]',$switchserver)
526: );
527: } else {
528: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
529: '<br />'.
530: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
531: );
532: }
533: $r->print(&Apache::loncommon::end_page());
534: return OK;
535: }
1.21 raeburn 536: if (keys(%domconfig) == 0) {
537: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 538: my @ids=&Apache::lonnet::current_machine_ids();
539: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 540: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 541: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 542: my $custom_img_count = 0;
543: foreach my $img (@loginimages) {
544: if ($designhash{$dom.'.login.'.$img} ne '') {
545: $custom_img_count ++;
546: }
547: }
548: foreach my $role (@roles) {
549: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
550: $custom_img_count ++;
551: }
552: }
553: if ($custom_img_count > 0) {
1.94 raeburn 554: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 555: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 556: $r->print(
557: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
558: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
559: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
560: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
561: if ($switch_server) {
1.30 raeburn 562: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 563: }
1.91 raeburn 564: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 565: return OK;
566: }
567: }
568: }
1.91 raeburn 569: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 570: }
571: return OK;
572: }
573:
574: sub process_changes {
1.160.6.24 raeburn 575: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 576: my %domconfig;
577: if (ref($values) eq 'HASH') {
578: %domconfig = %{$values};
579: }
1.3 raeburn 580: my $output;
581: if ($action eq 'login') {
1.160.6.24 raeburn 582: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 583: } elsif ($action eq 'rolecolors') {
1.9 raeburn 584: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 585: $lastactref,%domconfig);
1.3 raeburn 586: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 587: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 588: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 589: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 590: } elsif ($action eq 'autoupdate') {
591: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 592: } elsif ($action eq 'autocreate') {
593: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 594: } elsif ($action eq 'directorysrch') {
595: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 596: } elsif ($action eq 'usercreation') {
1.28 raeburn 597: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 598: } elsif ($action eq 'selfcreation') {
599: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 600: } elsif ($action eq 'usermodification') {
601: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 602: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 603: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 604: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 605: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 606: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 607: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 608: } elsif ($action eq 'coursecategories') {
1.160.6.43! raeburn 609: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 610: } elsif ($action eq 'serverstatuses') {
611: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 612: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 613: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 614: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.16 raeburn 616: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 617: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 618: } elsif ($action eq 'selfenrollment') {
619: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 620: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 621: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 622: } elsif ($action eq 'loadbalancing') {
623: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 624: }
625: return $output;
626: }
627:
628: sub print_config_box {
1.9 raeburn 629: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 630: my $rowtotal = 0;
1.49 raeburn 631: my $output;
632: if ($action eq 'coursecategories') {
633: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 634: } elsif ($action eq 'defaults') {
635: $output = &defaults_javascript($settings);
1.91 raeburn 636: }
1.160.6.40 raeburn 637: $output .=
1.30 raeburn 638: '<table class="LC_nested_outer">
1.3 raeburn 639: <tr>
1.66 raeburn 640: <th align="left" valign="middle"><span class="LC_nobreak">'.
641: &mt($item->{text}).' '.
642: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
643: '</tr>';
1.30 raeburn 644: $rowtotal ++;
1.110 raeburn 645: my $numheaders = 1;
646: if (ref($item->{'header'}) eq 'ARRAY') {
647: $numheaders = scalar(@{$item->{'header'}});
648: }
649: if ($numheaders > 1) {
1.64 raeburn 650: my $colspan = '';
1.145 raeburn 651: my $rightcolspan = '';
1.160.6.42 raeburn 652: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.5 raeburn 653: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 654: $colspan = ' colspan="2"';
655: }
1.145 raeburn 656: if ($action eq 'usersessions') {
657: $rightcolspan = ' colspan="3"';
658: }
1.30 raeburn 659: $output .= '
1.3 raeburn 660: <tr>
661: <td>
662: <table class="LC_nested">
663: <tr class="LC_info_row">
1.59 bisitz 664: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 665: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 666: </tr>';
1.69 raeburn 667: $rowtotal ++;
1.160.6.37 raeburn 668: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.40 raeburn 669: ($action eq 'usermodification') || ($action eq 'defaults') ||
670: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
1.160.6.37 raeburn 671: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 672: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 673: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 674: } elsif ($action eq 'login') {
1.160.6.5 raeburn 675: if ($numheaders == 3) {
676: $colspan = ' colspan="2"';
677: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
678: } else {
679: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
680: }
1.160.6.37 raeburn 681: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 682: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 683: } elsif ($action eq 'rolecolors') {
1.30 raeburn 684: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 685: }
1.30 raeburn 686: $output .= '
1.6 raeburn 687: </table>
688: </td>
689: </tr>
690: <tr>
691: <td>
692: <table class="LC_nested">
693: <tr class="LC_info_row">
1.160.6.37 raeburn 694: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 695: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 696: </tr>';
697: $rowtotal ++;
1.160.6.37 raeburn 698: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
699: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.42 raeburn 700: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
701: if ($action eq 'coursecategories') {
702: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
703: $colspan = ' colspan="2"';
704: } else {
705: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
706: }
707: $output .= '
1.63 raeburn 708: </table>
709: </td>
710: </tr>
711: <tr>
712: <td>
713: <table class="LC_nested">
714: <tr class="LC_info_row">
715: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 716: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 717: </tr>'."\n";
718: if ($action eq 'coursecategories') {
719: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
720: } else {
721: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
722: }
1.63 raeburn 723: $rowtotal ++;
1.160.6.40 raeburn 724: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
725: ($action eq 'defaults')) {
1.160.6.37 raeburn 726: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 727: } elsif ($action eq 'login') {
1.160.6.5 raeburn 728: if ($numheaders == 3) {
729: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
730: </table>
731: </td>
732: </tr>
733: <tr>
734: <td>
735: <table class="LC_nested">
736: <tr class="LC_info_row">
737: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 738: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 739: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
740: $rowtotal ++;
741: } else {
742: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
743: }
1.102 raeburn 744: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 745: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal).
746: &print_studentcode($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.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
755: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.39 raeburn 756: &print_textbookcourses($dom,$settings,\$rowtotal).'
757: </table>
758: </td>
759: </tr>
760: <tr>
761: <td>
762: <table class="LC_nested">
763: <tr class="LC_info_row">
764: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
765: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
766: </tr>'.
767: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 768: } elsif ($action eq 'requestauthor') {
769: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.122 jms 770: } elsif ($action eq 'rolecolors') {
1.30 raeburn 771: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 772: </table>
773: </td>
774: </tr>
775: <tr>
776: <td>
777: <table class="LC_nested">
778: <tr class="LC_info_row">
1.69 raeburn 779: <td class="LC_left_item"'.$colspan.' valign="top">'.
780: &mt($item->{'header'}->[2]->{'col1'}).'</td>
781: <td class="LC_right_item" valign="top">'.
782: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 783: </tr>'.
1.30 raeburn 784: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 785: </table>
786: </td>
787: </tr>
788: <tr>
789: <td>
790: <table class="LC_nested">
791: <tr class="LC_info_row">
1.59 bisitz 792: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
793: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 794: </tr>'.
1.30 raeburn 795: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
796: $rowtotal += 2;
1.6 raeburn 797: }
1.3 raeburn 798: } else {
1.30 raeburn 799: $output .= '
1.3 raeburn 800: <tr>
801: <td>
802: <table class="LC_nested">
1.30 raeburn 803: <tr class="LC_info_row">';
1.24 raeburn 804: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 805: $output .= '
1.59 bisitz 806: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 807: } elsif ($action eq 'serverstatuses') {
808: $output .= '
809: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
810: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
811:
1.6 raeburn 812: } else {
1.30 raeburn 813: $output .= '
1.69 raeburn 814: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
815: }
1.72 raeburn 816: if (defined($item->{'header'}->[0]->{'col3'})) {
817: $output .= '<td class="LC_left_item" valign="top">'.
818: &mt($item->{'header'}->[0]->{'col2'});
819: if ($action eq 'serverstatuses') {
820: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
821: }
1.69 raeburn 822: } else {
823: $output .= '<td class="LC_right_item" valign="top">'.
824: &mt($item->{'header'}->[0]->{'col2'});
825: }
826: $output .= '</td>';
827: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 828: if (defined($item->{'header'}->[0]->{'col4'})) {
829: $output .= '<td class="LC_left_item" valign="top">'.
830: &mt($item->{'header'}->[0]->{'col3'});
831: } else {
832: $output .= '<td class="LC_right_item" valign="top">'.
833: &mt($item->{'header'}->[0]->{'col3'});
834: }
1.69 raeburn 835: if ($action eq 'serverstatuses') {
836: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
837: }
838: $output .= '</td>';
1.6 raeburn 839: }
1.150 raeburn 840: if ($item->{'header'}->[0]->{'col4'}) {
841: $output .= '<td class="LC_right_item" valign="top">'.
842: &mt($item->{'header'}->[0]->{'col4'});
843: }
1.69 raeburn 844: $output .= '</tr>';
1.48 raeburn 845: $rowtotal ++;
1.160.6.5 raeburn 846: if ($action eq 'quotas') {
1.86 raeburn 847: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.37 raeburn 848: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.160.6.40 raeburn 849: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 850: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 851: } elsif ($action eq 'scantron') {
852: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 853: } elsif ($action eq 'helpsettings') {
1.160.6.5 raeburn 854: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 855: }
1.3 raeburn 856: }
1.30 raeburn 857: $output .= '
1.3 raeburn 858: </table>
859: </td>
860: </tr>
1.30 raeburn 861: </table><br />';
862: return ($output,$rowtotal);
1.1 raeburn 863: }
864:
1.3 raeburn 865: sub print_login {
1.160.6.5 raeburn 866: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 867: my ($css_class,$datatable);
1.6 raeburn 868: my %choices = &login_choices();
1.110 raeburn 869:
1.160.6.5 raeburn 870: if ($caller eq 'service') {
1.149 raeburn 871: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 872: my $choice = $choices{'disallowlogin'};
873: $css_class = ' class="LC_odd_row"';
1.128 raeburn 874: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 875: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 876: '<th>'.$choices{'server'}.'</th>'.
877: '<th>'.$choices{'serverpath'}.'</th>'.
878: '<th>'.$choices{'custompath'}.'</th>'.
879: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 880: my %disallowed;
881: if (ref($settings) eq 'HASH') {
882: if (ref($settings->{'loginvia'}) eq 'HASH') {
883: %disallowed = %{$settings->{'loginvia'}};
884: }
885: }
886: foreach my $lonhost (sort(keys(%servers))) {
887: my $direct = 'selected="selected"';
1.128 raeburn 888: if (ref($disallowed{$lonhost}) eq 'HASH') {
889: if ($disallowed{$lonhost}{'server'} ne '') {
890: $direct = '';
891: }
1.110 raeburn 892: }
1.115 raeburn 893: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 894: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 895: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
896: '</option>';
1.160.6.13 raeburn 897: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 898: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 899: my $selected = '';
1.128 raeburn 900: if (ref($disallowed{$lonhost}) eq 'HASH') {
901: if ($hostid eq $disallowed{$lonhost}{'server'}) {
902: $selected = 'selected="selected"';
903: }
1.110 raeburn 904: }
905: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
906: $servers{$hostid}.'</option>';
907: }
1.128 raeburn 908: $datatable .= '</select></td>'.
909: '<td><select name="'.$lonhost.'_serverpath">';
910: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
911: my $pathname = $path;
912: if ($path eq 'custom') {
913: $pathname = &mt('Custom Path').' ->';
914: }
915: my $selected = '';
916: if (ref($disallowed{$lonhost}) eq 'HASH') {
917: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
918: $selected = 'selected="selected"';
919: }
920: } elsif ($path eq '') {
921: $selected = 'selected="selected"';
922: }
923: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
924: }
925: $datatable .= '</select></td>';
926: my ($custom,$exempt);
927: if (ref($disallowed{$lonhost}) eq 'HASH') {
928: $custom = $disallowed{$lonhost}{'custompath'};
929: $exempt = $disallowed{$lonhost}{'exempt'};
930: }
931: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
932: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
933: '</tr>';
1.110 raeburn 934: }
935: $datatable .= '</table></td></tr>';
936: return $datatable;
1.160.6.5 raeburn 937: } elsif ($caller eq 'page') {
938: my %defaultchecked = (
939: 'coursecatalog' => 'on',
1.160.6.14 raeburn 940: 'helpdesk' => 'on',
1.160.6.5 raeburn 941: 'adminmail' => 'off',
942: 'newuser' => 'off',
943: );
1.160.6.14 raeburn 944: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 945: my (%checkedon,%checkedoff);
1.42 raeburn 946: foreach my $item (@toggles) {
1.160.6.5 raeburn 947: if ($defaultchecked{$item} eq 'on') {
948: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 949: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 950: } elsif ($defaultchecked{$item} eq 'off') {
951: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 952: $checkedon{$item} = ' ';
953: }
1.1 raeburn 954: }
1.160.6.5 raeburn 955: my @images = ('img','logo','domlogo','login');
956: my @logintext = ('textcol','bgcol');
957: my @bgs = ('pgbg','mainbg','sidebg');
958: my @links = ('link','alink','vlink');
959: my %designhash = &Apache::loncommon::get_domainconf($dom);
960: my %defaultdesign = %Apache::loncommon::defaultdesign;
961: my (%is_custom,%designs);
962: my %defaults = (
963: font => $defaultdesign{'login.font'},
964: );
1.6 raeburn 965: foreach my $item (@images) {
1.160.6.5 raeburn 966: $defaults{$item} = $defaultdesign{'login.'.$item};
967: $defaults{'showlogo'}{$item} = 1;
968: }
969: foreach my $item (@bgs) {
970: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 971: }
1.41 raeburn 972: foreach my $item (@logintext) {
1.160.6.5 raeburn 973: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 974: }
1.160.6.5 raeburn 975: foreach my $item (@links) {
976: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 977: }
1.160.6.5 raeburn 978: if (ref($settings) eq 'HASH') {
979: foreach my $item (@toggles) {
980: if ($settings->{$item} eq '1') {
981: $checkedon{$item} = ' checked="checked" ';
982: $checkedoff{$item} = ' ';
983: } elsif ($settings->{$item} eq '0') {
984: $checkedoff{$item} = ' checked="checked" ';
985: $checkedon{$item} = ' ';
986: }
1.6 raeburn 987: }
1.160.6.5 raeburn 988: foreach my $item (@images) {
989: if (defined($settings->{$item})) {
990: $designs{$item} = $settings->{$item};
991: $is_custom{$item} = 1;
992: }
993: if (defined($settings->{'showlogo'}{$item})) {
994: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
995: }
996: }
997: foreach my $item (@logintext) {
998: if ($settings->{$item} ne '') {
999: $designs{'logintext'}{$item} = $settings->{$item};
1000: $is_custom{$item} = 1;
1001: }
1002: }
1003: if ($settings->{'font'} ne '') {
1004: $designs{'font'} = $settings->{'font'};
1005: $is_custom{'font'} = 1;
1006: }
1007: foreach my $item (@bgs) {
1008: if ($settings->{$item} ne '') {
1009: $designs{'bgs'}{$item} = $settings->{$item};
1010: $is_custom{$item} = 1;
1011: }
1012: }
1013: foreach my $item (@links) {
1014: if ($settings->{$item} ne '') {
1015: $designs{'links'}{$item} = $settings->{$item};
1016: $is_custom{$item} = 1;
1017: }
1018: }
1019: } else {
1020: if ($designhash{$dom.'.login.font'} ne '') {
1021: $designs{'font'} = $designhash{$dom.'.login.font'};
1022: $is_custom{'font'} = 1;
1023: }
1024: foreach my $item (@images) {
1025: if ($designhash{$dom.'.login.'.$item} ne '') {
1026: $designs{$item} = $designhash{$dom.'.login.'.$item};
1027: $is_custom{$item} = 1;
1028: }
1029: }
1030: foreach my $item (@bgs) {
1031: if ($designhash{$dom.'.login.'.$item} ne '') {
1032: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1033: $is_custom{$item} = 1;
1034: }
1035: }
1036: foreach my $item (@links) {
1037: if ($designhash{$dom.'.login.'.$item} ne '') {
1038: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1039: $is_custom{$item} = 1;
1040: }
1.6 raeburn 1041: }
1042: }
1.160.6.5 raeburn 1043: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1044: logo => 'Institution Logo',
1045: domlogo => 'Domain Logo',
1046: login => 'Login box');
1047: my $itemcount = 1;
1048: foreach my $item (@toggles) {
1049: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1050: $datatable .=
1051: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1052: '</td><td>'.
1053: '<span class="LC_nobreak"><label><input type="radio" name="'.
1054: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1055: '</label> <label><input type="radio" name="'.$item.'"'.
1056: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1057: '</tr>';
1058: $itemcount ++;
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1061: $datatable .= '</tr></table></td></tr>';
1062: } elsif ($caller eq 'help') {
1063: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1064: my $switchserver = &check_switchserver($dom,$confname);
1065: my $itemcount = 1;
1066: $defaulturl = '/adm/loginproblems.html';
1067: $defaulttype = 'default';
1068: %lt = &Apache::lonlocal::texthash (
1069: del => 'Delete?',
1070: rep => 'Replace:',
1071: upl => 'Upload:',
1072: default => 'Default',
1073: custom => 'Custom',
1074: );
1075: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1076: my @currlangs;
1077: if (ref($settings) eq 'HASH') {
1078: if (ref($settings->{'helpurl'}) eq 'HASH') {
1079: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1080: next if ($settings->{'helpurl'}{$key} eq '');
1081: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1082: $type{$key} = 'custom';
1083: unless ($key eq 'nolang') {
1084: push(@currlangs,$key);
1085: }
1086: }
1087: } elsif ($settings->{'helpurl'} ne '') {
1088: $type{'nolang'} = 'custom';
1089: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1090: }
1091: }
1.160.6.5 raeburn 1092: foreach my $lang ('nolang',sort(@currlangs)) {
1093: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1094: $datatable .= '<tr'.$css_class.'>';
1095: if ($url{$lang} eq '') {
1096: $url{$lang} = $defaulturl;
1097: }
1098: if ($type{$lang} eq '') {
1099: $type{$lang} = $defaulttype;
1100: }
1101: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1102: if ($lang eq 'nolang') {
1103: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1104: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1105: } else {
1106: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1107: $langchoices{$lang},
1108: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1109: }
1110: $datatable .= '</span></td>'."\n".
1111: '<td class="LC_left_item">';
1112: if ($type{$lang} eq 'custom') {
1113: $datatable .= '<span class="LC_nobreak"><label>'.
1114: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1115: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1116: } else {
1117: $datatable .= $lt{'upl'};
1118: }
1119: $datatable .='<br />';
1120: if ($switchserver) {
1121: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1122: } else {
1123: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1124: }
1.160.6.5 raeburn 1125: $datatable .= '</td></tr>';
1126: $itemcount ++;
1.6 raeburn 1127: }
1.160.6.5 raeburn 1128: my @addlangs;
1129: foreach my $lang (sort(keys(%langchoices))) {
1130: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1131: push(@addlangs,$lang);
1132: }
1133: if (@addlangs > 0) {
1134: my %toadd;
1135: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1136: $toadd{''} = &mt('Select');
1137: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1138: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1139: &mt('Add log-in help page for a specific language:').' '.
1140: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1141: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1142: if ($switchserver) {
1143: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1144: } else {
1145: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1146: }
1.160.6.5 raeburn 1147: $datatable .= '</td></tr>';
1148: $itemcount ++;
1.6 raeburn 1149: }
1.160.6.5 raeburn 1150: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1151: }
1.6 raeburn 1152: return $datatable;
1153: }
1154:
1155: sub login_choices {
1156: my %choices =
1157: &Apache::lonlocal::texthash (
1.116 bisitz 1158: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1159: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1160: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1161: disallowlogin => "Login page requests redirected",
1162: hostid => "Server",
1.128 raeburn 1163: server => "Redirect to:",
1164: serverpath => "Path",
1165: custompath => "Custom",
1166: exempt => "Exempt IP(s)",
1.110 raeburn 1167: directlogin => "No redirect",
1168: newuser => "Link to create a user account",
1169: img => "Header",
1170: logo => "Main Logo",
1171: domlogo => "Domain Logo",
1172: login => "Log-in Header",
1173: textcol => "Text color",
1174: bgcol => "Box color",
1175: bgs => "Background colors",
1176: links => "Link colors",
1177: font => "Font color",
1178: pgbg => "Header",
1179: mainbg => "Page",
1180: sidebg => "Login box",
1181: link => "Link",
1182: alink => "Active link",
1183: vlink => "Visited link",
1.6 raeburn 1184: );
1185: return %choices;
1186: }
1187:
1188: sub print_rolecolors {
1.30 raeburn 1189: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1190: my %choices = &color_font_choices();
1191: my @bgs = ('pgbg','tabbg','sidebg');
1192: my @links = ('link','alink','vlink');
1193: my @images = ('img');
1194: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1195: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1196: my %defaultdesign = %Apache::loncommon::defaultdesign;
1197: my (%is_custom,%designs);
1.160.6.22 raeburn 1198: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1199: if (ref($settings) eq 'HASH') {
1200: if (ref($settings->{$role}) eq 'HASH') {
1201: if ($settings->{$role}->{'img'} ne '') {
1202: $designs{'img'} = $settings->{$role}->{'img'};
1203: $is_custom{'img'} = 1;
1204: }
1205: if ($settings->{$role}->{'font'} ne '') {
1206: $designs{'font'} = $settings->{$role}->{'font'};
1207: $is_custom{'font'} = 1;
1208: }
1.97 tempelho 1209: if ($settings->{$role}->{'fontmenu'} ne '') {
1210: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1211: $is_custom{'fontmenu'} = 1;
1212: }
1.6 raeburn 1213: foreach my $item (@bgs) {
1214: if ($settings->{$role}->{$item} ne '') {
1215: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1216: $is_custom{$item} = 1;
1217: }
1218: }
1219: foreach my $item (@links) {
1220: if ($settings->{$role}->{$item} ne '') {
1221: $designs{'links'}{$item} = $settings->{$role}->{$item};
1222: $is_custom{$item} = 1;
1223: }
1224: }
1225: }
1226: } else {
1227: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1228: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1229: $is_custom{'img'} = 1;
1230: }
1.97 tempelho 1231: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1232: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1233: $is_custom{'fontmenu'} = 1;
1234: }
1.6 raeburn 1235: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1236: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1237: $is_custom{'font'} = 1;
1238: }
1239: foreach my $item (@bgs) {
1240: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1241: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1242: $is_custom{$item} = 1;
1243:
1244: }
1245: }
1246: foreach my $item (@links) {
1247: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1248: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1249: $is_custom{$item} = 1;
1250: }
1251: }
1252: }
1253: my $itemcount = 1;
1.30 raeburn 1254: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1255: $datatable .= '</tr></table></td></tr>';
1256: return $datatable;
1257: }
1258:
1.160.6.22 raeburn 1259: sub role_defaults {
1260: my ($role,$bgs,$links,$images,$logintext) = @_;
1261: my %defaults;
1262: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1263: return %defaults;
1264: }
1265: my %defaultdesign = %Apache::loncommon::defaultdesign;
1266: if ($role eq 'login') {
1267: %defaults = (
1268: font => $defaultdesign{$role.'.font'},
1269: );
1270: if (ref($logintext) eq 'ARRAY') {
1271: foreach my $item (@{$logintext}) {
1272: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1273: }
1274: }
1275: foreach my $item (@{$images}) {
1276: $defaults{'showlogo'}{$item} = 1;
1277: }
1278: } else {
1279: %defaults = (
1280: img => $defaultdesign{$role.'.img'},
1281: font => $defaultdesign{$role.'.font'},
1282: fontmenu => $defaultdesign{$role.'.fontmenu'},
1283: );
1284: }
1285: foreach my $item (@{$bgs}) {
1286: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1287: }
1288: foreach my $item (@{$links}) {
1289: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1290: }
1291: foreach my $item (@{$images}) {
1292: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1293: }
1294: return %defaults;
1295: }
1296:
1.6 raeburn 1297: sub display_color_options {
1.9 raeburn 1298: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1299: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1300: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1301: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1302: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1303: '<td>'.$choices->{'font'}.'</td>';
1304: if (!$is_custom->{'font'}) {
1.30 raeburn 1305: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1306: } else {
1307: $datatable .= '<td> </td>';
1308: }
1.160.6.9 raeburn 1309: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1310:
1.8 raeburn 1311: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1312: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1313: ' value="'.$current_color.'" /> '.
1314: ' </td></tr>';
1.107 raeburn 1315: unless ($role eq 'login') {
1316: $datatable .= '<tr'.$css_class.'>'.
1317: '<td>'.$choices->{'fontmenu'}.'</td>';
1318: if (!$is_custom->{'fontmenu'}) {
1319: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1320: } else {
1321: $datatable .= '<td> </td>';
1322: }
1.160.6.22 raeburn 1323: $current_color = $designs->{'fontmenu'} ?
1324: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1325: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1326: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1327: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1328: ' value="'.$current_color.'" /> '.
1329: ' </td></tr>';
1.97 tempelho 1330: }
1.9 raeburn 1331: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1332: foreach my $img (@{$images}) {
1.18 albertel 1333: $itemcount ++;
1.6 raeburn 1334: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1335: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1336: '<td>'.$choices->{$img};
1.41 raeburn 1337: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1338: if ($role eq 'login') {
1339: if ($img eq 'login') {
1340: $login_hdr_pick =
1.135 bisitz 1341: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1342: $logincolors =
1343: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1344: $designs,$defaults);
1.70 raeburn 1345: } elsif ($img ne 'domlogo') {
1346: $datatable.= &logo_display_options($img,$defaults,$designs);
1347: }
1348: }
1349: $datatable .= '</td>';
1.6 raeburn 1350: if ($designs->{$img} ne '') {
1351: $imgfile = $designs->{$img};
1.18 albertel 1352: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1353: } else {
1354: $imgfile = $defaults->{$img};
1355: }
1356: if ($imgfile) {
1.9 raeburn 1357: my ($showfile,$fullsize);
1358: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1359: my $urldir = $1;
1360: my $filename = $2;
1361: my @info = &Apache::lonnet::stat_file($designs->{$img});
1362: if (@info) {
1363: my $thumbfile = 'tn-'.$filename;
1364: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1365: if (@thumb) {
1366: $showfile = $urldir.'/'.$thumbfile;
1367: } else {
1368: $showfile = $imgfile;
1369: }
1370: } else {
1371: $showfile = '';
1372: }
1373: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1374: $showfile = $imgfile;
1.6 raeburn 1375: my $imgdir = $1;
1376: my $filename = $2;
1.159 raeburn 1377: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1378: $showfile = "/$imgdir/tn-".$filename;
1379: } else {
1.159 raeburn 1380: my $input = $londocroot.$imgfile;
1381: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1382: if (!-e $output) {
1.9 raeburn 1383: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1384: my ($fullwidth,$fullheight) = &check_dimensions($input);
1385: if ($fullwidth ne '' && $fullheight ne '') {
1386: if ($fullwidth > $width && $fullheight > $height) {
1387: my $size = $width.'x'.$height;
1388: system("convert -sample $size $input $output");
1.159 raeburn 1389: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1390: }
1391: }
1.6 raeburn 1392: }
1393: }
1.16 raeburn 1394: }
1.6 raeburn 1395: if ($showfile) {
1.40 raeburn 1396: if ($showfile =~ m{^/(adm|res)/}) {
1397: if ($showfile =~ m{^/res/}) {
1398: my $local_showfile =
1399: &Apache::lonnet::filelocation('',$showfile);
1400: &Apache::lonnet::repcopy($local_showfile);
1401: }
1402: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1403: }
1404: if ($imgfile) {
1405: if ($imgfile =~ m{^/(adm|res)/}) {
1406: if ($imgfile =~ m{^/res/}) {
1407: my $local_imgfile =
1408: &Apache::lonnet::filelocation('',$imgfile);
1409: &Apache::lonnet::repcopy($local_imgfile);
1410: }
1411: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1412: } else {
1413: $fullsize = $imgfile;
1414: }
1415: }
1.41 raeburn 1416: $datatable .= '<td>';
1417: if ($img eq 'login') {
1.135 bisitz 1418: $datatable .= $login_hdr_pick;
1419: }
1.41 raeburn 1420: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1421: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1422: } else {
1.160.6.22 raeburn 1423: $datatable .= '<td> </td><td class="LC_left_item">'.
1424: &mt('Upload:').'<br />';
1.6 raeburn 1425: }
1426: } else {
1.160.6.22 raeburn 1427: $datatable .= '<td> </td><td class="LC_left_item">'.
1428: &mt('Upload:').'<br />';
1.6 raeburn 1429: }
1.9 raeburn 1430: if ($switchserver) {
1431: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1432: } else {
1.135 bisitz 1433: if ($img ne 'login') { # suppress file selection for Log-in header
1434: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1435: }
1.9 raeburn 1436: }
1437: $datatable .= '</td></tr>';
1.6 raeburn 1438: }
1439: $itemcount ++;
1440: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1441: $datatable .= '<tr'.$css_class.'>'.
1442: '<td>'.$choices->{'bgs'}.'</td>';
1443: my $bgs_def;
1444: foreach my $item (@{$bgs}) {
1445: if (!$is_custom->{$item}) {
1.70 raeburn 1446: $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 1447: }
1448: }
1449: if ($bgs_def) {
1.8 raeburn 1450: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1451: } else {
1452: $datatable .= '<td> </td>';
1453: }
1454: $datatable .= '<td class="LC_right_item">'.
1455: '<table border="0"><tr>';
1.160.6.13 raeburn 1456:
1.6 raeburn 1457: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1458: $datatable .= '<td align="center">'.$choices->{$item};
1459: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1460: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1461: $datatable .= ' ';
1.6 raeburn 1462: }
1.160.6.9 raeburn 1463: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1464: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1465: }
1466: $datatable .= '</tr></table></td></tr>';
1467: $itemcount ++;
1468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1469: $datatable .= '<tr'.$css_class.'>'.
1470: '<td>'.$choices->{'links'}.'</td>';
1471: my $links_def;
1472: foreach my $item (@{$links}) {
1473: if (!$is_custom->{$item}) {
1.30 raeburn 1474: $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 1475: }
1476: }
1477: if ($links_def) {
1.8 raeburn 1478: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1479: } else {
1480: $datatable .= '<td> </td>';
1481: }
1482: $datatable .= '<td class="LC_right_item">'.
1483: '<table border="0"><tr>';
1484: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1485: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1486: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1487: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1488: $datatable.=' ';
1.6 raeburn 1489: }
1.160.6.9 raeburn 1490: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1491: '" /></td>';
1492: }
1.30 raeburn 1493: $$rowtotal += $itemcount;
1.3 raeburn 1494: return $datatable;
1495: }
1496:
1.70 raeburn 1497: sub logo_display_options {
1498: my ($img,$defaults,$designs) = @_;
1499: my $checkedon;
1500: if (ref($defaults) eq 'HASH') {
1501: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1502: if ($defaults->{'showlogo'}{$img}) {
1503: $checkedon = 'checked="checked" ';
1504: }
1505: }
1506: }
1507: if (ref($designs) eq 'HASH') {
1508: if (ref($designs->{'showlogo'}) eq 'HASH') {
1509: if (defined($designs->{'showlogo'}{$img})) {
1510: if ($designs->{'showlogo'}{$img} == 0) {
1511: $checkedon = '';
1512: } elsif ($designs->{'showlogo'}{$img} == 1) {
1513: $checkedon = 'checked="checked" ';
1514: }
1515: }
1516: }
1517: }
1518: return '<br /><label> <input type="checkbox" name="'.
1519: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1520: &mt('show').'</label>'."\n";
1521: }
1522:
1.41 raeburn 1523: sub login_header_options {
1.135 bisitz 1524: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1525: my $output = '';
1.41 raeburn 1526: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1527: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1528: if (!$is_custom->{'textcol'}) {
1529: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1530: ' ';
1531: }
1532: if (!$is_custom->{'bgcol'}) {
1533: $output .= $choices->{'bgcol'}.': '.
1534: '<span id="css_'.$role.'_font" style="background-color: '.
1535: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1536: }
1537: $output .= '<br />';
1538: }
1539: $output .='<br />';
1540: return $output;
1541: }
1542:
1543: sub login_text_colors {
1.160.6.22 raeburn 1544: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1545: my $color_menu = '<table border="0"><tr>';
1546: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1547: $color_menu .= '<td align="center">'.$choices->{$item};
1548: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1549: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1550: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1551: }
1552: $color_menu .= '</tr></table><br />';
1553: return $color_menu;
1554: }
1555:
1556: sub image_changes {
1557: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1558: my $output;
1.135 bisitz 1559: if ($img eq 'login') {
1560: # suppress image for Log-in header
1561: } elsif (!$is_custom) {
1.70 raeburn 1562: if ($img ne 'domlogo') {
1.41 raeburn 1563: $output .= &mt('Default image:').'<br />';
1564: } else {
1565: $output .= &mt('Default in use:').'<br />';
1566: }
1567: }
1.135 bisitz 1568: if ($img eq 'login') { # suppress image for Log-in header
1569: $output .= '<td>'.$logincolors;
1.41 raeburn 1570: } else {
1.135 bisitz 1571: if ($img_import) {
1572: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1573: }
1574: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1575: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1576: if ($is_custom) {
1577: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1578: '<input type="checkbox" name="'.
1579: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1580: '</label> '.&mt('Replace:').'</span><br />';
1581: } else {
1.160.6.22 raeburn 1582: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1583: }
1.41 raeburn 1584: }
1585: return $output;
1586: }
1587:
1.3 raeburn 1588: sub print_quotas {
1.86 raeburn 1589: my ($dom,$settings,$rowtotal,$action) = @_;
1590: my $context;
1591: if ($action eq 'quotas') {
1592: $context = 'tools';
1593: } else {
1594: $context = $action;
1595: }
1.160.6.20 raeburn 1596: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1597: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1598: my $typecount = 0;
1.101 raeburn 1599: my ($css_class,%titles);
1.86 raeburn 1600: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1601: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1602: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1603: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1604: %titles = &courserequest_titles();
1.160.6.5 raeburn 1605: } elsif ($context eq 'requestauthor') {
1606: @usertools = ('author');
1607: @options = ('norequest','approval','automatic');
1608: %titles = &authorrequest_titles();
1.86 raeburn 1609: } else {
1.160.6.4 raeburn 1610: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1611: %titles = &tool_titles();
1.86 raeburn 1612: }
1.26 raeburn 1613: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1614: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1615: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1616: unless (($context eq 'requestcourses') ||
1617: ($context eq 'requestauthor')) {
1.86 raeburn 1618: if (ref($settings) eq 'HASH') {
1619: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1620: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1621: } else {
1622: $currdefquota = $settings->{$type};
1623: }
1.160.6.20 raeburn 1624: if (ref($settings->{authorquota}) eq 'HASH') {
1625: $currauthorquota = $settings->{authorquota}->{$type};
1626: }
1.78 raeburn 1627: }
1.72 raeburn 1628: }
1.3 raeburn 1629: if (defined($usertypes->{$type})) {
1630: $typecount ++;
1631: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1632: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1633: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1634: '<td class="LC_left_item">';
1.101 raeburn 1635: if ($context eq 'requestcourses') {
1636: $datatable .= '<table><tr>';
1637: }
1638: my %cell;
1.72 raeburn 1639: foreach my $item (@usertools) {
1.101 raeburn 1640: if ($context eq 'requestcourses') {
1641: my ($curroption,$currlimit);
1642: if (ref($settings) eq 'HASH') {
1643: if (ref($settings->{$item}) eq 'HASH') {
1644: $curroption = $settings->{$item}->{$type};
1645: if ($curroption =~ /^autolimit=(\d*)$/) {
1646: $currlimit = $1;
1647: }
1648: }
1649: }
1650: if (!$curroption) {
1651: $curroption = 'norequest';
1652: }
1653: $datatable .= '<th>'.$titles{$item}.'</th>';
1654: foreach my $option (@options) {
1655: my $val = $option;
1656: if ($option eq 'norequest') {
1657: $val = 0;
1658: }
1659: if ($option eq 'validate') {
1660: my $canvalidate = 0;
1661: if (ref($validations{$item}) eq 'HASH') {
1662: if ($validations{$item}{$type}) {
1663: $canvalidate = 1;
1664: }
1665: }
1666: next if (!$canvalidate);
1667: }
1668: my $checked = '';
1669: if ($option eq $curroption) {
1670: $checked = ' checked="checked"';
1671: } elsif ($option eq 'autolimit') {
1672: if ($curroption =~ /^autolimit/) {
1673: $checked = ' checked="checked"';
1674: }
1675: }
1676: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1677: '<input type="radio" name="crsreq_'.$item.
1678: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1679: $titles{$option}.'</label>';
1.101 raeburn 1680: if ($option eq 'autolimit') {
1.127 raeburn 1681: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1682: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1683: 'value="'.$currlimit.'" />';
1.101 raeburn 1684: }
1.127 raeburn 1685: $cell{$item} .= '</span> ';
1.103 raeburn 1686: if ($option eq 'autolimit') {
1.127 raeburn 1687: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1688: }
1.101 raeburn 1689: }
1.160.6.5 raeburn 1690: } elsif ($context eq 'requestauthor') {
1691: my $curroption;
1692: if (ref($settings) eq 'HASH') {
1693: $curroption = $settings->{$type};
1694: }
1695: if (!$curroption) {
1696: $curroption = 'norequest';
1697: }
1698: foreach my $option (@options) {
1699: my $val = $option;
1700: if ($option eq 'norequest') {
1701: $val = 0;
1702: }
1703: my $checked = '';
1704: if ($option eq $curroption) {
1705: $checked = ' checked="checked"';
1706: }
1707: $datatable .= '<span class="LC_nobreak"><label>'.
1708: '<input type="radio" name="authorreq_'.$type.
1709: '" value="'.$val.'"'.$checked.' />'.
1710: $titles{$option}.'</label></span> ';
1711: }
1.101 raeburn 1712: } else {
1713: my $checked = 'checked="checked" ';
1714: if (ref($settings) eq 'HASH') {
1715: if (ref($settings->{$item}) eq 'HASH') {
1716: if ($settings->{$item}->{$type} == 0) {
1717: $checked = '';
1718: } elsif ($settings->{$item}->{$type} == 1) {
1719: $checked = 'checked="checked" ';
1720: }
1.78 raeburn 1721: }
1.72 raeburn 1722: }
1.101 raeburn 1723: $datatable .= '<span class="LC_nobreak"><label>'.
1724: '<input type="checkbox" name="'.$context.'_'.$item.
1725: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1726: '</label></span> ';
1.72 raeburn 1727: }
1.101 raeburn 1728: }
1729: if ($context eq 'requestcourses') {
1730: $datatable .= '</tr><tr>';
1731: foreach my $item (@usertools) {
1.106 raeburn 1732: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1733: }
1734: $datatable .= '</tr></table>';
1.72 raeburn 1735: }
1.86 raeburn 1736: $datatable .= '</td>';
1.160.6.5 raeburn 1737: unless (($context eq 'requestcourses') ||
1738: ($context eq 'requestauthor')) {
1.86 raeburn 1739: $datatable .=
1.160.6.20 raeburn 1740: '<td class="LC_right_item">'.
1741: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1742: '<input type="text" name="quota_'.$type.
1.72 raeburn 1743: '" value="'.$currdefquota.
1.160.6.20 raeburn 1744: '" size="5" /></span>'.(' ' x 2).
1745: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1746: '<input type="text" name="authorquota_'.$type.
1747: '" value="'.$currauthorquota.
1748: '" size="5" /></span></td>';
1.86 raeburn 1749: }
1750: $datatable .= '</tr>';
1.3 raeburn 1751: }
1752: }
1753: }
1.160.6.5 raeburn 1754: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1755: $defaultquota = '20';
1.160.6.20 raeburn 1756: $authorquota = '500';
1.86 raeburn 1757: if (ref($settings) eq 'HASH') {
1758: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1759: $defaultquota = $settings->{'defaultquota'}->{'default'};
1760: } elsif (defined($settings->{'default'})) {
1761: $defaultquota = $settings->{'default'};
1762: }
1.160.6.20 raeburn 1763: if (ref($settings->{'authorquota'}) eq 'HASH') {
1764: $authorquota = $settings->{'authorquota'}->{'default'};
1765: }
1.3 raeburn 1766: }
1767: }
1768: $typecount ++;
1769: $css_class = $typecount%2?' class="LC_odd_row"':'';
1770: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1771: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1772: '<td class="LC_left_item">';
1.101 raeburn 1773: if ($context eq 'requestcourses') {
1774: $datatable .= '<table><tr>';
1775: }
1776: my %defcell;
1.72 raeburn 1777: foreach my $item (@usertools) {
1.101 raeburn 1778: if ($context eq 'requestcourses') {
1779: my ($curroption,$currlimit);
1780: if (ref($settings) eq 'HASH') {
1781: if (ref($settings->{$item}) eq 'HASH') {
1782: $curroption = $settings->{$item}->{'default'};
1783: if ($curroption =~ /^autolimit=(\d*)$/) {
1784: $currlimit = $1;
1785: }
1786: }
1787: }
1788: if (!$curroption) {
1789: $curroption = 'norequest';
1790: }
1791: $datatable .= '<th>'.$titles{$item}.'</th>';
1792: foreach my $option (@options) {
1793: my $val = $option;
1794: if ($option eq 'norequest') {
1795: $val = 0;
1796: }
1797: if ($option eq 'validate') {
1798: my $canvalidate = 0;
1799: if (ref($validations{$item}) eq 'HASH') {
1800: if ($validations{$item}{'default'}) {
1801: $canvalidate = 1;
1802: }
1803: }
1804: next if (!$canvalidate);
1805: }
1806: my $checked = '';
1807: if ($option eq $curroption) {
1808: $checked = ' checked="checked"';
1809: } elsif ($option eq 'autolimit') {
1810: if ($curroption =~ /^autolimit/) {
1811: $checked = ' checked="checked"';
1812: }
1813: }
1814: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1815: '<input type="radio" name="crsreq_'.$item.
1816: '_default" value="'.$val.'"'.$checked.' />'.
1817: $titles{$option}.'</label>';
1818: if ($option eq 'autolimit') {
1.127 raeburn 1819: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1820: $item.'_limit_default" size="1" '.
1821: 'value="'.$currlimit.'" />';
1822: }
1.127 raeburn 1823: $defcell{$item} .= '</span> ';
1.104 raeburn 1824: if ($option eq 'autolimit') {
1.127 raeburn 1825: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1826: }
1.101 raeburn 1827: }
1.160.6.5 raeburn 1828: } elsif ($context eq 'requestauthor') {
1829: my $curroption;
1830: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1831: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1832: }
1833: if (!$curroption) {
1834: $curroption = 'norequest';
1835: }
1836: foreach my $option (@options) {
1837: my $val = $option;
1838: if ($option eq 'norequest') {
1839: $val = 0;
1840: }
1841: my $checked = '';
1842: if ($option eq $curroption) {
1843: $checked = ' checked="checked"';
1844: }
1845: $datatable .= '<span class="LC_nobreak"><label>'.
1846: '<input type="radio" name="authorreq_default"'.
1847: ' value="'.$val.'"'.$checked.' />'.
1848: $titles{$option}.'</label></span> ';
1849: }
1.101 raeburn 1850: } else {
1851: my $checked = 'checked="checked" ';
1852: if (ref($settings) eq 'HASH') {
1853: if (ref($settings->{$item}) eq 'HASH') {
1854: if ($settings->{$item}->{'default'} == 0) {
1855: $checked = '';
1856: } elsif ($settings->{$item}->{'default'} == 1) {
1857: $checked = 'checked="checked" ';
1858: }
1.78 raeburn 1859: }
1.72 raeburn 1860: }
1.101 raeburn 1861: $datatable .= '<span class="LC_nobreak"><label>'.
1862: '<input type="checkbox" name="'.$context.'_'.$item.
1863: '" value="default" '.$checked.'/>'.$titles{$item}.
1864: '</label></span> ';
1865: }
1866: }
1867: if ($context eq 'requestcourses') {
1868: $datatable .= '</tr><tr>';
1869: foreach my $item (@usertools) {
1.106 raeburn 1870: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1871: }
1.101 raeburn 1872: $datatable .= '</tr></table>';
1.72 raeburn 1873: }
1.86 raeburn 1874: $datatable .= '</td>';
1.160.6.5 raeburn 1875: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 1876: $datatable .= '<td class="LC_right_item">'.
1877: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1878: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 1879: $defaultquota.'" size="5" /></span>'.(' ' x2).
1880: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1881: '<input type="text" name="authorquota" value="'.
1882: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1883: }
1884: $datatable .= '</tr>';
1.72 raeburn 1885: $typecount ++;
1886: $css_class = $typecount%2?' class="LC_odd_row"':'';
1887: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 1888: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1889: if ($context eq 'requestcourses') {
1.109 raeburn 1890: $datatable .= &mt('(overrides affiliation, if set)').
1891: '</td>'.
1892: '<td class="LC_left_item">'.
1893: '<table><tr>';
1.101 raeburn 1894: } else {
1.109 raeburn 1895: $datatable .= &mt('(overrides affiliation, if checked)').
1896: '</td>'.
1897: '<td class="LC_left_item" colspan="2">'.
1898: '<br />';
1.101 raeburn 1899: }
1900: my %advcell;
1.72 raeburn 1901: foreach my $item (@usertools) {
1.101 raeburn 1902: if ($context eq 'requestcourses') {
1903: my ($curroption,$currlimit);
1904: if (ref($settings) eq 'HASH') {
1905: if (ref($settings->{$item}) eq 'HASH') {
1906: $curroption = $settings->{$item}->{'_LC_adv'};
1907: if ($curroption =~ /^autolimit=(\d*)$/) {
1908: $currlimit = $1;
1909: }
1910: }
1911: }
1912: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1913: my $checked = '';
1914: if ($curroption eq '') {
1915: $checked = ' checked="checked"';
1916: }
1917: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1918: '<input type="radio" name="crsreq_'.$item.
1919: '__LC_adv" value=""'.$checked.' />'.
1920: &mt('No override set').'</label></span> ';
1.101 raeburn 1921: foreach my $option (@options) {
1922: my $val = $option;
1923: if ($option eq 'norequest') {
1924: $val = 0;
1925: }
1926: if ($option eq 'validate') {
1927: my $canvalidate = 0;
1928: if (ref($validations{$item}) eq 'HASH') {
1929: if ($validations{$item}{'_LC_adv'}) {
1930: $canvalidate = 1;
1931: }
1932: }
1933: next if (!$canvalidate);
1934: }
1935: my $checked = '';
1.104 raeburn 1936: if ($val eq $curroption) {
1.101 raeburn 1937: $checked = ' checked="checked"';
1938: } elsif ($option eq 'autolimit') {
1939: if ($curroption =~ /^autolimit/) {
1940: $checked = ' checked="checked"';
1941: }
1942: }
1943: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1944: '<input type="radio" name="crsreq_'.$item.
1945: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1946: $titles{$option}.'</label>';
1947: if ($option eq 'autolimit') {
1.127 raeburn 1948: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1949: $item.'_limit__LC_adv" size="1" '.
1950: 'value="'.$currlimit.'" />';
1951: }
1.127 raeburn 1952: $advcell{$item} .= '</span> ';
1.104 raeburn 1953: if ($option eq 'autolimit') {
1.127 raeburn 1954: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1955: }
1.101 raeburn 1956: }
1.160.6.5 raeburn 1957: } elsif ($context eq 'requestauthor') {
1958: my $curroption;
1959: if (ref($settings) eq 'HASH') {
1960: $curroption = $settings->{'_LC_adv'};
1961: }
1962: my $checked = '';
1963: if ($curroption eq '') {
1964: $checked = ' checked="checked"';
1965: }
1966: $datatable .= '<span class="LC_nobreak"><label>'.
1967: '<input type="radio" name="authorreq__LC_adv"'.
1968: ' value=""'.$checked.' />'.
1969: &mt('No override set').'</label></span> ';
1970: foreach my $option (@options) {
1971: my $val = $option;
1972: if ($option eq 'norequest') {
1973: $val = 0;
1974: }
1975: my $checked = '';
1976: if ($val eq $curroption) {
1977: $checked = ' checked="checked"';
1978: }
1979: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 1980: '<input type="radio" name="authorreq__LC_adv"'.
1981: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 1982: $titles{$option}.'</label></span> ';
1983: }
1.101 raeburn 1984: } else {
1985: my $checked = 'checked="checked" ';
1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{$item}) eq 'HASH') {
1988: if ($settings->{$item}->{'_LC_adv'} == 0) {
1989: $checked = '';
1990: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1991: $checked = 'checked="checked" ';
1992: }
1.79 raeburn 1993: }
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '<span class="LC_nobreak"><label>'.
1996: '<input type="checkbox" name="'.$context.'_'.$item.
1997: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1998: '</label></span> ';
1999: }
2000: }
2001: if ($context eq 'requestcourses') {
2002: $datatable .= '</tr><tr>';
2003: foreach my $item (@usertools) {
1.106 raeburn 2004: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2005: }
1.101 raeburn 2006: $datatable .= '</tr></table>';
1.72 raeburn 2007: }
1.98 raeburn 2008: $datatable .= '</td></tr>';
1.30 raeburn 2009: $$rowtotal += $typecount;
1.3 raeburn 2010: return $datatable;
2011: }
2012:
1.160.6.5 raeburn 2013: sub print_requestmail {
2014: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2015: my ($now,$datatable,%currapp);
1.102 raeburn 2016: $now = time;
2017: if (ref($settings) eq 'HASH') {
2018: if (ref($settings->{'notify'}) eq 'HASH') {
2019: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2020: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2021: }
2022: }
2023: }
1.160.6.16 raeburn 2024: my $numinrow = 2;
1.160.6.34 raeburn 2025: my $css_class;
2026: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2027: my $text;
2028: if ($action eq 'requestcourses') {
2029: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2030: } elsif ($action eq 'requestauthor') {
2031: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2032: } else {
1.160.6.34 raeburn 2033: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2034: }
1.160.6.34 raeburn 2035: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2036: ' <td>'.$text.'</td>'.
1.102 raeburn 2037: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2038: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2039: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2040: if ($numdc > 0) {
2041: $datatable .= $table;
1.102 raeburn 2042: } else {
2043: $datatable .= &mt('There are no active Domain Coordinators');
2044: }
2045: $datatable .='</td></tr>';
2046: $$rowtotal += $rows;
2047: return $datatable;
2048: }
2049:
1.160.6.30 raeburn 2050: sub print_studentcode {
2051: my ($settings,$rowtotal) = @_;
2052: my $rownum = 0;
2053: my ($output,%current);
2054: my @crstypes = ('official','unofficial','community','textbook');
2055: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2056: foreach my $type (@crstypes) {
2057: $current{$type} = $settings->{'uniquecode'}{$type};
2058: }
2059: }
2060: $output .= '<tr>'.
2061: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2062: '<td class="LC_left_item">';
2063: foreach my $type (@crstypes) {
2064: my $check = ' ';
2065: if ($current{$type}) {
2066: $check = ' checked="checked" ';
2067: }
2068: $output .= '<span class="LC_nobreak"><label>'.
2069: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2070: &mt($type).'</label></span>'.(' 'x2).' ';
2071: }
2072: $output .= '</td></tr>';
2073: $$rowtotal ++;
2074: return $output;
2075: }
2076:
2077: sub print_textbookcourses {
2078: my ($dom,$settings,$rowtotal) = @_;
2079: my $rownum = 0;
2080: my $css_class;
2081: my $itemcount = 1;
2082: my $maxnum = 0;
2083: my $bookshash;
2084: if (ref($settings) eq 'HASH') {
2085: $bookshash = $settings->{'textbooks'};
2086: }
2087: my %ordered;
2088: if (ref($bookshash) eq 'HASH') {
2089: foreach my $item (keys(%{$bookshash})) {
2090: if (ref($bookshash->{$item}) eq 'HASH') {
2091: my $num = $bookshash->{$item}{'order'};
2092: $ordered{$num} = $item;
2093: }
2094: }
2095: }
2096: my $confname = $dom.'-domainconfig';
2097: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.40 raeburn 2098: $maxnum = scalar(keys(%ordered));
1.160.6.30 raeburn 2099: my $datatable = &textbookcourses_javascript(\%ordered);
2100: if (keys(%ordered)) {
2101: my @items = sort { $a <=> $b } keys(%ordered);
2102: for (my $i=0; $i<@items; $i++) {
2103: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2104: my $key = $ordered{$items[$i]};
2105: my %coursehash=&Apache::lonnet::coursedescription($key);
2106: my $coursetitle = $coursehash{'description'};
2107: my ($subject,$title,$author,$image,$imgsrc,$cdom,$cnum);
2108: if (ref($bookshash->{$key}) eq 'HASH') {
2109: $subject = $bookshash->{$key}->{'subject'};
2110: $title = $bookshash->{$key}->{'title'};
2111: $author = $bookshash->{$key}->{'author'};
2112: $image = $bookshash->{$key}->{'image'};
2113: if ($image ne '') {
2114: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2115: my $imagethumb = "$path/tn-".$imagefile;
2116: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2117: }
2118: }
2119: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$key'".');"';
2120: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2121: .'<select name="'.$key.'"'.$chgstr.'>';
2122: for (my $k=0; $k<=$maxnum; $k++) {
2123: my $vpos = $k+1;
2124: my $selstr;
2125: if ($k == $i) {
2126: $selstr = ' selected="selected" ';
2127: }
2128: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2129: }
2130: $datatable .= '</select>'.(' 'x2).
2131: '<label><input type="checkbox" name="book_del" value="'.$key.'" />'.
2132: &mt('Delete?').'</label></span></td>'.
2133: '<td colspan="2">'.
2134: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="book_subject_'.$i.'" value="'.$subject.'" /></span> '.
2135: (' 'x2).
2136: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="book_title_'.$i.'" value="'.$title.'" /></span> '.
2137: (' 'x2).
2138: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="book_author_'.$i.'" value="'.$author.'" /></span> '.
2139: (' 'x2).
2140: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2141: if ($image) {
2142: $datatable .= '<span class="LC_nobreak">'.
2143: $imgsrc.
2144: '<label><input type="checkbox" name="book_image_del"'.
2145: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2146: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2147: }
2148: if ($switchserver) {
2149: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2150: } else {
2151: $datatable .= '<input type="file" name="book_image_'.$i.'" value="" />';
2152: }
2153: $datatable .= '<input type="hidden" name="book_id_'.$i.'" value="'.$key.'" /></span> '.
2154: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2155: $coursetitle.'</span></td></tr>'."\n";
2156: $itemcount ++;
2157: }
2158: }
2159: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2160: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'addbook_pos'".');"';
2161: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
2162: '<input type="hidden" name="book_maxnum" value="'.$maxnum.'" />'."\n".
2163: '<select name="addbook_pos"'.$chgstr.'>';
2164: for (my $k=0; $k<$maxnum+1; $k++) {
2165: my $vpos = $k+1;
2166: my $selstr;
2167: if ($k == $maxnum) {
2168: $selstr = ' selected="selected" ';
2169: }
2170: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2171: }
2172: $datatable .= '</select> '."\n".
2173: '<input type="checkbox" name="addbook" value="1" />'.&mt('Add').'</td>'."\n".
2174: '<td colspan="2">'.
2175: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="addbook_subject" value="" /></span> '."\n".
2176: (' 'x2).
2177: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="addbook_title" value="" /></span> '."\n".
2178: (' 'x2).
2179: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="addbook_author" value="" /></span> '."\n".
2180: (' 'x2).
2181: '<span class="LC_nobreak">'.&mt('Image:').' ';
2182: if ($switchserver) {
2183: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2184: } else {
2185: $datatable .= '<input type="file" name="addbook_image" value="" />';
2186: }
2187: $datatable .= '</span>'."\n".
2188: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2189: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'addbook_cdom').
2190: '<input type="text" size="25" name="addbook_cnum" value="" />'.
2191: &Apache::loncommon::selectcourse_link
2192: ('display','addbook_cnum','addbook_cdom',undef,undef,undef,'Course');
2193: '</span></td>'."\n".
2194: '</tr>'."\n";
2195: $itemcount ++;
2196: return $datatable;
2197: }
2198:
2199: sub textbookcourses_javascript {
2200: my ($textbooks) = @_;
2201: return unless(ref($textbooks) eq 'HASH');
2202: my $num = scalar(keys(%{$textbooks}));
2203: my @jsarray;
2204: foreach my $item (sort {$a <=> $b } (keys(%{$textbooks}))) {
2205: push(@jsarray,$textbooks->{$item});
2206: }
2207: my $jstext = ' var textbooks = Array('."'".join("','",@jsarray)."'".');'."\n";
2208: return <<"ENDSCRIPT";
2209: <script type="text/javascript">
2210: // <![CDATA[
2211: function reorderBooks(form,item) {
2212: var changedVal;
2213: $jstext
2214: var newpos = 'addbook_pos';
2215: var current = new Array;
2216: var maxh = 1 + $num;
2217: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2218: if (item == newpos) {
2219: changedVal = newitemVal;
2220: } else {
2221: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2222: current[newitemVal] = newpos;
2223: }
2224: for (var i=0; i<textbooks.length; i++) {
2225: var elementName = textbooks[i];
2226: if (elementName != item) {
2227: if (form.elements[elementName]) {
2228: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2229: current[currVal] = elementName;
2230: }
2231: }
2232: }
2233: var oldVal;
2234: for (var j=0; j<maxh; j++) {
2235: if (current[j] == undefined) {
2236: oldVal = j;
2237: }
2238: }
2239: if (oldVal < changedVal) {
2240: for (var k=oldVal+1; k<=changedVal ; k++) {
2241: var elementName = current[k];
2242: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2243: }
2244: } else {
2245: for (var k=changedVal; k<oldVal; k++) {
2246: var elementName = current[k];
2247: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2248: }
2249: }
2250: return;
2251: }
2252:
2253: // ]]>
2254: </script>
2255:
2256: ENDSCRIPT
2257: }
2258:
1.3 raeburn 2259: sub print_autoenroll {
1.30 raeburn 2260: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2261: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2262: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2263: if (ref($settings) eq 'HASH') {
2264: if (exists($settings->{'run'})) {
2265: if ($settings->{'run'} eq '0') {
2266: $runoff = ' checked="checked" ';
2267: $runon = ' ';
2268: } else {
2269: $runon = ' checked="checked" ';
2270: $runoff = ' ';
2271: }
2272: } else {
2273: if ($autorun) {
2274: $runon = ' checked="checked" ';
2275: $runoff = ' ';
2276: } else {
2277: $runoff = ' checked="checked" ';
2278: $runon = ' ';
2279: }
2280: }
1.129 raeburn 2281: if (exists($settings->{'co-owners'})) {
2282: if ($settings->{'co-owners'} eq '0') {
2283: $coownersoff = ' checked="checked" ';
2284: $coownerson = ' ';
2285: } else {
2286: $coownerson = ' checked="checked" ';
2287: $coownersoff = ' ';
2288: }
2289: } else {
2290: $coownersoff = ' checked="checked" ';
2291: $coownerson = ' ';
2292: }
1.3 raeburn 2293: if (exists($settings->{'sender_domain'})) {
2294: $defdom = $settings->{'sender_domain'};
2295: }
1.14 raeburn 2296: } else {
2297: if ($autorun) {
2298: $runon = ' checked="checked" ';
2299: $runoff = ' ';
2300: } else {
2301: $runoff = ' checked="checked" ';
2302: $runon = ' ';
2303: }
1.3 raeburn 2304: }
2305: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2306: my $notif_sender;
2307: if (ref($settings) eq 'HASH') {
2308: $notif_sender = $settings->{'sender_uname'};
2309: }
1.3 raeburn 2310: my $datatable='<tr class="LC_odd_row">'.
2311: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2312: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2313: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2314: $runon.' value="1" />'.&mt('Yes').'</label> '.
2315: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2316: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2317: '</tr><tr>'.
2318: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2319: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2320: &mt('username').': '.
2321: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2322: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2323: ': '.$domform.'</span></td></tr>'.
2324: '<tr class="LC_odd_row">'.
2325: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2326: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2327: '<input type="radio" name="autoassign_coowners"'.
2328: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2329: '<label><input type="radio" name="autoassign_coowners"'.
2330: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2331: '</tr>';
2332: $$rowtotal += 3;
1.3 raeburn 2333: return $datatable;
2334: }
2335:
2336: sub print_autoupdate {
1.30 raeburn 2337: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2338: my $datatable;
2339: if ($position eq 'top') {
2340: my $updateon = ' ';
2341: my $updateoff = ' checked="checked" ';
2342: my $classlistson = ' ';
2343: my $classlistsoff = ' checked="checked" ';
2344: if (ref($settings) eq 'HASH') {
2345: if ($settings->{'run'} eq '1') {
2346: $updateon = $updateoff;
2347: $updateoff = ' ';
2348: }
2349: if ($settings->{'classlists'} eq '1') {
2350: $classlistson = $classlistsoff;
2351: $classlistsoff = ' ';
2352: }
2353: }
2354: my %title = (
2355: run => 'Auto-update active?',
2356: classlists => 'Update information in classlists?',
2357: );
2358: $datatable = '<tr class="LC_odd_row">'.
2359: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2360: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2361: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2362: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2363: '<label><input type="radio" name="autoupdate_run"'.
2364: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2365: '</tr><tr>'.
2366: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2367: '<td class="LC_right_item"><span class="LC_nobreak">'.
2368: '<label><input type="radio" name="classlists"'.
2369: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2370: '<label><input type="radio" name="classlists"'.
2371: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2372: '</tr>';
1.30 raeburn 2373: $$rowtotal += 2;
1.131 raeburn 2374: } elsif ($position eq 'middle') {
2375: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2376: my $numinrow = 3;
2377: my $locknamesettings;
2378: $datatable .= &insttypes_row($settings,$types,$usertypes,
2379: $dom,$numinrow,$othertitle,
2380: 'lockablenames');
2381: $$rowtotal ++;
1.3 raeburn 2382: } else {
1.44 raeburn 2383: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2384: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2385: 'permanentemail','id');
1.33 raeburn 2386: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2387: my $numrows = 0;
1.26 raeburn 2388: if (ref($types) eq 'ARRAY') {
2389: if (@{$types} > 0) {
2390: $datatable =
2391: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2392: \@fields,$types,\$numrows);
1.30 raeburn 2393: $$rowtotal += @{$types};
1.26 raeburn 2394: }
1.3 raeburn 2395: }
2396: $datatable .=
2397: &usertype_update_row($settings,{'default' => $othertitle},
2398: \%fieldtitles,\@fields,['default'],
2399: \$numrows);
1.30 raeburn 2400: $$rowtotal ++;
1.3 raeburn 2401: }
2402: return $datatable;
2403: }
2404:
1.125 raeburn 2405: sub print_autocreate {
2406: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2407: my (%createon,%createoff,%currhash);
1.125 raeburn 2408: my @types = ('xml','req');
2409: if (ref($settings) eq 'HASH') {
2410: foreach my $item (@types) {
2411: $createoff{$item} = ' checked="checked" ';
2412: $createon{$item} = ' ';
2413: if (exists($settings->{$item})) {
2414: if ($settings->{$item}) {
2415: $createon{$item} = ' checked="checked" ';
2416: $createoff{$item} = ' ';
2417: }
2418: }
2419: }
1.160.6.16 raeburn 2420: if ($settings->{'xmldc'} ne '') {
2421: $currhash{$settings->{'xmldc'}} = 1;
2422: }
1.125 raeburn 2423: } else {
2424: foreach my $item (@types) {
2425: $createoff{$item} = ' checked="checked" ';
2426: $createon{$item} = ' ';
2427: }
2428: }
2429: $$rowtotal += 2;
1.160.6.16 raeburn 2430: my $numinrow = 2;
1.125 raeburn 2431: my $datatable='<tr class="LC_odd_row">'.
2432: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2433: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2434: '<input type="radio" name="autocreate_xml"'.
2435: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2436: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2437: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2438: '</td></tr><tr>'.
2439: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2440: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2441: '<input type="radio" name="autocreate_req"'.
2442: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2443: '<label><input type="radio" name="autocreate_req"'.
2444: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2445: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2446: 'autocreate_xmldc',%currhash);
1.125 raeburn 2447: if ($numdc > 1) {
1.143 raeburn 2448: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2449: &mt('Course creation processed as: (choose Dom. Coord.)').
2450: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2451: } else {
1.143 raeburn 2452: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2453: }
1.160.6.16 raeburn 2454: $$rowtotal += $rows;
1.125 raeburn 2455: return $datatable;
2456: }
2457:
1.23 raeburn 2458: sub print_directorysrch {
1.30 raeburn 2459: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2460: my $srchon = ' ';
2461: my $srchoff = ' checked="checked" ';
1.25 raeburn 2462: my ($exacton,$containson,$beginson);
1.24 raeburn 2463: my $localon = ' ';
2464: my $localoff = ' checked="checked" ';
1.23 raeburn 2465: if (ref($settings) eq 'HASH') {
2466: if ($settings->{'available'} eq '1') {
2467: $srchon = $srchoff;
2468: $srchoff = ' ';
2469: }
1.24 raeburn 2470: if ($settings->{'localonly'} eq '1') {
2471: $localon = $localoff;
2472: $localoff = ' ';
2473: }
1.25 raeburn 2474: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2475: foreach my $type (@{$settings->{'searchtypes'}}) {
2476: if ($type eq 'exact') {
2477: $exacton = ' checked="checked" ';
2478: } elsif ($type eq 'contains') {
2479: $containson = ' checked="checked" ';
2480: } elsif ($type eq 'begins') {
2481: $beginson = ' checked="checked" ';
2482: }
2483: }
2484: } else {
2485: if ($settings->{'searchtypes'} eq 'exact') {
2486: $exacton = ' checked="checked" ';
2487: } elsif ($settings->{'searchtypes'} eq 'contains') {
2488: $containson = ' checked="checked" ';
2489: } elsif ($settings->{'searchtypes'} eq 'specify') {
2490: $exacton = ' checked="checked" ';
2491: $containson = ' checked="checked" ';
2492: }
1.23 raeburn 2493: }
2494: }
2495: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2496: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2497:
2498: my $numinrow = 4;
1.26 raeburn 2499: my $cansrchrow = 0;
1.23 raeburn 2500: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2501: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2502: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2503: '<input type="radio" name="dirsrch_available"'.
2504: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2505: '<label><input type="radio" name="dirsrch_available"'.
2506: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2507: '</tr><tr>'.
1.30 raeburn 2508: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2509: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2510: '<input type="radio" name="dirsrch_localonly"'.
2511: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2512: '<label><input type="radio" name="dirsrch_localonly"'.
2513: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2514: '</tr>';
1.30 raeburn 2515: $$rowtotal += 2;
1.26 raeburn 2516: if (ref($usertypes) eq 'HASH') {
2517: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2518: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2519: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2520: $cansrchrow = 1;
2521: }
2522: }
2523: if ($cansrchrow) {
1.30 raeburn 2524: $$rowtotal ++;
1.26 raeburn 2525: $datatable .= '<tr>';
2526: } else {
2527: $datatable .= '<tr class="LC_odd_row">';
2528: }
1.30 raeburn 2529: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2530: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2531: foreach my $title (@{$titleorder}) {
2532: if (defined($searchtitles->{$title})) {
2533: my $check = ' ';
1.93 raeburn 2534: if (ref($settings) eq 'HASH') {
1.39 raeburn 2535: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2536: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2537: $check = ' checked="checked" ';
2538: }
1.25 raeburn 2539: }
2540: }
2541: $datatable .= '<td class="LC_left_item">'.
2542: '<span class="LC_nobreak"><label>'.
2543: '<input type="checkbox" name="searchby" '.
2544: 'value="'.$title.'"'.$check.'/>'.
2545: $searchtitles->{$title}.'</label></span></td>';
2546: }
2547: }
1.26 raeburn 2548: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2549: $$rowtotal ++;
1.26 raeburn 2550: if ($cansrchrow) {
2551: $datatable .= '<tr class="LC_odd_row">';
2552: } else {
2553: $datatable .= '<tr>';
2554: }
1.30 raeburn 2555: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2556: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2557: '<span class="LC_nobreak"><label>'.
2558: '<input type="checkbox" name="searchtypes" '.
2559: $exacton.' value="exact" />'.&mt('Exact match').
2560: '</label> '.
2561: '<label><input type="checkbox" name="searchtypes" '.
2562: $beginson.' value="begins" />'.&mt('Begins with').
2563: '</label> '.
2564: '<label><input type="checkbox" name="searchtypes" '.
2565: $containson.' value="contains" />'.&mt('Contains').
2566: '</label></span></td></tr>';
1.30 raeburn 2567: $$rowtotal ++;
1.25 raeburn 2568: return $datatable;
2569: }
2570:
1.28 raeburn 2571: sub print_contacts {
1.30 raeburn 2572: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2573: my $datatable;
2574: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2575: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2576: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.160.6.23 raeburn 2577: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2578: foreach my $type (@mailings) {
2579: $otheremails{$type} = '';
2580: }
1.134 raeburn 2581: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2582: if (ref($settings) eq 'HASH') {
2583: foreach my $item (@contacts) {
2584: if (exists($settings->{$item})) {
2585: $to{$item} = $settings->{$item};
2586: }
2587: }
2588: foreach my $type (@mailings) {
2589: if (exists($settings->{$type})) {
2590: if (ref($settings->{$type}) eq 'HASH') {
2591: foreach my $item (@contacts) {
2592: if ($settings->{$type}{$item}) {
2593: $checked{$type}{$item} = ' checked="checked" ';
2594: }
2595: }
2596: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2597: if ($type eq 'helpdeskmail') {
2598: $bccemails{$type} = $settings->{$type}{'bcc'};
2599: }
1.28 raeburn 2600: }
1.89 raeburn 2601: } elsif ($type eq 'lonstatusmail') {
2602: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2603: }
2604: }
2605: } else {
2606: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2607: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2608: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2609: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2610: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2611: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2612: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.23 raeburn 2613: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2614: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2615: }
2616: my ($titles,$short_titles) = &contact_titles();
2617: my $rownum = 0;
2618: my $css_class;
2619: foreach my $item (@contacts) {
1.69 raeburn 2620: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2621: $datatable .= '<tr'.$css_class.'>'.
2622: '<td><span class="LC_nobreak">'.$titles->{$item}.
2623: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2624: '<input type="text" name="'.$item.'" value="'.
2625: $to{$item}.'" /></td></tr>';
1.160.6.23 raeburn 2626: $rownum ++;
1.28 raeburn 2627: }
2628: foreach my $type (@mailings) {
1.69 raeburn 2629: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2630: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2631: '<td><span class="LC_nobreak">'.
2632: $titles->{$type}.': </span></td>'.
1.28 raeburn 2633: '<td class="LC_left_item">'.
2634: '<span class="LC_nobreak">';
2635: foreach my $item (@contacts) {
2636: $datatable .= '<label>'.
2637: '<input type="checkbox" name="'.$type.'"'.
2638: $checked{$type}{$item}.
2639: ' value="'.$item.'" />'.$short_titles->{$item}.
2640: '</label> ';
2641: }
2642: $datatable .= '</span><br />'.&mt('Others').': '.
2643: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2644: 'value="'.$otheremails{$type}.'" />';
2645: if ($type eq 'helpdeskmail') {
1.136 raeburn 2646: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2647: '<input type="text" name="'.$type.'_bcc" '.
2648: 'value="'.$bccemails{$type}.'" />';
2649: }
2650: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 2651: $rownum ++;
1.28 raeburn 2652: }
1.160.6.23 raeburn 2653: my %choices;
2654: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2655: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2656: &mt('LON-CAPA core group - MSU'),600,500));
2657: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2658: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2659: &mt('LON-CAPA core group - MSU'),600,500));
2660: my @toggles = ('reporterrors','reportupdates');
2661: my %defaultchecked = ('reporterrors' => 'on',
2662: 'reportupdates' => 'on');
2663: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2664: \%choices,$rownum);
2665: $datatable .= $reports;
1.30 raeburn 2666: $$rowtotal += $rownum;
1.28 raeburn 2667: return $datatable;
2668: }
2669:
1.118 jms 2670: sub print_helpsettings {
1.160.6.5 raeburn 2671: my ($dom,$confname,$settings,$rowtotal) = @_;
2672: my ($datatable,$itemcount);
2673: $itemcount = 1;
2674: my (%choices,%defaultchecked,@toggles);
2675: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2676: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2677: &mt('LON-CAPA bug tracker'),600,500));
2678: %defaultchecked = ('submitbugs' => 'on');
2679: @toggles = ('submitbugs',);
1.122 jms 2680:
1.160.6.5 raeburn 2681: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2682: \%choices,$itemcount);
2683: return $datatable;
1.121 raeburn 2684: }
2685:
2686: sub radiobutton_prefs {
1.160.6.16 raeburn 2687: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2688: $additional) = @_;
1.121 raeburn 2689: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2690: (ref($choices) eq 'HASH'));
2691:
2692: my (%checkedon,%checkedoff,$datatable,$css_class);
2693:
2694: foreach my $item (@{$toggles}) {
2695: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2696: $checkedon{$item} = ' checked="checked" ';
2697: $checkedoff{$item} = ' ';
1.121 raeburn 2698: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2699: $checkedoff{$item} = ' checked="checked" ';
2700: $checkedon{$item} = ' ';
2701: }
2702: }
2703: if (ref($settings) eq 'HASH') {
1.121 raeburn 2704: foreach my $item (@{$toggles}) {
1.118 jms 2705: if ($settings->{$item} eq '1') {
2706: $checkedon{$item} = ' checked="checked" ';
2707: $checkedoff{$item} = ' ';
2708: } elsif ($settings->{$item} eq '0') {
2709: $checkedoff{$item} = ' checked="checked" ';
2710: $checkedon{$item} = ' ';
2711: }
2712: }
1.121 raeburn 2713: }
1.160.6.16 raeburn 2714: if ($onclick) {
2715: $onclick = ' onclick="'.$onclick.'"';
2716: }
1.121 raeburn 2717: foreach my $item (@{$toggles}) {
1.118 jms 2718: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2719: $datatable .=
1.160.6.16 raeburn 2720: '<tr'.$css_class.'><td valign="top">'.
2721: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2722: '</span></td>'.
2723: '<td class="LC_right_item"><span class="LC_nobreak">'.
2724: '<label><input type="radio" name="'.
1.160.6.16 raeburn 2725: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2726: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 2727: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2728: '</span>'.$additional.
2729: '</td>'.
1.118 jms 2730: '</tr>';
2731: $itemcount ++;
1.121 raeburn 2732: }
2733: return ($datatable,$itemcount);
2734: }
2735:
2736: sub print_coursedefaults {
1.139 raeburn 2737: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2738: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2739: my $itemcount = 1;
1.160.6.16 raeburn 2740: my %choices = &Apache::lonlocal::texthash (
2741: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.160.6.21 raeburn 2742: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 2743: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2744: coursecredits => 'Credits can be specified for courses',
2745: );
1.160.6.21 raeburn 2746: my %staticdefaults = (
2747: anonsurvey_threshold => 10,
2748: uploadquota => 500,
2749: );
1.139 raeburn 2750: if ($position eq 'top') {
2751: %defaultchecked = ('canuse_pdfforms' => 'off');
1.160.6.16 raeburn 2752: @toggles = ('canuse_pdfforms');
1.139 raeburn 2753: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2754: \%choices,$itemcount);
1.139 raeburn 2755: } else {
2756: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.30 raeburn 2757: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2758: %curruploadquota);
1.160.6.16 raeburn 2759: my $currusecredits = 0;
1.160.6.30 raeburn 2760: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2761: if (ref($settings) eq 'HASH') {
2762: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 2763: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2764: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2765: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2766: }
2767: }
1.160.6.16 raeburn 2768: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2769: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2770: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.160.6.30 raeburn 2771: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2772: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2773: ($def_textbook_credits ne '')) {
1.160.6.16 raeburn 2774: $currusecredits = 1;
2775: }
2776: }
1.139 raeburn 2777: }
2778: if (!$currdefresponder) {
1.160.6.21 raeburn 2779: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2780: } elsif ($currdefresponder < 1) {
2781: $currdefresponder = 1;
2782: }
1.160.6.21 raeburn 2783: foreach my $type (@types) {
2784: if ($curruploadquota{$type} eq '') {
2785: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2786: }
2787: }
1.139 raeburn 2788: $datatable .=
1.160.6.16 raeburn 2789: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2790: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2791: '</span></td>'.
2792: '<td class="LC_right_item"><span class="LC_nobreak">'.
2793: '<input type="text" name="anonsurvey_threshold"'.
2794: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 2795: '</td></tr>'."\n";
2796: $itemcount ++;
2797: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2798: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2799: $choices{'uploadquota'}.
2800: '</span></td>'.
2801: '<td align="right" class="LC_right_item">'.
2802: '<table><tr>';
1.160.6.21 raeburn 2803: foreach my $type (@types) {
2804: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2805: '<input type="text" name="uploadquota_'.$type.'"'.
2806: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2807: }
2808: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 2809: $itemcount ++;
1.160.6.40 raeburn 2810: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 2811: my $display = 'none';
2812: if ($currusecredits) {
2813: $display = 'block';
2814: }
2815: my $additional = '<div id="credits" style="display: '.$display.'">'.
2816: '<span class="LC_nobreak">'.
2817: &mt('Default credits for official courses [_1]',
2818: '<input type="text" name="official_credits" value="'.
2819: $def_official_credits.'" size="3" />').
2820: '</span><br />'.
2821: '<span class="LC_nobreak">'.
2822: &mt('Default credits for unofficial courses [_1]',
2823: '<input type="text" name="unofficial_credits" value="'.
2824: $def_unofficial_credits.'" size="3" />').
1.160.6.30 raeburn 2825: '</span><br />'.
2826: '<span class="LC_nobreak">'.
2827: &mt('Default credits for textbook courses [_1]',
2828: '<input type="text" name="textbook_credits" value="'.
2829: $def_textbook_credits.'" size="3" />').
1.160.6.16 raeburn 2830: '</span></div>'."\n";
2831: %defaultchecked = ('coursecredits' => 'off');
2832: @toggles = ('coursecredits');
2833: my $current = {
2834: 'coursecredits' => $currusecredits,
2835: };
2836: (my $table,$itemcount) =
2837: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2838: \%choices,$itemcount,$onclick,$additional);
2839: $datatable .= $table;
1.160.6.37 raeburn 2840: $itemcount ++;
2841: }
2842: $$rowtotal += $itemcount;
2843: return $datatable;
2844: }
2845:
2846: sub print_selfenrollment {
2847: my ($position,$dom,$settings,$rowtotal) = @_;
2848: my ($css_class,$datatable);
2849: my $itemcount = 1;
2850: my @types = ('official','unofficial','community','textbook');
2851: if (($position eq 'top') || ($position eq 'middle')) {
2852: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
2853: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
2854: my @rows;
2855: my $key;
2856: if ($position eq 'top') {
2857: $key = 'admin';
2858: if (ref($rowsref) eq 'ARRAY') {
2859: @rows = @{$rowsref};
2860: }
2861: } elsif ($position eq 'middle') {
2862: $key = 'default';
2863: @rows = ('types','registered','approval','limit');
2864: }
2865: foreach my $row (@rows) {
2866: if (defined($titlesref->{$row})) {
2867: $itemcount ++;
2868: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2869: $datatable .= '<tr'.$css_class.'>'.
2870: '<td>'.$titlesref->{$row}.'</td>'.
2871: '<td class="LC_left_item">'.
2872: '<table><tr>';
2873: my (%current,%currentcap);
2874: if (ref($settings) eq 'HASH') {
2875: if (ref($settings->{$key}) eq 'HASH') {
2876: foreach my $type (@types) {
2877: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2878: $current{$type} = $settings->{$key}->{$type}->{$row};
2879: }
2880: if (($row eq 'limit') && ($key eq 'default')) {
2881: if (ref($settings->{$key}->{$type}) eq 'HASH') {
2882: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
2883: }
2884: }
2885: }
2886: }
2887: }
2888: my %roles = (
2889: '0' => &Apache::lonnet::plaintext('dc'),
2890: );
2891:
2892: foreach my $type (@types) {
2893: unless (($row eq 'registered') && ($key eq 'default')) {
2894: $datatable .= '<th>'.&mt($type).'</th>';
2895: }
2896: }
2897: unless (($row eq 'registered') && ($key eq 'default')) {
2898: $datatable .= '</tr><tr>';
2899: }
2900: foreach my $type (@types) {
2901: if ($type eq 'community') {
2902: $roles{'1'} = &mt('Community personnel');
2903: } else {
2904: $roles{'1'} = &mt('Course personnel');
2905: }
2906: $datatable .= '<td style="vertical-align: top">';
2907: if ($position eq 'top') {
2908: my %checked;
2909: if ($current{$type} eq '0') {
2910: $checked{'0'} = ' checked="checked"';
2911: } else {
2912: $checked{'1'} = ' checked="checked"';
2913: }
2914: foreach my $role ('1','0') {
2915: $datatable .= '<span class="LC_nobreak"><label>'.
2916: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
2917: 'value="'.$role.'"'.$checked{$role}.' />'.
2918: $roles{$role}.'</label></span> ';
2919: }
2920: } else {
2921: if ($row eq 'types') {
2922: my %checked;
2923: if ($current{$type} =~ /^(all|dom)$/) {
2924: $checked{$1} = ' checked="checked"';
2925: } else {
2926: $checked{''} = ' checked="checked"';
2927: }
2928: foreach my $val ('','dom','all') {
2929: $datatable .= '<span class="LC_nobreak"><label>'.
2930: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2931: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2932: }
2933: } elsif ($row eq 'registered') {
2934: my %checked;
2935: if ($current{$type} eq '1') {
2936: $checked{'1'} = ' checked="checked"';
2937: } else {
2938: $checked{'0'} = ' checked="checked"';
2939: }
2940: foreach my $val ('0','1') {
2941: $datatable .= '<span class="LC_nobreak"><label>'.
2942: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2943: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2944: }
2945: } elsif ($row eq 'approval') {
2946: my %checked;
2947: if ($current{$type} =~ /^([12])$/) {
2948: $checked{$1} = ' checked="checked"';
2949: } else {
2950: $checked{'0'} = ' checked="checked"';
2951: }
2952: for my $val (0..2) {
2953: $datatable .= '<span class="LC_nobreak"><label>'.
2954: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2955: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2956: }
2957: } elsif ($row eq 'limit') {
2958: my %checked;
2959: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
2960: $checked{$1} = ' checked="checked"';
2961: } else {
2962: $checked{'none'} = ' checked="checked"';
2963: }
2964: my $cap;
2965: if ($currentcap{$type} =~ /^\d+$/) {
2966: $cap = $currentcap{$type};
2967: }
2968: foreach my $val ('none','allstudents','selfenrolled') {
2969: $datatable .= '<span class="LC_nobreak"><label>'.
2970: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
2971: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
2972: }
2973: $datatable .= '<br />'.
2974: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
2975: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
2976: '</span>';
2977: }
2978: }
2979: $datatable .= '</td>';
2980: }
2981: $datatable .= '</tr>';
2982: }
2983: $datatable .= '</table></td></tr>';
2984: }
2985: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 2986: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
2987: }
2988: $$rowtotal += $itemcount;
2989: return $datatable;
2990: }
2991:
2992: sub print_validation_rows {
2993: my ($caller,$dom,$settings,$rowtotal) = @_;
2994: my ($itemsref,$namesref,$fieldsref);
2995: if ($caller eq 'selfenroll') {
2996: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
2997: } elsif ($caller eq 'requestcourses') {
2998: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
2999: }
3000: my %currvalidation;
3001: if (ref($settings) eq 'HASH') {
3002: if (ref($settings->{'validation'}) eq 'HASH') {
3003: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3004: }
1.160.6.39 raeburn 3005: }
3006: my $datatable;
3007: my $itemcount = 0;
3008: foreach my $item (@{$itemsref}) {
3009: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3010: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3011: $namesref->{$item}.
3012: '</span></td>'.
3013: '<td class="LC_left_item">';
3014: if (($item eq 'url') || ($item eq 'button')) {
3015: $datatable .= '<span class="LC_nobreak">'.
3016: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3017: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3018: } elsif ($item eq 'fields') {
3019: my @currfields;
3020: if (ref($currvalidation{$item}) eq 'ARRAY') {
3021: @currfields = @{$currvalidation{$item}};
3022: }
3023: foreach my $field (@{$fieldsref}) {
3024: my $check = '';
3025: if (grep(/^\Q$field\E$/,@currfields)) {
3026: $check = ' checked="checked"';
3027: }
3028: $datatable .= '<span class="LC_nobreak"><label>'.
3029: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3030: ' value="'.$field.'"'.$check.' />'.$field.
3031: '</label></span> ';
3032: }
3033: } elsif ($item eq 'markup') {
3034: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3035: $currvalidation{$item}.
1.160.6.37 raeburn 3036: '</textarea>';
1.160.6.39 raeburn 3037: }
3038: $datatable .= '</td></tr>'."\n";
3039: if (ref($rowtotal)) {
1.160.6.37 raeburn 3040: $itemcount ++;
3041: }
1.139 raeburn 3042: }
1.160.6.39 raeburn 3043: if ($caller eq 'requestcourses') {
3044: my %currhash;
3045: if (ref($settings->{'validation'}) eq 'HASH') {
3046: if ($settings->{'validation'}{'dc'} ne '') {
3047: $currhash{$settings->{'validation'}{'dc'}} = 1;
3048: }
3049: }
3050: my $numinrow = 2;
3051: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3052: 'validationdc',%currhash);
3053: if ($numdc > 1) {
3054: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
3055: &mt('Course creation processed as: (choose Dom. Coord.)').
3056: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
3057: } else {
3058: $datatable .= $dctable.'</td></tr>';
3059: }
3060: $itemcount ++;
3061: }
3062: if (ref($rowtotal)) {
3063: $$rowtotal += $itemcount;
3064: }
1.121 raeburn 3065: return $datatable;
1.118 jms 3066: }
3067:
1.137 raeburn 3068: sub print_usersessions {
3069: my ($position,$dom,$settings,$rowtotal) = @_;
3070: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3071: my (%by_ip,%by_location,@intdoms);
3072: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3073:
3074: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3075: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3076: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3077: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3078: my $itemcount = 1;
3079: if ($position eq 'top') {
1.152 raeburn 3080: if (keys(%serverhomes) > 1) {
1.145 raeburn 3081: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3082: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3083: } else {
1.140 raeburn 3084: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3085: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3086: }
1.137 raeburn 3087: } else {
1.145 raeburn 3088: if (keys(%by_location) == 0) {
3089: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3090: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3091: } else {
3092: my %lt = &usersession_titles();
3093: my $numinrow = 5;
3094: my $prefix;
3095: my @types;
3096: if ($position eq 'bottom') {
3097: $prefix = 'remote';
3098: @types = ('version','excludedomain','includedomain');
3099: } else {
3100: $prefix = 'hosted';
3101: @types = ('excludedomain','includedomain');
3102: }
3103: my (%current,%checkedon,%checkedoff);
3104: my @lcversions = &Apache::lonnet::all_loncaparevs();
3105: my @locations = sort(keys(%by_location));
3106: foreach my $type (@types) {
3107: $checkedon{$type} = '';
3108: $checkedoff{$type} = ' checked="checked"';
3109: }
3110: if (ref($settings) eq 'HASH') {
3111: if (ref($settings->{$prefix}) eq 'HASH') {
3112: foreach my $key (keys(%{$settings->{$prefix}})) {
3113: $current{$key} = $settings->{$prefix}{$key};
3114: if ($key eq 'version') {
3115: if ($current{$key} ne '') {
3116: $checkedon{$key} = ' checked="checked"';
3117: $checkedoff{$key} = '';
3118: }
3119: } elsif (ref($current{$key}) eq 'ARRAY') {
3120: $checkedon{$key} = ' checked="checked"';
3121: $checkedoff{$key} = '';
3122: }
1.137 raeburn 3123: }
3124: }
3125: }
1.145 raeburn 3126: foreach my $type (@types) {
3127: next if ($type ne 'version' && !@locations);
3128: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3129: $datatable .= '<tr'.$css_class.'>
3130: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3131: <span class="LC_nobreak">
3132: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3133: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3134: if ($type eq 'version') {
3135: my $selector = '<select name="'.$prefix.'_version">';
3136: foreach my $version (@lcversions) {
3137: my $selected = '';
3138: if ($current{'version'} eq $version) {
3139: $selected = ' selected="selected"';
3140: }
3141: $selector .= ' <option value="'.$version.'"'.
3142: $selected.'>'.$version.'</option>';
3143: }
3144: $selector .= '</select> ';
3145: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3146: } else {
3147: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3148: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3149: ' />'.(' 'x2).
3150: '<input type="button" value="'.&mt('uncheck all').'" '.
3151: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3152: "\n".
3153: '</div><div><table>';
3154: my $rem;
3155: for (my $i=0; $i<@locations; $i++) {
3156: my ($showloc,$value,$checkedtype);
3157: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3158: my $ip = $by_location{$locations[$i]}->[0];
3159: if (ref($by_ip{$ip}) eq 'ARRAY') {
3160: $value = join(':',@{$by_ip{$ip}});
3161: $showloc = join(', ',@{$by_ip{$ip}});
3162: if (ref($current{$type}) eq 'ARRAY') {
3163: foreach my $loc (@{$by_ip{$ip}}) {
3164: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3165: $checkedtype = ' checked="checked"';
3166: last;
3167: }
3168: }
1.138 raeburn 3169: }
3170: }
3171: }
1.145 raeburn 3172: $rem = $i%($numinrow);
3173: if ($rem == 0) {
3174: if ($i > 0) {
3175: $datatable .= '</tr>';
3176: }
3177: $datatable .= '<tr>';
3178: }
3179: $datatable .= '<td class="LC_left_item">'.
3180: '<span class="LC_nobreak"><label>'.
3181: '<input type="checkbox" name="'.$prefix.'_'.$type.
3182: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3183: '</label></span></td>';
1.137 raeburn 3184: }
1.145 raeburn 3185: $rem = @locations%($numinrow);
3186: my $colsleft = $numinrow - $rem;
3187: if ($colsleft > 1 ) {
3188: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3189: ' </td>';
3190: } elsif ($colsleft == 1) {
3191: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3192: }
1.145 raeburn 3193: $datatable .= '</tr></table>';
1.137 raeburn 3194: }
1.145 raeburn 3195: $datatable .= '</td></tr>';
3196: $itemcount ++;
1.137 raeburn 3197: }
3198: }
3199: }
3200: $$rowtotal += $itemcount;
3201: return $datatable;
3202: }
3203:
1.138 raeburn 3204: sub build_location_hashes {
3205: my ($intdoms,$by_ip,$by_location) = @_;
3206: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3207: (ref($by_location) eq 'HASH'));
3208: my %iphost = &Apache::lonnet::get_iphost();
3209: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3210: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3211: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3212: foreach my $id (@{$iphost{$primary_ip}}) {
3213: my $intdom = &Apache::lonnet::internet_dom($id);
3214: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3215: push(@{$intdoms},$intdom);
3216: }
3217: }
3218: }
3219: foreach my $ip (keys(%iphost)) {
3220: if (ref($iphost{$ip}) eq 'ARRAY') {
3221: foreach my $id (@{$iphost{$ip}}) {
3222: my $location = &Apache::lonnet::internet_dom($id);
3223: if ($location) {
3224: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3225: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3226: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3227: push(@{$by_ip->{$ip}},$location);
3228: }
3229: } else {
3230: $by_ip->{$ip} = [$location];
3231: }
3232: }
3233: }
3234: }
3235: }
3236: foreach my $ip (sort(keys(%{$by_ip}))) {
3237: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3238: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3239: my $first = $by_ip->{$ip}->[0];
3240: if (ref($by_location->{$first}) eq 'ARRAY') {
3241: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3242: push(@{$by_location->{$first}},$ip);
3243: }
3244: } else {
3245: $by_location->{$first} = [$ip];
3246: }
3247: }
3248: }
3249: return;
3250: }
3251:
1.145 raeburn 3252: sub current_offloads_to {
3253: my ($dom,$settings,$servers) = @_;
3254: my (%spareid,%otherdomconfigs);
1.152 raeburn 3255: if (ref($servers) eq 'HASH') {
1.145 raeburn 3256: foreach my $lonhost (sort(keys(%{$servers}))) {
3257: my $gotspares;
1.152 raeburn 3258: if (ref($settings) eq 'HASH') {
3259: if (ref($settings->{'spares'}) eq 'HASH') {
3260: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3261: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3262: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3263: $gotspares = 1;
3264: }
1.145 raeburn 3265: }
3266: }
3267: unless ($gotspares) {
3268: my $gotspares;
3269: my $serverhomeID =
3270: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3271: my $serverhomedom =
3272: &Apache::lonnet::host_domain($serverhomeID);
3273: if ($serverhomedom ne $dom) {
3274: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3275: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3276: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3277: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3278: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3279: $gotspares = 1;
3280: }
3281: }
3282: } else {
3283: $otherdomconfigs{$serverhomedom} =
3284: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3285: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3286: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3287: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3288: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3289: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3290: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3291: $gotspares = 1;
3292: }
3293: }
3294: }
3295: }
3296: }
3297: }
3298: }
3299: unless ($gotspares) {
3300: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3301: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3302: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3303: } else {
3304: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3305: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3306: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3307: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3308: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3309: } else {
1.150 raeburn 3310: my %what = (
3311: spareid => 1,
3312: );
3313: my ($result,$returnhash) =
3314: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3315: if ($result eq 'ok') {
3316: if (ref($returnhash) eq 'HASH') {
3317: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3318: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3319: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3320: }
3321: }
1.145 raeburn 3322: }
3323: }
3324: }
3325: }
3326: }
3327: }
3328: return %spareid;
3329: }
3330:
3331: sub spares_row {
1.152 raeburn 3332: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3333: my $css_class;
3334: my $numinrow = 4;
3335: my $itemcount = 1;
3336: my $datatable;
1.152 raeburn 3337: my %typetitles = &sparestype_titles();
3338: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3339: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3340: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3341: my ($othercontrol,$serverdom);
3342: if ($serverhome ne $server) {
3343: $serverdom = &Apache::lonnet::host_domain($serverhome);
3344: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3345: } else {
3346: $serverdom = &Apache::lonnet::host_domain($server);
3347: if ($serverdom ne $dom) {
3348: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3349: }
3350: }
3351: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3352: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3353: $datatable .= '<tr'.$css_class.'>
3354: <td rowspan="2">
1.160.6.13 raeburn 3355: <span class="LC_nobreak">'.
3356: &mt('[_1] when busy, offloads to:'
3357: ,'<b>'.$server.'</b>').
3358: "\n";
1.145 raeburn 3359: my (%current,%canselect);
1.152 raeburn 3360: my @choices =
3361: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3362: foreach my $type ('primary','default') {
3363: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3364: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3365: my @spares = @{$spareid->{$server}{$type}};
3366: if (@spares > 0) {
1.152 raeburn 3367: if ($othercontrol) {
3368: $current{$type} = join(', ',@spares);
3369: } else {
3370: $current{$type} .= '<table>';
3371: my $numspares = scalar(@spares);
3372: for (my $i=0; $i<@spares; $i++) {
3373: my $rem = $i%($numinrow);
3374: if ($rem == 0) {
3375: if ($i > 0) {
3376: $current{$type} .= '</tr>';
3377: }
3378: $current{$type} .= '<tr>';
1.145 raeburn 3379: }
1.152 raeburn 3380: $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'".');" /> '.
3381: $spareid->{$server}{$type}[$i].
3382: '</label></td>'."\n";
3383: }
3384: my $rem = @spares%($numinrow);
3385: my $colsleft = $numinrow - $rem;
3386: if ($colsleft > 1 ) {
3387: $current{$type} .= '<td colspan="'.$colsleft.
3388: '" class="LC_left_item">'.
3389: ' </td>';
3390: } elsif ($colsleft == 1) {
3391: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3392: }
1.152 raeburn 3393: $current{$type} .= '</tr></table>';
1.150 raeburn 3394: }
1.145 raeburn 3395: }
3396: }
3397: if ($current{$type} eq '') {
3398: $current{$type} = &mt('None specified');
3399: }
1.152 raeburn 3400: if ($othercontrol) {
3401: if ($type eq 'primary') {
3402: $canselect{$type} = $othercontrol;
3403: }
3404: } else {
3405: $canselect{$type} =
3406: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3407: '<select name="newspare_'.$type.'_'.$server.'" '.
3408: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3409: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3410: if (@choices > 0) {
3411: foreach my $lonhost (@choices) {
3412: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3413: }
3414: }
3415: $canselect{$type} .= '</select>'."\n";
3416: }
3417: } else {
3418: $current{$type} = &mt('Could not be determined');
3419: if ($type eq 'primary') {
3420: $canselect{$type} = $othercontrol;
3421: }
1.145 raeburn 3422: }
1.152 raeburn 3423: if ($type eq 'default') {
3424: $datatable .= '<tr'.$css_class.'>';
3425: }
3426: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3427: '<td>'.$current{$type}.'</td>'."\n".
3428: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3429: }
3430: $itemcount ++;
3431: }
3432: }
3433: $$rowtotal += $itemcount;
3434: return $datatable;
3435: }
3436:
1.152 raeburn 3437: sub possible_newspares {
3438: my ($server,$currspares,$serverhomes,$altids) = @_;
3439: my $serverhostname = &Apache::lonnet::hostname($server);
3440: my %excluded;
3441: if ($serverhostname ne '') {
3442: %excluded = (
3443: $serverhostname => 1,
3444: );
3445: }
3446: if (ref($currspares) eq 'HASH') {
3447: foreach my $type (keys(%{$currspares})) {
3448: if (ref($currspares->{$type}) eq 'ARRAY') {
3449: if (@{$currspares->{$type}} > 0) {
3450: foreach my $curr (@{$currspares->{$type}}) {
3451: my $hostname = &Apache::lonnet::hostname($curr);
3452: $excluded{$hostname} = 1;
3453: }
3454: }
3455: }
3456: }
3457: }
3458: my @choices;
3459: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3460: if (keys(%{$serverhomes}) > 1) {
3461: foreach my $name (sort(keys(%{$serverhomes}))) {
3462: unless ($excluded{$name}) {
3463: if (exists($altids->{$serverhomes->{$name}})) {
3464: push(@choices,$altids->{$serverhomes->{$name}});
3465: } else {
3466: push(@choices,$serverhomes->{$name});
1.145 raeburn 3467: }
3468: }
3469: }
3470: }
3471: }
1.152 raeburn 3472: return sort(@choices);
1.145 raeburn 3473: }
3474:
1.150 raeburn 3475: sub print_loadbalancing {
3476: my ($dom,$settings,$rowtotal) = @_;
3477: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3478: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3479: my $numinrow = 1;
3480: my $datatable;
3481: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 3482: my (%currbalancer,%currtargets,%currrules,%existing);
3483: if (ref($settings) eq 'HASH') {
3484: %existing = %{$settings};
3485: }
3486: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3487: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3488: \%currtargets,\%currrules);
1.150 raeburn 3489: } else {
3490: return;
3491: }
3492: my ($othertitle,$usertypes,$types) =
3493: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 3494: my $rownum = 8;
1.150 raeburn 3495: if (ref($types) eq 'ARRAY') {
3496: $rownum += scalar(@{$types});
3497: }
1.160.6.7 raeburn 3498: my @css_class = ('LC_odd_row','LC_even_row');
3499: my $balnum = 0;
3500: my $islast;
3501: my (@toshow,$disabledtext);
3502: if (keys(%currbalancer) > 0) {
3503: @toshow = sort(keys(%currbalancer));
3504: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3505: push(@toshow,'');
3506: }
3507: } else {
3508: @toshow = ('');
3509: $disabledtext = &mt('No existing load balancer');
3510: }
3511: foreach my $lonhost (@toshow) {
3512: if ($balnum == scalar(@toshow)-1) {
3513: $islast = 1;
3514: } else {
3515: $islast = 0;
3516: }
3517: my $cssidx = $balnum%2;
3518: my $targets_div_style = 'display: none';
3519: my $disabled_div_style = 'display: block';
3520: my $homedom_div_style = 'display: none';
3521: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3522: '<td rowspan="'.$rownum.'" valign="top">'.
3523: '<p>';
3524: if ($lonhost eq '') {
3525: $datatable .= '<span class="LC_nobreak">';
3526: if (keys(%currbalancer) > 0) {
3527: $datatable .= &mt('Add balancer:');
3528: } else {
3529: $datatable .= &mt('Enable balancer:');
3530: }
3531: $datatable .= ' '.
3532: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3533: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3534: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3535: '<option value="" selected="selected">'.&mt('None').
3536: '</option>'."\n";
3537: foreach my $server (sort(keys(%servers))) {
3538: next if ($currbalancer{$server});
3539: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3540: }
3541: $datatable .=
3542: '</select>'."\n".
3543: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3544: } else {
3545: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3546: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3547: &mt('Stop balancing').'</label>'.
3548: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3549: $targets_div_style = 'display: block';
3550: $disabled_div_style = 'display: none';
3551: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3552: $homedom_div_style = 'display: block';
3553: }
3554: }
3555: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3556: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3557: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3558: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3559: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3560: my @sparestypes = ('primary','default');
3561: my %typetitles = &sparestype_titles();
3562: foreach my $sparetype (@sparestypes) {
3563: my $targettable;
3564: for (my $i=0; $i<$numspares; $i++) {
3565: my $checked;
3566: if (ref($currtargets{$lonhost}) eq 'HASH') {
3567: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3568: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3569: $checked = ' checked="checked"';
3570: }
3571: }
3572: }
3573: my ($chkboxval,$disabled);
3574: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3575: $chkboxval = $spares[$i];
3576: }
3577: if (exists($currbalancer{$spares[$i]})) {
3578: $disabled = ' disabled="disabled"';
3579: }
3580: $targettable .=
3581: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3582: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3583: '</span></label></td>';
3584: my $rem = $i%($numinrow);
3585: if ($rem == 0) {
3586: if (($i > 0) && ($i < $numspares-1)) {
3587: $targettable .= '</tr>';
3588: }
3589: if ($i < $numspares-1) {
3590: $targettable .= '<tr>';
1.150 raeburn 3591: }
3592: }
3593: }
1.160.6.7 raeburn 3594: if ($targettable ne '') {
3595: my $rem = $numspares%($numinrow);
3596: my $colsleft = $numinrow - $rem;
3597: if ($colsleft > 1 ) {
3598: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3599: ' </td>';
3600: } elsif ($colsleft == 1) {
3601: $targettable .= '<td class="LC_left_item"> </td>';
3602: }
3603: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3604: '<table><tr>'.$targettable.'</tr></table><br />';
3605: }
3606: }
3607: $datatable .= '</div></td></tr>'.
3608: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3609: $othertitle,$usertypes,$types,\%servers,
3610: \%currbalancer,$lonhost,
3611: $targets_div_style,$homedom_div_style,
3612: $css_class[$cssidx],$balnum,$islast);
3613: $$rowtotal += $rownum;
3614: $balnum ++;
3615: }
3616: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3617: return $datatable;
3618: }
3619:
3620: sub get_loadbalancers_config {
3621: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3622: return unless ((ref($servers) eq 'HASH') &&
3623: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3624: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3625: if (keys(%{$existing}) > 0) {
3626: my $oldlonhost;
3627: foreach my $key (sort(keys(%{$existing}))) {
3628: if ($key eq 'lonhost') {
3629: $oldlonhost = $existing->{'lonhost'};
3630: $currbalancer->{$oldlonhost} = 1;
3631: } elsif ($key eq 'targets') {
3632: if ($oldlonhost) {
3633: $currtargets->{$oldlonhost} = $existing->{'targets'};
3634: }
3635: } elsif ($key eq 'rules') {
3636: if ($oldlonhost) {
3637: $currrules->{$oldlonhost} = $existing->{'rules'};
3638: }
3639: } elsif (ref($existing->{$key}) eq 'HASH') {
3640: $currbalancer->{$key} = 1;
3641: $currtargets->{$key} = $existing->{$key}{'targets'};
3642: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3643: }
3644: }
1.160.6.7 raeburn 3645: } else {
3646: my ($balancerref,$targetsref) =
3647: &Apache::lonnet::get_lonbalancer_config($servers);
3648: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3649: foreach my $server (sort(keys(%{$balancerref}))) {
3650: $currbalancer->{$server} = 1;
3651: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3652: }
3653: }
3654: }
1.160.6.7 raeburn 3655: return;
1.150 raeburn 3656: }
3657:
3658: sub loadbalancing_rules {
3659: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 3660: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3661: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3662: my $output;
1.160.6.7 raeburn 3663: my $num = 0;
3664: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3665: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3666: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3667: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 3668: $num ++;
1.150 raeburn 3669: my $current;
3670: if (ref($currrules) eq 'HASH') {
3671: $current = $currrules->{$type};
3672: }
1.160.6.26 raeburn 3673: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.160.6.7 raeburn 3674: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3675: $current = '';
3676: }
3677: }
3678: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 3679: $servers,$currbalancer,$lonhost,$dom,
3680: $targets_div_style,$homedom_div_style,
3681: $css_class,$balnum,$num,$islast);
1.150 raeburn 3682: }
3683: }
3684: return $output;
3685: }
3686:
3687: sub loadbalancing_titles {
3688: my ($dom,$intdom,$usertypes,$types) = @_;
3689: my %othertypes = (
3690: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3691: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3692: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3693: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 3694: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3695: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3696: );
1.160.6.26 raeburn 3697: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3698: if (ref($types) eq 'ARRAY') {
3699: unshift(@alltypes,@{$types},'default');
3700: }
3701: my %titles;
3702: foreach my $type (@alltypes) {
3703: if ($type =~ /^_LC_/) {
3704: $titles{$type} = $othertypes{$type};
3705: } elsif ($type eq 'default') {
3706: $titles{$type} = &mt('All users from [_1]',$dom);
3707: if (ref($types) eq 'ARRAY') {
3708: if (@{$types} > 0) {
3709: $titles{$type} = &mt('Other users from [_1]',$dom);
3710: }
3711: }
3712: } elsif (ref($usertypes) eq 'HASH') {
3713: $titles{$type} = $usertypes->{$type};
3714: }
3715: }
3716: return (\@alltypes,\%othertypes,\%titles);
3717: }
3718:
3719: sub loadbalance_rule_row {
1.160.6.7 raeburn 3720: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3721: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 3722: my @rulenames;
1.150 raeburn 3723: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 3724: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3725: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3726: } else {
1.160.6.26 raeburn 3727: @rulenames = ('default','homeserver');
3728: if ($type eq '_LC_external') {
3729: push(@rulenames,'externalbalancer');
3730: } else {
3731: push(@rulenames,'specific');
3732: }
3733: push(@rulenames,'none');
1.150 raeburn 3734: }
3735: my $style = $targets_div_style;
1.160.6.26 raeburn 3736: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3737: $style = $homedom_div_style;
3738: }
1.160.6.7 raeburn 3739: my $space;
3740: if ($islast && $num == 1) {
3741: $space = '<div display="inline-block"> </div>';
3742: }
3743: my $output =
3744: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3745: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3746: '<td valaign="top">'.$space.
3747: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3748: for (my $i=0; $i<@rulenames; $i++) {
3749: my $rule = $rulenames[$i];
3750: my ($checked,$extra);
3751: if ($rulenames[$i] eq 'default') {
3752: $rule = '';
3753: }
3754: if ($rulenames[$i] eq 'specific') {
3755: if (ref($servers) eq 'HASH') {
3756: my $default;
3757: if (($current ne '') && (exists($servers->{$current}))) {
3758: $checked = ' checked="checked"';
3759: }
3760: unless ($checked) {
3761: $default = ' selected="selected"';
3762: }
1.160.6.7 raeburn 3763: $extra =
3764: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3765: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3766: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3767: '<option value=""'.$default.'></option>'."\n";
3768: foreach my $server (sort(keys(%{$servers}))) {
3769: if (ref($currbalancer) eq 'HASH') {
3770: next if (exists($currbalancer->{$server}));
3771: }
1.150 raeburn 3772: my $selected;
1.160.6.7 raeburn 3773: if ($server eq $current) {
1.150 raeburn 3774: $selected = ' selected="selected"';
3775: }
1.160.6.7 raeburn 3776: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3777: }
3778: $extra .= '</select>';
3779: }
3780: } elsif ($rule eq $current) {
3781: $checked = ' checked="checked"';
3782: }
3783: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 3784: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3785: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3786: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3787: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3788: '</label>'.$extra.'</span><br />'."\n";
3789: }
3790: $output .= '</div></td></tr>'."\n";
3791: return $output;
3792: }
3793:
3794: sub offloadtype_text {
3795: my %ruletitles = &Apache::lonlocal::texthash (
3796: 'default' => 'Offloads to default destinations',
3797: 'homeserver' => "Offloads to user's home server",
3798: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3799: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 3800: 'none' => 'No offload',
1.160.6.26 raeburn 3801: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3802: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3803: );
3804: return %ruletitles;
3805: }
3806:
3807: sub sparestype_titles {
3808: my %typestitles = &Apache::lonlocal::texthash (
3809: 'primary' => 'primary',
3810: 'default' => 'default',
3811: );
3812: return %typestitles;
3813: }
3814:
1.28 raeburn 3815: sub contact_titles {
3816: my %titles = &Apache::lonlocal::texthash (
3817: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3818: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3819: 'errormail' => 'Error reports to be e-mailed to',
3820: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3821: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3822: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3823: 'requestsmail' => 'E-mail from course requests requiring approval',
1.160.6.15 raeburn 3824: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 3825: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3826: );
3827: my %short_titles = &Apache::lonlocal::texthash (
3828: adminemail => 'Admin E-mail address',
3829: supportemail => 'Support E-mail',
3830: );
3831: return (\%titles,\%short_titles);
3832: }
3833:
1.72 raeburn 3834: sub tool_titles {
3835: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 3836: aboutme => 'Personal web page',
1.86 raeburn 3837: blog => 'Blog',
1.160.6.4 raeburn 3838: webdav => 'WebDAV',
1.86 raeburn 3839: portfolio => 'Portfolio',
1.88 bisitz 3840: official => 'Official courses (with institutional codes)',
3841: unofficial => 'Unofficial courses',
1.98 raeburn 3842: community => 'Communities',
1.160.6.30 raeburn 3843: textbook => 'Textbook courses',
1.86 raeburn 3844: );
1.72 raeburn 3845: return %titles;
3846: }
3847:
1.101 raeburn 3848: sub courserequest_titles {
3849: my %titles = &Apache::lonlocal::texthash (
3850: official => 'Official',
3851: unofficial => 'Unofficial',
3852: community => 'Communities',
1.160.6.30 raeburn 3853: textbook => 'Textbook',
1.101 raeburn 3854: norequest => 'Not allowed',
1.104 raeburn 3855: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3856: validate => 'With validation',
3857: autolimit => 'Numerical limit',
1.103 raeburn 3858: unlimited => '(blank for unlimited)',
1.101 raeburn 3859: );
3860: return %titles;
3861: }
3862:
1.160.6.5 raeburn 3863: sub authorrequest_titles {
3864: my %titles = &Apache::lonlocal::texthash (
3865: norequest => 'Not allowed',
3866: approval => 'Approval by Dom. Coord.',
3867: automatic => 'Automatic approval',
3868: );
3869: return %titles;
3870: }
3871:
1.101 raeburn 3872: sub courserequest_conditions {
3873: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3874: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 3875: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3876: );
3877: return %conditions;
3878: }
3879:
3880:
1.27 raeburn 3881: sub print_usercreation {
1.30 raeburn 3882: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3883: my $numinrow = 4;
1.28 raeburn 3884: my $datatable;
3885: if ($position eq 'top') {
1.30 raeburn 3886: $$rowtotal ++;
1.34 raeburn 3887: my $rowcount = 0;
1.32 raeburn 3888: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3889: if (ref($rules) eq 'HASH') {
3890: if (keys(%{$rules}) > 0) {
1.32 raeburn 3891: $datatable .= &user_formats_row('username',$settings,$rules,
3892: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3893: $$rowtotal ++;
1.32 raeburn 3894: $rowcount ++;
3895: }
3896: }
3897: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3898: if (ref($idrules) eq 'HASH') {
3899: if (keys(%{$idrules}) > 0) {
3900: $datatable .= &user_formats_row('id',$settings,$idrules,
3901: $idruleorder,$numinrow,$rowcount);
3902: $$rowtotal ++;
3903: $rowcount ++;
1.28 raeburn 3904: }
3905: }
1.39 raeburn 3906: if ($rowcount == 0) {
3907: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3908: $$rowtotal ++;
3909: $rowcount ++;
3910: }
1.34 raeburn 3911: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 3912: my @creators = ('author','course','requestcrs');
1.37 raeburn 3913: my ($rules,$ruleorder) =
3914: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3915: my %lt = &usercreation_types();
3916: my %checked;
3917: if (ref($settings) eq 'HASH') {
3918: if (ref($settings->{'cancreate'}) eq 'HASH') {
3919: foreach my $item (@creators) {
3920: $checked{$item} = $settings->{'cancreate'}{$item};
3921: }
3922: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3923: foreach my $item (@creators) {
3924: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3925: $checked{$item} = 'none';
3926: }
3927: }
3928: }
3929: }
3930: my $rownum = 0;
3931: foreach my $item (@creators) {
3932: $rownum ++;
1.160.6.34 raeburn 3933: if ($checked{$item} eq '') {
3934: $checked{$item} = 'any';
1.34 raeburn 3935: }
3936: my $css_class;
3937: if ($rownum%2) {
3938: $css_class = '';
3939: } else {
3940: $css_class = ' class="LC_odd_row" ';
3941: }
3942: $datatable .= '<tr'.$css_class.'>'.
3943: '<td><span class="LC_nobreak">'.$lt{$item}.
3944: '</span></td><td align="right">';
1.160.6.34 raeburn 3945: my @options = ('any');
3946: if (ref($rules) eq 'HASH') {
3947: if (keys(%{$rules}) > 0) {
3948: push(@options,('official','unofficial'));
1.37 raeburn 3949: }
3950: }
1.160.6.34 raeburn 3951: push(@options,'none');
1.37 raeburn 3952: foreach my $option (@options) {
1.50 raeburn 3953: my $type = 'radio';
1.34 raeburn 3954: my $check = ' ';
1.160.6.34 raeburn 3955: if ($checked{$item} eq $option) {
3956: $check = ' checked="checked" ';
1.34 raeburn 3957: }
3958: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3959: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3960: $item.'" value="'.$option.'"'.$check.'/> '.
3961: $lt{$option}.'</label> </span>';
3962: }
3963: $datatable .= '</td></tr>';
3964: }
1.28 raeburn 3965: } else {
3966: my @contexts = ('author','course','domain');
3967: my @authtypes = ('int','krb4','krb5','loc');
3968: my %checked;
3969: if (ref($settings) eq 'HASH') {
3970: if (ref($settings->{'authtypes'}) eq 'HASH') {
3971: foreach my $item (@contexts) {
3972: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3973: foreach my $auth (@authtypes) {
3974: if ($settings->{'authtypes'}{$item}{$auth}) {
3975: $checked{$item}{$auth} = ' checked="checked" ';
3976: }
3977: }
3978: }
3979: }
1.27 raeburn 3980: }
1.35 raeburn 3981: } else {
3982: foreach my $item (@contexts) {
1.36 raeburn 3983: foreach my $auth (@authtypes) {
1.35 raeburn 3984: $checked{$item}{$auth} = ' checked="checked" ';
3985: }
3986: }
1.27 raeburn 3987: }
1.28 raeburn 3988: my %title = &context_names();
3989: my %authname = &authtype_names();
3990: my $rownum = 0;
3991: my $css_class;
3992: foreach my $item (@contexts) {
3993: if ($rownum%2) {
3994: $css_class = '';
3995: } else {
3996: $css_class = ' class="LC_odd_row" ';
3997: }
1.30 raeburn 3998: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3999: '<td>'.$title{$item}.
4000: '</td><td class="LC_left_item">'.
4001: '<span class="LC_nobreak">';
4002: foreach my $auth (@authtypes) {
4003: $datatable .= '<label>'.
4004: '<input type="checkbox" name="'.$item.'_auth" '.
4005: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4006: $authname{$auth}.'</label> ';
4007: }
4008: $datatable .= '</span></td></tr>';
4009: $rownum ++;
1.27 raeburn 4010: }
1.30 raeburn 4011: $$rowtotal += $rownum;
1.27 raeburn 4012: }
4013: return $datatable;
4014: }
4015:
1.160.6.34 raeburn 4016: sub print_selfcreation {
4017: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4018: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4019: if (ref($settings) eq 'HASH') {
4020: if (ref($settings->{'cancreate'}) eq 'HASH') {
4021: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4022: if (ref($createsettings) eq 'HASH') {
4023: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4024: @selfcreate = @{$createsettings->{'selfcreate'}};
4025: } elsif ($createsettings->{'selfcreate'} ne '') {
4026: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4027: @selfcreate = ('email','login','sso');
4028: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4029: @selfcreate = ($createsettings->{'selfcreate'});
4030: }
4031: }
4032: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4033: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 4034: }
4035: }
4036: }
4037: }
4038: my %radiohash;
4039: my $numinrow = 4;
4040: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4041: if ($position eq 'top') {
4042: my %choices = &Apache::lonlocal::texthash (
4043: cancreate_login => 'Institutional Login',
4044: cancreate_sso => 'Institutional Single Sign On',
4045: );
4046: my @toggles = sort(keys(%choices));
4047: my %defaultchecked = (
4048: 'cancreate_login' => 'off',
4049: 'cancreate_sso' => 'off',
4050: );
1.160.6.35 raeburn 4051: my ($onclick,$itemcount);
1.160.6.34 raeburn 4052: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4053: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 4054: $$rowtotal += $itemcount;
1.160.6.39 raeburn 4055:
1.160.6.34 raeburn 4056: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4057:
4058: if (ref($usertypes) eq 'HASH') {
4059: if (keys(%{$usertypes}) > 0) {
4060: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4061: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 4062: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 4063: $$rowtotal ++;
4064: }
4065: }
4066: } elsif ($position eq 'middle') {
4067: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4068: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4069: $usertypes->{'default'} = $othertitle;
4070: if (ref($types) eq 'ARRAY') {
4071: push(@{$types},'default');
4072: $usertypes->{'default'} = $othertitle;
4073: foreach my $status (@{$types}) {
4074: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 4075: $numinrow,$$rowtotal,$usertypes);
1.160.6.40 raeburn 4076: $$rowtotal ++;
1.160.6.34 raeburn 4077: }
4078: }
4079: } else {
1.160.6.40 raeburn 4080: my %choices = &Apache::lonlocal::texthash (
4081: cancreate_email => 'E-mail address as username',
4082: );
4083: my @toggles = sort(keys(%choices));
4084: my %defaultchecked = (
4085: 'cancreate_email' => 'off',
4086: );
4087: my $itemcount = 0;
4088: my $display = 'none';
4089: if (grep(/^\Qemail\E$/,@selfcreate)) {
4090: $display = 'block';
4091: }
4092: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4093: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4094: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4095: my $usertypes = {};
4096: my $order = [];
4097: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4098: $usertypes = $domdefaults{'inststatustypes'};
4099: $order = $domdefaults{'inststatusguest'};
4100: }
4101: if (ref($order) eq 'ARRAY') {
4102: push(@{$order},'default');
4103: if (@{$order} > 1) {
4104: $usertypes->{'default'} = &mt('Other users');
4105: $additional .= '<table><tr>';
4106: foreach my $status (@{$order}) {
4107: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4108: }
4109: $additional .= '</tr><tr>';
4110: foreach my $status (@{$order}) {
4111: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 4112: }
1.160.6.40 raeburn 4113: $additional .= '</tr></table>';
1.160.6.34 raeburn 4114: } else {
1.160.6.40 raeburn 4115: $usertypes->{'default'} = &mt('All users');
4116: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 4117: }
4118: }
1.160.6.40 raeburn 4119: $additional .= '</div>'."\n";
4120:
4121: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4122: \%choices,$itemcount,$onclick,$additional);
4123: $$rowtotal += $itemcount;
4124: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 4125: $$rowtotal ++;
1.160.6.35 raeburn 4126: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
4127: $numinrow = 1;
1.160.6.40 raeburn 4128: if (ref($order) eq 'ARRAY') {
4129: foreach my $status (@{$order}) {
1.160.6.35 raeburn 4130: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4131: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4132: $$rowtotal ++;
4133: }
4134: }
1.160.6.34 raeburn 4135: my ($emailrules,$emailruleorder) =
4136: &Apache::lonnet::inst_userrules($dom,'email');
4137: if (ref($emailrules) eq 'HASH') {
4138: if (keys(%{$emailrules}) > 0) {
4139: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 4140: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 4141: $$rowtotal ++;
4142: }
4143: }
1.160.6.35 raeburn 4144: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 4145: }
4146: return $datatable;
4147: }
4148:
1.160.6.40 raeburn 4149: sub email_as_username {
4150: my ($rowtotal,$processing,$type) = @_;
4151: my %choices =
4152: &Apache::lonlocal::texthash (
4153: automatic => 'Automatic approval',
4154: approval => 'Queued for approval',
4155: );
4156: my $output;
4157: foreach my $option ('automatic','approval') {
4158: my $checked;
4159: if (ref($processing) eq 'HASH') {
4160: if ($type eq '') {
4161: if (!exists($processing->{'default'})) {
4162: if ($option eq 'automatic') {
4163: $checked = ' checked="checked"';
4164: }
4165: } else {
4166: if ($processing->{'default'} eq $option) {
4167: $checked = ' checked="checked"';
4168: }
4169: }
4170: } else {
4171: if (!exists($processing->{$type})) {
4172: if ($option eq 'automatic') {
4173: $checked = ' checked="checked"';
4174: }
4175: } else {
4176: if ($processing->{$type} eq $option) {
4177: $checked = ' checked="checked"';
4178: }
4179: }
4180: }
4181: } elsif ($option eq 'automatic') {
4182: $checked = ' checked="checked"';
4183: }
4184: my $name = 'cancreate_emailprocess';
4185: if (($type ne '') && ($type ne 'default')) {
4186: $name .= '_'.$type;
4187: }
4188: $output .= '<span class="LC_nobreak"><label>'.
4189: '<input type="radio" name="'.$name.'"'.
4190: $checked.' value="'.$option.'" />'.
4191: $choices{$option}.'</label></span>';
4192: if ($type eq '') {
4193: $output .= ' ';
4194: } else {
4195: $output .= '<br />';
4196: }
4197: }
4198: $$rowtotal ++;
4199: return $output;
4200: }
4201:
1.160.6.5 raeburn 4202: sub captcha_choice {
4203: my ($context,$settings,$itemcount) = @_;
4204: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4205: my %lt = &captcha_phrases();
4206: $keyentry = 'hidden';
4207: if ($context eq 'cancreate') {
1.160.6.34 raeburn 4208: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 4209: } elsif ($context eq 'login') {
4210: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
4211: }
4212: if (ref($settings) eq 'HASH') {
4213: if ($settings->{'captcha'}) {
4214: $checked{$settings->{'captcha'}} = ' checked="checked"';
4215: } else {
4216: $checked{'original'} = ' checked="checked"';
4217: }
4218: if ($settings->{'captcha'} eq 'recaptcha') {
4219: $pubtext = $lt{'pub'};
4220: $privtext = $lt{'priv'};
4221: $keyentry = 'text';
4222: }
4223: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4224: $currpub = $settings->{'recaptchakeys'}{'public'};
4225: $currpriv = $settings->{'recaptchakeys'}{'private'};
4226: }
4227: } else {
4228: $checked{'original'} = ' checked="checked"';
4229: }
4230: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4231: my $output = '<tr'.$css_class.'>'.
4232: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
4233: '<table><tr><td>'."\n";
4234: foreach my $option ('original','recaptcha','notused') {
4235: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4236: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4237: $lt{$option}.'</label></span>';
4238: unless ($option eq 'notused') {
4239: $output .= (' 'x2)."\n";
4240: }
4241: }
4242: #
4243: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4244: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
4245: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
4246: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
4247: #
4248: $output .= '</td></tr>'."\n".
4249: '<tr><td>'."\n".
4250: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4251: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4252: $currpub.'" size="40" /></span><br />'."\n".
4253: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4254: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4255: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4256: '</td></tr>';
4257: return $output;
4258: }
4259:
1.32 raeburn 4260: sub user_formats_row {
4261: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4262: my $output;
4263: my %text = (
4264: 'username' => 'new usernames',
4265: 'id' => 'IDs',
1.45 raeburn 4266: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4267: );
4268: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4269: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4270: '<td><span class="LC_nobreak">';
4271: if ($type eq 'email') {
4272: $output .= &mt("Formats disallowed for $text{$type}: ");
4273: } else {
4274: $output .= &mt("Format rules to check for $text{$type}: ");
4275: }
4276: $output .= '</span></td>'.
4277: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4278: my $rem;
4279: if (ref($ruleorder) eq 'ARRAY') {
4280: for (my $i=0; $i<@{$ruleorder}; $i++) {
4281: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4282: my $rem = $i%($numinrow);
4283: if ($rem == 0) {
4284: if ($i > 0) {
4285: $output .= '</tr>';
4286: }
4287: $output .= '<tr>';
4288: }
4289: my $check = ' ';
1.39 raeburn 4290: if (ref($settings) eq 'HASH') {
4291: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4292: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4293: $check = ' checked="checked" ';
4294: }
1.27 raeburn 4295: }
4296: }
4297: $output .= '<td class="LC_left_item">'.
4298: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4299: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4300: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4301: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4302: }
4303: }
4304: $rem = @{$ruleorder}%($numinrow);
4305: }
4306: my $colsleft = $numinrow - $rem;
4307: if ($colsleft > 1 ) {
4308: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4309: ' </td>';
4310: } elsif ($colsleft == 1) {
4311: $output .= '<td class="LC_left_item"> </td>';
4312: }
4313: $output .= '</tr></table></td></tr>';
4314: return $output;
4315: }
4316:
1.34 raeburn 4317: sub usercreation_types {
4318: my %lt = &Apache::lonlocal::texthash (
4319: author => 'When adding a co-author',
4320: course => 'When adding a user to a course',
1.100 raeburn 4321: requestcrs => 'When requesting a course',
1.34 raeburn 4322: any => 'Any',
4323: official => 'Institutional only ',
4324: unofficial => 'Non-institutional only',
4325: none => 'None',
4326: );
4327: return %lt;
1.48 raeburn 4328: }
1.34 raeburn 4329:
1.160.6.34 raeburn 4330: sub selfcreation_types {
4331: my %lt = &Apache::lonlocal::texthash (
4332: selfcreate => 'User creates own account',
4333: any => 'Any',
4334: official => 'Institutional only ',
4335: unofficial => 'Non-institutional only',
4336: email => 'E-mail address',
4337: login => 'Institutional Login',
4338: sso => 'SSO',
4339: );
4340: }
4341:
1.28 raeburn 4342: sub authtype_names {
4343: my %lt = &Apache::lonlocal::texthash(
4344: int => 'Internal',
4345: krb4 => 'Kerberos 4',
4346: krb5 => 'Kerberos 5',
4347: loc => 'Local',
4348: );
4349: return %lt;
4350: }
4351:
4352: sub context_names {
4353: my %context_title = &Apache::lonlocal::texthash(
4354: author => 'Creating users when an Author',
4355: course => 'Creating users when in a course',
4356: domain => 'Creating users when a Domain Coordinator',
4357: );
4358: return %context_title;
4359: }
4360:
1.33 raeburn 4361: sub print_usermodification {
4362: my ($position,$dom,$settings,$rowtotal) = @_;
4363: my $numinrow = 4;
4364: my ($context,$datatable,$rowcount);
4365: if ($position eq 'top') {
4366: $rowcount = 0;
4367: $context = 'author';
4368: foreach my $role ('ca','aa') {
4369: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4370: $numinrow,$rowcount);
4371: $$rowtotal ++;
4372: $rowcount ++;
4373: }
1.160.6.37 raeburn 4374: } elsif ($position eq 'bottom') {
1.33 raeburn 4375: $context = 'course';
4376: $rowcount = 0;
4377: foreach my $role ('st','ep','ta','in','cr') {
4378: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4379: $numinrow,$rowcount);
4380: $$rowtotal ++;
4381: $rowcount ++;
4382: }
4383: }
4384: return $datatable;
4385: }
4386:
1.43 raeburn 4387: sub print_defaults {
1.160.6.40 raeburn 4388: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4389: my $rownum = 0;
4390: my ($datatable,$css_class);
1.160.6.40 raeburn 4391: if ($position eq 'top') {
4392: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4393: 'datelocale_def','portal_def');
4394: my %defaults;
4395: if (ref($settings) eq 'HASH') {
4396: %defaults = %{$settings};
1.43 raeburn 4397: } else {
1.160.6.40 raeburn 4398: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4399: foreach my $item (@items) {
4400: $defaults{$item} = $domdefaults{$item};
4401: }
1.43 raeburn 4402: }
1.160.6.40 raeburn 4403: my $titles = &defaults_titles($dom);
4404: foreach my $item (@items) {
4405: if ($rownum%2) {
4406: $css_class = '';
4407: } else {
4408: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 4409: }
1.160.6.40 raeburn 4410: $datatable .= '<tr'.$css_class.'>'.
4411: '<td><span class="LC_nobreak">'.$titles->{$item}.
4412: '</span></td><td class="LC_right_item" colspan="3">';
4413: if ($item eq 'auth_def') {
4414: my @authtypes = ('internal','krb4','krb5','localauth');
4415: my %shortauth = (
4416: internal => 'int',
4417: krb4 => 'krb4',
4418: krb5 => 'krb5',
4419: localauth => 'loc'
4420: );
4421: my %authnames = &authtype_names();
4422: foreach my $auth (@authtypes) {
4423: my $checked = ' ';
4424: if ($defaults{$item} eq $auth) {
4425: $checked = ' checked="checked" ';
4426: }
4427: $datatable .= '<label><input type="radio" name="'.$item.
4428: '" value="'.$auth.'"'.$checked.'/>'.
4429: $authnames{$shortauth{$auth}}.'</label> ';
4430: }
4431: } elsif ($item eq 'timezone_def') {
4432: my $includeempty = 1;
4433: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4434: } elsif ($item eq 'datelocale_def') {
4435: my $includeempty = 1;
4436: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4437: } elsif ($item eq 'lang_def') {
4438: my %langchoices = &get_languages_hash();
4439: $langchoices{''} = 'No language preference';
4440: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4441: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4442: \%langchoices);
4443: } else {
4444: my $size;
4445: if ($item eq 'portal_def') {
4446: $size = ' size="25"';
4447: }
4448: $datatable .= '<input type="text" name="'.$item.'" value="'.
4449: $defaults{$item}.'"'.$size.' />';
4450: }
4451: $datatable .= '</td></tr>';
4452: $rownum ++;
4453: }
4454: } else {
4455: my (%defaults);
4456: if (ref($settings) eq 'HASH') {
4457: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4458: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4459: my $maxnum = @{$settings->{'inststatusorder'}};
4460: for (my $i=0; $i<$maxnum; $i++) {
4461: $css_class = $rownum%2?' class="LC_odd_row"':'';
4462: my $item = $settings->{'inststatusorder'}->[$i];
4463: my $title = $settings->{'inststatustypes'}->{$item};
4464: my $guestok;
4465: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4466: $guestok = 1;
4467: }
4468: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4469: $datatable .= '<tr'.$css_class.'>'.
4470: '<td><span class="LC_nobreak">'.
4471: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4472: for (my $k=0; $k<=$maxnum; $k++) {
4473: my $vpos = $k+1;
4474: my $selstr;
4475: if ($k == $i) {
4476: $selstr = ' selected="selected" ';
4477: }
4478: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4479: }
4480: my ($checkedon,$checkedoff);
4481: $checkedoff = ' checked="checked"';
4482: if ($guestok) {
4483: $checkedon = $checkedoff;
4484: $checkedoff = '';
4485: }
4486: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4487: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4488: &mt('delete').'</span></td>'.
4489: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4490: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4491: '</span></td>'.
4492: '<td class="LC_right_item"><span class="LC_nobreak">'.
4493: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4494: &mt('Yes').'</label>'.(' 'x2).
4495: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4496: &mt('No').'</label></span></td></tr>';
4497: }
4498: $css_class = $rownum%2?' class="LC_odd_row"':'';
4499: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4500: $datatable .= '<tr '.$css_class.'>'.
4501: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4502: for (my $k=0; $k<=$maxnum; $k++) {
4503: my $vpos = $k+1;
4504: my $selstr;
4505: if ($k == $maxnum) {
4506: $selstr = ' selected="selected" ';
4507: }
4508: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4509: }
4510: $datatable .= '</select> '.&mt('Internal ID:').
4511: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4512: ' '.&mt('(new)').
4513: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4514: &mt('Name displayed:').
4515: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4516: '<td class="LC_right_item"><span class="LC_nobreak">'.
4517: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4518: &mt('Yes').'</label>'.(' 'x2).
4519: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4520: &mt('No').'</label></span></td></tr>';
4521: '</tr>'."\n";
4522: $rownum ++;
1.141 raeburn 4523: }
1.43 raeburn 4524: }
4525: }
4526: $$rowtotal += $rownum;
4527: return $datatable;
4528: }
4529:
1.160.6.5 raeburn 4530: sub get_languages_hash {
4531: my %langchoices;
4532: foreach my $id (&Apache::loncommon::languageids()) {
4533: my $code = &Apache::loncommon::supportedlanguagecode($id);
4534: if ($code ne '') {
4535: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4536: }
4537: }
4538: return %langchoices;
4539: }
4540:
1.43 raeburn 4541: sub defaults_titles {
1.141 raeburn 4542: my ($dom) = @_;
1.43 raeburn 4543: my %titles = &Apache::lonlocal::texthash (
4544: 'auth_def' => 'Default authentication type',
4545: 'auth_arg_def' => 'Default authentication argument',
4546: 'lang_def' => 'Default language',
1.54 raeburn 4547: 'timezone_def' => 'Default timezone',
1.68 raeburn 4548: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4549: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4550: );
1.141 raeburn 4551: if ($dom) {
4552: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4553: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4554: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4555: $protocol = 'http' if ($protocol ne 'https');
4556: if ($uint_dom) {
4557: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4558: $uint_dom);
4559: }
4560: }
1.43 raeburn 4561: return (\%titles);
4562: }
4563:
1.46 raeburn 4564: sub print_scantronformat {
4565: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4566: my $itemcount = 1;
1.60 raeburn 4567: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4568: %confhash);
1.46 raeburn 4569: my $switchserver = &check_switchserver($dom,$confname);
4570: my %lt = &Apache::lonlocal::texthash (
1.95 www 4571: default => 'Default bubblesheet format file error',
4572: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4573: );
4574: my %scantronfiles = (
4575: default => 'default.tab',
4576: custom => 'custom.tab',
4577: );
4578: foreach my $key (keys(%scantronfiles)) {
4579: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4580: .$scantronfiles{$key};
4581: }
4582: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4583: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4584: if (!$switchserver) {
4585: my $servadm = $r->dir_config('lonAdmEMail');
4586: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4587: if ($configuserok eq 'ok') {
4588: if ($author_ok eq 'ok') {
4589: my %legacyfile = (
4590: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4591: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4592: );
4593: my %md5chk;
4594: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4595: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4596: chomp($md5chk{$type});
1.46 raeburn 4597: }
4598: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4599: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4600: ($scantronurls{$type},my $error) =
1.46 raeburn 4601: &legacy_scantronformat($r,$dom,$confname,
4602: $type,$legacyfile{$type},
4603: $scantronurls{$type},
4604: $scantronfiles{$type});
1.60 raeburn 4605: if ($error ne '') {
4606: $error{$type} = $error;
4607: }
4608: }
4609: if (keys(%error) == 0) {
4610: $is_custom = 1;
4611: $confhash{'scantron'}{'scantronformat'} =
4612: $scantronurls{'custom'};
4613: my $putresult =
4614: &Apache::lonnet::put_dom('configuration',
4615: \%confhash,$dom);
4616: if ($putresult ne 'ok') {
4617: $error{'custom'} =
4618: '<span class="LC_error">'.
4619: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4620: }
1.46 raeburn 4621: }
4622: } else {
1.60 raeburn 4623: ($scantronurls{'default'},my $error) =
1.46 raeburn 4624: &legacy_scantronformat($r,$dom,$confname,
4625: 'default',$legacyfile{'default'},
4626: $scantronurls{'default'},
4627: $scantronfiles{'default'});
1.60 raeburn 4628: if ($error eq '') {
4629: $confhash{'scantron'}{'scantronformat'} = '';
4630: my $putresult =
4631: &Apache::lonnet::put_dom('configuration',
4632: \%confhash,$dom);
4633: if ($putresult ne 'ok') {
4634: $error{'default'} =
4635: '<span class="LC_error">'.
4636: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4637: }
4638: } else {
4639: $error{'default'} = $error;
4640: }
1.46 raeburn 4641: }
4642: }
4643: }
4644: } else {
1.95 www 4645: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4646: }
4647: }
4648: if (ref($settings) eq 'HASH') {
4649: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4650: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4651: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4652: $scantronurl = '';
4653: } else {
4654: $scantronurl = $settings->{'scantronformat'};
4655: }
4656: $is_custom = 1;
4657: } else {
4658: $scantronurl = $scantronurls{'default'};
4659: }
4660: } else {
1.60 raeburn 4661: if ($is_custom) {
4662: $scantronurl = $scantronurls{'custom'};
4663: } else {
4664: $scantronurl = $scantronurls{'default'};
4665: }
1.46 raeburn 4666: }
4667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4668: $datatable .= '<tr'.$css_class.'>';
4669: if (!$is_custom) {
1.65 raeburn 4670: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4671: '<span class="LC_nobreak">';
1.46 raeburn 4672: if ($scantronurl) {
1.160.6.21 raeburn 4673: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4674: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4675: } else {
4676: $datatable = &mt('File unavailable for display');
4677: }
1.65 raeburn 4678: $datatable .= '</span></td>';
1.60 raeburn 4679: if (keys(%error) == 0) {
4680: $datatable .= '<td valign="bottom">';
4681: if (!$switchserver) {
4682: $datatable .= &mt('Upload:').'<br />';
4683: }
4684: } else {
4685: my $errorstr;
4686: foreach my $key (sort(keys(%error))) {
4687: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4688: }
4689: $datatable .= '<td>'.$errorstr;
4690: }
1.46 raeburn 4691: } else {
4692: if (keys(%error) > 0) {
4693: my $errorstr;
4694: foreach my $key (sort(keys(%error))) {
4695: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4696: }
1.60 raeburn 4697: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4698: } elsif ($scantronurl) {
1.160.6.26 raeburn 4699: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 4700: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4701: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 4702: $link.
4703: '<label><input type="checkbox" name="scantronformat_del"'.
4704: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4705: '<td><span class="LC_nobreak"> '.
4706: &mt('Replace:').'</span><br />';
1.46 raeburn 4707: }
4708: }
4709: if (keys(%error) == 0) {
4710: if ($switchserver) {
4711: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4712: } else {
1.65 raeburn 4713: $datatable .='<span class="LC_nobreak"> '.
4714: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4715: }
4716: }
4717: $datatable .= '</td></tr>';
4718: $$rowtotal ++;
4719: return $datatable;
4720: }
4721:
4722: sub legacy_scantronformat {
4723: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4724: my ($url,$error);
4725: my @statinfo = &Apache::lonnet::stat_file($newurl);
4726: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4727: (my $result,$url) =
4728: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4729: '','',$newfile);
4730: if ($result ne 'ok') {
1.130 raeburn 4731: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4732: }
4733: }
4734: return ($url,$error);
4735: }
1.43 raeburn 4736:
1.49 raeburn 4737: sub print_coursecategories {
1.57 raeburn 4738: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4739: my $datatable;
4740: if ($position eq 'top') {
1.160.6.42 raeburn 4741: my (%checked);
4742: my @catitems = ('unauth','auth');
4743: my @cattypes = ('std','domonly','codesrch','none');
4744: $checked{'unauth'} = 'std';
4745: $checked{'auth'} = 'std';
4746: if (ref($settings) eq 'HASH') {
4747: foreach my $type (@cattypes) {
4748: if ($type eq $settings->{'unauth'}) {
4749: $checked{'unauth'} = $type;
4750: }
4751: if ($type eq $settings->{'auth'}) {
4752: $checked{'auth'} = $type;
4753: }
4754: }
4755: }
4756: my %lt = &Apache::lonlocal::texthash (
4757: unauth => 'Catalog type for unauthenticated users',
4758: auth => 'Catalog type for authenticated users',
4759: none => 'No catalog',
4760: std => 'Standard catalog',
4761: domonly => 'Domain-only catalog',
4762: codesrch => "Code search form",
4763: );
4764: my $itemcount = 0;
4765: foreach my $item (@catitems) {
4766: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4767: $datatable .= '<tr '.$css_class.'>'.
4768: '<td>'.$lt{$item}.'</td>'.
4769: '<td class="LC_right_item"><span class="LC_nobreak">';
4770: foreach my $type (@cattypes) {
4771: my $ischecked;
4772: if ($checked{$item} eq $type) {
4773: $ischecked=' checked="checked"';
4774: }
4775: $datatable .= '<label>'.
4776: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4777: ' />'.$lt{$type}.'</label> ';
4778: }
4779: $datatable .= '</td></tr>';
4780: $itemcount ++;
4781: }
4782: $$rowtotal += $itemcount;
4783: } elsif ($position eq 'middle') {
1.57 raeburn 4784: my $toggle_cats_crs = ' ';
4785: my $toggle_cats_dom = ' checked="checked" ';
4786: my $can_cat_crs = ' ';
4787: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4788: my $toggle_catscomm_comm = ' ';
4789: my $toggle_catscomm_dom = ' checked="checked" ';
4790: my $can_catcomm_comm = ' ';
4791: my $can_catcomm_dom = ' checked="checked" ';
4792:
1.57 raeburn 4793: if (ref($settings) eq 'HASH') {
4794: if ($settings->{'togglecats'} eq 'crs') {
4795: $toggle_cats_crs = $toggle_cats_dom;
4796: $toggle_cats_dom = ' ';
4797: }
4798: if ($settings->{'categorize'} eq 'crs') {
4799: $can_cat_crs = $can_cat_dom;
4800: $can_cat_dom = ' ';
4801: }
1.120 raeburn 4802: if ($settings->{'togglecatscomm'} eq 'comm') {
4803: $toggle_catscomm_comm = $toggle_catscomm_dom;
4804: $toggle_catscomm_dom = ' ';
4805: }
4806: if ($settings->{'categorizecomm'} eq 'comm') {
4807: $can_catcomm_comm = $can_catcomm_dom;
4808: $can_catcomm_dom = ' ';
4809: }
1.57 raeburn 4810: }
4811: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4812: togglecats => 'Show/Hide a course in catalog',
4813: togglecatscomm => 'Show/Hide a community in catalog',
4814: categorize => 'Assign a category to a course',
4815: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4816: );
4817: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4818: dom => 'Set in Domain',
4819: crs => 'Set in Course',
4820: comm => 'Set in Community',
1.57 raeburn 4821: );
4822: $datatable = '<tr class="LC_odd_row">'.
4823: '<td>'.$title{'togglecats'}.'</td>'.
4824: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4825: '<input type="radio" name="togglecats"'.
4826: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4827: '<label><input type="radio" name="togglecats"'.
4828: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4829: '</tr><tr>'.
4830: '<td>'.$title{'categorize'}.'</td>'.
4831: '<td class="LC_right_item"><span class="LC_nobreak">'.
4832: '<label><input type="radio" name="categorize"'.
4833: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4834: '<label><input type="radio" name="categorize"'.
4835: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4836: '</tr><tr class="LC_odd_row">'.
4837: '<td>'.$title{'togglecatscomm'}.'</td>'.
4838: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4839: '<input type="radio" name="togglecatscomm"'.
4840: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4841: '<label><input type="radio" name="togglecatscomm"'.
4842: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4843: '</tr><tr>'.
4844: '<td>'.$title{'categorizecomm'}.'</td>'.
4845: '<td class="LC_right_item"><span class="LC_nobreak">'.
4846: '<label><input type="radio" name="categorizecomm"'.
4847: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4848: '<label><input type="radio" name="categorizecomm"'.
4849: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4850: '</tr>';
1.120 raeburn 4851: $$rowtotal += 4;
1.57 raeburn 4852: } else {
4853: my $css_class;
4854: my $itemcount = 1;
4855: my $cathash;
4856: if (ref($settings) eq 'HASH') {
4857: $cathash = $settings->{'cats'};
4858: }
4859: if (ref($cathash) eq 'HASH') {
4860: my (@cats,@trails,%allitems,%idx,@jsarray);
4861: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4862: \%allitems,\%idx,\@jsarray);
4863: my $maxdepth = scalar(@cats);
4864: my $colattrib = '';
4865: if ($maxdepth > 2) {
4866: $colattrib = ' colspan="2" ';
4867: }
4868: my @path;
4869: if (@cats > 0) {
4870: if (ref($cats[0]) eq 'ARRAY') {
4871: my $numtop = @{$cats[0]};
4872: my $maxnum = $numtop;
1.120 raeburn 4873: my %default_names = (
4874: instcode => &mt('Official courses'),
4875: communities => &mt('Communities'),
4876: );
4877:
4878: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4879: ($cathash->{'instcode::0'} eq '') ||
4880: (!grep(/^communities$/,@{$cats[0]})) ||
4881: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4882: $maxnum ++;
4883: }
4884: my $lastidx;
4885: for (my $i=0; $i<$numtop; $i++) {
4886: my $parent = $cats[0][$i];
4887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4888: my $item = &escape($parent).'::0';
4889: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4890: $lastidx = $idx{$item};
4891: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4892: .'<select name="'.$item.'"'.$chgstr.'>';
4893: for (my $k=0; $k<=$maxnum; $k++) {
4894: my $vpos = $k+1;
4895: my $selstr;
4896: if ($k == $i) {
4897: $selstr = ' selected="selected" ';
4898: }
4899: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4900: }
1.160.6.29 raeburn 4901: $datatable .= '</select></span></td><td>';
1.120 raeburn 4902: if ($parent eq 'instcode' || $parent eq 'communities') {
4903: $datatable .= '<span class="LC_nobreak">'
4904: .$default_names{$parent}.'</span>';
4905: if ($parent eq 'instcode') {
4906: $datatable .= '<br /><span class="LC_nobreak">('
4907: .&mt('with institutional codes')
4908: .')</span></td><td'.$colattrib.'>';
4909: } else {
4910: $datatable .= '<table><tr><td>';
4911: }
4912: $datatable .= '<span class="LC_nobreak">'
4913: .'<label><input type="radio" name="'
4914: .$parent.'" value="1" checked="checked" />'
4915: .&mt('Display').'</label>';
4916: if ($parent eq 'instcode') {
4917: $datatable .= ' ';
4918: } else {
4919: $datatable .= '</span></td></tr><tr><td>'
4920: .'<span class="LC_nobreak">';
4921: }
4922: $datatable .= '<label><input type="radio" name="'
4923: .$parent.'" value="0" />'
4924: .&mt('Do not display').'</label></span>';
4925: if ($parent eq 'communities') {
4926: $datatable .= '</td></tr></table>';
4927: }
4928: $datatable .= '</td>';
1.57 raeburn 4929: } else {
4930: $datatable .= $parent
1.160.6.29 raeburn 4931: .' <span class="LC_nobreak"><label>'
4932: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 4933: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4934: }
4935: my $depth = 1;
4936: push(@path,$parent);
4937: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4938: pop(@path);
4939: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4940: $itemcount ++;
4941: }
1.48 raeburn 4942: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4943: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4944: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4945: for (my $k=0; $k<=$maxnum; $k++) {
4946: my $vpos = $k+1;
4947: my $selstr;
1.57 raeburn 4948: if ($k == $numtop) {
1.48 raeburn 4949: $selstr = ' selected="selected" ';
4950: }
4951: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4952: }
1.59 bisitz 4953: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4954: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4955: .'</tr>'."\n";
1.48 raeburn 4956: $itemcount ++;
1.120 raeburn 4957: foreach my $default ('instcode','communities') {
4958: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4959: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4960: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4961: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4962: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4963: for (my $k=0; $k<=$maxnum; $k++) {
4964: my $vpos = $k+1;
4965: my $selstr;
4966: if ($k == $maxnum) {
4967: $selstr = ' selected="selected" ';
4968: }
4969: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4970: }
1.120 raeburn 4971: $datatable .= '</select></span></td>'.
4972: '<td><span class="LC_nobreak">'.
4973: $default_names{$default}.'</span>';
4974: if ($default eq 'instcode') {
4975: $datatable .= '<br /><span class="LC_nobreak">('
4976: .&mt('with institutional codes').')</span>';
4977: }
4978: $datatable .= '</td>'
4979: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4980: .&mt('Display').'</label> '
4981: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4982: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4983: }
4984: }
4985: }
1.57 raeburn 4986: } else {
4987: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4988: }
4989: } else {
1.160.6.42 raeburn 4990: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 4991: .&initialize_categories($itemcount);
1.48 raeburn 4992: }
1.57 raeburn 4993: $$rowtotal += $itemcount;
1.48 raeburn 4994: }
4995: return $datatable;
4996: }
4997:
1.69 raeburn 4998: sub print_serverstatuses {
4999: my ($dom,$settings,$rowtotal) = @_;
5000: my $datatable;
5001: my @pages = &serverstatus_pages();
5002: my (%namedaccess,%machineaccess);
5003: foreach my $type (@pages) {
5004: $namedaccess{$type} = '';
5005: $machineaccess{$type}= '';
5006: }
5007: if (ref($settings) eq 'HASH') {
5008: foreach my $type (@pages) {
5009: if (exists($settings->{$type})) {
5010: if (ref($settings->{$type}) eq 'HASH') {
5011: foreach my $key (keys(%{$settings->{$type}})) {
5012: if ($key eq 'namedusers') {
5013: $namedaccess{$type} = $settings->{$type}->{$key};
5014: } elsif ($key eq 'machines') {
5015: $machineaccess{$type} = $settings->{$type}->{$key};
5016: }
5017: }
5018: }
5019: }
5020: }
5021: }
1.81 raeburn 5022: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5023: my $rownum = 0;
5024: my $css_class;
5025: foreach my $type (@pages) {
5026: $rownum ++;
5027: $css_class = $rownum%2?' class="LC_odd_row"':'';
5028: $datatable .= '<tr'.$css_class.'>'.
5029: '<td><span class="LC_nobreak">'.
5030: $titles->{$type}.'</span></td>'.
5031: '<td class="LC_left_item">'.
5032: '<input type="text" name="'.$type.'_namedusers" '.
5033: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5034: '<td class="LC_right_item">'.
5035: '<span class="LC_nobreak">'.
5036: '<input type="text" name="'.$type.'_machines" '.
5037: 'value="'.$machineaccess{$type}.'" size="10" />'.
5038: '</td></tr>'."\n";
5039: }
5040: $$rowtotal += $rownum;
5041: return $datatable;
5042: }
5043:
5044: sub serverstatus_pages {
5045: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 5046: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 5047: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.36 raeburn 5048: 'uniquecodes','diskusage');
1.69 raeburn 5049: }
5050:
1.160.6.40 raeburn 5051: sub defaults_javascript {
5052: my ($settings) = @_;
5053: my ($output,$jstext);
5054: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5055: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5056: if ($maxnum eq '') {
5057: $maxnum = 0;
5058: }
5059: $maxnum ++;
5060: $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
5061: return <<"ENDSCRIPT";
5062: <script type="text/javascript">
5063: // <![CDATA[
5064: function reorderTypes(form,caller) {
5065: var changedVal;
5066: $jstext
5067: var newpos = 'addinststatus_pos';
5068: var current = new Array;
5069: var maxh = $maxnum;
5070: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5071: var oldVal;
5072: if (caller == newpos) {
5073: changedVal = newitemVal;
5074: } else {
5075: var curritem = 'inststatus_pos_'+caller;
5076: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5077: current[newitemVal] = newpos;
5078: }
5079: for (var i=0; i<inststatuses.length; i++) {
5080: if (inststatuses[i] != caller) {
5081: var elementName = 'inststatus_pos_'+inststatuses[i];
5082: if (form.elements[elementName]) {
5083: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5084: current[currVal] = elementName;
5085: }
5086: }
5087: }
5088: for (var j=0; j<maxh; j++) {
5089: if (current[j] == undefined) {
5090: oldVal = j;
5091: }
5092: }
5093: if (oldVal < changedVal) {
5094: for (var k=oldVal+1; k<=changedVal ; k++) {
5095: var elementName = current[k];
5096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5097: }
5098: } else {
5099: for (var k=changedVal; k<oldVal; k++) {
5100: var elementName = current[k];
5101: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5102: }
5103: }
5104: return;
5105: }
5106:
5107: // ]]>
5108: </script>
5109:
5110: ENDSCRIPT
5111: }
5112: }
5113:
1.49 raeburn 5114: sub coursecategories_javascript {
5115: my ($settings) = @_;
1.57 raeburn 5116: my ($output,$jstext,$cathash);
1.49 raeburn 5117: if (ref($settings) eq 'HASH') {
1.57 raeburn 5118: $cathash = $settings->{'cats'};
5119: }
5120: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5121: my (@cats,@jsarray,%idx);
1.57 raeburn 5122: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5123: if (@jsarray > 0) {
5124: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5125: for (my $i=0; $i<@jsarray; $i++) {
5126: if (ref($jsarray[$i]) eq 'ARRAY') {
5127: my $catstr = join('","',@{$jsarray[$i]});
5128: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5129: }
5130: }
5131: }
5132: } else {
5133: $jstext = ' var categories = Array(1);'."\n".
5134: ' categories[0] = Array("instcode_pos");'."\n";
5135: }
1.160.6.42 raeburn 5136: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5137: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5138: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5139: $output = <<"ENDSCRIPT";
5140: <script type="text/javascript">
1.109 raeburn 5141: // <![CDATA[
1.49 raeburn 5142: function reorderCats(form,parent,item,idx) {
5143: var changedVal;
5144: $jstext
5145: var newpos = 'addcategory_pos';
5146: if (parent == '') {
5147: var has_instcode = 0;
5148: var maxtop = categories[idx].length;
5149: for (var j=0; j<maxtop; j++) {
5150: if (categories[idx][j] == 'instcode::0') {
5151: has_instcode == 1;
5152: }
5153: }
5154: if (has_instcode == 0) {
5155: categories[idx][maxtop] = 'instcode_pos';
5156: }
5157: } else {
5158: newpos += '_'+parent;
5159: }
5160: var maxh = 1 + categories[idx].length;
5161: var current = new Array;
5162: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5163: if (item == newpos) {
5164: changedVal = newitemVal;
5165: } else {
5166: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5167: current[newitemVal] = newpos;
5168: }
5169: for (var i=0; i<categories[idx].length; i++) {
5170: var elementName = categories[idx][i];
5171: if (elementName != item) {
5172: if (form.elements[elementName]) {
5173: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5174: current[currVal] = elementName;
5175: }
5176: }
5177: }
5178: var oldVal;
5179: for (var j=0; j<maxh; j++) {
5180: if (current[j] == undefined) {
5181: oldVal = j;
5182: }
5183: }
5184: if (oldVal < changedVal) {
5185: for (var k=oldVal+1; k<=changedVal ; k++) {
5186: var elementName = current[k];
5187: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5188: }
5189: } else {
5190: for (var k=changedVal; k<oldVal; k++) {
5191: var elementName = current[k];
5192: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5193: }
5194: }
5195: return;
5196: }
1.120 raeburn 5197:
5198: function categoryCheck(form) {
5199: if (form.elements['addcategory_name'].value == 'instcode') {
5200: alert('$instcode_reserved\\n$choose_again');
5201: return false;
5202: }
5203: if (form.elements['addcategory_name'].value == 'communities') {
5204: alert('$communities_reserved\\n$choose_again');
5205: return false;
5206: }
5207: return true;
5208: }
5209:
1.109 raeburn 5210: // ]]>
1.49 raeburn 5211: </script>
5212:
5213: ENDSCRIPT
5214: return $output;
5215: }
5216:
1.48 raeburn 5217: sub initialize_categories {
5218: my ($itemcount) = @_;
1.120 raeburn 5219: my ($datatable,$css_class,$chgstr);
5220: my %default_names = (
5221: instcode => 'Official courses (with institutional codes)',
5222: communities => 'Communities',
5223: );
5224: my $select0 = ' selected="selected"';
5225: my $select1 = '';
5226: foreach my $default ('instcode','communities') {
5227: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5228: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5229: if ($default eq 'communities') {
5230: $select1 = $select0;
5231: $select0 = '';
5232: }
5233: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5234: .'<select name="'.$default.'_pos">'
5235: .'<option value="0"'.$select0.'>1</option>'
5236: .'<option value="1"'.$select1.'>2</option>'
5237: .'<option value="2">3</option></select> '
5238: .$default_names{$default}
5239: .'</span></td><td><span class="LC_nobreak">'
5240: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5241: .&mt('Display').'</label> <label>'
5242: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5243: .'</label></span></td></tr>';
1.120 raeburn 5244: $itemcount ++;
5245: }
1.48 raeburn 5246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5247: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5248: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5249: .'<select name="addcategory_pos"'.$chgstr.'>'
5250: .'<option value="0">1</option>'
5251: .'<option value="1">2</option>'
5252: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5253: .&mt('Add category').'</td><td>'.&mt('Name:')
5254: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5255: return $datatable;
5256: }
5257:
5258: sub build_category_rows {
1.49 raeburn 5259: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5260: my ($text,$name,$item,$chgstr);
1.48 raeburn 5261: if (ref($cats) eq 'ARRAY') {
5262: my $maxdepth = scalar(@{$cats});
5263: if (ref($cats->[$depth]) eq 'HASH') {
5264: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5265: my $numchildren = @{$cats->[$depth]{$parent}};
5266: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 5267: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5268: my ($idxnum,$parent_name,$parent_item);
5269: my $higher = $depth - 1;
5270: if ($higher == 0) {
5271: $parent_name = &escape($parent).'::'.$higher;
5272: } else {
5273: if (ref($path) eq 'ARRAY') {
5274: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5275: }
5276: }
5277: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5278: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5279: if ($j < $numchildren) {
1.48 raeburn 5280: $name = $cats->[$depth]{$parent}[$j];
5281: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5282: $idxnum = $idx->{$item};
5283: } else {
5284: $name = $parent_name;
5285: $item = $parent_item;
1.48 raeburn 5286: }
1.49 raeburn 5287: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5288: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5289: for (my $i=0; $i<=$numchildren; $i++) {
5290: my $vpos = $i+1;
5291: my $selstr;
5292: if ($j == $i) {
5293: $selstr = ' selected="selected" ';
5294: }
5295: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5296: }
5297: $text .= '</select> ';
5298: if ($j < $numchildren) {
5299: my $deeper = $depth+1;
5300: $text .= $name.' '
5301: .'<label><input type="checkbox" name="deletecategory" value="'
5302: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5303: if(ref($path) eq 'ARRAY') {
5304: push(@{$path},$name);
1.49 raeburn 5305: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5306: pop(@{$path});
5307: }
5308: } else {
1.59 bisitz 5309: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5310: if ($j == $numchildren) {
5311: $text .= $name;
5312: } else {
5313: $text .= $item;
5314: }
5315: $text .= '" value="" />';
5316: }
5317: $text .= '</td></tr>';
5318: }
5319: $text .= '</table></td>';
5320: } else {
5321: my $higher = $depth-1;
5322: if ($higher == 0) {
5323: $name = &escape($parent).'::'.$higher;
5324: } else {
5325: if (ref($path) eq 'ARRAY') {
5326: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5327: }
5328: }
5329: my $colspan;
5330: if ($parent ne 'instcode') {
5331: $colspan = $maxdepth - $depth - 1;
5332: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5333: }
5334: }
5335: }
5336: }
5337: return $text;
5338: }
5339:
1.33 raeburn 5340: sub modifiable_userdata_row {
1.160.6.35 raeburn 5341: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5342: my ($role,$rolename,$statustype);
5343: $role = $item;
1.160.6.34 raeburn 5344: if ($context eq 'cancreate') {
1.160.6.35 raeburn 5345: if ($item =~ /^emailusername_(.+)$/) {
5346: $statustype = $1;
5347: $role = 'emailusername';
5348: if (ref($usertypes) eq 'HASH') {
5349: if ($usertypes->{$statustype}) {
5350: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5351: } else {
5352: $rolename = &mt('Data provided by user');
5353: }
5354: }
1.160.6.34 raeburn 5355: }
5356: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5357: if (ref($usertypes) eq 'HASH') {
5358: $rolename = $usertypes->{$role};
5359: } else {
5360: $rolename = $role;
5361: }
1.33 raeburn 5362: } else {
1.63 raeburn 5363: if ($role eq 'cr') {
5364: $rolename = &mt('Custom role');
5365: } else {
5366: $rolename = &Apache::lonnet::plaintext($role);
5367: }
1.33 raeburn 5368: }
1.160.6.34 raeburn 5369: my (@fields,%fieldtitles);
5370: if (ref($fieldsref) eq 'ARRAY') {
5371: @fields = @{$fieldsref};
5372: } else {
5373: @fields = ('lastname','firstname','middlename','generation',
5374: 'permanentemail','id');
5375: }
5376: if ((ref($titlesref) eq 'HASH')) {
5377: %fieldtitles = %{$titlesref};
5378: } else {
5379: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5380: }
1.33 raeburn 5381: my $output;
5382: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5383: $output = '<tr '.$css_class.'>'.
5384: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5385: '<td class="LC_left_item" colspan="2"><table>';
5386: my $rem;
5387: my %checks;
5388: if (ref($settings) eq 'HASH') {
5389: if (ref($settings->{$context}) eq 'HASH') {
5390: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 5391: my $hashref = $settings->{$context}->{$role};
5392: if ($role eq 'emailusername') {
5393: if ($statustype) {
5394: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5395: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 5396: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 5397: foreach my $field (@fields) {
5398: if ($hashref->{$field}) {
5399: $checks{$field} = $hashref->{$field};
5400: }
5401: }
5402: }
5403: }
5404: }
5405: } else {
5406: if (ref($hashref) eq 'HASH') {
5407: foreach my $field (@fields) {
5408: if ($hashref->{$field}) {
5409: $checks{$field} = ' checked="checked" ';
5410: }
5411: }
1.33 raeburn 5412: }
5413: }
5414: }
5415: }
5416: }
1.160.6.39 raeburn 5417:
1.33 raeburn 5418: for (my $i=0; $i<@fields; $i++) {
5419: my $rem = $i%($numinrow);
5420: if ($rem == 0) {
5421: if ($i > 0) {
5422: $output .= '</tr>';
5423: }
5424: $output .= '<tr>';
5425: }
5426: my $check = ' ';
1.160.6.35 raeburn 5427: unless ($role eq 'emailusername') {
5428: if (exists($checks{$fields[$i]})) {
5429: $check = $checks{$fields[$i]}
5430: } else {
5431: if ($role eq 'st') {
5432: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 5433: $check = ' checked="checked" ';
1.160.6.35 raeburn 5434: }
1.33 raeburn 5435: }
5436: }
5437: }
5438: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 5439: '<span class="LC_nobreak">';
5440: if ($role eq 'emailusername') {
5441: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5442: $checks{$fields[$i]} = 'omit';
5443: }
5444: foreach my $option ('required','optional','omit') {
5445: my $checked='';
5446: if ($checks{$fields[$i]} eq $option) {
5447: $checked='checked="checked" ';
5448: }
5449: $output .= '<label>'.
5450: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5451: &mt($option).'</label>'.(' ' x2);
5452: }
5453: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5454: } else {
5455: $output .= '<label>'.
5456: '<input type="checkbox" name="canmodify_'.$role.'" '.
5457: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5458: '</label>';
5459: }
5460: $output .= '</span></td>';
1.33 raeburn 5461: $rem = @fields%($numinrow);
5462: }
5463: my $colsleft = $numinrow - $rem;
5464: if ($colsleft > 1 ) {
5465: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5466: ' </td>';
5467: } elsif ($colsleft == 1) {
5468: $output .= '<td class="LC_left_item"> </td>';
5469: }
5470: $output .= '</tr></table></td></tr>';
5471: return $output;
5472: }
1.28 raeburn 5473:
1.93 raeburn 5474: sub insttypes_row {
1.160.6.34 raeburn 5475: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5476: my %lt = &Apache::lonlocal::texthash (
5477: cansearch => 'Users allowed to search',
5478: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5479: lockablenames => 'User preference to lock name',
1.93 raeburn 5480: );
5481: my $showdom;
5482: if ($context eq 'cansearch') {
5483: $showdom = ' ('.$dom.')';
5484: }
1.160.6.5 raeburn 5485: my $class = 'LC_left_item';
5486: if ($context eq 'statustocreate') {
5487: $class = 'LC_right_item';
5488: }
1.160.6.34 raeburn 5489: my $css_class = ' class="LC_odd_row"';
5490: if ($rownum ne '') {
5491: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5492: }
5493: my $output = '<tr'.$css_class.'>'.
5494: '<td>'.$lt{$context}.$showdom.
5495: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5496: my $rem;
5497: if (ref($types) eq 'ARRAY') {
5498: for (my $i=0; $i<@{$types}; $i++) {
5499: if (defined($usertypes->{$types->[$i]})) {
5500: my $rem = $i%($numinrow);
5501: if ($rem == 0) {
5502: if ($i > 0) {
5503: $output .= '</tr>';
5504: }
5505: $output .= '<tr>';
1.23 raeburn 5506: }
1.26 raeburn 5507: my $check = ' ';
1.99 raeburn 5508: if (ref($settings) eq 'HASH') {
5509: if (ref($settings->{$context}) eq 'ARRAY') {
5510: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5511: $check = ' checked="checked" ';
5512: }
5513: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5514: $check = ' checked="checked" ';
5515: }
1.23 raeburn 5516: }
1.26 raeburn 5517: $output .= '<td class="LC_left_item">'.
5518: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5519: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5520: 'value="'.$types->[$i].'"'.$check.'/>'.
5521: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5522: }
5523: }
1.26 raeburn 5524: $rem = @{$types}%($numinrow);
1.23 raeburn 5525: }
5526: my $colsleft = $numinrow - $rem;
1.131 raeburn 5527: if (($rem == 0) && (@{$types} > 0)) {
5528: $output .= '<tr>';
5529: }
1.23 raeburn 5530: if ($colsleft > 1) {
1.25 raeburn 5531: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5532: } else {
1.25 raeburn 5533: $output .= '<td class="LC_left_item">';
1.23 raeburn 5534: }
5535: my $defcheck = ' ';
1.99 raeburn 5536: if (ref($settings) eq 'HASH') {
5537: if (ref($settings->{$context}) eq 'ARRAY') {
5538: if (grep(/^default$/,@{$settings->{$context}})) {
5539: $defcheck = ' checked="checked" ';
5540: }
5541: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5542: $defcheck = ' checked="checked" ';
5543: }
1.23 raeburn 5544: }
1.25 raeburn 5545: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5546: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5547: 'value="default"'.$defcheck.'/>'.
5548: $othertitle.'</label></span></td>'.
5549: '</tr></table></td></tr>';
5550: return $output;
1.23 raeburn 5551: }
5552:
5553: sub sorted_searchtitles {
5554: my %searchtitles = &Apache::lonlocal::texthash(
5555: 'uname' => 'username',
5556: 'lastname' => 'last name',
5557: 'lastfirst' => 'last name, first name',
5558: );
5559: my @titleorder = ('uname','lastname','lastfirst');
5560: return (\%searchtitles,\@titleorder);
5561: }
5562:
1.25 raeburn 5563: sub sorted_searchtypes {
5564: my %srchtypes_desc = (
5565: exact => 'is exact match',
5566: contains => 'contains ..',
5567: begins => 'begins with ..',
5568: );
5569: my @srchtypeorder = ('exact','begins','contains');
5570: return (\%srchtypes_desc,\@srchtypeorder);
5571: }
5572:
1.3 raeburn 5573: sub usertype_update_row {
5574: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5575: my $datatable;
5576: my $numinrow = 4;
5577: foreach my $type (@{$types}) {
5578: if (defined($usertypes->{$type})) {
5579: $$rownums ++;
5580: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5581: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5582: '</td><td class="LC_left_item"><table>';
5583: for (my $i=0; $i<@{$fields}; $i++) {
5584: my $rem = $i%($numinrow);
5585: if ($rem == 0) {
5586: if ($i > 0) {
5587: $datatable .= '</tr>';
5588: }
5589: $datatable .= '<tr>';
5590: }
5591: my $check = ' ';
1.39 raeburn 5592: if (ref($settings) eq 'HASH') {
5593: if (ref($settings->{'fields'}) eq 'HASH') {
5594: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5595: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5596: $check = ' checked="checked" ';
5597: }
1.3 raeburn 5598: }
5599: }
5600: }
5601:
5602: if ($i == @{$fields}-1) {
5603: my $colsleft = $numinrow - $rem;
5604: if ($colsleft > 1) {
5605: $datatable .= '<td colspan="'.$colsleft.'">';
5606: } else {
5607: $datatable .= '<td>';
5608: }
5609: } else {
5610: $datatable .= '<td>';
5611: }
1.8 raeburn 5612: $datatable .= '<span class="LC_nobreak"><label>'.
5613: '<input type="checkbox" name="updateable_'.$type.
5614: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5615: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5616: }
5617: $datatable .= '</tr></table></td></tr>';
5618: }
5619: }
5620: return $datatable;
1.1 raeburn 5621: }
5622:
5623: sub modify_login {
1.160.6.24 raeburn 5624: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 5625: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5626: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5627: %title = ( coursecatalog => 'Display course catalog',
5628: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 5629: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 5630: newuser => 'Link for visitors to create a user account',
5631: loginheader => 'Log-in box header');
5632: @offon = ('off','on');
1.112 raeburn 5633: if (ref($domconfig{login}) eq 'HASH') {
5634: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5635: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5636: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5637: }
5638: }
5639: }
1.9 raeburn 5640: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5641: \%domconfig,\%loginhash);
1.160.6.14 raeburn 5642: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5643: foreach my $item (@toggles) {
5644: $loginhash{login}{$item} = $env{'form.'.$item};
5645: }
1.41 raeburn 5646: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5647: if (ref($colchanges{'login'}) eq 'HASH') {
5648: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5649: \%loginhash);
5650: }
1.110 raeburn 5651:
1.149 raeburn 5652: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 5653: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5654: if (keys(%servers) > 1) {
5655: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5656: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5657: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5658: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5659: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5660: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5661: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5662: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5663: $changes{'loginvia'}{$lonhost} = 1;
5664: } else {
5665: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5666: $changes{'loginvia'}{$lonhost} = 1;
5667: }
5668: } else {
5669: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5670: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5671: $changes{'loginvia'}{$lonhost} = 1;
5672: }
5673: }
5674: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5675: foreach my $item (@loginvia_attribs) {
5676: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5677: }
5678: } else {
5679: foreach my $item (@loginvia_attribs) {
5680: my $new = $env{'form.'.$lonhost.'_'.$item};
5681: if (($item eq 'serverpath') && ($new eq 'custom')) {
5682: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5683: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5684: $new = '/';
5685: }
5686: }
5687: if (($item eq 'custompath') &&
5688: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5689: $new = '';
5690: }
5691: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5692: $changes{'loginvia'}{$lonhost} = 1;
5693: }
5694: if ($item eq 'exempt') {
5695: $new =~ s/^\s+//;
5696: $new =~ s/\s+$//;
5697: my @poss_ips = split(/\s*[,:]\s*/,$new);
5698: my @okips;
5699: foreach my $ip (@poss_ips) {
5700: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
5701: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
5702: push(@okips,$ip);
5703: }
5704: }
5705: }
5706: if (@okips > 0) {
5707: $new = join(',',@okips);
5708: } else {
5709: $new = '';
5710: }
5711: }
5712: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5713: }
5714: }
1.112 raeburn 5715: } else {
1.128 raeburn 5716: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5717: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5718: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5719: foreach my $item (@loginvia_attribs) {
5720: my $new = $env{'form.'.$lonhost.'_'.$item};
5721: if (($item eq 'serverpath') && ($new eq 'custom')) {
5722: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5723: $new = '/';
5724: }
5725: }
5726: if (($item eq 'custompath') &&
5727: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5728: $new = '';
5729: }
5730: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5731: }
1.110 raeburn 5732: }
5733: }
5734: }
5735: }
1.119 raeburn 5736:
1.160.6.5 raeburn 5737: my $servadm = $r->dir_config('lonAdmEMail');
5738: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5739: if (ref($domconfig{'login'}) eq 'HASH') {
5740: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5741: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5742: if ($lang eq 'nolang') {
5743: push(@currlangs,$lang);
5744: } elsif (defined($langchoices{$lang})) {
5745: push(@currlangs,$lang);
5746: } else {
5747: next;
5748: }
5749: }
5750: }
5751: }
5752: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5753: if (@currlangs > 0) {
5754: foreach my $lang (@currlangs) {
5755: if (grep(/^\Q$lang\E$/,@delurls)) {
5756: $changes{'helpurl'}{$lang} = 1;
5757: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5758: $changes{'helpurl'}{$lang} = 1;
5759: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5760: push(@newlangs,$lang);
5761: } else {
5762: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5763: }
5764: }
5765: }
5766: unless (grep(/^nolang$/,@currlangs)) {
5767: if ($env{'form.loginhelpurl_nolang.filename'}) {
5768: $changes{'helpurl'}{'nolang'} = 1;
5769: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5770: push(@newlangs,'nolang');
5771: }
5772: }
5773: if ($env{'form.loginhelpurl_add_lang'}) {
5774: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5775: ($env{'form.loginhelpurl_add_file.filename'})) {
5776: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5777: $addedfile = $env{'form.loginhelpurl_add_lang'};
5778: }
5779: }
5780: if ((@newlangs > 0) || ($addedfile)) {
5781: my $error;
5782: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5783: if ($configuserok eq 'ok') {
5784: if ($switchserver) {
5785: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5786: } elsif ($author_ok eq 'ok') {
5787: my @allnew = @newlangs;
5788: if ($addedfile ne '') {
5789: push(@allnew,$addedfile);
5790: }
5791: foreach my $lang (@allnew) {
5792: my $formelem = 'loginhelpurl_'.$lang;
5793: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5794: $formelem = 'loginhelpurl_add_file';
5795: }
5796: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5797: "help/$lang",'','',$newfile{$lang});
5798: if ($result eq 'ok') {
5799: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5800: $changes{'helpurl'}{$lang} = 1;
5801: } else {
5802: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5803: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
5804: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
5805: (!grep(/^\Q$lang\E$/,@delurls))) {
5806:
5807: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5808: }
5809: }
5810: }
5811: } else {
5812: $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);
5813: }
5814: } else {
5815: $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);
5816: }
5817: if ($error) {
5818: &Apache::lonnet::logthis($error);
5819: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5820: }
5821: }
5822: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
5823:
5824: my $defaulthelpfile = '/adm/loginproblems.html';
5825: my $defaulttext = &mt('Default in use');
5826:
1.1 raeburn 5827: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
5828: $dom);
5829: if ($putresult eq 'ok') {
1.160.6.14 raeburn 5830: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5831: my %defaultchecked = (
5832: 'coursecatalog' => 'on',
1.160.6.14 raeburn 5833: 'helpdesk' => 'on',
1.42 raeburn 5834: 'adminmail' => 'off',
1.43 raeburn 5835: 'newuser' => 'off',
1.42 raeburn 5836: );
1.55 raeburn 5837: if (ref($domconfig{'login'}) eq 'HASH') {
5838: foreach my $item (@toggles) {
5839: if ($defaultchecked{$item} eq 'on') {
5840: if (($domconfig{'login'}{$item} eq '0') &&
5841: ($env{'form.'.$item} eq '1')) {
5842: $changes{$item} = 1;
5843: } elsif (($domconfig{'login'}{$item} eq '' ||
5844: $domconfig{'login'}{$item} eq '1') &&
5845: ($env{'form.'.$item} eq '0')) {
5846: $changes{$item} = 1;
5847: }
5848: } elsif ($defaultchecked{$item} eq 'off') {
5849: if (($domconfig{'login'}{$item} eq '1') &&
5850: ($env{'form.'.$item} eq '0')) {
5851: $changes{$item} = 1;
5852: } elsif (($domconfig{'login'}{$item} eq '' ||
5853: $domconfig{'login'}{$item} eq '0') &&
5854: ($env{'form.'.$item} eq '1')) {
5855: $changes{$item} = 1;
5856: }
1.42 raeburn 5857: }
5858: }
1.41 raeburn 5859: }
1.6 raeburn 5860: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 5861: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 5862: if (ref($lastactref) eq 'HASH') {
5863: $lastactref->{'domainconfig'} = 1;
5864: }
1.1 raeburn 5865: $resulttext = &mt('Changes made:').'<ul>';
5866: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 5867: if ($item eq 'loginvia') {
1.112 raeburn 5868: if (ref($changes{$item}) eq 'HASH') {
5869: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5870: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5871: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5872: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5873: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5874: $protocol = 'http' if ($protocol ne 'https');
5875: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5876:
5877: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5878: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5879: } else {
5880: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5881: }
5882: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5883: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5884: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5885: }
5886: $resulttext .= '</li>';
5887: } else {
5888: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5889: }
1.112 raeburn 5890: } else {
1.128 raeburn 5891: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5892: }
5893: }
1.128 raeburn 5894: $resulttext .= '</ul></li>';
1.112 raeburn 5895: }
1.160.6.5 raeburn 5896: } elsif ($item eq 'helpurl') {
5897: if (ref($changes{$item}) eq 'HASH') {
5898: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5899: if (grep(/^\Q$lang\E$/,@delurls)) {
5900: my ($chg,$link);
5901: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5902: if ($lang eq 'nolang') {
5903: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5904: } else {
5905: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5906: }
5907: $resulttext .= '<li>'.$chg.'</li>';
5908: } else {
5909: my $chg;
5910: if ($lang eq 'nolang') {
5911: $chg = &mt('custom log-in help file for no preferred language');
5912: } else {
5913: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5914: }
5915: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5916: $loginhash{'login'}{'helpurl'}{$lang}.
5917: '?inhibitmenu=yes',$chg,600,500).
5918: '</li>';
5919: }
5920: }
5921: }
5922: } elsif ($item eq 'captcha') {
5923: if (ref($loginhash{'login'}) eq 'HASH') {
5924: my $chgtxt;
5925: if ($loginhash{'login'}{$item} eq 'notused') {
5926: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5927: } else {
5928: my %captchas = &captcha_phrases();
5929: if ($captchas{$loginhash{'login'}{$item}}) {
5930: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5931: } else {
5932: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5933: }
5934: }
5935: $resulttext .= '<li>'.$chgtxt.'</li>';
5936: }
5937: } elsif ($item eq 'recaptchakeys') {
5938: if (ref($loginhash{'login'}) eq 'HASH') {
5939: my ($privkey,$pubkey);
5940: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5941: $pubkey = $loginhash{'login'}{$item}{'public'};
5942: $privkey = $loginhash{'login'}{$item}{'private'};
5943: }
5944: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5945: if (!$pubkey) {
5946: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5947: } else {
5948: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5949: }
5950: if (!$privkey) {
5951: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5952: } else {
5953: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5954: }
5955: $chgtxt .= '</ul>';
5956: $resulttext .= '<li>'.$chgtxt.'</li>';
5957: }
1.41 raeburn 5958: } else {
5959: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5960: }
1.1 raeburn 5961: }
1.6 raeburn 5962: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5963: } else {
5964: $resulttext = &mt('No changes made to log-in page settings');
5965: }
5966: } else {
1.11 albertel 5967: $resulttext = '<span class="LC_error">'.
5968: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5969: }
1.6 raeburn 5970: if ($errors) {
1.9 raeburn 5971: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5972: $errors.'</ul>';
5973: }
5974: return $resulttext;
5975: }
5976:
5977: sub color_font_choices {
5978: my %choices =
5979: &Apache::lonlocal::texthash (
5980: img => "Header",
5981: bgs => "Background colors",
5982: links => "Link colors",
1.55 raeburn 5983: images => "Images",
1.6 raeburn 5984: font => "Font color",
1.160.6.22 raeburn 5985: fontmenu => "Font menu",
1.76 raeburn 5986: pgbg => "Page",
1.6 raeburn 5987: tabbg => "Header",
5988: sidebg => "Border",
5989: link => "Link",
5990: alink => "Active link",
5991: vlink => "Visited link",
5992: );
5993: return %choices;
5994: }
5995:
5996: sub modify_rolecolors {
1.160.6.24 raeburn 5997: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5998: my ($resulttext,%rolehash);
5999: $rolehash{'rolecolors'} = {};
1.55 raeburn 6000: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6001: if ($domconfig{'rolecolors'} eq '') {
6002: $domconfig{'rolecolors'} = {};
6003: }
6004: }
1.9 raeburn 6005: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6006: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6007: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6008: $dom);
6009: if ($putresult eq 'ok') {
6010: if (keys(%changes) > 0) {
1.41 raeburn 6011: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 6012: if (ref($lastactref) eq 'HASH') {
6013: $lastactref->{'domainconfig'} = 1;
6014: }
1.6 raeburn 6015: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6016: $rolehash{'rolecolors'});
6017: } else {
6018: $resulttext = &mt('No changes made to default color schemes');
6019: }
6020: } else {
1.11 albertel 6021: $resulttext = '<span class="LC_error">'.
6022: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6023: }
6024: if ($errors) {
6025: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6026: $errors.'</ul>';
6027: }
6028: return $resulttext;
6029: }
6030:
6031: sub modify_colors {
1.9 raeburn 6032: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6033: my (%changes,%choices);
1.51 raeburn 6034: my @bgs;
1.6 raeburn 6035: my @links = ('link','alink','vlink');
1.41 raeburn 6036: my @logintext;
1.6 raeburn 6037: my @images;
6038: my $servadm = $r->dir_config('lonAdmEMail');
6039: my $errors;
1.160.6.22 raeburn 6040: my %defaults;
1.6 raeburn 6041: foreach my $role (@{$roles}) {
6042: if ($role eq 'login') {
1.12 raeburn 6043: %choices = &login_choices();
1.41 raeburn 6044: @logintext = ('textcol','bgcol');
1.12 raeburn 6045: } else {
6046: %choices = &color_font_choices();
6047: }
6048: if ($role eq 'login') {
1.41 raeburn 6049: @images = ('img','logo','domlogo','login');
1.51 raeburn 6050: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6051: } else {
6052: @images = ('img');
1.160.6.22 raeburn 6053: @bgs = ('pgbg','tabbg','sidebg');
6054: }
6055: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6056: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6057: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6058: }
6059: if ($role eq 'login') {
6060: foreach my $item (@logintext) {
1.160.6.39 raeburn 6061: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6062: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6063: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6064: }
6065: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 6066: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6067: }
6068: }
6069: } else {
1.160.6.39 raeburn 6070: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6071: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6072: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6073: }
6074: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 6075: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6076: }
1.6 raeburn 6077: }
1.160.6.22 raeburn 6078: foreach my $item (@bgs) {
1.160.6.39 raeburn 6079: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6080: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6081: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6082: }
6083: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 6084: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6085: }
6086: }
6087: foreach my $item (@links) {
1.160.6.39 raeburn 6088: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6089: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6090: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6091: }
6092: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 6093: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6094: }
1.6 raeburn 6095: }
1.46 raeburn 6096: my ($configuserok,$author_ok,$switchserver) =
6097: &config_check($dom,$confname,$servadm);
1.9 raeburn 6098: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6099: if (ref($domconfig->{$role}) ne 'HASH') {
6100: $domconfig->{$role} = {};
6101: }
1.8 raeburn 6102: foreach my $img (@images) {
1.70 raeburn 6103: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6104: if (defined($env{'form.login_showlogo_'.$img})) {
6105: $confhash->{$role}{'showlogo'}{$img} = 1;
6106: } else {
6107: $confhash->{$role}{'showlogo'}{$img} = 0;
6108: }
6109: }
1.18 albertel 6110: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6111: && !defined($domconfig->{$role}{$img})
6112: && !$env{'form.'.$role.'_del_'.$img}
6113: && $env{'form.'.$role.'_import_'.$img}) {
6114: # import the old configured image from the .tab setting
6115: # if they haven't provided a new one
6116: $domconfig->{$role}{$img} =
6117: $env{'form.'.$role.'_import_'.$img};
6118: }
1.6 raeburn 6119: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6120: my $error;
1.6 raeburn 6121: if ($configuserok eq 'ok') {
1.9 raeburn 6122: if ($switchserver) {
1.12 raeburn 6123: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6124: } else {
6125: if ($author_ok eq 'ok') {
6126: my ($result,$logourl) =
6127: &publishlogo($r,'upload',$role.'_'.$img,
6128: $dom,$confname,$img,$width,$height);
6129: if ($result eq 'ok') {
6130: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6131: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6132: } else {
1.12 raeburn 6133: $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 6134: }
6135: } else {
1.46 raeburn 6136: $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 6137: }
6138: }
6139: } else {
1.46 raeburn 6140: $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 6141: }
6142: if ($error) {
1.8 raeburn 6143: &Apache::lonnet::logthis($error);
1.11 albertel 6144: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6145: }
6146: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6147: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6148: my $error;
6149: if ($configuserok eq 'ok') {
6150: # is confname an author?
6151: if ($switchserver eq '') {
6152: if ($author_ok eq 'ok') {
6153: my ($result,$logourl) =
6154: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6155: $dom,$confname,$img,$width,$height);
6156: if ($result eq 'ok') {
6157: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6158: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6159: }
6160: }
6161: }
6162: }
1.6 raeburn 6163: }
6164: }
6165: }
6166: if (ref($domconfig) eq 'HASH') {
6167: if (ref($domconfig->{$role}) eq 'HASH') {
6168: foreach my $img (@images) {
6169: if ($domconfig->{$role}{$img} ne '') {
6170: if ($env{'form.'.$role.'_del_'.$img}) {
6171: $confhash->{$role}{$img} = '';
1.12 raeburn 6172: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6173: } else {
1.9 raeburn 6174: if ($confhash->{$role}{$img} eq '') {
6175: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6176: }
1.6 raeburn 6177: }
6178: } else {
6179: if ($env{'form.'.$role.'_del_'.$img}) {
6180: $confhash->{$role}{$img} = '';
1.12 raeburn 6181: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6182: }
6183: }
1.70 raeburn 6184: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6185: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6186: if ($confhash->{$role}{'showlogo'}{$img} ne
6187: $domconfig->{$role}{'showlogo'}{$img}) {
6188: $changes{$role}{'showlogo'}{$img} = 1;
6189: }
6190: } else {
6191: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6192: $changes{$role}{'showlogo'}{$img} = 1;
6193: }
6194: }
6195: }
6196: }
1.6 raeburn 6197: if ($domconfig->{$role}{'font'} ne '') {
6198: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6199: $changes{$role}{'font'} = 1;
6200: }
6201: } else {
6202: if ($confhash->{$role}{'font'}) {
6203: $changes{$role}{'font'} = 1;
6204: }
6205: }
1.107 raeburn 6206: if ($role ne 'login') {
6207: if ($domconfig->{$role}{'fontmenu'} ne '') {
6208: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6209: $changes{$role}{'fontmenu'} = 1;
6210: }
6211: } else {
6212: if ($confhash->{$role}{'fontmenu'}) {
6213: $changes{$role}{'fontmenu'} = 1;
6214: }
1.97 tempelho 6215: }
6216: }
1.6 raeburn 6217: foreach my $item (@bgs) {
6218: if ($domconfig->{$role}{$item} ne '') {
6219: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6220: $changes{$role}{'bgs'}{$item} = 1;
6221: }
6222: } else {
6223: if ($confhash->{$role}{$item}) {
6224: $changes{$role}{'bgs'}{$item} = 1;
6225: }
6226: }
6227: }
6228: foreach my $item (@links) {
6229: if ($domconfig->{$role}{$item} ne '') {
6230: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6231: $changes{$role}{'links'}{$item} = 1;
6232: }
6233: } else {
6234: if ($confhash->{$role}{$item}) {
6235: $changes{$role}{'links'}{$item} = 1;
6236: }
6237: }
6238: }
1.41 raeburn 6239: foreach my $item (@logintext) {
6240: if ($domconfig->{$role}{$item} ne '') {
6241: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6242: $changes{$role}{'logintext'}{$item} = 1;
6243: }
6244: } else {
6245: if ($confhash->{$role}{$item}) {
6246: $changes{$role}{'logintext'}{$item} = 1;
6247: }
6248: }
6249: }
1.6 raeburn 6250: } else {
6251: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6252: \@logintext,$confhash,\%changes);
1.6 raeburn 6253: }
6254: } else {
6255: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6256: \@logintext,$confhash,\%changes);
1.6 raeburn 6257: }
6258: }
6259: return ($errors,%changes);
6260: }
6261:
1.46 raeburn 6262: sub config_check {
6263: my ($dom,$confname,$servadm) = @_;
6264: my ($configuserok,$author_ok,$switchserver,%currroles);
6265: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6266: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6267: $confname,$servadm);
6268: if ($configuserok eq 'ok') {
6269: $switchserver = &check_switchserver($dom,$confname);
6270: if ($switchserver eq '') {
6271: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6272: }
6273: }
6274: return ($configuserok,$author_ok,$switchserver);
6275: }
6276:
1.6 raeburn 6277: sub default_change_checker {
1.41 raeburn 6278: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6279: foreach my $item (@{$links}) {
6280: if ($confhash->{$role}{$item}) {
6281: $changes->{$role}{'links'}{$item} = 1;
6282: }
6283: }
6284: foreach my $item (@{$bgs}) {
6285: if ($confhash->{$role}{$item}) {
6286: $changes->{$role}{'bgs'}{$item} = 1;
6287: }
6288: }
1.41 raeburn 6289: foreach my $item (@{$logintext}) {
6290: if ($confhash->{$role}{$item}) {
6291: $changes->{$role}{'logintext'}{$item} = 1;
6292: }
6293: }
1.6 raeburn 6294: foreach my $img (@{$images}) {
6295: if ($env{'form.'.$role.'_del_'.$img}) {
6296: $confhash->{$role}{$img} = '';
1.12 raeburn 6297: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6298: }
1.70 raeburn 6299: if ($role eq 'login') {
6300: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6301: $changes->{$role}{'showlogo'}{$img} = 1;
6302: }
6303: }
1.6 raeburn 6304: }
6305: if ($confhash->{$role}{'font'}) {
6306: $changes->{$role}{'font'} = 1;
6307: }
1.48 raeburn 6308: }
1.6 raeburn 6309:
6310: sub display_colorchgs {
6311: my ($dom,$changes,$roles,$confhash) = @_;
6312: my (%choices,$resulttext);
6313: if (!grep(/^login$/,@{$roles})) {
6314: $resulttext = &mt('Changes made:').'<br />';
6315: }
6316: foreach my $role (@{$roles}) {
6317: if ($role eq 'login') {
6318: %choices = &login_choices();
6319: } else {
6320: %choices = &color_font_choices();
6321: }
6322: if (ref($changes->{$role}) eq 'HASH') {
6323: if ($role ne 'login') {
6324: $resulttext .= '<h4>'.&mt($role).'</h4>';
6325: }
6326: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6327: if ($role ne 'login') {
6328: $resulttext .= '<ul>';
6329: }
6330: if (ref($changes->{$role}{$key}) eq 'HASH') {
6331: if ($role ne 'login') {
6332: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6333: }
6334: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6335: if (($role eq 'login') && ($key eq 'showlogo')) {
6336: if ($confhash->{$role}{$key}{$item}) {
6337: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6338: } else {
6339: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6340: }
6341: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6342: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6343: } else {
1.12 raeburn 6344: my $newitem = $confhash->{$role}{$item};
6345: if ($key eq 'images') {
6346: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6347: }
6348: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6349: }
6350: }
6351: if ($role ne 'login') {
6352: $resulttext .= '</ul></li>';
6353: }
6354: } else {
6355: if ($confhash->{$role}{$key} eq '') {
6356: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6357: } else {
6358: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6359: }
6360: }
6361: if ($role ne 'login') {
6362: $resulttext .= '</ul>';
6363: }
6364: }
6365: }
6366: }
1.3 raeburn 6367: return $resulttext;
1.1 raeburn 6368: }
6369:
1.9 raeburn 6370: sub thumb_dimensions {
6371: return ('200','50');
6372: }
6373:
1.16 raeburn 6374: sub check_dimensions {
6375: my ($inputfile) = @_;
6376: my ($fullwidth,$fullheight);
6377: if ($inputfile =~ m|^[/\w.\-]+$|) {
6378: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6379: my $imageinfo = <PIPE>;
6380: if (!close(PIPE)) {
6381: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6382: }
6383: chomp($imageinfo);
6384: my ($fullsize) =
1.21 raeburn 6385: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6386: if ($fullsize) {
6387: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6388: }
6389: }
6390: }
6391: return ($fullwidth,$fullheight);
6392: }
6393:
1.9 raeburn 6394: sub check_configuser {
6395: my ($uhome,$dom,$confname,$servadm) = @_;
6396: my ($configuserok,%currroles);
6397: if ($uhome eq 'no_host') {
6398: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6399: my $configpass = &LONCAPA::Enrollment::create_password();
6400: $configuserok =
6401: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6402: $configpass,'','','','','',undef,$servadm);
6403: } else {
6404: $configuserok = 'ok';
6405: %currroles =
6406: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6407: }
6408: return ($configuserok,%currroles);
6409: }
6410:
6411: sub check_authorstatus {
6412: my ($dom,$confname,%currroles) = @_;
6413: my $author_ok;
1.40 raeburn 6414: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6415: my $start = time;
6416: my $end = 0;
6417: $author_ok =
6418: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6419: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6420: } else {
6421: $author_ok = 'ok';
6422: }
6423: return $author_ok;
6424: }
6425:
6426: sub publishlogo {
1.46 raeburn 6427: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6428: my ($output,$fname,$logourl);
6429: if ($action eq 'upload') {
6430: $fname=$env{'form.'.$formname.'.filename'};
6431: chop($env{'form.'.$formname});
6432: } else {
6433: ($fname) = ($formname =~ /([^\/]+)$/);
6434: }
1.46 raeburn 6435: if ($savefileas ne '') {
6436: $fname = $savefileas;
6437: }
1.9 raeburn 6438: $fname=&Apache::lonnet::clean_filename($fname);
6439: # See if there is anything left
6440: unless ($fname) { return ('error: no uploaded file'); }
6441: $fname="$subdir/$fname";
1.160.6.5 raeburn 6442: my $docroot=$r->dir_config('lonDocRoot');
6443: my $filepath="$docroot/priv";
6444: my $relpath = "$dom/$confname";
1.9 raeburn 6445: my ($fnamepath,$file,$fetchthumb);
6446: $file=$fname;
6447: if ($fname=~m|/|) {
6448: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6449: }
1.160.6.26 raeburn 6450: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6451: my $count;
1.160.6.5 raeburn 6452: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6453: $filepath.="/$parts[$count]";
6454: if ((-e $filepath)!=1) {
6455: mkdir($filepath,02770);
6456: }
6457: }
6458: # Check for bad extension and disallow upload
6459: if ($file=~/\.(\w+)$/ &&
6460: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6461: $output =
1.160.6.25 raeburn 6462: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6463: } elsif ($file=~/\.(\w+)$/ &&
6464: !defined(&Apache::loncommon::fileembstyle($1))) {
6465: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6466: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 6467: $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 6468: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 6469: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6470: } else {
6471: my $source = $filepath.'/'.$file;
6472: my $logfile;
6473: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 6474: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6475: }
6476: print $logfile
6477: "\n================= Publish ".localtime()." ================\n".
6478: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6479: # Save the file
6480: if (!open(FH,'>'.$source)) {
6481: &Apache::lonnet::logthis('Failed to create '.$source);
6482: return (&mt('Failed to create file'));
6483: }
6484: if ($action eq 'upload') {
6485: if (!print FH ($env{'form.'.$formname})) {
6486: &Apache::lonnet::logthis('Failed to write to '.$source);
6487: return (&mt('Failed to write file'));
6488: }
6489: } else {
6490: my $original = &Apache::lonnet::filelocation('',$formname);
6491: if(!copy($original,$source)) {
6492: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6493: return (&mt('Failed to write file'));
6494: }
6495: }
6496: close(FH);
6497: chmod(0660, $source); # Permissions to rw-rw---.
6498:
6499: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6500: my $copyfile=$targetdir.'/'.$file;
6501:
6502: my @parts=split(/\//,$targetdir);
6503: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6504: for (my $count=5;$count<=$#parts;$count++) {
6505: $path.="/$parts[$count]";
6506: if (!-e $path) {
6507: print $logfile "\nCreating directory ".$path;
6508: mkdir($path,02770);
6509: }
6510: }
6511: my $versionresult;
6512: if (-e $copyfile) {
6513: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6514: } else {
6515: $versionresult = 'ok';
6516: }
6517: if ($versionresult eq 'ok') {
6518: if (copy($source,$copyfile)) {
6519: print $logfile "\nCopied original source to ".$copyfile."\n";
6520: $output = 'ok';
6521: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6522: push(@{$modified_urls},[$copyfile,$source]);
6523: my $metaoutput =
6524: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6525: unless ($registered_cleanup) {
6526: my $handlers = $r->get_handlers('PerlCleanupHandler');
6527: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6528: $registered_cleanup=1;
6529: }
1.9 raeburn 6530: } else {
6531: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6532: $output = &mt('Failed to copy file to RES space').", $!";
6533: }
6534: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6535: my $inputfile = $filepath.'/'.$file;
6536: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6537: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6538: if ($fullwidth ne '' && $fullheight ne '') {
6539: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6540: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6541: system("convert -sample $thumbsize $inputfile $outfile");
6542: chmod(0660, $filepath.'/tn-'.$file);
6543: if (-e $outfile) {
6544: my $copyfile=$targetdir.'/tn-'.$file;
6545: if (copy($outfile,$copyfile)) {
6546: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6547: my $thumb_metaoutput =
6548: &write_metadata($dom,$confname,$formname,
6549: $targetdir,'tn-'.$file,$logfile);
6550: push(@{$modified_urls},[$copyfile,$outfile]);
6551: unless ($registered_cleanup) {
6552: my $handlers = $r->get_handlers('PerlCleanupHandler');
6553: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6554: $registered_cleanup=1;
6555: }
1.16 raeburn 6556: } else {
6557: print $logfile "\nUnable to write ".$copyfile.
6558: ':'.$!."\n";
6559: }
6560: }
1.9 raeburn 6561: }
6562: }
6563: }
6564: } else {
6565: $output = $versionresult;
6566: }
6567: }
6568: return ($output,$logourl);
6569: }
6570:
6571: sub logo_versioning {
6572: my ($targetdir,$file,$logfile) = @_;
6573: my $target = $targetdir.'/'.$file;
6574: my ($maxversion,$fn,$extn,$output);
6575: $maxversion = 0;
6576: if ($file =~ /^(.+)\.(\w+)$/) {
6577: $fn=$1;
6578: $extn=$2;
6579: }
6580: opendir(DIR,$targetdir);
6581: while (my $filename=readdir(DIR)) {
6582: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6583: $maxversion=($1>$maxversion)?$1:$maxversion;
6584: }
6585: }
6586: $maxversion++;
6587: print $logfile "\nCreating old version ".$maxversion."\n";
6588: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6589: if (copy($target,$copyfile)) {
6590: print $logfile "Copied old target to ".$copyfile."\n";
6591: $copyfile=$copyfile.'.meta';
6592: if (copy($target.'.meta',$copyfile)) {
6593: print $logfile "Copied old target metadata to ".$copyfile."\n";
6594: $output = 'ok';
6595: } else {
6596: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6597: $output = &mt('Failed to copy old meta').", $!, ";
6598: }
6599: } else {
6600: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6601: $output = &mt('Failed to copy old target').", $!, ";
6602: }
6603: return $output;
6604: }
6605:
6606: sub write_metadata {
6607: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6608: my (%metadatafields,%metadatakeys,$output);
6609: $metadatafields{'title'}=$formname;
6610: $metadatafields{'creationdate'}=time;
6611: $metadatafields{'lastrevisiondate'}=time;
6612: $metadatafields{'copyright'}='public';
6613: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6614: $env{'user.domain'};
6615: $metadatafields{'authorspace'}=$confname.':'.$dom;
6616: $metadatafields{'domain'}=$dom;
6617: {
6618: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6619: my $mfh;
1.155 raeburn 6620: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 6621: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6622: unless ($_=~/\./) {
6623: my $unikey=$_;
6624: $unikey=~/^([A-Za-z]+)/;
6625: my $tag=$1;
6626: $tag=~tr/A-Z/a-z/;
6627: print $mfh "\n\<$tag";
6628: foreach (split(/\,/,$metadatakeys{$unikey})) {
6629: my $value=$metadatafields{$unikey.'.'.$_};
6630: $value=~s/\"/\'\'/g;
6631: print $mfh ' '.$_.'="'.$value.'"';
6632: }
6633: print $mfh '>'.
6634: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6635: .'</'.$tag.'>';
6636: }
6637: }
6638: $output = 'ok';
6639: print $logfile "\nWrote metadata";
6640: close($mfh);
6641: } else {
6642: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6643: $output = &mt('Could not write metadata');
6644: }
6645: }
1.155 raeburn 6646: return $output;
6647: }
6648:
6649: sub notifysubscribed {
6650: foreach my $targetsource (@{$modified_urls}){
6651: next unless (ref($targetsource) eq 'ARRAY');
6652: my ($target,$source)=@{$targetsource};
6653: if ($source ne '') {
6654: if (open(my $logfh,'>>'.$source.'.log')) {
6655: print $logfh "\nCleanup phase: Notifications\n";
6656: my @subscribed=&subscribed_hosts($target);
6657: foreach my $subhost (@subscribed) {
6658: print $logfh "\nNotifying host ".$subhost.':';
6659: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6660: print $logfh $reply;
6661: }
6662: my @subscribedmeta=&subscribed_hosts("$target.meta");
6663: foreach my $subhost (@subscribedmeta) {
6664: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6665: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6666: $subhost);
6667: print $logfh $reply;
6668: }
6669: print $logfh "\n============ Done ============\n";
1.160 raeburn 6670: close($logfh);
1.155 raeburn 6671: }
6672: }
6673: }
6674: return OK;
6675: }
6676:
6677: sub subscribed_hosts {
6678: my ($target) = @_;
6679: my @subscribed;
6680: if (open(my $fh,"<$target.subscription")) {
6681: while (my $subline=<$fh>) {
6682: if ($subline =~ /^($match_lonid):/) {
6683: my $host = $1;
6684: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6685: unless (grep(/^\Q$host\E$/,@subscribed)) {
6686: push(@subscribed,$host);
6687: }
6688: }
6689: }
6690: }
6691: }
6692: return @subscribed;
1.9 raeburn 6693: }
6694:
6695: sub check_switchserver {
6696: my ($dom,$confname) = @_;
6697: my ($allowed,$switchserver);
6698: my $home = &Apache::lonnet::homeserver($confname,$dom);
6699: if ($home eq 'no_host') {
6700: $home = &Apache::lonnet::domain($dom,'primary');
6701: }
6702: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 6703: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6704: if (!$allowed) {
1.160.6.11 raeburn 6705: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 6706: }
6707: return $switchserver;
6708: }
6709:
1.1 raeburn 6710: sub modify_quotas {
1.160.6.30 raeburn 6711: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 6712: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 6713: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 6714: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
6715: $validationfieldsref);
1.86 raeburn 6716: if ($action eq 'quotas') {
6717: $context = 'tools';
1.160.6.26 raeburn 6718: } else {
1.86 raeburn 6719: $context = $action;
6720: }
6721: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 6722: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 6723: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 6724: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
6725: %titles = &courserequest_titles();
6726: $toolregexp = join('|',@usertools);
6727: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 6728: $confname = $dom.'-domainconfig';
6729: my $servadm = $r->dir_config('lonAdmEMail');
6730: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 6731: ($validationitemsref,$validationnamesref,$validationfieldsref) =
6732: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 6733: } elsif ($context eq 'requestauthor') {
6734: @usertools = ('author');
6735: %titles = &authorrequest_titles();
1.86 raeburn 6736: } else {
1.160.6.4 raeburn 6737: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 6738: %titles = &tool_titles();
1.86 raeburn 6739: }
1.160.6.27 raeburn 6740: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 6741: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6742: foreach my $key (keys(%env)) {
1.101 raeburn 6743: if ($context eq 'requestcourses') {
6744: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
6745: my $item = $1;
6746: my $type = $2;
6747: if ($type =~ /^limit_(.+)/) {
6748: $limithash{$item}{$1} = $env{$key};
6749: } else {
6750: $confhash{$item}{$type} = $env{$key};
6751: }
6752: }
1.160.6.5 raeburn 6753: } elsif ($context eq 'requestauthor') {
6754: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
6755: $confhash{$1} = $env{$key};
6756: }
1.101 raeburn 6757: } else {
1.86 raeburn 6758: if ($key =~ /^form\.quota_(.+)$/) {
6759: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 6760: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
6761: $confhash{'authorquota'}{$1} = $env{$key};
6762: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 6763: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
6764: }
1.72 raeburn 6765: }
6766: }
1.160.6.5 raeburn 6767: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 6768: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 6769: @approvalnotify = sort(@approvalnotify);
6770: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 6771: my @crstypes = ('official','unofficial','community','textbook');
6772: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
6773: foreach my $type (@hasuniquecode) {
6774: if (grep(/^\Q$type\E$/,@crstypes)) {
6775: $confhash{'uniquecode'}{$type} = 1;
6776: }
6777: }
6778: my ($newbook,@allpos);
6779: if ($context eq 'requestcourses') {
6780: if ($env{'form.addbook'}) {
6781: if (($env{'form.addbook_cnum'} =~ /^$match_courseid$/) &&
6782: ($env{'form.addbook_cdom'} =~ /^$match_domain$/)) {
6783: if (&Apache::lonnet::homeserver($env{'form.addbook_cnum'},
6784: $env{'form.addbook_cdom'}) eq 'no_host') {
6785: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6786: '</span></li>';
6787: } else {
6788: $newbook = $env{'form.addbook_cdom'}.'_'.$env{'form.addbook_cnum'};
6789: my $position = $env{'form.addbook_pos'};
6790: $position =~ s/\D+//g;
6791: if ($position ne '') {
6792: $allpos[$position] = $newbook;
6793: }
6794: }
6795: } else {
6796: $errors .= '<li><span class="LC_error">'.&mt('Invalid LON-CAPA course for textbook').
6797: '</span></li>';
6798: }
6799: }
1.160.6.39 raeburn 6800:
1.160.6.30 raeburn 6801: }
1.102 raeburn 6802: if (ref($domconfig{$action}) eq 'HASH') {
6803: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
6804: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
6805: $changes{'notify'}{'approval'} = 1;
6806: }
6807: } else {
1.144 raeburn 6808: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6809: $changes{'notify'}{'approval'} = 1;
6810: }
6811: }
1.160.6.30 raeburn 6812: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
6813: if (ref($confhash{'uniquecode'}) eq 'HASH') {
6814: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
6815: unless ($confhash{'uniquecode'}{$crstype}) {
6816: $changes{'uniquecode'} = 1;
6817: }
6818: }
6819: unless ($changes{'uniquecode'}) {
6820: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
6821: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
6822: $changes{'uniquecode'} = 1;
6823: }
6824: }
6825: }
6826: } else {
6827: $changes{'uniquecode'} = 1;
6828: }
6829: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
6830: $changes{'uniquecode'} = 1;
6831: }
6832: if ($context eq 'requestcourses') {
6833: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6834: my %deletions;
6835: my @todelete = &Apache::loncommon::get_env_multiple('form.book_del');
6836: if (@todelete) {
6837: map { $deletions{$_} = 1; } @todelete;
6838: }
6839: my %imgdeletions;
6840: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.book_image_del');
6841: if (@todeleteimages) {
6842: map { $imgdeletions{$_} = 1; } @todeleteimages;
6843: }
6844: my $maxnum = $env{'form.book_maxnum'};
6845: for (my $i=0; $i<=$maxnum; $i++) {
6846: my $key = $env{'form.book_id_'.$i};
6847: if (ref($domconfig{$action}{'textbooks'}{$key}) eq 'HASH') {
6848: if ($deletions{$key}) {
6849: if ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6850: #FIXME need to obsolete item in RES space
6851: }
6852: next;
6853: } else {
6854: my $newpos = $env{'form.'.$key};
6855: $newpos =~ s/\D+//g;
6856: foreach my $item ('subject','title','author') {
6857: $confhash{'textbooks'}{$key}{$item} = $env{'form.book_'.$item.'_'.$i};
6858: if ($domconfig{$action}{'textbooks'}{$key}{$item} ne $confhash{'textbooks'}{$key}{$item}) {
6859: $changes{'textbooks'}{$key} = 1;
6860: }
6861: }
6862: $allpos[$newpos] = $key;
6863: }
6864: if ($imgdeletions{$key}) {
6865: $changes{'textbooks'}{$key} = 1;
6866: #FIXME need to obsolete item in RES space
6867: } elsif ($env{'form.book_image_'.$i.'.filename'}) {
6868: my ($cdom,$cnum) = split(/_/,$key);
6869: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,'book_image_'.$i,
6870: $cdom,$cnum,$configuserok,
6871: $switchserver,$author_ok);
6872: if ($imgurl) {
6873: $confhash{'textbooks'}{$key}{'image'} = $imgurl;
6874: $changes{'textbooks'}{$key} = 1;
6875: }
6876: if ($error) {
6877: &Apache::lonnet::logthis($error);
6878: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6879: }
6880: } elsif ($domconfig{$action}{'textbooks'}{$key}{'image'}) {
6881: $confhash{'textbooks'}{$key}{'image'} =
6882: $domconfig{$action}{'textbooks'}{$key}{'image'};
6883: }
6884: }
6885: }
6886: }
6887: }
1.102 raeburn 6888: } else {
1.144 raeburn 6889: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 6890: $changes{'notify'}{'approval'} = 1;
6891: }
1.160.6.30 raeburn 6892: if (ref($confhash{'uniquecode'} eq 'HASH')) {
6893: $changes{'uniquecode'} = 1;
6894: }
6895: }
6896: if ($context eq 'requestcourses') {
6897: if ($newbook) {
6898: $changes{'textbooks'}{$newbook} = 1;
6899: foreach my $item ('subject','title','author') {
6900: $env{'form.addbook_'.$item} =~ s/(`)/'/g;
6901: if ($env{'form.addbook_'.$item}) {
6902: $confhash{'textbooks'}{$newbook}{$item} = $env{'form.addbook_'.$item};
6903: }
6904: }
6905: if ($env{'form.addbook_image.filename'} ne '') {
6906: my ($cdom,$cnum) = split(/_/,$newbook);
1.160.6.39 raeburn 6907: my ($imageurl,$error) =
1.160.6.30 raeburn 6908: &process_textbook_image($r,$dom,$confname,'addbook_image',$cdom,$cnum,$configuserok,
6909: $switchserver,$author_ok);
6910: if ($imageurl) {
6911: $confhash{'textbooks'}{$newbook}{'image'} = $imageurl;
6912: }
6913: if ($error) {
6914: &Apache::lonnet::logthis($error);
6915: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6916: }
6917: }
6918: }
6919: if (@allpos > 0) {
6920: my $idx = 0;
6921: foreach my $item (@allpos) {
6922: if ($item ne '') {
6923: $confhash{'textbooks'}{$item}{'order'} = $idx;
6924: if (ref($domconfig{$action}) eq 'HASH') {
6925: if (ref($domconfig{$action}{'textbooks'}) eq 'HASH') {
6926: if (ref($domconfig{$action}{'textbooks'}{$item}) eq 'HASH') {
6927: if ($domconfig{$action}{'textbooks'}{$item}{'order'} ne $idx) {
6928: $changes{'textbooks'}{$item} = 1;
6929: }
6930: }
6931: }
6932: }
6933: $idx ++;
6934: }
6935: }
6936: }
1.160.6.39 raeburn 6937: if (ref($validationitemsref) eq 'ARRAY') {
6938: foreach my $item (@{$validationitemsref}) {
6939: if ($item eq 'fields') {
6940: my @changed;
6941: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
6942: if (@{$confhash{'validation'}{$item}} > 0) {
6943: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
6944: }
6945: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6946: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
6947: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
6948: $domconfig{'requestcourses'}{'validation'}{$item});
6949: } else {
6950: @changed = @{$confhash{'validation'}{$item}};
6951: }
6952: } else {
6953: @changed = @{$confhash{'validation'}{$item}};
6954: }
6955: if (@changed) {
6956: if ($confhash{'validation'}{$item}) {
6957: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
6958: } else {
6959: $changes{'validation'}{$item} = &mt('None');
6960: }
6961: }
6962: } else {
6963: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
6964: if ($item eq 'markup') {
6965: if ($env{'form.requestcourses_validation_'.$item}) {
6966: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
6967: }
6968: }
6969: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6970: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
6971: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6972: }
6973: } else {
6974: if ($confhash{'validation'}{$item} ne '') {
6975: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
6976: }
6977: }
6978: }
6979: }
6980: }
6981: if ($env{'form.validationdc'}) {
6982: my $newval = $env{'form.validationdc'};
6983: my %domcoords = &get_active_dcs($dom);
6984: if (exists($domcoords{$newval})) {
6985: $confhash{'validation'}{'dc'} = $newval;
6986: }
6987: }
6988: if (ref($confhash{'validation'}) eq 'HASH') {
6989: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
6990: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
6991: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
6992: if ($confhash{'validation'}{'dc'} eq '') {
6993: $changes{'validation'}{'dc'} = &mt('None');
6994: } else {
6995: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
6996: }
6997: }
6998: } elsif ($confhash{'validation'}{'dc'} ne '') {
6999: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7000: }
7001: } elsif ($confhash{'validation'}{'dc'} ne '') {
7002: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7003: }
7004: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7005: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7006: $changes{'validation'}{'dc'} = &mt('None');
7007: }
7008: }
1.102 raeburn 7009: }
7010: } else {
1.86 raeburn 7011: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 7012: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7013: }
1.72 raeburn 7014: foreach my $item (@usertools) {
7015: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7016: my $unset;
1.101 raeburn 7017: if ($context eq 'requestcourses') {
1.104 raeburn 7018: $unset = '0';
7019: if ($type eq '_LC_adv') {
7020: $unset = '';
7021: }
1.101 raeburn 7022: if ($confhash{$item}{$type} eq 'autolimit') {
7023: $confhash{$item}{$type} .= '=';
7024: unless ($limithash{$item}{$type} =~ /\D/) {
7025: $confhash{$item}{$type} .= $limithash{$item}{$type};
7026: }
7027: }
1.160.6.5 raeburn 7028: } elsif ($context eq 'requestauthor') {
7029: $unset = '0';
7030: if ($type eq '_LC_adv') {
7031: $unset = '';
7032: }
1.72 raeburn 7033: } else {
1.101 raeburn 7034: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7035: $confhash{$item}{$type} = 1;
7036: } else {
7037: $confhash{$item}{$type} = 0;
7038: }
1.72 raeburn 7039: }
1.86 raeburn 7040: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 7041: if ($action eq 'requestauthor') {
7042: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7043: $changes{$type} = 1;
7044: }
7045: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7046: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7047: $changes{$item}{$type} = 1;
7048: }
7049: } else {
7050: if ($context eq 'requestcourses') {
1.104 raeburn 7051: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7052: $changes{$item}{$type} = 1;
7053: }
7054: } else {
7055: if (!$confhash{$item}{$type}) {
7056: $changes{$item}{$type} = 1;
7057: }
7058: }
7059: }
7060: } else {
7061: if ($context eq 'requestcourses') {
1.104 raeburn 7062: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7063: $changes{$item}{$type} = 1;
7064: }
1.160.6.5 raeburn 7065: } elsif ($context eq 'requestauthor') {
7066: if ($confhash{$type} ne $unset) {
7067: $changes{$type} = 1;
7068: }
1.72 raeburn 7069: } else {
7070: if (!$confhash{$item}{$type}) {
7071: $changes{$item}{$type} = 1;
7072: }
7073: }
7074: }
1.1 raeburn 7075: }
7076: }
1.160.6.5 raeburn 7077: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7078: if (ref($domconfig{'quotas'}) eq 'HASH') {
7079: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7080: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7081: if (exists($confhash{'defaultquota'}{$key})) {
7082: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7083: $changes{'defaultquota'}{$key} = 1;
7084: }
7085: } else {
7086: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7087: }
7088: }
1.86 raeburn 7089: } else {
7090: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7091: if (exists($confhash{'defaultquota'}{$key})) {
7092: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7093: $changes{'defaultquota'}{$key} = 1;
7094: }
7095: } else {
7096: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7097: }
1.1 raeburn 7098: }
7099: }
1.160.6.20 raeburn 7100: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7101: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7102: if (exists($confhash{'authorquota'}{$key})) {
7103: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7104: $changes{'authorquota'}{$key} = 1;
7105: }
7106: } else {
7107: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7108: }
7109: }
7110: }
1.1 raeburn 7111: }
1.86 raeburn 7112: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7113: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7114: if (ref($domconfig{'quotas'}) eq 'HASH') {
7115: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7116: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7117: $changes{'defaultquota'}{$key} = 1;
7118: }
7119: } else {
7120: if (!exists($domconfig{'quotas'}{$key})) {
7121: $changes{'defaultquota'}{$key} = 1;
7122: }
1.72 raeburn 7123: }
7124: } else {
1.86 raeburn 7125: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7126: }
1.1 raeburn 7127: }
7128: }
1.160.6.20 raeburn 7129: if (ref($confhash{'authorquota'}) eq 'HASH') {
7130: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7131: if (ref($domconfig{'quotas'}) eq 'HASH') {
7132: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7133: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7134: $changes{'authorquota'}{$key} = 1;
7135: }
7136: } else {
7137: $changes{'authorquota'}{$key} = 1;
7138: }
7139: } else {
7140: $changes{'authorquota'}{$key} = 1;
7141: }
7142: }
7143: }
1.1 raeburn 7144: }
1.72 raeburn 7145:
1.160.6.5 raeburn 7146: if ($context eq 'requestauthor') {
7147: $domdefaults{'requestauthor'} = \%confhash;
7148: } else {
7149: foreach my $key (keys(%confhash)) {
1.160.6.30 raeburn 7150: unless (($context eq 'requestcourses') && ($key eq 'textbooks')) {
7151: $domdefaults{$key} = $confhash{$key};
7152: }
1.160.6.5 raeburn 7153: }
1.72 raeburn 7154: }
1.160.6.5 raeburn 7155:
1.1 raeburn 7156: my %quotahash = (
1.86 raeburn 7157: $action => { %confhash }
1.1 raeburn 7158: );
7159: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7160: $dom);
7161: if ($putresult eq 'ok') {
7162: if (keys(%changes) > 0) {
1.72 raeburn 7163: my $cachetime = 24*60*60;
7164: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 7165: if (ref($lastactref) eq 'HASH') {
7166: $lastactref->{'domdefaults'} = 1;
7167: }
1.1 raeburn 7168: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 7169: unless (($context eq 'requestcourses') ||
7170: ($context eq 'requestauthor')) {
1.86 raeburn 7171: if (ref($changes{'defaultquota'}) eq 'HASH') {
7172: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7173: foreach my $type (@{$types},'default') {
7174: if (defined($changes{'defaultquota'}{$type})) {
7175: my $typetitle = $usertypes->{$type};
7176: if ($type eq 'default') {
7177: $typetitle = $othertitle;
7178: }
1.160.6.28 raeburn 7179: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7180: }
7181: }
1.86 raeburn 7182: $resulttext .= '</ul></li>';
1.72 raeburn 7183: }
1.160.6.20 raeburn 7184: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 7185: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 7186: foreach my $type (@{$types},'default') {
7187: if (defined($changes{'authorquota'}{$type})) {
7188: my $typetitle = $usertypes->{$type};
7189: if ($type eq 'default') {
7190: $typetitle = $othertitle;
7191: }
1.160.6.28 raeburn 7192: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 7193: }
7194: }
7195: $resulttext .= '</ul></li>';
7196: }
1.72 raeburn 7197: }
1.80 raeburn 7198: my %newenv;
1.72 raeburn 7199: foreach my $item (@usertools) {
1.160.6.5 raeburn 7200: my (%haschgs,%inconf);
7201: if ($context eq 'requestauthor') {
7202: %haschgs = %changes;
7203: %inconf = %confhash;
7204: } else {
7205: if (ref($changes{$item}) eq 'HASH') {
7206: %haschgs = %{$changes{$item}};
7207: }
7208: if (ref($confhash{$item}) eq 'HASH') {
7209: %inconf = %{$confhash{$item}};
7210: }
7211: }
7212: if (keys(%haschgs) > 0) {
1.80 raeburn 7213: my $newacc =
7214: &Apache::lonnet::usertools_access($env{'user.name'},
7215: $env{'user.domain'},
1.86 raeburn 7216: $item,'reload',$context);
1.160.6.5 raeburn 7217: if (($context eq 'requestcourses') ||
7218: ($context eq 'requestauthor')) {
1.108 raeburn 7219: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7220: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7221: }
7222: } else {
7223: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7224: $newenv{'environment.availabletools.'.$item} = $newacc;
7225: }
1.80 raeburn 7226: }
1.160.6.5 raeburn 7227: unless ($context eq 'requestauthor') {
7228: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7229: }
1.72 raeburn 7230: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 7231: if ($haschgs{$type}) {
1.72 raeburn 7232: my $typetitle = $usertypes->{$type};
7233: if ($type eq 'default') {
7234: $typetitle = $othertitle;
7235: } elsif ($type eq '_LC_adv') {
7236: $typetitle = 'LON-CAPA Advanced Users';
7237: }
1.160.6.5 raeburn 7238: if ($inconf{$type}) {
1.101 raeburn 7239: if ($context eq 'requestcourses') {
7240: my $cond;
1.160.6.5 raeburn 7241: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7242: if ($1 eq '') {
7243: $cond = &mt('(Automatic processing of any request).');
7244: } else {
7245: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7246: }
7247: } else {
1.160.6.5 raeburn 7248: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7249: }
7250: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 7251: } elsif ($context eq 'requestauthor') {
7252: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7253: $titles{$inconf{$type}},$typetitle);
7254:
1.101 raeburn 7255: } else {
7256: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7257: }
1.72 raeburn 7258: } else {
1.104 raeburn 7259: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 7260: if ($inconf{$type} eq '0') {
1.104 raeburn 7261: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7262: } else {
7263: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7264: }
7265: } else {
7266: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7267: }
1.72 raeburn 7268: }
7269: }
1.26 raeburn 7270: }
1.160.6.5 raeburn 7271: unless ($context eq 'requestauthor') {
7272: $resulttext .= '</ul></li>';
7273: }
1.26 raeburn 7274: }
1.1 raeburn 7275: }
1.160.6.5 raeburn 7276: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7277: if (ref($changes{'notify'}) eq 'HASH') {
7278: if ($changes{'notify'}{'approval'}) {
7279: if (ref($confhash{'notify'}) eq 'HASH') {
7280: if ($confhash{'notify'}{'approval'}) {
7281: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7282: } else {
1.160.6.5 raeburn 7283: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7284: }
7285: }
7286: }
7287: }
7288: }
1.160.6.30 raeburn 7289: if ($action eq 'requestcourses') {
7290: my @offon = ('off','on');
7291: if ($changes{'uniquecode'}) {
7292: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7293: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7294: $resulttext .= '<li>'.
7295: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7296: '</li>';
7297: } else {
7298: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7299: '</li>';
7300: }
7301: }
7302: if (ref($changes{'textbooks'}) eq 'HASH') {
7303: $resulttext .= '<li>'.&mt('Available textbooks updated').'<ul>';
7304: foreach my $key (sort(keys(%{$changes{'textbooks'}}))) {
7305: my %coursehash = &Apache::lonnet::coursedescription($key);
7306: my $coursetitle = $coursehash{'description'};
7307: my $position = $confhash{'textbooks'}{$key}{'order'} + 1;
7308: $resulttext .= '<li>';
7309: foreach my $item ('subject','title','author') {
7310: my $name = $item.':';
7311: $name =~ s/^(\w)/\U$1/;
7312: $resulttext .= &mt($name).' '.$confhash{'textbooks'}{$key}{$item}.'<br />';
7313: }
7314: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7315: if ($confhash{'textbooks'}{$key}{'image'}) {
7316: $resulttext .= ' '.&mt('Image: [_1]',
7317: '<img src="'.$confhash{'textbooks'}{$key}{'image'}.'"'.
7318: ' alt="Textbook cover" />').'<br />';
7319: }
7320: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
7321: }
7322: $resulttext .= '</ul></li>';
7323: }
1.160.6.39 raeburn 7324: if (ref($changes{'validation'}) eq 'HASH') {
7325: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7326: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7327: foreach my $item (@{$validationitemsref}) {
7328: if (exists($changes{'validation'}{$item})) {
7329: if ($item eq 'markup') {
7330: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7331: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7332: } else {
7333: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7334: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7335: }
7336: }
7337: }
7338: if (exists($changes{'validation'}{'dc'})) {
7339: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7340: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7341: }
7342: }
7343: }
1.160.6.30 raeburn 7344: }
1.1 raeburn 7345: $resulttext .= '</ul>';
1.80 raeburn 7346: if (keys(%newenv)) {
7347: &Apache::lonnet::appenv(\%newenv);
7348: }
1.1 raeburn 7349: } else {
1.86 raeburn 7350: if ($context eq 'requestcourses') {
7351: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 7352: } elsif ($context eq 'requestauthor') {
7353: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7354: } else {
1.90 weissno 7355: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7356: }
1.1 raeburn 7357: }
7358: } else {
1.11 albertel 7359: $resulttext = '<span class="LC_error">'.
7360: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7361: }
1.160.6.30 raeburn 7362: if ($errors) {
7363: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7364: '<ul>'.$errors.'</ul></p>';
7365: }
1.3 raeburn 7366: return $resulttext;
1.1 raeburn 7367: }
7368:
1.160.6.30 raeburn 7369: sub process_textbook_image {
7370: my ($r,$dom,$confname,$caller,$cdom,$cnum,$configuserok,$switchserver,$author_ok) = @_;
7371: my $filename = $env{'form.'.$caller.'.filename'};
7372: my ($error,$url);
7373: my ($width,$height) = (50,50);
7374: if ($configuserok eq 'ok') {
7375: if ($switchserver) {
7376: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7377: $switchserver);
7378: } elsif ($author_ok eq 'ok') {
7379: my ($result,$imageurl) =
7380: &publishlogo($r,'upload',$caller,$dom,$confname,
7381: "textbooks/$dom/$cnum/cover",$width,$height);
7382: if ($result eq 'ok') {
7383: $url = $imageurl;
7384: } else {
7385: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7386: }
7387: } else {
7388: $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);
7389: }
7390: } else {
7391: $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);
7392: }
7393: return ($url,$error);
7394: }
7395:
1.3 raeburn 7396: sub modify_autoenroll {
1.160.6.24 raeburn 7397: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7398: my ($resulttext,%changes);
7399: my %currautoenroll;
7400: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7401: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7402: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7403: }
7404: }
7405: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7406: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7407: sender => 'Sender for notification messages',
7408: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7409: my @offon = ('off','on');
1.17 raeburn 7410: my $sender_uname = $env{'form.sender_uname'};
7411: my $sender_domain = $env{'form.sender_domain'};
7412: if ($sender_domain eq '') {
7413: $sender_uname = '';
7414: } elsif ($sender_uname eq '') {
7415: $sender_domain = '';
7416: }
1.129 raeburn 7417: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7418: my %autoenrollhash = (
1.129 raeburn 7419: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7420: 'sender_uname' => $sender_uname,
7421: 'sender_domain' => $sender_domain,
7422: 'co-owners' => $coowners,
1.1 raeburn 7423: }
7424: );
1.4 raeburn 7425: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7426: $dom);
1.1 raeburn 7427: if ($putresult eq 'ok') {
7428: if (exists($currautoenroll{'run'})) {
7429: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7430: $changes{'run'} = 1;
7431: }
7432: } elsif ($autorun) {
7433: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7434: $changes{'run'} = 1;
1.1 raeburn 7435: }
7436: }
1.17 raeburn 7437: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7438: $changes{'sender'} = 1;
7439: }
1.17 raeburn 7440: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7441: $changes{'sender'} = 1;
7442: }
1.129 raeburn 7443: if ($currautoenroll{'co-owners'} ne '') {
7444: if ($currautoenroll{'co-owners'} ne $coowners) {
7445: $changes{'coowners'} = 1;
7446: }
7447: } elsif ($coowners) {
7448: $changes{'coowners'} = 1;
7449: }
1.1 raeburn 7450: if (keys(%changes) > 0) {
7451: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7452: if ($changes{'run'}) {
1.1 raeburn 7453: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7454: }
7455: if ($changes{'sender'}) {
1.17 raeburn 7456: if ($sender_uname eq '' || $sender_domain eq '') {
7457: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7458: } else {
7459: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7460: }
1.1 raeburn 7461: }
1.129 raeburn 7462: if ($changes{'coowners'}) {
7463: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7464: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7465: if (ref($lastactref) eq 'HASH') {
7466: $lastactref->{'domainconfig'} = 1;
7467: }
1.129 raeburn 7468: }
1.1 raeburn 7469: $resulttext .= '</ul>';
7470: } else {
7471: $resulttext = &mt('No changes made to auto-enrollment settings');
7472: }
7473: } else {
1.11 albertel 7474: $resulttext = '<span class="LC_error">'.
7475: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7476: }
1.3 raeburn 7477: return $resulttext;
1.1 raeburn 7478: }
7479:
7480: sub modify_autoupdate {
1.3 raeburn 7481: my ($dom,%domconfig) = @_;
1.1 raeburn 7482: my ($resulttext,%currautoupdate,%fields,%changes);
7483: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7484: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7485: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7486: }
7487: }
7488: my @offon = ('off','on');
7489: my %title = &Apache::lonlocal::texthash (
7490: run => 'Auto-update:',
7491: classlists => 'Updates to user information in classlists?'
7492: );
1.44 raeburn 7493: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7494: my %fieldtitles = &Apache::lonlocal::texthash (
7495: id => 'Student/Employee ID',
1.20 raeburn 7496: permanentemail => 'E-mail address',
1.1 raeburn 7497: lastname => 'Last Name',
7498: firstname => 'First Name',
7499: middlename => 'Middle Name',
1.132 raeburn 7500: generation => 'Generation',
1.1 raeburn 7501: );
1.142 raeburn 7502: $othertitle = &mt('All users');
1.1 raeburn 7503: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7504: $othertitle = &mt('Other users');
1.1 raeburn 7505: }
7506: foreach my $key (keys(%env)) {
7507: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7508: my ($usertype,$item) = ($1,$2);
7509: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7510: if ($usertype eq 'default') {
7511: push(@{$fields{$1}},$2);
7512: } elsif (ref($types) eq 'ARRAY') {
7513: if (grep(/^\Q$usertype\E$/,@{$types})) {
7514: push(@{$fields{$1}},$2);
7515: }
7516: }
7517: }
1.1 raeburn 7518: }
7519: }
1.131 raeburn 7520: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7521: @lockablenames = sort(@lockablenames);
7522: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7523: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7524: if (@changed) {
7525: $changes{'lockablenames'} = 1;
7526: }
7527: } else {
7528: if (@lockablenames) {
7529: $changes{'lockablenames'} = 1;
7530: }
7531: }
1.1 raeburn 7532: my %updatehash = (
7533: autoupdate => { run => $env{'form.autoupdate_run'},
7534: classlists => $env{'form.classlists'},
7535: fields => {%fields},
1.131 raeburn 7536: lockablenames => \@lockablenames,
1.1 raeburn 7537: }
7538: );
7539: foreach my $key (keys(%currautoupdate)) {
7540: if (($key eq 'run') || ($key eq 'classlists')) {
7541: if (exists($updatehash{autoupdate}{$key})) {
7542: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7543: $changes{$key} = 1;
7544: }
7545: }
7546: } elsif ($key eq 'fields') {
7547: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7548: foreach my $item (@{$types},'default') {
1.1 raeburn 7549: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7550: my $change = 0;
7551: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7552: if (!exists($fields{$item})) {
7553: $change = 1;
1.132 raeburn 7554: last;
1.1 raeburn 7555: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7556: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7557: $change = 1;
1.132 raeburn 7558: last;
1.1 raeburn 7559: }
7560: }
7561: }
7562: if ($change) {
7563: push(@{$changes{$key}},$item);
7564: }
1.26 raeburn 7565: }
1.1 raeburn 7566: }
7567: }
1.131 raeburn 7568: } elsif ($key eq 'lockablenames') {
7569: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7570: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7571: if (@changed) {
7572: $changes{'lockablenames'} = 1;
7573: }
7574: } else {
7575: if (@lockablenames) {
7576: $changes{'lockablenames'} = 1;
7577: }
7578: }
7579: }
7580: }
7581: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7582: if (@lockablenames) {
7583: $changes{'lockablenames'} = 1;
1.1 raeburn 7584: }
7585: }
1.26 raeburn 7586: foreach my $item (@{$types},'default') {
7587: if (defined($fields{$item})) {
7588: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7589: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7590: my $change = 0;
7591: if (ref($fields{$item}) eq 'ARRAY') {
7592: foreach my $type (@{$fields{$item}}) {
7593: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7594: $change = 1;
7595: last;
7596: }
7597: }
7598: }
7599: if ($change) {
7600: push(@{$changes{'fields'}},$item);
7601: }
7602: } else {
1.26 raeburn 7603: push(@{$changes{'fields'}},$item);
7604: }
7605: } else {
7606: push(@{$changes{'fields'}},$item);
1.1 raeburn 7607: }
7608: }
7609: }
7610: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7611: $dom);
7612: if ($putresult eq 'ok') {
7613: if (keys(%changes) > 0) {
7614: $resulttext = &mt('Changes made:').'<ul>';
7615: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7616: if ($key eq 'lockablenames') {
7617: $resulttext .= '<li>';
7618: if (@lockablenames) {
7619: $usertypes->{'default'} = $othertitle;
7620: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7621: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7622: } else {
7623: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7624: }
7625: $resulttext .= '</li>';
7626: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7627: foreach my $item (@{$changes{$key}}) {
7628: my @newvalues;
7629: foreach my $type (@{$fields{$item}}) {
7630: push(@newvalues,$fieldtitles{$type});
7631: }
1.3 raeburn 7632: my $newvaluestr;
7633: if (@newvalues > 0) {
7634: $newvaluestr = join(', ',@newvalues);
7635: } else {
7636: $newvaluestr = &mt('none');
1.6 raeburn 7637: }
1.1 raeburn 7638: if ($item eq 'default') {
1.26 raeburn 7639: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7640: } else {
1.26 raeburn 7641: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7642: }
7643: }
7644: } else {
7645: my $newvalue;
7646: if ($key eq 'run') {
7647: $newvalue = $offon[$env{'form.autoupdate_run'}];
7648: } else {
7649: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7650: }
1.1 raeburn 7651: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7652: }
7653: }
7654: $resulttext .= '</ul>';
7655: } else {
1.3 raeburn 7656: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7657: }
7658: } else {
1.11 albertel 7659: $resulttext = '<span class="LC_error">'.
7660: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7661: }
1.3 raeburn 7662: return $resulttext;
1.1 raeburn 7663: }
7664:
1.125 raeburn 7665: sub modify_autocreate {
7666: my ($dom,%domconfig) = @_;
7667: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
7668: if (ref($domconfig{'autocreate'}) eq 'HASH') {
7669: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
7670: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
7671: }
7672: }
7673: my %title= ( xml => 'Auto-creation of courses in XML course description files',
7674: req => 'Auto-creation of validated requests for official courses',
7675: xmldc => 'Identity of course creator of courses from XML files',
7676: );
7677: my @types = ('xml','req');
7678: foreach my $item (@types) {
7679: $newvals{$item} = $env{'form.autocreate_'.$item};
7680: $newvals{$item} =~ s/\D//g;
7681: $newvals{$item} = 0 if ($newvals{$item} eq '');
7682: }
7683: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
7684: my %domcoords = &get_active_dcs($dom);
7685: unless (exists($domcoords{$newvals{'xmldc'}})) {
7686: $newvals{'xmldc'} = '';
7687: }
7688: %autocreatehash = (
7689: autocreate => { xml => $newvals{'xml'},
7690: req => $newvals{'req'},
7691: }
7692: );
7693: if ($newvals{'xmldc'} ne '') {
7694: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
7695: }
7696: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
7697: $dom);
7698: if ($putresult eq 'ok') {
7699: my @items = @types;
7700: if ($newvals{'xml'}) {
7701: push(@items,'xmldc');
7702: }
7703: foreach my $item (@items) {
7704: if (exists($currautocreate{$item})) {
7705: if ($currautocreate{$item} ne $newvals{$item}) {
7706: $changes{$item} = 1;
7707: }
7708: } elsif ($newvals{$item}) {
7709: $changes{$item} = 1;
7710: }
7711: }
7712: if (keys(%changes) > 0) {
7713: my @offon = ('off','on');
7714: $resulttext = &mt('Changes made:').'<ul>';
7715: foreach my $item (@types) {
7716: if ($changes{$item}) {
7717: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 7718: $resulttext .= '<li>'.
7719: &mt("$title{$item} set to [_1]$newtxt [_2]",
7720: '<b>','</b>').
7721: '</li>';
1.125 raeburn 7722: }
7723: }
7724: if ($changes{'xmldc'}) {
7725: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
7726: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 7727: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 7728: }
7729: $resulttext .= '</ul>';
7730: } else {
7731: $resulttext = &mt('No changes made to auto-creation settings');
7732: }
7733: } else {
7734: $resulttext = '<span class="LC_error">'.
7735: &mt('An error occurred: [_1]',$putresult).'</span>';
7736: }
7737: return $resulttext;
7738: }
7739:
1.23 raeburn 7740: sub modify_directorysrch {
7741: my ($dom,%domconfig) = @_;
7742: my ($resulttext,%changes);
7743: my %currdirsrch;
7744: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
7745: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
7746: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
7747: }
7748: }
7749: my %title = ( available => 'Directory search available',
1.24 raeburn 7750: localonly => 'Other domains can search',
1.23 raeburn 7751: searchby => 'Search types',
7752: searchtypes => 'Search latitude');
7753: my @offon = ('off','on');
1.24 raeburn 7754: my @otherdoms = ('Yes','No');
1.23 raeburn 7755:
1.25 raeburn 7756: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 7757: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
7758: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
7759:
1.44 raeburn 7760: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 7761: if (keys(%{$usertypes}) == 0) {
7762: @cansearch = ('default');
7763: } else {
7764: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
7765: foreach my $type (@{$currdirsrch{'cansearch'}}) {
7766: if (!grep(/^\Q$type\E$/,@cansearch)) {
7767: push(@{$changes{'cansearch'}},$type);
7768: }
1.23 raeburn 7769: }
1.26 raeburn 7770: foreach my $type (@cansearch) {
7771: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
7772: push(@{$changes{'cansearch'}},$type);
7773: }
1.23 raeburn 7774: }
1.26 raeburn 7775: } else {
7776: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 7777: }
7778: }
7779:
7780: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
7781: foreach my $by (@{$currdirsrch{'searchby'}}) {
7782: if (!grep(/^\Q$by\E$/,@searchby)) {
7783: push(@{$changes{'searchby'}},$by);
7784: }
7785: }
7786: foreach my $by (@searchby) {
7787: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
7788: push(@{$changes{'searchby'}},$by);
7789: }
7790: }
7791: } else {
7792: push(@{$changes{'searchby'}},@searchby);
7793: }
1.25 raeburn 7794:
7795: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
7796: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
7797: if (!grep(/^\Q$type\E$/,@searchtypes)) {
7798: push(@{$changes{'searchtypes'}},$type);
7799: }
7800: }
7801: foreach my $type (@searchtypes) {
7802: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
7803: push(@{$changes{'searchtypes'}},$type);
7804: }
7805: }
7806: } else {
7807: if (exists($currdirsrch{'searchtypes'})) {
7808: foreach my $type (@searchtypes) {
7809: if ($type ne $currdirsrch{'searchtypes'}) {
7810: push(@{$changes{'searchtypes'}},$type);
7811: }
7812: }
7813: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
7814: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
7815: }
7816: } else {
7817: push(@{$changes{'searchtypes'}},@searchtypes);
7818: }
7819: }
7820:
1.23 raeburn 7821: my %dirsrch_hash = (
7822: directorysrch => { available => $env{'form.dirsrch_available'},
7823: cansearch => \@cansearch,
1.24 raeburn 7824: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 7825: searchby => \@searchby,
1.25 raeburn 7826: searchtypes => \@searchtypes,
1.23 raeburn 7827: }
7828: );
7829: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
7830: $dom);
7831: if ($putresult eq 'ok') {
7832: if (exists($currdirsrch{'available'})) {
7833: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
7834: $changes{'available'} = 1;
7835: }
7836: } else {
7837: if ($env{'form.dirsrch_available'} eq '1') {
7838: $changes{'available'} = 1;
7839: }
7840: }
1.24 raeburn 7841: if (exists($currdirsrch{'localonly'})) {
7842: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
7843: $changes{'localonly'} = 1;
7844: }
7845: } else {
7846: if ($env{'form.dirsrch_localonly'} eq '1') {
7847: $changes{'localonly'} = 1;
7848: }
7849: }
1.23 raeburn 7850: if (keys(%changes) > 0) {
7851: $resulttext = &mt('Changes made:').'<ul>';
7852: if ($changes{'available'}) {
7853: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
7854: }
1.24 raeburn 7855: if ($changes{'localonly'}) {
7856: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
7857: }
7858:
1.23 raeburn 7859: if (ref($changes{'cansearch'}) eq 'ARRAY') {
7860: my $chgtext;
1.26 raeburn 7861: if (ref($usertypes) eq 'HASH') {
7862: if (keys(%{$usertypes}) > 0) {
7863: foreach my $type (@{$types}) {
7864: if (grep(/^\Q$type\E$/,@cansearch)) {
7865: $chgtext .= $usertypes->{$type}.'; ';
7866: }
7867: }
7868: if (grep(/^default$/,@cansearch)) {
7869: $chgtext .= $othertitle;
7870: } else {
7871: $chgtext =~ s/\; $//;
7872: }
1.160.6.13 raeburn 7873: $resulttext .=
7874: '<li>'.
7875: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
7876: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
7877: '</li>';
1.23 raeburn 7878: }
7879: }
7880: }
7881: if (ref($changes{'searchby'}) eq 'ARRAY') {
7882: my ($searchtitles,$titleorder) = &sorted_searchtitles();
7883: my $chgtext;
7884: foreach my $type (@{$titleorder}) {
7885: if (grep(/^\Q$type\E$/,@searchby)) {
7886: if (defined($searchtitles->{$type})) {
7887: $chgtext .= $searchtitles->{$type}.'; ';
7888: }
7889: }
7890: }
7891: $chgtext =~ s/\; $//;
7892: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
7893: }
1.25 raeburn 7894: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
7895: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
7896: my $chgtext;
7897: foreach my $type (@{$srchtypeorder}) {
7898: if (grep(/^\Q$type\E$/,@searchtypes)) {
7899: if (defined($srchtypes_desc->{$type})) {
7900: $chgtext .= $srchtypes_desc->{$type}.'; ';
7901: }
7902: }
7903: }
7904: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 7905: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 7906: }
7907: $resulttext .= '</ul>';
7908: } else {
7909: $resulttext = &mt('No changes made to institution directory search settings');
7910: }
7911: } else {
7912: $resulttext = '<span class="LC_error">'.
1.27 raeburn 7913: &mt('An error occurred: [_1]',$putresult).'</span>';
7914: }
7915: return $resulttext;
7916: }
7917:
1.28 raeburn 7918: sub modify_contacts {
1.160.6.24 raeburn 7919: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 7920: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
7921: if (ref($domconfig{'contacts'}) eq 'HASH') {
7922: foreach my $key (keys(%{$domconfig{'contacts'}})) {
7923: $currsetting{$key} = $domconfig{'contacts'}{$key};
7924: }
7925: }
1.134 raeburn 7926: my (%others,%to,%bcc);
1.28 raeburn 7927: my @contacts = ('supportemail','adminemail');
1.102 raeburn 7928: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.160.6.23 raeburn 7929: 'requestsmail','updatesmail','idconflictsmail');
7930: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 7931: foreach my $type (@mailings) {
7932: @{$newsetting{$type}} =
7933: &Apache::loncommon::get_env_multiple('form.'.$type);
7934: foreach my $item (@contacts) {
7935: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
7936: $contacts_hash{contacts}{$type}{$item} = 1;
7937: } else {
7938: $contacts_hash{contacts}{$type}{$item} = 0;
7939: }
7940: }
7941: $others{$type} = $env{'form.'.$type.'_others'};
7942: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 7943: if ($type eq 'helpdeskmail') {
7944: $bcc{$type} = $env{'form.'.$type.'_bcc'};
7945: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
7946: }
1.28 raeburn 7947: }
7948: foreach my $item (@contacts) {
7949: $to{$item} = $env{'form.'.$item};
7950: $contacts_hash{'contacts'}{$item} = $to{$item};
7951: }
1.160.6.23 raeburn 7952: foreach my $item (@toggles) {
7953: if ($env{'form.'.$item} =~ /^(0|1)$/) {
7954: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
7955: }
7956: }
1.28 raeburn 7957: if (keys(%currsetting) > 0) {
7958: foreach my $item (@contacts) {
7959: if ($to{$item} ne $currsetting{$item}) {
7960: $changes{$item} = 1;
7961: }
7962: }
7963: foreach my $type (@mailings) {
7964: foreach my $item (@contacts) {
7965: if (ref($currsetting{$type}) eq 'HASH') {
7966: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
7967: push(@{$changes{$type}},$item);
7968: }
7969: } else {
7970: push(@{$changes{$type}},@{$newsetting{$type}});
7971: }
7972: }
7973: if ($others{$type} ne $currsetting{$type}{'others'}) {
7974: push(@{$changes{$type}},'others');
7975: }
1.134 raeburn 7976: if ($type eq 'helpdeskmail') {
7977: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
7978: push(@{$changes{$type}},'bcc');
7979: }
7980: }
1.28 raeburn 7981: }
7982: } else {
7983: my %default;
7984: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
7985: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
7986: $default{'errormail'} = 'adminemail';
7987: $default{'packagesmail'} = 'adminemail';
7988: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 7989: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 7990: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 7991: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 7992: foreach my $item (@contacts) {
7993: if ($to{$item} ne $default{$item}) {
7994: $changes{$item} = 1;
1.160.6.23 raeburn 7995: }
1.28 raeburn 7996: }
7997: foreach my $type (@mailings) {
7998: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
7999:
8000: push(@{$changes{$type}},@{$newsetting{$type}});
8001: }
8002: if ($others{$type} ne '') {
8003: push(@{$changes{$type}},'others');
1.134 raeburn 8004: }
8005: if ($type eq 'helpdeskmail') {
8006: if ($bcc{$type} ne '') {
8007: push(@{$changes{$type}},'bcc');
8008: }
8009: }
1.28 raeburn 8010: }
8011: }
1.160.6.23 raeburn 8012: foreach my $item (@toggles) {
8013: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8014: $changes{$item} = 1;
8015: } elsif ((!$env{'form.'.$item}) &&
8016: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8017: $changes{$item} = 1;
8018: }
8019: }
1.28 raeburn 8020: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8021: $dom);
8022: if ($putresult eq 'ok') {
8023: if (keys(%changes) > 0) {
1.160.6.24 raeburn 8024: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8025: if (ref($lastactref) eq 'HASH') {
8026: $lastactref->{'domainconfig'} = 1;
8027: }
1.28 raeburn 8028: my ($titles,$short_titles) = &contact_titles();
8029: $resulttext = &mt('Changes made:').'<ul>';
8030: foreach my $item (@contacts) {
8031: if ($changes{$item}) {
8032: $resulttext .= '<li>'.$titles->{$item}.
8033: &mt(' set to: ').
8034: '<span class="LC_cusr_emph">'.
8035: $to{$item}.'</span></li>';
8036: }
8037: }
8038: foreach my $type (@mailings) {
8039: if (ref($changes{$type}) eq 'ARRAY') {
8040: $resulttext .= '<li>'.$titles->{$type}.': ';
8041: my @text;
8042: foreach my $item (@{$newsetting{$type}}) {
8043: push(@text,$short_titles->{$item});
8044: }
8045: if ($others{$type} ne '') {
8046: push(@text,$others{$type});
8047: }
8048: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8049: join(', ',@text).'</span>';
8050: if ($type eq 'helpdeskmail') {
8051: if ($bcc{$type} ne '') {
8052: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8053: }
8054: }
8055: $resulttext .= '</li>';
1.28 raeburn 8056: }
8057: }
1.160.6.23 raeburn 8058: my @offon = ('off','on');
8059: if ($changes{'reporterrors'}) {
8060: $resulttext .= '<li>'.
8061: &mt('E-mail error reports to [_1] set to "'.
8062: $offon[$env{'form.reporterrors'}].'".',
8063: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8064: &mt('LON-CAPA core group - MSU'),600,500)).
8065: '</li>';
8066: }
8067: if ($changes{'reportupdates'}) {
8068: $resulttext .= '<li>'.
8069: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8070: $offon[$env{'form.reportupdates'}].'".',
8071: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8072: &mt('LON-CAPA core group - MSU'),600,500)).
8073: '</li>';
8074: }
1.28 raeburn 8075: $resulttext .= '</ul>';
8076: } else {
1.34 raeburn 8077: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8078: }
8079: } else {
8080: $resulttext = '<span class="LC_error">'.
8081: &mt('An error occurred: [_1].',$putresult).'</span>';
8082: }
8083: return $resulttext;
8084: }
8085:
8086: sub modify_usercreation {
1.27 raeburn 8087: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8088: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8089: my $warningmsg;
1.27 raeburn 8090: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8091: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 8092: if ($key eq 'cancreate') {
8093: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8094: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8095: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8096: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8097: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8098: } else {
8099: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8100: }
1.50 raeburn 8101: }
1.43 raeburn 8102: }
1.160.6.34 raeburn 8103: } elsif ($key eq 'email_rule') {
8104: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8105: } else {
8106: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 8107: }
8108: }
1.34 raeburn 8109: }
1.160.6.34 raeburn 8110: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
8111: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
8112: my @contexts = ('author','course','requestcrs');
8113: foreach my $item(@contexts) {
8114: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8115: }
1.34 raeburn 8116: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8117: foreach my $item (@contexts) {
1.160.6.34 raeburn 8118: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8119: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8120: }
1.27 raeburn 8121: }
1.34 raeburn 8122: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8123: foreach my $item (@contexts) {
1.43 raeburn 8124: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8125: if ($cancreate{$item} ne 'any') {
8126: push(@{$changes{'cancreate'}},$item);
8127: }
8128: } else {
8129: if ($cancreate{$item} ne 'none') {
8130: push(@{$changes{'cancreate'}},$item);
8131: }
1.27 raeburn 8132: }
8133: }
8134: } else {
1.43 raeburn 8135: foreach my $item (@contexts) {
1.34 raeburn 8136: push(@{$changes{'cancreate'}},$item);
8137: }
1.27 raeburn 8138: }
1.34 raeburn 8139:
1.27 raeburn 8140: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8141: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8142: if (!grep(/^\Q$type\E$/,@username_rule)) {
8143: push(@{$changes{'username_rule'}},$type);
8144: }
8145: }
8146: foreach my $type (@username_rule) {
8147: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8148: push(@{$changes{'username_rule'}},$type);
8149: }
8150: }
8151: } else {
8152: push(@{$changes{'username_rule'}},@username_rule);
8153: }
8154:
1.32 raeburn 8155: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8156: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8157: if (!grep(/^\Q$type\E$/,@id_rule)) {
8158: push(@{$changes{'id_rule'}},$type);
8159: }
8160: }
8161: foreach my $type (@id_rule) {
8162: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8163: push(@{$changes{'id_rule'}},$type);
8164: }
8165: }
8166: } else {
8167: push(@{$changes{'id_rule'}},@id_rule);
8168: }
8169:
1.43 raeburn 8170: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8171: my @authtypes = ('int','krb4','krb5','loc');
8172: my %authhash;
1.43 raeburn 8173: foreach my $item (@authen_contexts) {
1.28 raeburn 8174: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8175: foreach my $auth (@authtypes) {
8176: if (grep(/^\Q$auth\E$/,@authallowed)) {
8177: $authhash{$item}{$auth} = 1;
8178: } else {
8179: $authhash{$item}{$auth} = 0;
8180: }
8181: }
8182: }
8183: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8184: foreach my $item (@authen_contexts) {
1.28 raeburn 8185: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8186: foreach my $auth (@authtypes) {
8187: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8188: push(@{$changes{'authtypes'}},$item);
8189: last;
8190: }
8191: }
8192: }
8193: }
8194: } else {
1.43 raeburn 8195: foreach my $item (@authen_contexts) {
1.28 raeburn 8196: push(@{$changes{'authtypes'}},$item);
8197: }
8198: }
8199:
1.160.6.34 raeburn 8200: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8201: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8202: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8203: $save_usercreate{'id_rule'} = \@id_rule;
8204: $save_usercreate{'username_rule'} = \@username_rule,
8205: $save_usercreate{'authtypes'} = \%authhash;
8206:
1.27 raeburn 8207: my %usercreation_hash = (
1.160.6.34 raeburn 8208: usercreation => \%save_usercreate,
8209: );
1.27 raeburn 8210:
8211: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8212: $dom);
1.50 raeburn 8213:
1.160.6.34 raeburn 8214: if ($putresult eq 'ok') {
8215: if (keys(%changes) > 0) {
8216: $resulttext = &mt('Changes made:').'<ul>';
8217: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8218: my %lt = &usercreation_types();
8219: foreach my $type (@{$changes{'cancreate'}}) {
8220: my $chgtext = $lt{$type}.', ';
8221: if ($cancreate{$type} eq 'none') {
8222: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8223: } elsif ($cancreate{$type} eq 'any') {
8224: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8225: } elsif ($cancreate{$type} eq 'official') {
8226: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8227: } elsif ($cancreate{$type} eq 'unofficial') {
8228: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8229: }
8230: $resulttext .= '<li>'.$chgtext.'</li>';
8231: }
8232: }
8233: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8234: my ($rules,$ruleorder) =
8235: &Apache::lonnet::inst_userrules($dom,'username');
8236: my $chgtext = '<ul>';
8237: foreach my $type (@username_rule) {
8238: if (ref($rules->{$type}) eq 'HASH') {
8239: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8240: }
8241: }
8242: $chgtext .= '</ul>';
8243: if (@username_rule > 0) {
8244: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8245: } else {
8246: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8247: }
8248: }
8249: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8250: my ($idrules,$idruleorder) =
8251: &Apache::lonnet::inst_userrules($dom,'id');
8252: my $chgtext = '<ul>';
8253: foreach my $type (@id_rule) {
8254: if (ref($idrules->{$type}) eq 'HASH') {
8255: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8256: }
8257: }
8258: $chgtext .= '</ul>';
8259: if (@id_rule > 0) {
8260: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8261: } else {
8262: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8263: }
8264: }
8265: my %authname = &authtype_names();
8266: my %context_title = &context_names();
8267: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8268: my $chgtext = '<ul>';
8269: foreach my $type (@{$changes{'authtypes'}}) {
8270: my @allowed;
8271: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8272: foreach my $auth (@authtypes) {
8273: if ($authhash{$type}{$auth}) {
8274: push(@allowed,$authname{$auth});
8275: }
8276: }
8277: if (@allowed > 0) {
8278: $chgtext .= join(', ',@allowed).'</li>';
8279: } else {
8280: $chgtext .= &mt('none').'</li>';
8281: }
8282: }
8283: $chgtext .= '</ul>';
8284: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8285: $resulttext .= '</li>';
8286: }
8287: $resulttext .= '</ul>';
8288: } else {
8289: $resulttext = &mt('No changes made to user creation settings');
8290: }
8291: } else {
8292: $resulttext = '<span class="LC_error">'.
8293: &mt('An error occurred: [_1]',$putresult).'</span>';
8294: }
8295: if ($warningmsg ne '') {
8296: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8297: }
8298: return $resulttext;
8299: }
8300:
8301: sub modify_selfcreation {
8302: my ($dom,%domconfig) = @_;
8303: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8304: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 8305: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8306: if (ref($types) eq 'ARRAY') {
8307: $usertypes->{'default'} = $othertitle;
8308: push(@{$types},'default');
8309: }
1.160.6.34 raeburn 8310: #
8311: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8312: #
8313: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8314: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8315: if ($key eq 'cancreate') {
8316: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8317: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8318: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8319: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.40 raeburn 8320: ($item eq 'emailusername') || ($item eq 'notify') ||
8321: ($item eq 'selfcreateprocessing')) {
1.160.6.34 raeburn 8322: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8323: } else {
8324: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8325: }
8326: }
8327: }
8328: } elsif ($key eq 'email_rule') {
8329: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8330: } else {
8331: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8332: }
8333: }
8334: }
8335: #
8336: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8337: #
8338: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8339: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8340: if ($key eq 'selfcreate') {
8341: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8342: } else {
8343: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8344: }
8345: }
8346: }
8347:
8348: my @contexts = ('selfcreate');
8349: @{$cancreate{'selfcreate'}} = ();
8350: %{$cancreate{'emailusername'}} = ();
8351: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 8352: %{$cancreate{'selfcreateprocessing'}} = ();
1.50 raeburn 8353: my %selfcreatetypes = (
8354: sso => 'users authenticated by institutional single sign on',
8355: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 8356: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8357: );
1.160.6.34 raeburn 8358: #
8359: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8360: # is permitted.
8361: #
1.160.6.40 raeburn 8362:
8363: my @statuses;
8364: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8365: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8366: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8367: }
8368: }
8369: push(@statuses,'default');
8370:
1.160.6.35 raeburn 8371: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 8372: if ($item eq 'email') {
1.160.6.40 raeburn 8373: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 8374: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 8375: push(@contexts,'selfcreateprocessing');
8376: foreach my $type (@statuses) {
8377: if ($type eq 'default') {
8378: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8379: } else {
8380: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8381: }
8382: }
1.160.6.34 raeburn 8383: }
8384: } else {
8385: if ($env{'form.cancreate_'.$item}) {
8386: push(@{$cancreate{'selfcreate'}},$item);
8387: }
8388: }
8389: }
8390: my (@email_rule,%userinfo,%savecaptcha);
8391: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8392: #
1.160.6.35 raeburn 8393: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8394: # 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 8395: #
1.160.6.40 raeburn 8396:
8397: if ($env{'form.cancreate_email'} eq 'email') {
1.160.6.37 raeburn 8398: push(@contexts,'emailusername');
1.160.6.35 raeburn 8399: if (ref($types) eq 'ARRAY') {
8400: foreach my $type (@{$types}) {
8401: if (ref($infofields) eq 'ARRAY') {
8402: foreach my $field (@{$infofields}) {
8403: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8404: $cancreate{'emailusername'}{$type}{$field} = $1;
8405: }
8406: }
1.160.6.34 raeburn 8407: }
8408: }
8409: }
8410: #
8411: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8412: # queued requests for self-creation of account using e-mail address as username
8413: #
8414:
8415: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8416: @approvalnotify = sort(@approvalnotify);
8417: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8418: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8419: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8420: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8421: push(@{$changes{'cancreate'}},'notify');
8422: }
8423: } else {
8424: if ($cancreate{'notify'}{'approval'}) {
8425: push(@{$changes{'cancreate'}},'notify');
8426: }
8427: }
8428: } elsif ($cancreate{'notify'}{'approval'}) {
8429: push(@{$changes{'cancreate'}},'notify');
8430: }
8431:
8432: #
8433: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8434: #
8435: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8436: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8437: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8438: if (@{$curr_usercreation{'email_rule'}} > 0) {
8439: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8440: if (!grep(/^\Q$type\E$/,@email_rule)) {
8441: push(@{$changes{'email_rule'}},$type);
8442: }
8443: }
8444: }
8445: if (@email_rule > 0) {
8446: foreach my $type (@email_rule) {
8447: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8448: push(@{$changes{'email_rule'}},$type);
8449: }
8450: }
8451: }
8452: } elsif (@email_rule > 0) {
8453: push(@{$changes{'email_rule'}},@email_rule);
8454: }
8455: }
8456: #
1.160.6.40 raeburn 8457: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 8458: # institutional log-in.
8459: #
8460: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8461: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8462: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8463: ($domdefaults{'auth_def'} eq 'localauth'))) {
8464: $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.').' '.
8465: &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.');
8466: }
8467: }
8468: my @fields = ('lastname','firstname','middlename','generation',
8469: 'permanentemail','id');
8470: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8471: #
8472: # Where usernames may created for institutional log-in and/or institutional single sign on:
8473: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8474: # may self-create accounts
8475: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8476: # which the user may supply, if institutional data is unavailable.
8477: #
8478: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8479: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 8480: if (@{$types} > 1) {
1.160.6.34 raeburn 8481: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8482: push(@contexts,'statustocreate');
8483: } else {
8484: undef($cancreate{'statustocreate'});
8485: }
8486: foreach my $type (@{$types}) {
8487: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8488: foreach my $field (@fields) {
8489: if (grep(/^\Q$field\E$/,@modifiable)) {
8490: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8491: } else {
8492: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8493: }
8494: }
8495: }
8496: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8497: foreach my $type (@{$types}) {
8498: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8499: foreach my $field (@fields) {
8500: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8501: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8502: push(@{$changes{'selfcreate'}},$type);
8503: last;
8504: }
8505: }
8506: }
8507: }
8508: } else {
8509: foreach my $type (@{$types}) {
8510: push(@{$changes{'selfcreate'}},$type);
8511: }
8512: }
8513: }
8514: }
8515: foreach my $item (@contexts) {
8516: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8517: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8518: if (ref($cancreate{$item}) eq 'ARRAY') {
8519: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8520: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8521: push(@{$changes{'cancreate'}},$item);
8522: }
8523: }
8524: }
8525: }
8526: if (ref($cancreate{$item}) eq 'ARRAY') {
8527: foreach my $type (@{$cancreate{$item}}) {
8528: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8529: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8530: push(@{$changes{'cancreate'}},$item);
8531: }
8532: }
8533: }
8534: }
8535: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8536: if (ref($cancreate{$item}) eq 'HASH') {
8537: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 8538: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8539: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8540: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8541: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8542: push(@{$changes{'cancreate'}},$item);
8543: }
8544: }
8545: }
1.160.6.40 raeburn 8546: } elsif ($item eq 'selfcreateprocessing') {
8547: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8548: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8549: push(@{$changes{'cancreate'}},$item);
8550: }
8551: }
1.160.6.35 raeburn 8552: } else {
8553: if (!$cancreate{$item}{$curr}) {
8554: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8555: push(@{$changes{'cancreate'}},$item);
8556: }
1.160.6.34 raeburn 8557: }
8558: }
8559: }
8560: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 8561: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8562: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8563: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8564: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8565: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8566: push(@{$changes{'cancreate'}},$item);
8567: }
8568: }
8569: } else {
8570: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8571: push(@{$changes{'cancreate'}},$item);
8572: }
8573: }
8574: }
1.160.6.40 raeburn 8575: } elsif ($item eq 'selfcreateprocessing') {
8576: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8577: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8578: push(@{$changes{'cancreate'}},$item);
8579: }
8580: }
1.160.6.35 raeburn 8581: } else {
8582: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8583: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8584: push(@{$changes{'cancreate'}},$item);
8585: }
1.160.6.34 raeburn 8586: }
8587: }
8588: }
8589: }
8590: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8591: if (ref($cancreate{$item}) eq 'ARRAY') {
8592: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8593: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8594: push(@{$changes{'cancreate'}},$item);
8595: }
8596: }
8597: } elsif (ref($cancreate{$item}) eq 'HASH') {
8598: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8599: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8600: push(@{$changes{'cancreate'}},$item);
8601: }
8602: }
8603: }
8604: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 8605: if (ref($cancreate{$item}) eq 'HASH') {
8606: foreach my $type (keys(%{$cancreate{$item}})) {
8607: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8608: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8609: if ($cancreate{$item}{$type}{$field}) {
8610: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8611: push(@{$changes{'cancreate'}},$item);
8612: }
8613: last;
8614: }
8615: }
8616: }
8617: }
1.160.6.34 raeburn 8618: }
8619: }
8620: }
8621: #
8622: # Populate %save_usercreate hash with updates to self-creation configuration.
8623: #
8624: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8625: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8626: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8627: if (ref($cancreate{'notify'}) eq 'HASH') {
8628: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8629: }
1.160.6.40 raeburn 8630: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8631: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8632: }
1.160.6.34 raeburn 8633: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8634: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8635: }
8636: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8637: $save_usercreate{'emailrule'} = \@email_rule;
8638:
8639: my %userconfig_hash = (
8640: usercreation => \%save_usercreate,
8641: usermodification => \%save_usermodify,
8642: );
8643: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
8644: $dom);
8645: #
8646: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
8647: #
1.27 raeburn 8648: if ($putresult eq 'ok') {
8649: if (keys(%changes) > 0) {
8650: $resulttext = &mt('Changes made:').'<ul>';
8651: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 8652: my %lt = &selfcreation_types();
1.34 raeburn 8653: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 8654: my $chgtext;
1.45 raeburn 8655: if ($type eq 'selfcreate') {
1.50 raeburn 8656: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 8657: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 8658: } else {
1.160.6.34 raeburn 8659: $chgtext .= &mt('Self-creation of a new account is permitted for:').
8660: '<ul>';
1.50 raeburn 8661: foreach my $case (@{$cancreate{$type}}) {
8662: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
8663: }
8664: $chgtext .= '</ul>';
1.100 raeburn 8665: if (ref($cancreate{$type}) eq 'ARRAY') {
8666: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
8667: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8668: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 8669: $chgtext .= '<br />'.
8670: '<span class="LC_warning">'.
8671: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8672: '</span>';
1.100 raeburn 8673: }
8674: }
8675: }
8676: }
1.43 raeburn 8677: }
1.93 raeburn 8678: } elsif ($type eq 'statustocreate') {
1.96 raeburn 8679: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
8680: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
8681: if (@{$cancreate{'selfcreate'}} > 0) {
8682: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 8683: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 8684: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8685: $chgtext .= '<br />'.
8686: '<span class="LC_warning">'.
8687: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
8688: '</span>';
8689: }
1.96 raeburn 8690: } elsif (ref($usertypes) eq 'HASH') {
8691: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 8692: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
8693: } else {
8694: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
8695: }
8696: $chgtext .= '<ul>';
8697: foreach my $case (@{$cancreate{$type}}) {
8698: if ($case eq 'default') {
8699: $chgtext .= '<li>'.$othertitle.'</li>';
8700: } else {
8701: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 8702: }
8703: }
1.100 raeburn 8704: $chgtext .= '</ul>';
8705: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 8706: $chgtext .= '<br /><span class="LC_warning">'.
8707: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
8708: '</span>';
1.100 raeburn 8709: }
8710: }
8711: } else {
8712: if (@{$cancreate{$type}} == 0) {
8713: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
8714: } else {
8715: $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 8716: }
8717: }
8718: }
1.160.6.40 raeburn 8719: } elsif ($type eq 'selfcreateprocessing') {
8720: my %choices = &Apache::lonlocal::texthash (
8721: automatic => 'Automatic approval',
8722: approval => 'Queued for approval',
8723: );
8724: if (@statuses > 1) {
8725: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
8726: '<ul>';
8727: foreach my $type (@statuses) {
8728: if ($type eq 'default') {
8729: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8730: } else {
8731: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
8732: }
8733: }
8734: $chgtext .= '</ul>';
8735: } else {
8736: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
8737: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
8738: }
1.160.6.5 raeburn 8739: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 8740: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 8741: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
8742: } else {
8743: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 8744: if ($captchas{$savecaptcha{$type}}) {
8745: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 8746: } else {
8747: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
8748: }
8749: }
8750: } elsif ($type eq 'recaptchakeys') {
8751: my ($privkey,$pubkey);
1.160.6.34 raeburn 8752: if (ref($savecaptcha{$type}) eq 'HASH') {
8753: $pubkey = $savecaptcha{$type}{'public'};
8754: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 8755: }
8756: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
8757: if (!$pubkey) {
8758: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
8759: } else {
8760: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8761: }
8762: if (!$privkey) {
8763: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
8764: } else {
8765: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
8766: }
8767: $chgtext .= '</ul>';
1.160.6.34 raeburn 8768: } elsif ($type eq 'emailusername') {
8769: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 8770: if (ref($types) eq 'ARRAY') {
8771: foreach my $type (@{$types}) {
8772: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
8773: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
8774: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',$usertypes->{$type}).
8775: '<ul>';
8776: foreach my $field (@{$infofields}) {
8777: if ($cancreate{'emailusername'}{$type}{$field}) {
8778: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
8779: }
8780: }
8781: }
8782: $chgtext .= '</ul>';
8783: } else {
8784: $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 8785: }
8786: }
8787: }
8788: }
8789: } elsif ($type eq 'notify') {
8790: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
8791: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8792: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
8793: if ($cancreate{'notify'}{'approval'}) {
8794: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
8795: }
8796: }
1.43 raeburn 8797: }
1.34 raeburn 8798: }
1.160.6.34 raeburn 8799: if ($chgtext) {
8800: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 8801: }
8802: }
8803: }
1.43 raeburn 8804: if (ref($changes{'email_rule'}) eq 'ARRAY') {
8805: my ($emailrules,$emailruleorder) =
8806: &Apache::lonnet::inst_userrules($dom,'email');
8807: my $chgtext = '<ul>';
8808: foreach my $type (@email_rule) {
8809: if (ref($emailrules->{$type}) eq 'HASH') {
8810: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
8811: }
8812: }
8813: $chgtext .= '</ul>';
8814: if (@email_rule > 0) {
1.160.6.34 raeburn 8815: $resulttext .= '<li>'.
8816: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
8817: $chgtext.
8818: '</li>';
1.43 raeburn 8819: } else {
1.160.6.34 raeburn 8820: $resulttext .= '<li>'.
8821: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
8822: '</li>';
1.43 raeburn 8823: }
8824: }
1.160.6.34 raeburn 8825: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
8826: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
8827: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8828: foreach my $type (@{$changes{'selfcreate'}}) {
8829: my $typename = $type;
8830: if (ref($usertypes) eq 'HASH') {
8831: if ($usertypes->{$type} ne '') {
8832: $typename = $usertypes->{$type};
1.28 raeburn 8833: }
8834: }
1.160.6.34 raeburn 8835: my @modifiable;
8836: $resulttext .= '<li>'.
8837: &mt('Self-creation of account by users with status: [_1]',
8838: '<span class="LC_cusr_emph">'.$typename.'</span>').
8839: ' - '.&mt('modifiable fields (if institutional data blank): ');
8840: foreach my $field (@fields) {
8841: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
8842: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
8843: }
8844: }
8845: if (@modifiable > 0) {
8846: $resulttext .= join(', ',@modifiable);
1.43 raeburn 8847: } else {
1.160.6.34 raeburn 8848: $resulttext .= &mt('none');
1.43 raeburn 8849: }
1.160.6.34 raeburn 8850: $resulttext .= '</li>';
1.28 raeburn 8851: }
1.160.6.34 raeburn 8852: $resulttext .= '</ul></li>';
1.28 raeburn 8853: }
1.27 raeburn 8854: $resulttext .= '</ul>';
8855: } else {
1.160.6.34 raeburn 8856: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 8857: }
8858: } else {
8859: $resulttext = '<span class="LC_error">'.
1.23 raeburn 8860: &mt('An error occurred: [_1]',$putresult).'</span>';
8861: }
1.43 raeburn 8862: if ($warningmsg ne '') {
8863: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8864: }
1.23 raeburn 8865: return $resulttext;
8866: }
8867:
1.160.6.5 raeburn 8868: sub process_captcha {
8869: my ($container,$changes,$newsettings,$current) = @_;
8870: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
8871: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
8872: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
8873: $newsettings->{'captcha'} = 'original';
8874: }
8875: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
8876: if ($container eq 'cancreate') {
8877: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8878: push(@{$changes->{'cancreate'}},'captcha');
8879: } elsif (!defined($changes->{'cancreate'})) {
8880: $changes->{'cancreate'} = ['captcha'];
8881: }
8882: } else {
8883: $changes->{'captcha'} = 1;
8884: }
8885: }
8886: my ($newpub,$newpriv,$currpub,$currpriv);
8887: if ($newsettings->{'captcha'} eq 'recaptcha') {
8888: $newpub = $env{'form.'.$container.'_recaptchapub'};
8889: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
8890: $newpub =~ s/\W//g;
8891: $newpriv =~ s/\W//g;
8892: $newsettings->{'recaptchakeys'} = {
8893: public => $newpub,
8894: private => $newpriv,
8895: };
8896: }
8897: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
8898: $currpub = $current->{'recaptchakeys'}{'public'};
8899: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 8900: unless ($newsettings->{'captcha'} eq 'recaptcha') {
8901: $newsettings->{'recaptchakeys'} = {
8902: public => '',
8903: private => '',
8904: }
8905: }
1.160.6.5 raeburn 8906: }
8907: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
8908: if ($container eq 'cancreate') {
8909: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
8910: push(@{$changes->{'cancreate'}},'recaptchakeys');
8911: } elsif (!defined($changes->{'cancreate'})) {
8912: $changes->{'cancreate'} = ['recaptchakeys'];
8913: }
8914: } else {
8915: $changes->{'recaptchakeys'} = 1;
8916: }
8917: }
8918: return;
8919: }
8920:
1.33 raeburn 8921: sub modify_usermodification {
8922: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 8923: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 8924: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8925: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 8926: if ($key eq 'selfcreate') {
8927: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
8928: } else {
8929: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
8930: }
1.33 raeburn 8931: }
8932: }
1.160.6.34 raeburn 8933: my @contexts = ('author','course');
1.33 raeburn 8934: my %context_title = (
8935: author => 'In author context',
8936: course => 'In course context',
8937: );
8938: my @fields = ('lastname','firstname','middlename','generation',
8939: 'permanentemail','id');
8940: my %roles = (
8941: author => ['ca','aa'],
8942: course => ['st','ep','ta','in','cr'],
8943: );
8944: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8945: foreach my $context (@contexts) {
8946: foreach my $role (@{$roles{$context}}) {
8947: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
8948: foreach my $item (@fields) {
8949: if (grep(/^\Q$item\E$/,@modifiable)) {
8950: $modifyhash{$context}{$role}{$item} = 1;
8951: } else {
8952: $modifyhash{$context}{$role}{$item} = 0;
8953: }
8954: }
8955: }
8956: if (ref($curr_usermodification{$context}) eq 'HASH') {
8957: foreach my $role (@{$roles{$context}}) {
8958: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
8959: foreach my $field (@fields) {
8960: if ($modifyhash{$context}{$role}{$field} ne
8961: $curr_usermodification{$context}{$role}{$field}) {
8962: push(@{$changes{$context}},$role);
8963: last;
8964: }
8965: }
8966: }
8967: }
8968: } else {
8969: foreach my $context (@contexts) {
8970: foreach my $role (@{$roles{$context}}) {
8971: push(@{$changes{$context}},$role);
8972: }
8973: }
8974: }
8975: }
8976: my %usermodification_hash = (
8977: usermodification => \%modifyhash,
8978: );
8979: my $putresult = &Apache::lonnet::put_dom('configuration',
8980: \%usermodification_hash,$dom);
8981: if ($putresult eq 'ok') {
8982: if (keys(%changes) > 0) {
8983: $resulttext = &mt('Changes made: ').'<ul>';
8984: foreach my $context (@contexts) {
8985: if (ref($changes{$context}) eq 'ARRAY') {
8986: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
8987: if (ref($changes{$context}) eq 'ARRAY') {
8988: foreach my $role (@{$changes{$context}}) {
8989: my $rolename;
1.160.6.34 raeburn 8990: if ($role eq 'cr') {
8991: $rolename = &mt('Custom');
1.33 raeburn 8992: } else {
1.160.6.34 raeburn 8993: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 8994: }
8995: my @modifiable;
1.160.6.34 raeburn 8996: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 8997: foreach my $field (@fields) {
8998: if ($modifyhash{$context}{$role}{$field}) {
8999: push(@modifiable,$fieldtitles{$field});
9000: }
9001: }
9002: if (@modifiable > 0) {
9003: $resulttext .= join(', ',@modifiable);
9004: } else {
9005: $resulttext .= &mt('none');
9006: }
9007: $resulttext .= '</li>';
9008: }
9009: $resulttext .= '</ul></li>';
9010: }
9011: }
9012: }
9013: $resulttext .= '</ul>';
9014: } else {
9015: $resulttext = &mt('No changes made to user modification settings');
9016: }
9017: } else {
9018: $resulttext = '<span class="LC_error">'.
9019: &mt('An error occurred: [_1]',$putresult).'</span>';
9020: }
9021: return $resulttext;
9022: }
9023:
1.43 raeburn 9024: sub modify_defaults {
1.160.6.27 raeburn 9025: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9026: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 9027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9028: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9029: my @authtypes = ('internal','krb4','krb5','localauth');
9030: foreach my $item (@items) {
9031: $newvalues{$item} = $env{'form.'.$item};
9032: if ($item eq 'auth_def') {
9033: if ($newvalues{$item} ne '') {
9034: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9035: push(@errors,$item);
9036: }
9037: }
9038: } elsif ($item eq 'lang_def') {
9039: if ($newvalues{$item} ne '') {
9040: if ($newvalues{$item} =~ /^(\w+)/) {
9041: my $langcode = $1;
1.103 raeburn 9042: if ($langcode ne 'x_chef') {
9043: if (code2language($langcode) eq '') {
9044: push(@errors,$item);
9045: }
1.43 raeburn 9046: }
9047: } else {
9048: push(@errors,$item);
9049: }
9050: }
1.54 raeburn 9051: } elsif ($item eq 'timezone_def') {
9052: if ($newvalues{$item} ne '') {
1.62 raeburn 9053: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9054: push(@errors,$item);
9055: }
9056: }
1.68 raeburn 9057: } elsif ($item eq 'datelocale_def') {
9058: if ($newvalues{$item} ne '') {
9059: my @datelocale_ids = DateTime::Locale->ids();
9060: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9061: push(@errors,$item);
9062: }
9063: }
1.141 raeburn 9064: } elsif ($item eq 'portal_def') {
9065: if ($newvalues{$item} ne '') {
9066: 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])\/?$/) {
9067: push(@errors,$item);
9068: }
9069: }
1.43 raeburn 9070: }
9071: if (grep(/^\Q$item\E$/,@errors)) {
9072: $newvalues{$item} = $domdefaults{$item};
9073: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9074: $changes{$item} = 1;
9075: }
1.72 raeburn 9076: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9077: }
9078: my %defaults_hash = (
1.72 raeburn 9079: defaults => \%newvalues,
9080: );
1.43 raeburn 9081: my $title = &defaults_titles();
1.160.6.40 raeburn 9082:
9083: my $currinststatus;
9084: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9085: $currinststatus = $domconfig{'inststatus'};
9086: } else {
9087: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9088: $currinststatus = {
9089: inststatustypes => $usertypes,
9090: inststatusorder => $types,
9091: inststatusguest => [],
9092: };
9093: }
9094: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9095: my @allpos;
9096: my %guests;
9097: my %alltypes;
9098: my ($currtitles,$currguests,$currorder);
9099: if (ref($currinststatus) eq 'HASH') {
9100: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9101: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9102: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9103: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9104: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9105: }
9106: }
9107: unless (grep(/^\Q$type\E$/,@todelete)) {
9108: my $position = $env{'form.inststatus_pos_'.$type};
9109: $position =~ s/\D+//g;
9110: $allpos[$position] = $type;
9111: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9112: $alltypes{$type} =~ s/`//g;
9113: if ($env{'form.inststatus_guest_'.$type}) {
9114: $guests{$type} = 1;
9115: }
9116: }
9117: }
9118: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9119: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9120: }
9121: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9122: $currtitles =~ s/,$//;
9123: }
9124: }
9125: if ($env{'form.addinststatus'}) {
9126: my $newtype = $env{'form.addinststatus'};
9127: $newtype =~ s/\W//g;
9128: unless (exists($alltypes{$newtype})) {
9129: if ($env{'form.addinststatus_guest'}) {
9130: $guests{$newtype} = 1;
9131: }
9132: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9133: $alltypes{$newtype} =~ s/`//g;
9134: my $position = $env{'form.addinststatus_pos'};
9135: $position =~ s/\D+//g;
9136: if ($position ne '') {
9137: $allpos[$position] = $newtype;
9138: }
9139: }
9140: }
9141: my (@orderedstatus,@orderedguests);
9142: foreach my $type (@allpos) {
9143: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9144: push(@orderedstatus,$type);
9145: if ($guests{$type}) {
9146: push(@orderedguests,$type);
9147: }
9148: }
9149: }
9150: foreach my $type (keys(%alltypes)) {
9151: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9152: delete($alltypes{$type});
9153: }
9154: }
9155: $defaults_hash{'inststatus'} = {
9156: inststatustypes => \%alltypes,
9157: inststatusorder => \@orderedstatus,
9158: inststatusguest => \@orderedguests,
9159: };
9160: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9161: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9162: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9163: }
9164: }
9165: if ($currorder ne join(',',@orderedstatus)) {
9166: $changes{'inststatus'}{'inststatusorder'} = 1;
9167: }
9168: if ($currguests ne join(',',@orderedguests)) {
9169: $changes{'inststatus'}{'inststatusguest'} = 1;
9170: }
9171: my $newtitles;
9172: foreach my $item (@orderedstatus) {
9173: $newtitles .= $alltypes{$item}.',';
9174: }
9175: $newtitles =~ s/,$//;
9176: if ($currtitles ne $newtitles) {
9177: $changes{'inststatus'}{'inststatustypes'} = 1;
9178: }
1.43 raeburn 9179: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9180: $dom);
9181: if ($putresult eq 'ok') {
9182: if (keys(%changes) > 0) {
9183: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 9184: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9185: 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";
9186: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 9187: if ($item eq 'inststatus') {
9188: if (ref($changes{'inststatus'}) eq 'HASH') {
9189: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9190: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9191: foreach my $type (@orderedstatus) {
9192: $resulttext .= $alltypes{$type}.', ';
9193: }
9194: $resulttext =~ s/, $//;
9195: $resulttext .= '</li>';
9196: }
9197: if ($changes{'inststatus'}{'inststatusguest'}) {
9198: $resulttext .= '<li>';
9199: if (@orderedguests) {
9200: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9201: foreach my $type (@orderedguests) {
9202: $resulttext .= $alltypes{$type}.', ';
9203: }
9204: $resulttext =~ s/, $//;
9205: } else {
9206: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9207: }
9208: $resulttext .= '</li>';
9209: }
9210: }
9211: } else {
9212: my $value = $env{'form.'.$item};
9213: if ($value eq '') {
9214: $value = &mt('none');
9215: } elsif ($item eq 'auth_def') {
9216: my %authnames = &authtype_names();
9217: my %shortauth = (
9218: internal => 'int',
9219: krb4 => 'krb4',
9220: krb5 => 'krb5',
9221: localauth => 'loc',
9222: );
9223: $value = $authnames{$shortauth{$value}};
9224: }
9225: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9226: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9227: }
9228: }
9229: $resulttext .= '</ul>';
9230: $mailmsgtext .= "\n";
9231: my $cachetime = 24*60*60;
1.72 raeburn 9232: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9233: if (ref($lastactref) eq 'HASH') {
9234: $lastactref->{'domdefaults'} = 1;
9235: }
1.68 raeburn 9236: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 9237: my $notify = 1;
9238: if (ref($domconfig{'contacts'}) eq 'HASH') {
9239: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9240: $notify = 0;
9241: }
9242: }
9243: if ($notify) {
9244: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9245: "LON-CAPA Domain Settings Change - $dom",
9246: $mailmsgtext);
9247: }
1.54 raeburn 9248: }
1.43 raeburn 9249: } else {
1.54 raeburn 9250: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9251: }
9252: } else {
9253: $resulttext = '<span class="LC_error">'.
9254: &mt('An error occurred: [_1]',$putresult).'</span>';
9255: }
9256: if (@errors > 0) {
9257: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9258: foreach my $item (@errors) {
9259: $resulttext .= ' "'.$title->{$item}.'",';
9260: }
9261: $resulttext =~ s/,$//;
9262: }
9263: return $resulttext;
9264: }
9265:
1.46 raeburn 9266: sub modify_scantron {
1.160.6.24 raeburn 9267: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9268: my ($resulttext,%confhash,%changes,$errors);
9269: my $custom = 'custom.tab';
9270: my $default = 'default.tab';
9271: my $servadm = $r->dir_config('lonAdmEMail');
9272: my ($configuserok,$author_ok,$switchserver) =
9273: &config_check($dom,$confname,$servadm);
9274: if ($env{'form.scantronformat.filename'} ne '') {
9275: my $error;
9276: if ($configuserok eq 'ok') {
9277: if ($switchserver) {
1.130 raeburn 9278: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9279: } else {
9280: if ($author_ok eq 'ok') {
9281: my ($result,$scantronurl) =
9282: &publishlogo($r,'upload','scantronformat',$dom,
9283: $confname,'scantron','','',$custom);
9284: if ($result eq 'ok') {
9285: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9286: $changes{'scantronformat'} = 1;
1.46 raeburn 9287: } else {
9288: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9289: }
9290: } else {
9291: $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);
9292: }
9293: }
9294: } else {
9295: $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);
9296: }
9297: if ($error) {
9298: &Apache::lonnet::logthis($error);
9299: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9300: }
9301: }
1.48 raeburn 9302: if (ref($domconfig{'scantron'}) eq 'HASH') {
9303: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9304: if ($env{'form.scantronformat_del'}) {
9305: $confhash{'scantron'}{'scantronformat'} = '';
9306: $changes{'scantronformat'} = 1;
1.46 raeburn 9307: }
9308: }
9309: }
9310: if (keys(%confhash) > 0) {
9311: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9312: $dom);
9313: if ($putresult eq 'ok') {
9314: if (keys(%changes) > 0) {
1.48 raeburn 9315: if (ref($confhash{'scantron'}) eq 'HASH') {
9316: $resulttext = &mt('Changes made:').'<ul>';
9317: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9318: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9319: } else {
1.130 raeburn 9320: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9321: }
1.48 raeburn 9322: $resulttext .= '</ul>';
9323: } else {
1.130 raeburn 9324: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9325: }
9326: $resulttext .= '</ul>';
9327: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9328: if (ref($lastactref) eq 'HASH') {
9329: $lastactref->{'domainconfig'} = 1;
9330: }
1.46 raeburn 9331: } else {
1.130 raeburn 9332: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9333: }
9334: } else {
9335: $resulttext = '<span class="LC_error">'.
9336: &mt('An error occurred: [_1]',$putresult).'</span>';
9337: }
9338: } else {
1.130 raeburn 9339: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9340: }
9341: if ($errors) {
9342: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9343: $errors.'</ul>';
9344: }
9345: return $resulttext;
9346: }
9347:
1.48 raeburn 9348: sub modify_coursecategories {
1.160.6.43! raeburn 9349: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9350: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9351: $cathash);
1.48 raeburn 9352: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 9353: my @catitems = ('unauth','auth');
9354: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9355: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9356: $cathash = $domconfig{'coursecategories'}{'cats'};
9357: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9358: $changes{'togglecats'} = 1;
9359: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9360: }
9361: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9362: $changes{'categorize'} = 1;
9363: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9364: }
1.120 raeburn 9365: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9366: $changes{'togglecatscomm'} = 1;
9367: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9368: }
9369: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9370: $changes{'categorizecomm'} = 1;
9371: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9372: }
1.160.6.42 raeburn 9373: foreach my $item (@catitems) {
9374: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9375: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9376: $changes{$item} = 1;
9377: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9378: }
9379: }
9380: }
1.57 raeburn 9381: } else {
9382: $changes{'togglecats'} = 1;
9383: $changes{'categorize'} = 1;
1.124 raeburn 9384: $changes{'togglecatscomm'} = 1;
9385: $changes{'categorizecomm'} = 1;
1.87 raeburn 9386: $domconfig{'coursecategories'} = {
9387: togglecats => $env{'form.togglecats'},
9388: categorize => $env{'form.categorize'},
1.124 raeburn 9389: togglecatscomm => $env{'form.togglecatscomm'},
9390: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9391: };
1.160.6.42 raeburn 9392: foreach my $item (@catitems) {
9393: if ($env{'form.coursecat_'.$item} ne 'std') {
9394: $changes{$item} = 1;
9395: }
9396: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9397: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9398: }
9399: }
1.57 raeburn 9400: }
9401: if (ref($cathash) eq 'HASH') {
9402: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9403: push (@deletecategory,'instcode::0');
9404: }
1.120 raeburn 9405: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9406: push(@deletecategory,'communities::0');
9407: }
1.48 raeburn 9408: }
1.57 raeburn 9409: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9410: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9411: if (@deletecategory > 0) {
9412: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9413: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9414: foreach my $item (@deletecategory) {
1.57 raeburn 9415: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9416: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9417: $deletions{$item} = 1;
1.57 raeburn 9418: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9419: }
9420: }
9421: }
1.57 raeburn 9422: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9423: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9424: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9425: $reorderings{$item} = 1;
1.57 raeburn 9426: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9427: }
9428: if ($env{'form.addcategory_name_'.$item} ne '') {
9429: my $newcat = $env{'form.addcategory_name_'.$item};
9430: my $newdepth = $depth+1;
9431: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9432: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9433: $adds{$newitem} = 1;
9434: }
9435: if ($env{'form.subcat_'.$item} ne '') {
9436: my $newcat = $env{'form.subcat_'.$item};
9437: my $newdepth = $depth+1;
9438: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9439: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9440: $adds{$newitem} = 1;
9441: }
9442: }
9443: }
9444: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9445: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9446: my $newitem = 'instcode::0';
1.57 raeburn 9447: if ($cathash->{$newitem} eq '') {
9448: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9449: $adds{$newitem} = 1;
9450: }
9451: } else {
9452: my $newitem = 'instcode::0';
1.57 raeburn 9453: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9454: $adds{$newitem} = 1;
9455: }
9456: }
1.120 raeburn 9457: if ($env{'form.communities'} eq '1') {
9458: if (ref($cathash) eq 'HASH') {
9459: my $newitem = 'communities::0';
9460: if ($cathash->{$newitem} eq '') {
9461: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9462: $adds{$newitem} = 1;
9463: }
9464: } else {
9465: my $newitem = 'communities::0';
9466: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9467: $adds{$newitem} = 1;
9468: }
9469: }
1.48 raeburn 9470: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9471: if (($env{'form.addcategory_name'} ne 'instcode') &&
9472: ($env{'form.addcategory_name'} ne 'communities')) {
9473: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9474: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9475: $adds{$newitem} = 1;
9476: }
1.48 raeburn 9477: }
1.57 raeburn 9478: my $putresult;
1.48 raeburn 9479: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9480: if (keys(%deletions) > 0) {
9481: foreach my $key (keys(%deletions)) {
9482: if ($predelallitems{$key} ne '') {
9483: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9484: }
9485: }
9486: }
9487: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9488: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9489: if (ref($chkcats[0]) eq 'ARRAY') {
9490: my $depth = 0;
9491: my $chg = 0;
9492: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9493: my $name = $chkcats[0][$i];
9494: my $item;
9495: if ($name eq '') {
9496: $chg ++;
9497: } else {
9498: $item = &escape($name).'::0';
9499: if ($chg) {
1.57 raeburn 9500: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9501: }
9502: $depth ++;
1.57 raeburn 9503: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9504: $depth --;
9505: }
9506: }
9507: }
1.57 raeburn 9508: }
9509: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9510: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9511: if ($putresult eq 'ok') {
1.57 raeburn 9512: my %title = (
1.120 raeburn 9513: togglecats => 'Show/Hide a course in catalog',
9514: categorize => 'Assign a category to a course',
9515: togglecatscomm => 'Show/Hide a community in catalog',
9516: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9517: );
9518: my %level = (
1.120 raeburn 9519: dom => 'set in Domain ("Modify Course/Community")',
9520: crs => 'set in Course ("Course Configuration")',
9521: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 9522: none => 'No catalog',
9523: std => 'Standard catalog',
9524: domonly => 'Domain-only catalog',
9525: codesrch => 'Code search form',
1.57 raeburn 9526: );
1.48 raeburn 9527: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9528: if ($changes{'togglecats'}) {
9529: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9530: }
9531: if ($changes{'categorize'}) {
9532: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9533: }
1.120 raeburn 9534: if ($changes{'togglecatscomm'}) {
9535: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9536: }
9537: if ($changes{'categorizecomm'}) {
9538: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9539: }
1.160.6.42 raeburn 9540: if ($changes{'unauth'}) {
9541: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9542: }
9543: if ($changes{'auth'}) {
9544: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9545: }
1.57 raeburn 9546: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9547: my $cathash;
9548: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9549: $cathash = $domconfig{'coursecategories'}{'cats'};
9550: } else {
9551: $cathash = {};
9552: }
9553: my (@cats,@trails,%allitems);
9554: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9555: if (keys(%deletions) > 0) {
9556: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9557: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9558: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9559: }
9560: $resulttext .= '</ul></li>';
9561: }
9562: if (keys(%reorderings) > 0) {
9563: my %sort_by_trail;
9564: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9565: foreach my $key (keys(%reorderings)) {
9566: if ($allitems{$key} ne '') {
9567: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9568: }
1.48 raeburn 9569: }
1.57 raeburn 9570: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9571: $resulttext .= '<li>'.$trails[$trail].'</li>';
9572: }
9573: $resulttext .= '</ul></li>';
1.48 raeburn 9574: }
1.57 raeburn 9575: if (keys(%adds) > 0) {
9576: my %sort_by_trail;
9577: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9578: foreach my $key (keys(%adds)) {
9579: if ($allitems{$key} ne '') {
9580: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9581: }
9582: }
9583: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9584: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9585: }
1.57 raeburn 9586: $resulttext .= '</ul></li>';
1.48 raeburn 9587: }
9588: }
9589: $resulttext .= '</ul>';
1.160.6.43! raeburn 9590: if ($changes{'unauth'} || $changes{'auth'}) {
! 9591: &Apache::loncommon::devalidate_domconfig_cache($dom);
! 9592: if (ref($lastactref) eq 'HASH') {
! 9593: $lastactref->{'domainconfig'} = 1;
! 9594: }
! 9595: }
1.48 raeburn 9596: } else {
9597: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9598: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9599: }
9600: } else {
1.120 raeburn 9601: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9602: }
9603: return $resulttext;
9604: }
9605:
1.69 raeburn 9606: sub modify_serverstatuses {
9607: my ($dom,%domconfig) = @_;
9608: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9609: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9610: %currserverstatus = %{$domconfig{'serverstatuses'}};
9611: }
9612: my @pages = &serverstatus_pages();
9613: foreach my $type (@pages) {
9614: $newserverstatus{$type}{'namedusers'} = '';
9615: $newserverstatus{$type}{'machines'} = '';
9616: if (defined($env{'form.'.$type.'_namedusers'})) {
9617: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
9618: my @okusers;
9619: foreach my $user (@users) {
9620: my ($uname,$udom) = split(/:/,$user);
9621: if (($udom =~ /^$match_domain$/) &&
9622: (&Apache::lonnet::domain($udom)) &&
9623: ($uname =~ /^$match_username$/)) {
9624: if (!grep(/^\Q$user\E/,@okusers)) {
9625: push(@okusers,$user);
9626: }
9627: }
9628: }
9629: if (@okusers > 0) {
9630: @okusers = sort(@okusers);
9631: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
9632: }
9633: }
9634: if (defined($env{'form.'.$type.'_machines'})) {
9635: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
9636: my @okmachines;
9637: foreach my $ip (@machines) {
9638: my @parts = split(/\./,$ip);
9639: next if (@parts < 4);
9640: my $badip = 0;
9641: for (my $i=0; $i<4; $i++) {
9642: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
9643: $badip = 1;
9644: last;
9645: }
9646: }
9647: if (!$badip) {
9648: push(@okmachines,$ip);
9649: }
9650: }
9651: @okmachines = sort(@okmachines);
9652: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
9653: }
9654: }
9655: my %serverstatushash = (
9656: serverstatuses => \%newserverstatus,
9657: );
9658: foreach my $type (@pages) {
1.83 raeburn 9659: foreach my $setting ('namedusers','machines') {
1.84 raeburn 9660: my (@current,@new);
1.83 raeburn 9661: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 9662: if ($currserverstatus{$type}{$setting} ne '') {
9663: @current = split(/,/,$currserverstatus{$type}{$setting});
9664: }
9665: }
9666: if ($newserverstatus{$type}{$setting} ne '') {
9667: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 9668: }
9669: if (@current > 0) {
9670: if (@new > 0) {
9671: foreach my $item (@current) {
9672: if (!grep(/^\Q$item\E$/,@new)) {
9673: $changes{$type}{$setting} = 1;
1.82 raeburn 9674: last;
9675: }
9676: }
1.84 raeburn 9677: foreach my $item (@new) {
9678: if (!grep(/^\Q$item\E$/,@current)) {
9679: $changes{$type}{$setting} = 1;
9680: last;
1.82 raeburn 9681: }
9682: }
9683: } else {
1.83 raeburn 9684: $changes{$type}{$setting} = 1;
1.69 raeburn 9685: }
1.83 raeburn 9686: } elsif (@new > 0) {
9687: $changes{$type}{$setting} = 1;
1.69 raeburn 9688: }
9689: }
9690: }
9691: if (keys(%changes) > 0) {
1.81 raeburn 9692: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9693: my $putresult = &Apache::lonnet::put_dom('configuration',
9694: \%serverstatushash,$dom);
9695: if ($putresult eq 'ok') {
9696: $resulttext .= &mt('Changes made:').'<ul>';
9697: foreach my $type (@pages) {
1.84 raeburn 9698: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 9699: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 9700: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 9701: if ($newserverstatus{$type}{'namedusers'} eq '') {
9702: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
9703: } else {
9704: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
9705: }
1.84 raeburn 9706: }
9707: if ($changes{$type}{'machines'}) {
1.69 raeburn 9708: if ($newserverstatus{$type}{'machines'} eq '') {
9709: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
9710: } else {
9711: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
9712: }
9713:
9714: }
9715: $resulttext .= '</ul></li>';
9716: }
9717: }
9718: $resulttext .= '</ul>';
9719: } else {
9720: $resulttext = '<span class="LC_error">'.
9721: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
9722:
9723: }
9724: } else {
9725: $resulttext = &mt('No changes made to access to server status pages');
9726: }
9727: return $resulttext;
9728: }
9729:
1.118 jms 9730: sub modify_helpsettings {
1.122 jms 9731: my ($r,$dom,$confname,%domconfig) = @_;
1.160.6.5 raeburn 9732: my ($resulttext,$errors,%changes,%helphash);
9733: my %defaultchecked = ('submitbugs' => 'on');
9734: my @offon = ('off','on');
1.118 jms 9735: my @toggles = ('submitbugs');
9736: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9737: foreach my $item (@toggles) {
1.160.6.5 raeburn 9738: if ($defaultchecked{$item} eq 'on') {
9739: if ($domconfig{'helpsettings'}{$item} eq '') {
9740: if ($env{'form.'.$item} eq '0') {
9741: $changes{$item} = 1;
9742: }
9743: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9744: $changes{$item} = 1;
9745: }
9746: } elsif ($defaultchecked{$item} eq 'off') {
9747: if ($domconfig{'helpsettings'}{$item} eq '') {
9748: if ($env{'form.'.$item} eq '1') {
9749: $changes{$item} = 1;
9750: }
9751: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
9752: $changes{$item} = 1;
9753: }
1.160.6.26 raeburn 9754: }
1.160.6.5 raeburn 9755: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
9756: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 9757: }
9758: }
1.118 jms 9759: }
1.123 jms 9760: my $putresult;
9761: if (keys(%changes) > 0) {
1.160.6.5 raeburn 9762: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
9763: if ($putresult eq 'ok') {
9764: $resulttext = &mt('Changes made:').'<ul>';
9765: foreach my $item (sort(keys(%changes))) {
9766: if ($item eq 'submitbugs') {
9767: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
9768: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
9769: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
9770: }
9771: }
9772: $resulttext .= '</ul>';
9773: } else {
9774: $resulttext = &mt('No changes made to help settings');
9775: $errors .= '<li><span class="LC_error">'.
9776: &mt('An error occurred storing the settings: [_1]',
9777: $putresult).'</span></li>';
9778: }
1.118 jms 9779: }
9780: if ($errors) {
1.160.6.5 raeburn 9781: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 9782: $errors.'</ul>';
9783: }
9784: return $resulttext;
9785: }
9786:
1.121 raeburn 9787: sub modify_coursedefaults {
1.160.6.27 raeburn 9788: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 9789: my ($resulttext,$errors,%changes,%defaultshash);
9790: my %defaultchecked = ('canuse_pdfforms' => 'off');
9791: my @toggles = ('canuse_pdfforms');
1.160.6.21 raeburn 9792: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.30 raeburn 9793: 'uploadquota_community','uploadquota_textbook');
9794: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 9795: my %staticdefaults = (
9796: anonsurvey_threshold => 10,
9797: uploadquota => 500,
9798: );
1.121 raeburn 9799:
9800: $defaultshash{'coursedefaults'} = {};
9801:
9802: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
9803: if ($domconfig{'coursedefaults'} eq '') {
9804: $domconfig{'coursedefaults'} = {};
9805: }
9806: }
9807:
9808: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
9809: foreach my $item (@toggles) {
9810: if ($defaultchecked{$item} eq 'on') {
9811: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9812: ($env{'form.'.$item} eq '0')) {
9813: $changes{$item} = 1;
1.160.6.16 raeburn 9814: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 9815: $changes{$item} = 1;
9816: }
9817: } elsif ($defaultchecked{$item} eq 'off') {
9818: if (($domconfig{'coursedefaults'}{$item} eq '') &&
9819: ($env{'form.'.$item} eq '1')) {
9820: $changes{$item} = 1;
9821: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
9822: $changes{$item} = 1;
9823: }
9824: }
9825: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
9826: }
1.160.6.21 raeburn 9827: foreach my $item (@numbers) {
9828: my ($currdef,$newdef);
1.160.6.26 raeburn 9829: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 9830: if ($item eq 'anonsurvey_threshold') {
9831: $currdef = $domconfig{'coursedefaults'}{$item};
9832: $newdef =~ s/\D//g;
9833: if ($newdef eq '' || $newdef < 1) {
9834: $newdef = 1;
9835: }
9836: $defaultshash{'coursedefaults'}{$item} = $newdef;
9837: } else {
9838: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
9839: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9840: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
9841: }
9842: $newdef =~ s/[^\w.\-]//g;
9843: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
9844: }
9845: if ($currdef ne $newdef) {
9846: my $staticdef;
9847: if ($item eq 'anonsurvey_threshold') {
9848: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
9849: $changes{$item} = 1;
9850: }
9851: } else {
9852: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
9853: $changes{'uploadquota'} = 1;
9854: }
9855: }
1.139 raeburn 9856: }
9857: }
1.160.6.37 raeburn 9858:
1.160.6.16 raeburn 9859: my $officialcreds = $env{'form.official_credits'};
1.160.6.30 raeburn 9860: $officialcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 9861: my $unofficialcreds = $env{'form.unofficial_credits'};
1.160.6.30 raeburn 9862: $unofficialcreds =~ s/[^\d.]+//g;
9863: my $textbookcreds = $env{'form.textbook_credits'};
9864: $textbookcreds =~ s/[^\d.]+//g;
1.160.6.16 raeburn 9865: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
9866: ($env{'form.coursecredits'} eq '1')) {
9867: $changes{'coursecredits'} = 1;
9868: } else {
9869: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.160.6.30 raeburn 9870: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
9871: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.160.6.16 raeburn 9872: $changes{'coursecredits'} = 1;
9873: }
9874: }
9875: $defaultshash{'coursedefaults'}{'coursecredits'} = {
9876: official => $officialcreds,
9877: unofficial => $unofficialcreds,
1.160.6.30 raeburn 9878: textbook => $textbookcreds,
1.160.6.16 raeburn 9879: }
1.121 raeburn 9880: }
9881: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
9882: $dom);
9883: if ($putresult eq 'ok') {
9884: if (keys(%changes) > 0) {
1.160.6.27 raeburn 9885: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.37 raeburn 9886: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
9887: ($changes{'uploadquota'})) {
1.160.6.16 raeburn 9888: if ($changes{'canuse_pdfforms'}) {
9889: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
9890: }
9891: if ($changes{'coursecredits'}) {
9892: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9893: $domdefaults{'officialcredits'} =
9894: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
9895: $domdefaults{'unofficialcredits'} =
9896: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.160.6.30 raeburn 9897: $domdefaults{'textbookcredits'} =
9898: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.160.6.16 raeburn 9899: }
9900: }
1.160.6.21 raeburn 9901: if ($changes{'uploadquota'}) {
9902: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9903: foreach my $type (@types) {
9904: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
9905: }
9906: }
9907: }
1.121 raeburn 9908: my $cachetime = 24*60*60;
9909: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9910: if (ref($lastactref) eq 'HASH') {
9911: $lastactref->{'domdefaults'} = 1;
9912: }
1.121 raeburn 9913: }
9914: $resulttext = &mt('Changes made:').'<ul>';
9915: foreach my $item (sort(keys(%changes))) {
9916: if ($item eq 'canuse_pdfforms') {
9917: if ($env{'form.'.$item} eq '1') {
9918: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
9919: } else {
9920: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
9921: }
1.139 raeburn 9922: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 9923: $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 9924: } elsif ($item eq 'uploadquota') {
9925: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
9926: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
9927: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
9928: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 9929: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
9930:
1.160.6.21 raeburn 9931: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
9932: '</ul>'.
9933: '</li>';
9934: } else {
9935: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
9936: }
1.160.6.16 raeburn 9937: } elsif ($item eq 'coursecredits') {
9938: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
9939: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 9940: ($domdefaults{'unofficialcredits'} eq '') &&
9941: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 9942: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9943: } else {
9944: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
9945: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
9946: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 9947: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 9948: '</ul>'.
9949: '</li>';
9950: }
9951: } else {
9952: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
9953: }
1.140 raeburn 9954: }
1.121 raeburn 9955: }
9956: $resulttext .= '</ul>';
9957: } else {
9958: $resulttext = &mt('No changes made to course defaults');
9959: }
9960: } else {
9961: $resulttext = '<span class="LC_error">'.
9962: &mt('An error occurred: [_1]',$putresult).'</span>';
9963: }
9964: return $resulttext;
9965: }
9966:
1.160.6.37 raeburn 9967: sub modify_selfenrollment {
9968: my ($dom,$lastactref,%domconfig) = @_;
9969: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
9970: my @types = ('official','unofficial','community','textbook');
9971: my %titles = &tool_titles();
9972: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
9973: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
9974: $ordered{'default'} = ['types','registered','approval','limit'];
9975:
9976: my (%roles,%shown,%toplevel);
9977: $roles{'0'} = &Apache::lonnet::plaintext('dc');
9978:
9979: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
9980: if ($domconfig{'selfenrollment'} eq '') {
9981: $domconfig{'selfenrollment'} = {};
9982: }
9983: }
9984: %toplevel = (
9985: admin => 'Configuration Rights',
9986: default => 'Default settings',
9987: validation => 'Validation of self-enrollment requests',
9988: );
9989: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
9990:
9991: if (ref($ordered{'admin'}) eq 'ARRAY') {
9992: foreach my $item (@{$ordered{'admin'}}) {
9993: foreach my $type (@types) {
9994: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
9995: $selfenrollhash{'admin'}{$type}{$item} = 1;
9996: } else {
9997: $selfenrollhash{'admin'}{$type}{$item} = 0;
9998: }
9999: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10000: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10001: if ($selfenrollhash{'admin'}{$type}{$item} ne
10002: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10003: push(@{$changes{'admin'}{$type}},$item);
10004: }
10005: } else {
10006: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10007: push(@{$changes{'admin'}{$type}},$item);
10008: }
10009: }
10010: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10011: push(@{$changes{'admin'}{$type}},$item);
10012: }
10013: }
10014: }
10015: }
10016:
10017: foreach my $item (@{$ordered{'default'}}) {
10018: foreach my $type (@types) {
10019: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10020: if ($item eq 'types') {
10021: unless (($value eq 'all') || ($value eq 'dom')) {
10022: $value = '';
10023: }
10024: } elsif ($item eq 'registered') {
10025: unless ($value eq '1') {
10026: $value = 0;
10027: }
10028: } elsif ($item eq 'approval') {
10029: unless ($value =~ /^[012]$/) {
10030: $value = 0;
10031: }
10032: } else {
10033: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10034: $value = 'none';
10035: }
10036: }
10037: $selfenrollhash{'default'}{$type}{$item} = $value;
10038: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10039: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10040: if ($selfenrollhash{'default'}{$type}{$item} ne
10041: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10042: push(@{$changes{'default'}{$type}},$item);
10043: }
10044: } else {
10045: push(@{$changes{'default'}{$type}},$item);
10046: }
10047: } else {
10048: push(@{$changes{'default'}{$type}},$item);
10049: }
10050: if ($item eq 'limit') {
10051: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10052: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10053: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10054: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10055: }
10056: } else {
10057: $selfenrollhash{'default'}{$type}{'cap'} = '';
10058: }
10059: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10060: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10061: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10062: push(@{$changes{'default'}{$type}},'cap');
10063: }
10064: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10065: push(@{$changes{'default'}{$type}},'cap');
10066: }
10067: }
10068: }
10069: }
10070:
10071: foreach my $item (@{$itemsref}) {
10072: if ($item eq 'fields') {
10073: my @changed;
10074: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10075: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10076: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10077: }
10078: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10079: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10080: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10081: $domconfig{'selfenrollment'}{'validation'}{$item});
10082: } else {
10083: @changed = @{$selfenrollhash{'validation'}{$item}};
10084: }
10085: } else {
10086: @changed = @{$selfenrollhash{'validation'}{$item}};
10087: }
10088: if (@changed) {
10089: if ($selfenrollhash{'validation'}{$item}) {
10090: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10091: } else {
10092: $changes{'validation'}{$item} = &mt('None');
10093: }
10094: }
10095: } else {
10096: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10097: if ($item eq 'markup') {
10098: if ($env{'form.selfenroll_validation_'.$item}) {
10099: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10100: }
10101: }
10102: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10103: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10104: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10105: }
10106: }
10107: }
10108: }
10109:
10110: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10111: $dom);
10112: if ($putresult eq 'ok') {
10113: if (keys(%changes) > 0) {
10114: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10115: $resulttext = &mt('Changes made:').'<ul>';
10116: foreach my $key ('admin','default','validation') {
10117: if (ref($changes{$key}) eq 'HASH') {
10118: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10119: if ($key eq 'validation') {
10120: foreach my $item (@{$itemsref}) {
10121: if (exists($changes{$key}{$item})) {
10122: if ($item eq 'markup') {
10123: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10124: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10125: } else {
10126: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10127: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10128: }
10129: }
10130: }
10131: } else {
10132: foreach my $type (@types) {
10133: if ($type eq 'community') {
10134: $roles{'1'} = &mt('Community personnel');
10135: } else {
10136: $roles{'1'} = &mt('Course personnel');
10137: }
10138: if (ref($changes{$key}{$type}) eq 'ARRAY') {
10139: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10140: if ($key eq 'admin') {
10141: my @mgrdc = ();
10142: if (ref($ordered{$key}) eq 'ARRAY') {
10143: foreach my $item (@{$ordered{'admin'}}) {
10144: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10145: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10146: push(@mgrdc,$item);
10147: }
10148: }
10149: }
10150: if (@mgrdc) {
10151: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10152: } else {
10153: delete($domdefaults{$type.'selfenrolladmdc'});
10154: }
10155: }
10156: } else {
10157: if (ref($ordered{$key}) eq 'ARRAY') {
10158: foreach my $item (@{$ordered{$key}}) {
10159: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10160: $domdefaults{$type.'selfenroll'.$item} =
10161: $selfenrollhash{$key}{$type}{$item};
10162: }
10163: }
10164: }
10165: }
10166: }
10167: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10168: foreach my $item (@{$ordered{$key}}) {
10169: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10170: $resulttext .= '<li>';
10171: if ($key eq 'admin') {
10172: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10173: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10174: } else {
10175: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10176: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10177: }
10178: $resulttext .= '</li>';
10179: }
10180: }
10181: $resulttext .= '</ul></li>';
10182: }
10183: }
10184: $resulttext .= '</ul></li>';
10185: }
10186: }
10187: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10188: my $cachetime = 24*60*60;
10189: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10190: if (ref($lastactref) eq 'HASH') {
10191: $lastactref->{'domdefaults'} = 1;
10192: }
10193: }
10194: }
10195: $resulttext .= '</ul>';
10196: } else {
10197: $resulttext = &mt('No changes made to self-enrollment settings');
10198: }
10199: } else {
10200: $resulttext = '<span class="LC_error">'.
10201: &mt('An error occurred: [_1]',$putresult).'</span>';
10202: }
10203: return $resulttext;
10204: }
10205:
1.137 raeburn 10206: sub modify_usersessions {
1.160.6.27 raeburn 10207: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10208: my @hostingtypes = ('version','excludedomain','includedomain');
10209: my @offloadtypes = ('primary','default');
10210: my %types = (
10211: remote => \@hostingtypes,
10212: hosted => \@hostingtypes,
10213: spares => \@offloadtypes,
10214: );
10215: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10216: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10217: my (%by_ip,%by_location,@intdoms);
10218: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10219: my @locations = sort(keys(%by_location));
1.137 raeburn 10220: my (%defaultshash,%changes);
10221: foreach my $prefix (@prefixes) {
10222: $defaultshash{'usersessions'}{$prefix} = {};
10223: }
1.160.6.27 raeburn 10224: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10225: my $resulttext;
1.138 raeburn 10226: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10227: foreach my $prefix (@prefixes) {
1.145 raeburn 10228: next if ($prefix eq 'spares');
10229: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10230: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10231: if ($type eq 'version') {
10232: my $value = $env{'form.'.$prefix.'_'.$type};
10233: my $okvalue;
10234: if ($value ne '') {
10235: if (grep(/^\Q$value\E$/,@lcversions)) {
10236: $okvalue = $value;
10237: }
10238: }
10239: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10240: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10241: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10242: if ($inuse == 0) {
10243: $changes{$prefix}{$type} = 1;
10244: } else {
10245: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10246: $changes{$prefix}{$type} = 1;
10247: }
10248: if ($okvalue ne '') {
10249: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10250: }
10251: }
10252: } else {
10253: if (($inuse == 1) && ($okvalue ne '')) {
10254: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10255: $changes{$prefix}{$type} = 1;
10256: }
10257: }
10258: } else {
10259: if (($inuse == 1) && ($okvalue ne '')) {
10260: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10261: $changes{$prefix}{$type} = 1;
10262: }
10263: }
10264: } else {
10265: if (($inuse == 1) && ($okvalue ne '')) {
10266: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10267: $changes{$prefix}{$type} = 1;
10268: }
10269: }
10270: } else {
10271: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10272: my @okvals;
10273: foreach my $val (@vals) {
1.138 raeburn 10274: if ($val =~ /:/) {
10275: my @items = split(/:/,$val);
10276: foreach my $item (@items) {
10277: if (ref($by_location{$item}) eq 'ARRAY') {
10278: push(@okvals,$item);
10279: }
10280: }
10281: } else {
10282: if (ref($by_location{$val}) eq 'ARRAY') {
10283: push(@okvals,$val);
10284: }
1.137 raeburn 10285: }
10286: }
10287: @okvals = sort(@okvals);
10288: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10289: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10290: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10291: if ($inuse == 0) {
10292: $changes{$prefix}{$type} = 1;
10293: } else {
10294: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10295: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10296: if (@changed > 0) {
10297: $changes{$prefix}{$type} = 1;
10298: }
10299: }
10300: } else {
10301: if ($inuse == 1) {
10302: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10303: $changes{$prefix}{$type} = 1;
10304: }
10305: }
10306: } else {
10307: if ($inuse == 1) {
10308: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10309: $changes{$prefix}{$type} = 1;
10310: }
10311: }
10312: } else {
10313: if ($inuse == 1) {
10314: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10315: $changes{$prefix}{$type} = 1;
10316: }
10317: }
10318: }
10319: }
10320: }
1.145 raeburn 10321:
10322: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10323: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10324: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10325: my $savespares;
10326:
10327: foreach my $lonhost (sort(keys(%servers))) {
10328: my $serverhomeID =
10329: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10330: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10331: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10332: my %spareschg;
10333: foreach my $type (@{$types{'spares'}}) {
10334: my @okspares;
10335: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10336: foreach my $server (@checked) {
1.152 raeburn 10337: if (&Apache::lonnet::hostname($server) ne '') {
10338: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10339: unless (grep(/^\Q$server\E$/,@okspares)) {
10340: push(@okspares,$server);
10341: }
1.145 raeburn 10342: }
10343: }
10344: }
10345: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10346: my $newspare;
1.152 raeburn 10347: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10348: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10349: $newspare = $new;
10350: }
10351: }
1.152 raeburn 10352: my @spares;
10353: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10354: @spares = sort(@okspares,$newspare);
10355: } else {
10356: @spares = sort(@okspares);
10357: }
10358: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10359: if (ref($spareid{$lonhost}) eq 'HASH') {
10360: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10361: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10362: if (@diffs > 0) {
10363: $spareschg{$type} = 1;
10364: }
10365: }
10366: }
10367: }
10368: if (keys(%spareschg) > 0) {
10369: $changes{'spares'}{$lonhost} = \%spareschg;
10370: }
10371: }
10372:
10373: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10374: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10375: if (ref($changes{'spares'}) eq 'HASH') {
10376: if (keys(%{$changes{'spares'}}) > 0) {
10377: $savespares = 1;
10378: }
10379: }
10380: } else {
10381: $savespares = 1;
10382: }
10383: }
10384:
1.147 raeburn 10385: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10386: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10387: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10388: $dom);
10389: if ($putresult eq 'ok') {
10390: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10391: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10392: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10393: }
10394: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10395: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10396: }
10397: }
10398: my $cachetime = 24*60*60;
10399: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10400: if (ref($lastactref) eq 'HASH') {
10401: $lastactref->{'domdefaults'} = 1;
10402: }
1.147 raeburn 10403: if (keys(%changes) > 0) {
10404: my %lt = &usersession_titles();
10405: $resulttext = &mt('Changes made:').'<ul>';
10406: foreach my $prefix (@prefixes) {
10407: if (ref($changes{$prefix}) eq 'HASH') {
10408: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10409: if ($prefix eq 'spares') {
10410: if (ref($changes{$prefix}) eq 'HASH') {
10411: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10412: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10413: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 10414: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10415: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10416: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10417: foreach my $type (@{$types{$prefix}}) {
10418: if ($changes{$prefix}{$lonhost}{$type}) {
10419: my $offloadto = &mt('None');
10420: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10421: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10422: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10423: }
1.145 raeburn 10424: }
1.147 raeburn 10425: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10426: }
1.137 raeburn 10427: }
10428: }
1.147 raeburn 10429: $resulttext .= '</li>';
1.137 raeburn 10430: }
10431: }
1.147 raeburn 10432: } else {
10433: foreach my $type (@{$types{$prefix}}) {
10434: if (defined($changes{$prefix}{$type})) {
10435: my $newvalue;
10436: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10437: if (ref($defaultshash{'usersessions'}{$prefix})) {
10438: if ($type eq 'version') {
10439: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10440: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10441: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10442: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10443: }
1.145 raeburn 10444: }
10445: }
10446: }
1.147 raeburn 10447: if ($newvalue eq '') {
10448: if ($type eq 'version') {
10449: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10450: } else {
10451: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10452: }
1.145 raeburn 10453: } else {
1.147 raeburn 10454: if ($type eq 'version') {
10455: $newvalue .= ' '.&mt('(or later)');
10456: }
10457: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10458: }
1.137 raeburn 10459: }
10460: }
10461: }
1.147 raeburn 10462: $resulttext .= '</ul>';
1.137 raeburn 10463: }
10464: }
1.147 raeburn 10465: $resulttext .= '</ul>';
10466: } else {
10467: $resulttext = $nochgmsg;
1.137 raeburn 10468: }
10469: } else {
10470: $resulttext = '<span class="LC_error">'.
10471: &mt('An error occurred: [_1]',$putresult).'</span>';
10472: }
10473: } else {
1.147 raeburn 10474: $resulttext = $nochgmsg;
1.137 raeburn 10475: }
10476: return $resulttext;
10477: }
10478:
1.150 raeburn 10479: sub modify_loadbalancing {
10480: my ($dom,%domconfig) = @_;
10481: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10482: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10483: my ($othertitle,$usertypes,$types) =
10484: &Apache::loncommon::sorted_inst_types($dom);
10485: my %servers = &Apache::lonnet::internet_dom_servers($dom);
10486: my @sparestypes = ('primary','default');
10487: my %typetitles = &sparestype_titles();
10488: my $resulttext;
1.160.6.7 raeburn 10489: my (%currbalancer,%currtargets,%currrules,%existing);
10490: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10491: %existing = %{$domconfig{'loadbalancing'}};
10492: }
10493: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10494: \%currtargets,\%currrules);
10495: my ($saveloadbalancing,%defaultshash,%changes);
10496: my ($alltypes,$othertypes,$titles) =
10497: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10498: my %ruletitles = &offloadtype_text();
10499: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10500: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10501: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10502: if ($balancer eq '') {
10503: next;
10504: }
10505: if (!exists($servers{$balancer})) {
10506: if (exists($currbalancer{$balancer})) {
10507: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10508: }
1.160.6.7 raeburn 10509: next;
10510: }
10511: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10512: push(@{$changes{'delete'}},$balancer);
10513: next;
10514: }
10515: if (!exists($currbalancer{$balancer})) {
10516: push(@{$changes{'add'}},$balancer);
10517: }
10518: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10519: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10520: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10521: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10522: $saveloadbalancing = 1;
10523: }
10524: foreach my $sparetype (@sparestypes) {
10525: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10526: my @offloadto;
10527: foreach my $target (@targets) {
10528: if (($servers{$target}) && ($target ne $balancer)) {
10529: if ($sparetype eq 'default') {
10530: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10531: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10532: }
10533: }
1.160.6.7 raeburn 10534: unless(grep(/^\Q$target\E$/,@offloadto)) {
10535: push(@offloadto,$target);
10536: }
1.150 raeburn 10537: }
1.160.6.7 raeburn 10538: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10539: }
10540: }
1.160.6.7 raeburn 10541: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10542: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 10543: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10544: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10545: if (@targetdiffs > 0) {
1.160.6.7 raeburn 10546: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10547: }
1.160.6.7 raeburn 10548: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10549: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10550: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10551: }
10552: }
10553: }
10554: } else {
1.160.6.7 raeburn 10555: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
10556: foreach my $sparetype (@sparestypes) {
10557: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10558: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10559: $changes{'curr'}{$balancer}{'targets'} = 1;
10560: }
1.150 raeburn 10561: }
10562: }
1.160.6.7 raeburn 10563: }
1.150 raeburn 10564: }
10565: my $ishomedom;
1.160.6.7 raeburn 10566: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10567: $ishomedom = 1;
1.150 raeburn 10568: }
10569: if (ref($alltypes) eq 'ARRAY') {
10570: foreach my $type (@{$alltypes}) {
10571: my $rule;
1.160.6.7 raeburn 10572: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10573: (!$ishomedom)) {
1.160.6.7 raeburn 10574: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10575: }
10576: if ($rule eq 'specific') {
10577: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 10578: }
1.160.6.7 raeburn 10579: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10580: if (ref($currrules{$balancer}) eq 'HASH') {
10581: if ($rule ne $currrules{$balancer}{$type}) {
10582: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10583: }
10584: } elsif ($rule ne '') {
1.160.6.7 raeburn 10585: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10586: }
10587: }
10588: }
1.160.6.7 raeburn 10589: }
10590: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10591: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10592: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10593: $defaultshash{'loadbalancing'} = {};
10594: }
10595: my $putresult = &Apache::lonnet::put_dom('configuration',
10596: \%defaultshash,$dom);
10597: if ($putresult eq 'ok') {
10598: if (keys(%changes) > 0) {
10599: if (ref($changes{'delete'}) eq 'ARRAY') {
10600: foreach my $balancer (sort(@{$changes{'delete'}})) {
10601: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.27 raeburn 10602: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
10603: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10604: }
1.160.6.7 raeburn 10605: }
10606: if (ref($changes{'add'}) eq 'ARRAY') {
10607: foreach my $balancer (sort(@{$changes{'add'}})) {
10608: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
10609: }
10610: }
10611: if (ref($changes{'curr'}) eq 'HASH') {
10612: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
10613: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
10614: if ($changes{'curr'}{$balancer}{'targets'}) {
10615: my %offloadstr;
10616: foreach my $sparetype (@sparestypes) {
10617: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10618: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10619: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
10620: }
10621: }
1.150 raeburn 10622: }
1.160.6.7 raeburn 10623: if (keys(%offloadstr) == 0) {
10624: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 10625: } else {
1.160.6.7 raeburn 10626: my $showoffload;
10627: foreach my $sparetype (@sparestypes) {
10628: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
10629: if (defined($offloadstr{$sparetype})) {
10630: $showoffload .= $offloadstr{$sparetype};
10631: } else {
10632: $showoffload .= &mt('None');
10633: }
10634: $showoffload .= (' 'x3);
10635: }
10636: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 10637: }
10638: }
10639: }
1.160.6.7 raeburn 10640: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
10641: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
10642: foreach my $type (@{$alltypes}) {
10643: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
10644: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
10645: my $balancetext;
10646: if ($rule eq '') {
10647: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 10648: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
10649: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.160.6.7 raeburn 10650: $balancetext = $ruletitles{$rule};
10651: } else {
10652: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
10653: }
1.160.6.26 raeburn 10654: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 10655: }
10656: }
10657: }
10658: }
1.160.6.29 raeburn 10659: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
1.160.6.27 raeburn 10660: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 10661: }
1.160.6.7 raeburn 10662: }
10663: if ($resulttext ne '') {
10664: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 10665: } else {
10666: $resulttext = $nochgmsg;
10667: }
10668: } else {
1.160.6.7 raeburn 10669: $resulttext = $nochgmsg;
1.150 raeburn 10670: }
10671: } else {
1.160.6.7 raeburn 10672: $resulttext = '<span class="LC_error">'.
10673: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 10674: }
10675: } else {
1.160.6.7 raeburn 10676: $resulttext = $nochgmsg;
1.150 raeburn 10677: }
10678: return $resulttext;
10679: }
10680:
1.48 raeburn 10681: sub recurse_check {
10682: my ($chkcats,$categories,$depth,$name) = @_;
10683: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
10684: my $chg = 0;
10685: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
10686: my $category = $chkcats->[$depth]{$name}[$j];
10687: my $item;
10688: if ($category eq '') {
10689: $chg ++;
10690: } else {
10691: my $deeper = $depth + 1;
10692: $item = &escape($category).':'.&escape($name).':'.$depth;
10693: if ($chg) {
10694: $categories->{$item} -= $chg;
10695: }
10696: &recurse_check($chkcats,$categories,$deeper,$category);
10697: $deeper --;
10698: }
10699: }
10700: }
10701: return;
10702: }
10703:
10704: sub recurse_cat_deletes {
10705: my ($item,$coursecategories,$deletions) = @_;
10706: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
10707: my $subdepth = $depth + 1;
10708: if (ref($coursecategories) eq 'HASH') {
10709: foreach my $subitem (keys(%{$coursecategories})) {
10710: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
10711: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
10712: delete($coursecategories->{$subitem});
10713: $deletions->{$subitem} = 1;
10714: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 10715: }
1.48 raeburn 10716: }
10717: }
10718: return;
10719: }
10720:
1.125 raeburn 10721: sub get_active_dcs {
10722: my ($dom) = @_;
1.160.6.16 raeburn 10723: my $now = time;
10724: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 10725: my %domcoords;
10726: my $numdcs = 0;
10727: foreach my $server (keys(%dompersonnel)) {
10728: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
10729: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.160.6.16 raeburn 10730: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 10731: }
10732: }
10733: return %domcoords;
10734: }
10735:
10736: sub active_dc_picker {
1.160.6.16 raeburn 10737: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.39 raeburn 10738: my %domcoords = &get_active_dcs($dom);
1.160.6.16 raeburn 10739: my @domcoord = keys(%domcoords);
10740: if (keys(%currhash)) {
10741: foreach my $dc (keys(%currhash)) {
10742: unless (exists($domcoords{$dc})) {
10743: push(@domcoord,$dc);
10744: }
10745: }
10746: }
10747: @domcoord = sort(@domcoord);
10748: my $numdcs = scalar(@domcoord);
10749: my $rows = 0;
10750: my $table;
1.125 raeburn 10751: if ($numdcs > 1) {
1.160.6.16 raeburn 10752: $table = '<table>';
10753: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 10754: my $rem = $i%($numinrow);
10755: if ($rem == 0) {
10756: if ($i > 0) {
1.160.6.16 raeburn 10757: $table .= '</tr>';
1.125 raeburn 10758: }
1.160.6.16 raeburn 10759: $table .= '<tr>';
10760: $rows ++;
1.125 raeburn 10761: }
1.160.6.16 raeburn 10762: my $check = '';
10763: if ($inputtype eq 'radio') {
10764: if (keys(%currhash) == 0) {
10765: if (!$i) {
10766: $check = ' checked="checked"';
10767: }
10768: } elsif (exists($currhash{$domcoord[$i]})) {
10769: $check = ' checked="checked"';
10770: }
10771: } else {
10772: if (exists($currhash{$domcoord[$i]})) {
10773: $check = ' checked="checked"';
1.125 raeburn 10774: }
10775: }
1.160.6.16 raeburn 10776: if ($i == @domcoord - 1) {
1.125 raeburn 10777: my $colsleft = $numinrow - $rem;
10778: if ($colsleft > 1) {
1.160.6.16 raeburn 10779: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 10780: } else {
1.160.6.16 raeburn 10781: $table .= '<td class="LC_left_item">';
1.125 raeburn 10782: }
10783: } else {
1.160.6.16 raeburn 10784: $table .= '<td class="LC_left_item">';
10785: }
10786: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
10787: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
10788: $table .= '<span class="LC_nobreak"><label>'.
10789: '<input type="'.$inputtype.'" name="'.$name.'"'.
10790: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
10791: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 10792: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 10793: }
1.160.6.33 raeburn 10794: $table .= '</label></span></td>';
1.125 raeburn 10795: }
1.160.6.16 raeburn 10796: $table .= '</tr></table>';
10797: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 10798: my ($dcname,$dcdom) = split(':',$domcoord[0]);
10799: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 10800: if ($inputtype eq 'radio') {
1.160.6.31 raeburn 10801: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
10802: if ($user ne $dcname.':'.$dcdom) {
10803: $table .= ' ('.$dcname.':'.$dcdom.')';
10804: }
1.160.6.16 raeburn 10805: } else {
10806: my $check;
10807: if (exists($currhash{$domcoord[0]})) {
10808: $check = ' checked="checked"';
10809: }
1.160.6.31 raeburn 10810: $table .= '<span class="LC_nobreak"><label>'.
10811: '<input type="checkbox" name="'.$name.'" '.
10812: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
10813: if ($user ne $dcname.':'.$dcdom) {
10814: $table .= ' ('.$dcname.':'.$dcdom.')';
10815: }
10816: $table .= '</label></span>';
1.160.6.16 raeburn 10817: $rows ++;
10818: }
1.125 raeburn 10819: }
1.160.6.16 raeburn 10820: return ($numdcs,$table,$rows);
1.125 raeburn 10821: }
10822:
1.137 raeburn 10823: sub usersession_titles {
10824: return &Apache::lonlocal::texthash(
10825: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
10826: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 10827: spares => 'Servers offloaded to, when busy',
1.137 raeburn 10828: version => 'LON-CAPA version requirement',
1.138 raeburn 10829: excludedomain => 'Allow all, but exclude specific domains',
10830: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 10831: primary => 'Primary (checked first)',
1.154 raeburn 10832: default => 'Default',
1.137 raeburn 10833: );
10834: }
10835:
1.152 raeburn 10836: sub id_for_thisdom {
10837: my (%servers) = @_;
10838: my %altids;
10839: foreach my $server (keys(%servers)) {
10840: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
10841: if ($serverhome ne $server) {
10842: $altids{$serverhome} = $server;
10843: }
10844: }
10845: return %altids;
10846: }
10847:
1.150 raeburn 10848: sub count_servers {
10849: my ($currbalancer,%servers) = @_;
10850: my (@spares,$numspares);
10851: foreach my $lonhost (sort(keys(%servers))) {
10852: next if ($currbalancer eq $lonhost);
10853: push(@spares,$lonhost);
10854: }
10855: if ($currbalancer) {
10856: $numspares = scalar(@spares);
10857: } else {
10858: $numspares = scalar(@spares) - 1;
10859: }
10860: return ($numspares,@spares);
10861: }
10862:
10863: sub lonbalance_targets_js {
1.160.6.7 raeburn 10864: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 10865: my $select = &mt('Select');
10866: my ($alltargets,$allishome,$allinsttypes,@alltypes);
10867: if (ref($servers) eq 'HASH') {
10868: $alltargets = join("','",sort(keys(%{$servers})));
10869: my @homedoms;
10870: foreach my $server (sort(keys(%{$servers}))) {
10871: if (&Apache::lonnet::host_domain($server) eq $dom) {
10872: push(@homedoms,'1');
10873: } else {
10874: push(@homedoms,'0');
10875: }
10876: }
10877: $allishome = join("','",@homedoms);
10878: }
10879: if (ref($types) eq 'ARRAY') {
10880: if (@{$types} > 0) {
10881: @alltypes = @{$types};
10882: }
10883: }
10884: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
10885: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 10886: my (%currbalancer,%currtargets,%currrules,%existing);
10887: if (ref($settings) eq 'HASH') {
10888: %existing = %{$settings};
10889: }
10890: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
10891: \%currtargets,\%currrules);
10892: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 10893: return <<"END";
10894:
10895: <script type="text/javascript">
10896: // <![CDATA[
10897:
1.160.6.7 raeburn 10898: currBalancers = new Array('$balancers');
10899:
10900: function toggleTargets(balnum) {
10901: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
10902: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
10903: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
10904: var prevbalancer = prevhostitem.value;
10905: var baltotal = document.getElementById('loadbalancing_total').value;
10906: prevhostitem.value = balancer;
10907: if (prevbalancer != '') {
10908: var prevIdx = currBalancers.indexOf(prevbalancer);
10909: if (prevIdx != -1) {
10910: currBalancers.splice(prevIdx,1);
10911: }
10912: }
1.150 raeburn 10913: if (balancer == '') {
1.160.6.7 raeburn 10914: hideSpares(balnum);
1.150 raeburn 10915: } else {
1.160.6.7 raeburn 10916: var currIdx = currBalancers.indexOf(balancer);
10917: if (currIdx == -1) {
10918: currBalancers.push(balancer);
10919: }
1.150 raeburn 10920: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 10921: var ishomedom = homedoms[lonhostitem.selectedIndex];
10922: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 10923: }
1.160.6.7 raeburn 10924: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 10925: return;
10926: }
10927:
1.160.6.7 raeburn 10928: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 10929: var alltargets = new Array('$alltargets');
10930: var insttypes = new Array('$allinsttypes');
1.151 raeburn 10931: var offloadtypes = new Array('primary','default');
10932:
1.160.6.7 raeburn 10933: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
10934: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 10935:
1.151 raeburn 10936: for (var i=0; i<offloadtypes.length; i++) {
10937: var count = 0;
10938: for (var j=0; j<alltargets.length; j++) {
10939: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 10940: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
10941: item.value = alltargets[j];
10942: item.style.textAlign='left';
10943: item.style.textFace='normal';
10944: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
10945: if (currBalancers.indexOf(alltargets[j]) == -1) {
10946: item.disabled = '';
10947: } else {
10948: item.disabled = 'disabled';
10949: item.checked = false;
10950: }
1.151 raeburn 10951: count ++;
10952: }
1.150 raeburn 10953: }
10954: }
1.151 raeburn 10955: for (var k=0; k<insttypes.length; k++) {
10956: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 10957: if (ishomedom == 1) {
1.160.6.7 raeburn 10958: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10959: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10960: } else {
1.160.6.7 raeburn 10961: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
10962: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 10963: }
10964: } else {
1.160.6.7 raeburn 10965: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
10966: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 10967: }
1.151 raeburn 10968: if ((insttypes[k] != '_LC_external') &&
10969: ((insttypes[k] != '_LC_internetdom') ||
10970: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 10971: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
10972: item.options.length = 0;
10973: item.options[0] = new Option("","",true,true);
10974: var idx = 0;
1.151 raeburn 10975: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 10976: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
10977: idx ++;
10978: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 10979: }
10980: }
10981: }
10982: }
10983: return;
10984: }
10985:
1.160.6.7 raeburn 10986: function hideSpares(balnum) {
1.150 raeburn 10987: var alltargets = new Array('$alltargets');
10988: var insttypes = new Array('$allinsttypes');
10989: var offloadtypes = new Array('primary','default');
10990:
1.160.6.7 raeburn 10991: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
10992: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 10993:
10994: var total = alltargets.length - 1;
10995: for (var i=0; i<offloadtypes; i++) {
10996: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 10997: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
10998: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
10999: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11000: }
1.150 raeburn 11001: }
11002: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 11003: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11004: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11005: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 11006: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11007: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11008: }
11009: }
11010: return;
11011: }
11012:
1.160.6.7 raeburn 11013: function checkOffloads(item,balnum,type) {
1.150 raeburn 11014: var alltargets = new Array('$alltargets');
11015: var offloadtypes = new Array('primary','default');
11016: if (item.checked) {
11017: var total = alltargets.length - 1;
11018: var other;
11019: if (type == offloadtypes[0]) {
1.151 raeburn 11020: other = offloadtypes[1];
1.150 raeburn 11021: } else {
1.151 raeburn 11022: other = offloadtypes[0];
1.150 raeburn 11023: }
11024: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 11025: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11026: if (server == item.value) {
1.160.6.7 raeburn 11027: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11028: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11029: }
11030: }
11031: }
11032: }
11033: return;
11034: }
11035:
1.160.6.7 raeburn 11036: function singleServerToggle(balnum,type) {
11037: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11038: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 11039: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11040: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11041:
11042: } else {
1.160.6.7 raeburn 11043: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11044: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11045: }
11046: return;
11047: }
11048:
1.160.6.7 raeburn 11049: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11050: if (type == '_LC_external') {
1.160.6.26 raeburn 11051: return;
1.150 raeburn 11052: }
1.160.6.7 raeburn 11053: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11054: for (var i=0; i<typesRules.length; i++) {
11055: if (formname.elements[typesRules[i]].checked) {
11056: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 11057: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11058: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11059: } else {
1.160.6.7 raeburn 11060: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11061: }
11062: }
11063: }
11064: return;
11065: }
11066:
11067: function balancerDeleteChange(balnum) {
11068: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11069: var baltotal = document.getElementById('loadbalancing_total').value;
11070: var addtarget;
11071: var removetarget;
11072: var action = 'delete';
11073: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11074: var lonhost = hostitem.value;
11075: var currIdx = currBalancers.indexOf(lonhost);
11076: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11077: if (currIdx != -1) {
11078: currBalancers.splice(currIdx,1);
11079: }
11080: addtarget = lonhost;
11081: } else {
11082: if (currIdx == -1) {
11083: currBalancers.push(lonhost);
11084: }
11085: removetarget = lonhost;
11086: action = 'undelete';
11087: }
11088: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11089: }
11090: return;
11091: }
11092:
11093: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11094: if (baltotal > 1) {
11095: var offloadtypes = new Array('primary','default');
11096: var alltargets = new Array('$alltargets');
11097: var insttypes = new Array('$allinsttypes');
11098: for (var i=0; i<baltotal; i++) {
11099: if (i != balnum) {
11100: for (var j=0; j<offloadtypes.length; j++) {
11101: var total = alltargets.length - 1;
11102: for (var k=0; k<total; k++) {
11103: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11104: var server = serveritem.value;
11105: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11106: if (server == addtarget) {
11107: serveritem.disabled = '';
11108: }
11109: }
11110: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11111: if (server == removetarget) {
11112: serveritem.disabled = 'disabled';
11113: serveritem.checked = false;
11114: }
11115: }
11116: }
11117: }
11118: for (var j=0; j<insttypes.length; j++) {
11119: if (insttypes[j] != '_LC_external') {
11120: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11121: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11122: var currSel = singleserver.selectedIndex;
11123: var currVal = singleserver.options[currSel].value;
11124: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11125: var numoptions = singleserver.options.length;
11126: var needsnew = 1;
11127: for (var k=0; k<numoptions; k++) {
11128: if (singleserver.options[k] == addtarget) {
11129: needsnew = 0;
11130: break;
11131: }
11132: }
11133: if (needsnew == 1) {
11134: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11135: }
11136: }
11137: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11138: singleserver.options.length = 0;
11139: if ((currVal) && (currVal != removetarget)) {
11140: singleserver.options[0] = new Option("","",false,false);
11141: } else {
11142: singleserver.options[0] = new Option("","",true,true);
11143: }
11144: var idx = 0;
11145: for (var m=0; m<alltargets.length; m++) {
11146: if (currBalancers.indexOf(alltargets[m]) == -1) {
11147: idx ++;
11148: if (currVal == alltargets[m]) {
11149: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11150: } else {
11151: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11152: }
11153: }
11154: }
11155: }
11156: }
11157: }
11158: }
1.150 raeburn 11159: }
11160: }
11161: }
11162: return;
11163: }
11164:
1.152 raeburn 11165: // ]]>
11166: </script>
11167:
11168: END
11169: }
11170:
11171: sub new_spares_js {
11172: my @sparestypes = ('primary','default');
11173: my $types = join("','",@sparestypes);
11174: my $select = &mt('Select');
11175: return <<"END";
11176:
11177: <script type="text/javascript">
11178: // <![CDATA[
11179:
11180: function updateNewSpares(formname,lonhost) {
11181: var types = new Array('$types');
11182: var include = new Array();
11183: var exclude = new Array();
11184: for (var i=0; i<types.length; i++) {
11185: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11186: for (var j=0; j<spareboxes.length; j++) {
11187: if (formname.elements[spareboxes[j]].checked) {
11188: exclude.push(formname.elements[spareboxes[j]].value);
11189: } else {
11190: include.push(formname.elements[spareboxes[j]].value);
11191: }
11192: }
11193: }
11194: for (var i=0; i<types.length; i++) {
11195: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11196: var selIdx = newSpare.selectedIndex;
11197: var currnew = newSpare.options[selIdx].value;
11198: var okSpares = new Array();
11199: for (var j=0; j<newSpare.options.length; j++) {
11200: var possible = newSpare.options[j].value;
11201: if (possible != '') {
11202: if (exclude.indexOf(possible) == -1) {
11203: okSpares.push(possible);
11204: } else {
11205: if (currnew == possible) {
11206: selIdx = 0;
11207: }
11208: }
11209: }
11210: }
11211: for (var k=0; k<include.length; k++) {
11212: if (okSpares.indexOf(include[k]) == -1) {
11213: okSpares.push(include[k]);
11214: }
11215: }
11216: okSpares.sort();
11217: newSpare.options.length = 0;
11218: if (selIdx == 0) {
11219: newSpare.options[0] = new Option("$select","",true,true);
11220: } else {
11221: newSpare.options[0] = new Option("$select","",false,false);
11222: }
11223: for (var m=0; m<okSpares.length; m++) {
11224: var idx = m+1;
11225: var selThis = 0;
11226: if (selIdx != 0) {
11227: if (okSpares[m] == currnew) {
11228: selThis = 1;
11229: }
11230: }
11231: if (selThis == 1) {
11232: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11233: } else {
11234: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11235: }
11236: }
11237: }
11238: return;
11239: }
11240:
11241: function checkNewSpares(lonhost,type) {
11242: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11243: var chosen = newSpare.options[newSpare.selectedIndex].value;
11244: if (chosen != '') {
11245: var othertype;
11246: var othernewSpare;
11247: if (type == 'primary') {
11248: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11249: }
11250: if (type == 'default') {
11251: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11252: }
11253: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11254: othernewSpare.selectedIndex = 0;
11255: }
11256: }
11257: return;
11258: }
11259:
11260: // ]]>
11261: </script>
11262:
11263: END
11264:
11265: }
11266:
11267: sub common_domprefs_js {
11268: return <<"END";
11269:
11270: <script type="text/javascript">
11271: // <![CDATA[
11272:
1.150 raeburn 11273: function getIndicesByName(formname,item) {
1.152 raeburn 11274: var group = new Array();
1.150 raeburn 11275: for (var i=0;i<formname.elements.length;i++) {
11276: if (formname.elements[i].name == item) {
1.152 raeburn 11277: group.push(formname.elements[i].id);
1.150 raeburn 11278: }
11279: }
1.152 raeburn 11280: return group;
1.150 raeburn 11281: }
11282:
11283: // ]]>
11284: </script>
11285:
11286: END
1.152 raeburn 11287:
1.150 raeburn 11288: }
11289:
1.160.6.5 raeburn 11290: sub recaptcha_js {
11291: my %lt = &captcha_phrases();
11292: return <<"END";
11293:
11294: <script type="text/javascript">
11295: // <![CDATA[
11296:
11297: function updateCaptcha(caller,context) {
11298: var privitem;
11299: var pubitem;
11300: var privtext;
11301: var pubtext;
11302: if (document.getElementById(context+'_recaptchapub')) {
11303: pubitem = document.getElementById(context+'_recaptchapub');
11304: } else {
11305: return;
11306: }
11307: if (document.getElementById(context+'_recaptchapriv')) {
11308: privitem = document.getElementById(context+'_recaptchapriv');
11309: } else {
11310: return;
11311: }
11312: if (document.getElementById(context+'_recaptchapubtxt')) {
11313: pubtext = document.getElementById(context+'_recaptchapubtxt');
11314: } else {
11315: return;
11316: }
11317: if (document.getElementById(context+'_recaptchaprivtxt')) {
11318: privtext = document.getElementById(context+'_recaptchaprivtxt');
11319: } else {
11320: return;
11321: }
11322: if (caller.checked) {
11323: if (caller.value == 'recaptcha') {
11324: pubitem.type = 'text';
11325: privitem.type = 'text';
11326: pubitem.size = '40';
11327: privitem.size = '40';
11328: pubtext.innerHTML = "$lt{'pub'}";
11329: privtext.innerHTML = "$lt{'priv'}";
11330: } else {
11331: pubitem.type = 'hidden';
11332: privitem.type = 'hidden';
11333: pubtext.innerHTML = '';
11334: privtext.innerHTML = '';
11335: }
11336: }
11337: return;
11338: }
11339:
11340: // ]]>
11341: </script>
11342:
11343: END
11344:
11345: }
11346:
1.160.6.40 raeburn 11347: sub toggle_display_js {
1.160.6.16 raeburn 11348: return <<"END";
11349:
11350: <script type="text/javascript">
11351: // <![CDATA[
11352:
1.160.6.40 raeburn 11353: function toggleDisplay(domForm,caller) {
11354: if (document.getElementById(caller)) {
11355: var divitem = document.getElementById(caller);
11356: var optionsElement = domForm.coursecredits;
11357: if (caller == 'emailoptions') {
11358: optionsElement = domForm.cancreate_email;
11359: }
11360: if (optionsElement.length) {
1.160.6.16 raeburn 11361: var currval;
1.160.6.40 raeburn 11362: for (var i=0; i<optionsElement.length; i++) {
11363: if (optionsElement[i].checked) {
11364: currval = optionsElement[i].value;
1.160.6.16 raeburn 11365: }
11366: }
11367: if (currval == 1) {
1.160.6.40 raeburn 11368: divitem.style.display = 'block';
1.160.6.16 raeburn 11369: } else {
1.160.6.40 raeburn 11370: divitem.style.display = 'none';
1.160.6.16 raeburn 11371: }
11372: }
11373: }
11374: return;
11375: }
11376:
11377: // ]]>
11378: </script>
11379:
11380: END
11381:
11382: }
11383:
1.160.6.5 raeburn 11384: sub captcha_phrases {
11385: return &Apache::lonlocal::texthash (
11386: priv => 'Private key',
11387: pub => 'Public key',
11388: original => 'original (CAPTCHA)',
11389: recaptcha => 'successor (ReCAPTCHA)',
11390: notused => 'unused',
11391: );
11392: }
11393:
1.160.6.24 raeburn 11394: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 11395: my ($dom,$cachekeys) = @_;
11396: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 11397: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11398: my %thismachine;
11399: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 11400: my @posscached = ('domainconfig','domdefaults');
1.160.6.24 raeburn 11401: if (keys(%servers) > 1) {
11402: foreach my $server (keys(%servers)) {
11403: next if ($thismachine{$server});
1.160.6.27 raeburn 11404: my @cached;
11405: foreach my $name (@posscached) {
11406: if ($cachekeys->{$name}) {
11407: push(@cached,&escape($name).':'.&escape($dom));
11408: }
11409: }
11410: if (@cached) {
11411: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11412: }
1.160.6.24 raeburn 11413: }
11414: }
11415: return;
11416: }
11417:
1.3 raeburn 11418: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>