Annotation of loncom/interface/domainprefs.pm, revision 1.260
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.260 ! raeburn 4: # $Id: domainprefs.pm,v 1.259 2015/03/16 13:16:27 raeburn Exp $
1.2 albertel 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.183 bisitz 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.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 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.197 raeburn 97: used by course owners to request creation of a course, and to display/store
1.223 bisitz 98: default quota sizes for Authoring Spaces.
1.101 raeburn 99:
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.216 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.232 raeburn 167: use Apache::lonuserutils();
1.235 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',
216: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 217: 'coursedefaults','usersessions','loadbalancing',
1.236 raeburn 218: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 219: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 220: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 221: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 222: 'requestcourses','requestauthor','coursecategories',
223: 'serverstatuses','helpsettings',
1.231 raeburn 224: 'coursedefaults','selfenrollment','usersessions');
1.171 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.230 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.168 raeburn 250: header => [{col1 => 'Log-in Page Items',
251: col2 => '',},
252: {col1 => 'Log-in Help',
1.256 raeburn 253: col2 => 'Value'},
254: {col1 => 'Custom HTML in document head',
1.168 raeburn 255: col2 => 'Value'}],
1.230 raeburn 256: print => \&print_login,
257: modify => \&modify_login,
1.30 raeburn 258: },
1.43 raeburn 259: 'defaults' =>
1.236 raeburn 260: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 261: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 262: header => [{col1 => 'Setting',
1.236 raeburn 263: col2 => 'Value'},
264: {col1 => 'Institutional user types',
265: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 266: print => \&print_defaults,
267: modify => \&modify_defaults,
1.43 raeburn 268: },
1.30 raeburn 269: 'quotas' =>
1.197 raeburn 270: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 271: help => 'Domain_Configuration_Quotas',
1.77 raeburn 272: header => [{col1 => 'User affiliation',
1.72 raeburn 273: col2 => 'Available tools',
1.213 raeburn 274: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 275: print => \&print_quotas,
276: modify => \&modify_quotas,
1.30 raeburn 277: },
278: 'autoenroll' =>
279: { text => 'Auto-enrollment settings',
1.67 raeburn 280: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 281: header => [{col1 => 'Configuration setting',
282: col2 => 'Value(s)'}],
1.230 raeburn 283: print => \&print_autoenroll,
284: modify => \&modify_autoenroll,
1.30 raeburn 285: },
286: 'autoupdate' =>
287: { text => 'Auto-update settings',
1.67 raeburn 288: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',},
1.131 raeburn 291: {col1 => 'Setting',
292: col2 => 'Affiliation'},
1.43 raeburn 293: {col1 => 'User population',
1.227 bisitz 294: col2 => 'Updatable user data'}],
1.230 raeburn 295: print => \&print_autoupdate,
296: modify => \&modify_autoupdate,
1.30 raeburn 297: },
1.125 raeburn 298: 'autocreate' =>
299: { text => 'Auto-course creation settings',
300: help => 'Domain_Configuration_Auto_Creation',
301: header => [{col1 => 'Configuration Setting',
302: col2 => 'Value',}],
1.230 raeburn 303: print => \&print_autocreate,
304: modify => \&modify_autocreate,
1.125 raeburn 305: },
1.30 raeburn 306: 'directorysrch' =>
307: { text => 'Institutional directory searches',
1.67 raeburn 308: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 309: header => [{col1 => 'Setting',
310: col2 => 'Value',}],
1.230 raeburn 311: print => \&print_directorysrch,
312: modify => \&modify_directorysrch,
1.30 raeburn 313: },
314: 'contacts' =>
315: { text => 'Contact Information',
1.67 raeburn 316: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 317: header => [{col1 => 'Setting',
318: col2 => 'Value',}],
1.230 raeburn 319: print => \&print_contacts,
320: modify => \&modify_contacts,
1.30 raeburn 321: },
322: 'usercreation' =>
323: { text => 'User creation',
1.67 raeburn 324: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 325: header => [{col1 => 'Format rule type',
326: col2 => 'Format rules in force'},
1.34 raeburn 327: {col1 => 'User account creation',
328: col2 => 'Usernames which may be created',},
1.30 raeburn 329: {col1 => 'Context',
1.43 raeburn 330: col2 => 'Assignable authentication types'}],
1.230 raeburn 331: print => \&print_usercreation,
332: modify => \&modify_usercreation,
1.30 raeburn 333: },
1.224 raeburn 334: 'selfcreation' =>
335: { text => 'Users self-creating accounts',
336: help => 'Domain_Configuration_Self_Creation',
337: header => [{col1 => 'Self-creation with institutional username',
338: col2 => 'Enabled?'},
339: {col1 => 'Institutional user type (login/SSO self-creation)',
340: col2 => 'Information user can enter'},
341: {col1 => 'Self-creation with e-mail as username',
342: col2 => 'Settings'}],
1.230 raeburn 343: print => \&print_selfcreation,
344: modify => \&modify_selfcreation,
1.224 raeburn 345: },
1.69 raeburn 346: 'usermodification' =>
1.33 raeburn 347: { text => 'User modification',
1.67 raeburn 348: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 349: header => [{col1 => 'Target user has role',
1.227 bisitz 350: col2 => 'User information updatable in author context'},
1.33 raeburn 351: {col1 => 'Target user has role',
1.227 bisitz 352: col2 => 'User information updatable in course context'}],
1.230 raeburn 353: print => \&print_usermodification,
354: modify => \&modify_usermodification,
1.33 raeburn 355: },
1.69 raeburn 356: 'scantron' =>
1.95 www 357: { text => 'Bubblesheet format file',
1.67 raeburn 358: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 359: header => [ {col1 => 'Item',
360: col2 => '',
361: }],
1.230 raeburn 362: print => \&print_scantron,
363: modify => \&modify_scantron,
1.46 raeburn 364: },
1.86 raeburn 365: 'requestcourses' =>
366: {text => 'Request creation of courses',
367: help => 'Domain_Configuration_Request_Courses',
368: header => [{col1 => 'User affiliation',
1.102 raeburn 369: col2 => 'Availability/Processing of requests',},
370: {col1 => 'Setting',
1.216 raeburn 371: col2 => 'Value'},
372: {col1 => 'Available textbooks',
1.235 raeburn 373: col2 => ''},
1.242 raeburn 374: {col1 => 'Available templates',
375: col2 => ''},
1.235 raeburn 376: {col1 => 'Validation (not official courses)',
377: col2 => 'Value'},],
1.230 raeburn 378: print => \&print_quotas,
379: modify => \&modify_quotas,
1.86 raeburn 380: },
1.163 raeburn 381: 'requestauthor' =>
1.223 bisitz 382: {text => 'Request Authoring Space',
1.163 raeburn 383: help => 'Domain_Configuration_Request_Author',
384: header => [{col1 => 'User affiliation',
385: col2 => 'Availability/Processing of requests',},
386: {col1 => 'Setting',
387: col2 => 'Value'}],
1.230 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.163 raeburn 390: },
1.69 raeburn 391: 'coursecategories' =>
1.120 raeburn 392: { text => 'Cataloging of courses/communities',
1.67 raeburn 393: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 394: header => [{col1 => 'Catalog type/availability',
395: col2 => '',},
396: {col1 => 'Category settings for standard catalog',
1.57 raeburn 397: col2 => '',},
398: {col1 => 'Categories',
399: col2 => '',
400: }],
1.230 raeburn 401: print => \&print_coursecategories,
402: modify => \&modify_coursecategories,
1.69 raeburn 403: },
404: 'serverstatuses' =>
1.77 raeburn 405: {text => 'Access to server status pages',
1.69 raeburn 406: help => 'Domain_Configuration_Server_Status',
407: header => [{col1 => 'Status Page',
408: col2 => 'Other named users',
409: col3 => 'Specific IPs',
410: }],
1.230 raeburn 411: print => \&print_serverstatuses,
412: modify => \&modify_serverstatuses,
1.69 raeburn 413: },
1.118 jms 414: 'helpsettings' =>
415: {text => 'Help page settings',
416: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 417: header => [{col1 => 'Help Settings (logged-in users)',
418: col2 => 'Value'}],
1.230 raeburn 419: print => \&print_helpsettings,
420: modify => \&modify_helpsettings,
1.118 jms 421: },
1.121 raeburn 422: 'coursedefaults' =>
423: {text => 'Course/Community defaults',
424: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 425: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
426: col2 => 'Value',},
427: {col1 => 'Defaults which can be overridden for each course by a DC',
428: col2 => 'Value',},],
1.230 raeburn 429: print => \&print_coursedefaults,
430: modify => \&modify_coursedefaults,
1.121 raeburn 431: },
1.231 raeburn 432: 'selfenrollment' =>
433: {text => 'Self-enrollment in Course/Community',
434: help => 'Domain_Configuration_Selfenrollment',
435: header => [{col1 => 'Configuration Rights',
436: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
437: {col1 => 'Defaults',
438: col2 => 'Value'},
439: {col1 => 'Self-enrollment validation (optional)',
440: col2 => 'Value'},],
441: print => \&print_selfenrollment,
442: modify => \&modify_selfenrollment,
443: },
1.120 raeburn 444: 'privacy' =>
445: {text => 'User Privacy',
446: help => 'Domain_Configuration_User_Privacy',
447: header => [{col1 => 'Setting',
448: col2 => 'Value',}],
1.230 raeburn 449: print => \&print_privacy,
450: modify => \&modify_privacy,
1.120 raeburn 451: },
1.141 raeburn 452: 'usersessions' =>
1.145 raeburn 453: {text => 'User session hosting/offloading',
1.137 raeburn 454: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 455: header => [{col1 => 'Domain server',
456: col2 => 'Servers to offload sessions to when busy'},
457: {col1 => 'Hosting of users from other domains',
1.137 raeburn 458: col2 => 'Rules'},
459: {col1 => "Hosting domain's own users elsewhere",
460: col2 => 'Rules'}],
1.230 raeburn 461: print => \&print_usersessions,
462: modify => \&modify_usersessions,
1.137 raeburn 463: },
1.150 raeburn 464: 'loadbalancing' =>
1.185 raeburn 465: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 466: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 467: header => [{col1 => 'Balancers',
1.150 raeburn 468: col2 => 'Default destinations',
1.183 bisitz 469: col3 => 'User affiliation',
1.150 raeburn 470: col4 => 'Overrides'},
471: ],
1.230 raeburn 472: print => \&print_loadbalancing,
473: modify => \&modify_loadbalancing,
1.150 raeburn 474: },
1.3 raeburn 475: );
1.110 raeburn 476: if (keys(%servers) > 1) {
477: $prefs{'login'} = { text => 'Log-in page options',
478: help => 'Domain_Configuration_Login_Page',
479: header => [{col1 => 'Log-in Service',
480: col2 => 'Server Setting',},
481: {col1 => 'Log-in Page Items',
1.168 raeburn 482: col2 => ''},
483: {col1 => 'Log-in Help',
1.256 raeburn 484: col2 => 'Value'},
485: {col1 => 'Custom HTML in document head',
1.168 raeburn 486: col2 => 'Value'}],
1.230 raeburn 487: print => \&print_login,
488: modify => \&modify_login,
1.110 raeburn 489: };
490: }
1.174 foxr 491:
1.6 raeburn 492: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 493: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 494: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 495: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 496: text=>"Settings to display/modify"});
1.9 raeburn 497: my $confname = $dom.'-domainconfig';
1.174 foxr 498:
1.3 raeburn 499: if ($phase eq 'process') {
1.212 raeburn 500: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
501: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 502: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 503: $r->rflush();
1.212 raeburn 504: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 505: }
1.30 raeburn 506: } elsif ($phase eq 'display') {
1.192 raeburn 507: my $js = &recaptcha_js().
1.236 raeburn 508: &toggle_display_js();
1.171 raeburn 509: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 510: my ($othertitle,$usertypes,$types) =
511: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 512: $js .= &lonbalance_targets_js($dom,$types,\%servers,
513: $domconfig{'loadbalancing'}).
1.170 raeburn 514: &new_spares_js().
515: &common_domprefs_js().
516: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 517: }
1.216 raeburn 518: if (grep(/^requestcourses$/,@actions)) {
519: my $javascript_validations;
520: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
521: $js .= <<END;
522: <script type="text/javascript">
523: $javascript_validations
524: </script>
525: $coursebrowserjs
526: END
527: }
1.150 raeburn 528: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 529: } else {
1.180 raeburn 530: # check if domconfig user exists for the domain.
531: my $servadm = $r->dir_config('lonAdmEMail');
532: my ($configuserok,$author_ok,$switchserver) =
533: &config_check($dom,$confname,$servadm);
534: unless ($configuserok eq 'ok') {
1.181 raeburn 535: &Apache::lonconfigsettings::print_header($r,$phase,$context);
536: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 537: $confname).
1.181 raeburn 538: '<br />'
539: );
1.180 raeburn 540: if ($switchserver) {
1.181 raeburn 541: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
542: '<br />'.
543: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
544: '<br />'.
545: &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).
546: '<br />'.
547: &mt('To do that now, use the following link: [_1]',$switchserver)
548: );
549: } else {
550: $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.').
551: '<br />'.
552: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
553: );
1.180 raeburn 554: }
555: $r->print(&Apache::loncommon::end_page());
556: return OK;
557: }
1.21 raeburn 558: if (keys(%domconfig) == 0) {
559: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 560: my @ids=&Apache::lonnet::current_machine_ids();
561: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 562: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 563: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 564: my $custom_img_count = 0;
565: foreach my $img (@loginimages) {
566: if ($designhash{$dom.'.login.'.$img} ne '') {
567: $custom_img_count ++;
568: }
569: }
570: foreach my $role (@roles) {
571: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
572: $custom_img_count ++;
573: }
574: }
575: if ($custom_img_count > 0) {
1.94 raeburn 576: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 577: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 578: $r->print(
579: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
580: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
581: &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 />'.
582: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
583: if ($switch_server) {
1.30 raeburn 584: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 585: }
1.91 raeburn 586: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 587: return OK;
588: }
589: }
590: }
1.91 raeburn 591: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 592: }
593: return OK;
594: }
595:
596: sub process_changes {
1.205 raeburn 597: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 598: my %domconfig;
599: if (ref($values) eq 'HASH') {
600: %domconfig = %{$values};
601: }
1.3 raeburn 602: my $output;
603: if ($action eq 'login') {
1.205 raeburn 604: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 605: } elsif ($action eq 'rolecolors') {
1.9 raeburn 606: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 607: $lastactref,%domconfig);
1.3 raeburn 608: } elsif ($action eq 'quotas') {
1.216 raeburn 609: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 610: } elsif ($action eq 'autoenroll') {
1.205 raeburn 611: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 612: } elsif ($action eq 'autoupdate') {
613: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 614: } elsif ($action eq 'autocreate') {
615: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 616: } elsif ($action eq 'directorysrch') {
617: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 618: } elsif ($action eq 'usercreation') {
1.28 raeburn 619: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 620: } elsif ($action eq 'selfcreation') {
621: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 622: } elsif ($action eq 'usermodification') {
623: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 624: } elsif ($action eq 'contacts') {
1.205 raeburn 625: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 626: } elsif ($action eq 'defaults') {
1.212 raeburn 627: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 628: } elsif ($action eq 'scantron') {
1.205 raeburn 629: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 630: } elsif ($action eq 'coursecategories') {
1.239 raeburn 631: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 632: } elsif ($action eq 'serverstatuses') {
633: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 634: } elsif ($action eq 'requestcourses') {
1.216 raeburn 635: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 636: } elsif ($action eq 'requestauthor') {
1.216 raeburn 637: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 638: } elsif ($action eq 'helpsettings') {
1.122 jms 639: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 640: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 641: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 642: } elsif ($action eq 'selfenrollment') {
643: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 644: } elsif ($action eq 'usersessions') {
1.212 raeburn 645: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 646: } elsif ($action eq 'loadbalancing') {
647: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 648: }
649: return $output;
650: }
651:
652: sub print_config_box {
1.9 raeburn 653: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 654: my $rowtotal = 0;
1.49 raeburn 655: my $output;
656: if ($action eq 'coursecategories') {
657: $output = &coursecategories_javascript($settings);
1.236 raeburn 658: } elsif ($action eq 'defaults') {
659: $output = &defaults_javascript($settings);
1.91 raeburn 660: }
1.236 raeburn 661: $output .=
1.30 raeburn 662: '<table class="LC_nested_outer">
1.3 raeburn 663: <tr>
1.66 raeburn 664: <th align="left" valign="middle"><span class="LC_nobreak">'.
665: &mt($item->{text}).' '.
666: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
667: '</tr>';
1.30 raeburn 668: $rowtotal ++;
1.110 raeburn 669: my $numheaders = 1;
670: if (ref($item->{'header'}) eq 'ARRAY') {
671: $numheaders = scalar(@{$item->{'header'}});
672: }
673: if ($numheaders > 1) {
1.64 raeburn 674: my $colspan = '';
1.145 raeburn 675: my $rightcolspan = '';
1.238 raeburn 676: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.256 raeburn 677: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 678: $colspan = ' colspan="2"';
679: }
1.145 raeburn 680: if ($action eq 'usersessions') {
681: $rightcolspan = ' colspan="3"';
682: }
1.30 raeburn 683: $output .= '
1.3 raeburn 684: <tr>
685: <td>
686: <table class="LC_nested">
687: <tr class="LC_info_row">
1.59 bisitz 688: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 689: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 690: </tr>';
1.69 raeburn 691: $rowtotal ++;
1.230 raeburn 692: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 693: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230 raeburn 694: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
695: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 696: } elsif ($action eq 'coursecategories') {
1.230 raeburn 697: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 698: } elsif ($action eq 'login') {
1.256 raeburn 699: if ($numheaders == 4) {
1.168 raeburn 700: $colspan = ' colspan="2"';
701: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
702: } else {
703: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
704: }
1.230 raeburn 705: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 706: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 707: } elsif ($action eq 'rolecolors') {
1.30 raeburn 708: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 709: }
1.30 raeburn 710: $output .= '
1.6 raeburn 711: </table>
712: </td>
713: </tr>
714: <tr>
715: <td>
716: <table class="LC_nested">
717: <tr class="LC_info_row">
1.230 raeburn 718: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 719: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 720: </tr>';
721: $rowtotal ++;
1.230 raeburn 722: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
723: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238 raeburn 724: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
725: if ($action eq 'coursecategories') {
726: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
727: $colspan = ' colspan="2"';
728: } else {
729: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
730: }
731: $output .= '
1.63 raeburn 732: </table>
733: </td>
734: </tr>
735: <tr>
736: <td>
737: <table class="LC_nested">
738: <tr class="LC_info_row">
739: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 740: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 741: </tr>'."\n";
742: if ($action eq 'coursecategories') {
743: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
744: } else {
745: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
746: }
1.63 raeburn 747: $rowtotal ++;
1.236 raeburn 748: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
749: ($action eq 'defaults')) {
1.230 raeburn 750: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 751: } elsif ($action eq 'login') {
1.256 raeburn 752: if ($numheaders == 4) {
1.168 raeburn 753: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
754: </table>
755: </td>
756: </tr>
757: <tr>
758: <td>
759: <table class="LC_nested">
760: <tr class="LC_info_row">
761: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 762: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 763: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
764: $rowtotal ++;
765: } else {
766: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
767: }
1.256 raeburn 768: $output .= '
769: </table>
770: </td>
771: </tr>
772: <tr>
773: <td>
774: <table class="LC_nested">
775: <tr class="LC_info_row">';
776: if ($numheaders == 4) {
777: $output .= '
778: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
779: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
780: </tr>';
781: } else {
782: $output .= '
783: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
784: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
785: </tr>';
786: }
787: $rowtotal ++;
788: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 789: } elsif ($action eq 'requestcourses') {
1.247 raeburn 790: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
791: $rowtotal ++;
792: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 793: </table>
794: </td>
795: </tr>
796: <tr>
797: <td>
798: <table class="LC_nested">
799: <tr class="LC_info_row">
800: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
801: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 802: &textbookcourses_javascript($settings).
803: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
804: </table>
805: </td>
806: </tr>
807: <tr>
808: <td>
809: <table class="LC_nested">
810: <tr class="LC_info_row">
811: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
812: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
813: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 814: </table>
815: </td>
816: </tr>
817: <tr>
818: <td>
819: <table class="LC_nested">
820: <tr class="LC_info_row">
1.242 raeburn 821: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
822: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 823: </tr>'.
824: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 825: } elsif ($action eq 'requestauthor') {
826: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 827: $rowtotal ++;
1.122 jms 828: } elsif ($action eq 'rolecolors') {
1.30 raeburn 829: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
1.69 raeburn 837: <td class="LC_left_item"'.$colspan.' valign="top">'.
838: &mt($item->{'header'}->[2]->{'col1'}).'</td>
839: <td class="LC_right_item" valign="top">'.
840: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 841: </tr>'.
1.30 raeburn 842: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
1.59 bisitz 850: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
851: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 852: </tr>'.
1.30 raeburn 853: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
854: $rowtotal += 2;
1.6 raeburn 855: }
1.3 raeburn 856: } else {
1.30 raeburn 857: $output .= '
1.3 raeburn 858: <tr>
859: <td>
860: <table class="LC_nested">
1.30 raeburn 861: <tr class="LC_info_row">';
1.24 raeburn 862: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 863: $output .= '
1.59 bisitz 864: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 865: } elsif ($action eq 'serverstatuses') {
866: $output .= '
867: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
868: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
869:
1.6 raeburn 870: } else {
1.30 raeburn 871: $output .= '
1.69 raeburn 872: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
873: }
1.72 raeburn 874: if (defined($item->{'header'}->[0]->{'col3'})) {
875: $output .= '<td class="LC_left_item" valign="top">'.
876: &mt($item->{'header'}->[0]->{'col2'});
877: if ($action eq 'serverstatuses') {
878: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
879: }
1.69 raeburn 880: } else {
881: $output .= '<td class="LC_right_item" valign="top">'.
882: &mt($item->{'header'}->[0]->{'col2'});
883: }
884: $output .= '</td>';
885: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 886: if (defined($item->{'header'}->[0]->{'col4'})) {
887: $output .= '<td class="LC_left_item" valign="top">'.
888: &mt($item->{'header'}->[0]->{'col3'});
889: } else {
890: $output .= '<td class="LC_right_item" valign="top">'.
891: &mt($item->{'header'}->[0]->{'col3'});
892: }
1.69 raeburn 893: if ($action eq 'serverstatuses') {
894: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
895: }
896: $output .= '</td>';
1.6 raeburn 897: }
1.150 raeburn 898: if ($item->{'header'}->[0]->{'col4'}) {
899: $output .= '<td class="LC_right_item" valign="top">'.
900: &mt($item->{'header'}->[0]->{'col4'});
901: }
1.69 raeburn 902: $output .= '</tr>';
1.48 raeburn 903: $rowtotal ++;
1.168 raeburn 904: if ($action eq 'quotas') {
1.86 raeburn 905: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 906: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.236 raeburn 907: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.230 raeburn 908: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 909: } elsif ($action eq 'scantron') {
910: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 911: } elsif ($action eq 'helpsettings') {
1.168 raeburn 912: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 913: }
1.3 raeburn 914: }
1.30 raeburn 915: $output .= '
1.3 raeburn 916: </table>
917: </td>
918: </tr>
1.30 raeburn 919: </table><br />';
920: return ($output,$rowtotal);
1.1 raeburn 921: }
922:
1.3 raeburn 923: sub print_login {
1.168 raeburn 924: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 925: my ($css_class,$datatable);
1.6 raeburn 926: my %choices = &login_choices();
1.110 raeburn 927:
1.168 raeburn 928: if ($caller eq 'service') {
1.149 raeburn 929: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 930: my $choice = $choices{'disallowlogin'};
931: $css_class = ' class="LC_odd_row"';
1.128 raeburn 932: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 933: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 934: '<th>'.$choices{'server'}.'</th>'.
935: '<th>'.$choices{'serverpath'}.'</th>'.
936: '<th>'.$choices{'custompath'}.'</th>'.
937: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 938: my %disallowed;
939: if (ref($settings) eq 'HASH') {
940: if (ref($settings->{'loginvia'}) eq 'HASH') {
941: %disallowed = %{$settings->{'loginvia'}};
942: }
943: }
944: foreach my $lonhost (sort(keys(%servers))) {
945: my $direct = 'selected="selected"';
1.128 raeburn 946: if (ref($disallowed{$lonhost}) eq 'HASH') {
947: if ($disallowed{$lonhost}{'server'} ne '') {
948: $direct = '';
949: }
1.110 raeburn 950: }
1.115 raeburn 951: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 952: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 953: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
954: '</option>';
1.184 raeburn 955: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 956: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 957: my $selected = '';
1.128 raeburn 958: if (ref($disallowed{$lonhost}) eq 'HASH') {
959: if ($hostid eq $disallowed{$lonhost}{'server'}) {
960: $selected = 'selected="selected"';
961: }
1.110 raeburn 962: }
963: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
964: $servers{$hostid}.'</option>';
965: }
1.128 raeburn 966: $datatable .= '</select></td>'.
967: '<td><select name="'.$lonhost.'_serverpath">';
968: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
969: my $pathname = $path;
970: if ($path eq 'custom') {
971: $pathname = &mt('Custom Path').' ->';
972: }
973: my $selected = '';
974: if (ref($disallowed{$lonhost}) eq 'HASH') {
975: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
976: $selected = 'selected="selected"';
977: }
978: } elsif ($path eq '') {
979: $selected = 'selected="selected"';
980: }
981: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
982: }
983: $datatable .= '</select></td>';
984: my ($custom,$exempt);
985: if (ref($disallowed{$lonhost}) eq 'HASH') {
986: $custom = $disallowed{$lonhost}{'custompath'};
987: $exempt = $disallowed{$lonhost}{'exempt'};
988: }
989: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
990: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
991: '</tr>';
1.110 raeburn 992: }
993: $datatable .= '</table></td></tr>';
994: return $datatable;
1.168 raeburn 995: } elsif ($caller eq 'page') {
996: my %defaultchecked = (
997: 'coursecatalog' => 'on',
1.188 raeburn 998: 'helpdesk' => 'on',
1.168 raeburn 999: 'adminmail' => 'off',
1000: 'newuser' => 'off',
1001: );
1.188 raeburn 1002: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1003: my (%checkedon,%checkedoff);
1.42 raeburn 1004: foreach my $item (@toggles) {
1.168 raeburn 1005: if ($defaultchecked{$item} eq 'on') {
1006: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1007: $checkedoff{$item} = ' ';
1.168 raeburn 1008: } elsif ($defaultchecked{$item} eq 'off') {
1009: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1010: $checkedon{$item} = ' ';
1011: }
1.1 raeburn 1012: }
1.168 raeburn 1013: my @images = ('img','logo','domlogo','login');
1014: my @logintext = ('textcol','bgcol');
1015: my @bgs = ('pgbg','mainbg','sidebg');
1016: my @links = ('link','alink','vlink');
1017: my %designhash = &Apache::loncommon::get_domainconf($dom);
1018: my %defaultdesign = %Apache::loncommon::defaultdesign;
1019: my (%is_custom,%designs);
1020: my %defaults = (
1021: font => $defaultdesign{'login.font'},
1022: );
1.6 raeburn 1023: foreach my $item (@images) {
1.168 raeburn 1024: $defaults{$item} = $defaultdesign{'login.'.$item};
1025: $defaults{'showlogo'}{$item} = 1;
1026: }
1027: foreach my $item (@bgs) {
1028: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1029: }
1.41 raeburn 1030: foreach my $item (@logintext) {
1.168 raeburn 1031: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1032: }
1.168 raeburn 1033: foreach my $item (@links) {
1034: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1035: }
1.168 raeburn 1036: if (ref($settings) eq 'HASH') {
1037: foreach my $item (@toggles) {
1038: if ($settings->{$item} eq '1') {
1039: $checkedon{$item} = ' checked="checked" ';
1040: $checkedoff{$item} = ' ';
1041: } elsif ($settings->{$item} eq '0') {
1042: $checkedoff{$item} = ' checked="checked" ';
1043: $checkedon{$item} = ' ';
1044: }
1045: }
1046: foreach my $item (@images) {
1047: if (defined($settings->{$item})) {
1048: $designs{$item} = $settings->{$item};
1049: $is_custom{$item} = 1;
1050: }
1051: if (defined($settings->{'showlogo'}{$item})) {
1052: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1053: }
1054: }
1055: foreach my $item (@logintext) {
1056: if ($settings->{$item} ne '') {
1057: $designs{'logintext'}{$item} = $settings->{$item};
1058: $is_custom{$item} = 1;
1059: }
1060: }
1061: if ($settings->{'font'} ne '') {
1062: $designs{'font'} = $settings->{'font'};
1063: $is_custom{'font'} = 1;
1064: }
1065: foreach my $item (@bgs) {
1066: if ($settings->{$item} ne '') {
1067: $designs{'bgs'}{$item} = $settings->{$item};
1068: $is_custom{$item} = 1;
1069: }
1070: }
1071: foreach my $item (@links) {
1072: if ($settings->{$item} ne '') {
1073: $designs{'links'}{$item} = $settings->{$item};
1074: $is_custom{$item} = 1;
1075: }
1076: }
1077: } else {
1078: if ($designhash{$dom.'.login.font'} ne '') {
1079: $designs{'font'} = $designhash{$dom.'.login.font'};
1080: $is_custom{'font'} = 1;
1081: }
1082: foreach my $item (@images) {
1083: if ($designhash{$dom.'.login.'.$item} ne '') {
1084: $designs{$item} = $designhash{$dom.'.login.'.$item};
1085: $is_custom{$item} = 1;
1086: }
1087: }
1088: foreach my $item (@bgs) {
1089: if ($designhash{$dom.'.login.'.$item} ne '') {
1090: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1091: $is_custom{$item} = 1;
1092: }
1.6 raeburn 1093: }
1.168 raeburn 1094: foreach my $item (@links) {
1095: if ($designhash{$dom.'.login.'.$item} ne '') {
1096: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1097: $is_custom{$item} = 1;
1098: }
1.6 raeburn 1099: }
1100: }
1.168 raeburn 1101: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1102: logo => 'Institution Logo',
1103: domlogo => 'Domain Logo',
1104: login => 'Login box');
1105: my $itemcount = 1;
1106: foreach my $item (@toggles) {
1107: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1108: $datatable .=
1109: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1110: '</td><td>'.
1111: '<span class="LC_nobreak"><label><input type="radio" name="'.
1112: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1113: '</label> <label><input type="radio" name="'.$item.'"'.
1114: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1115: '</tr>';
1116: $itemcount ++;
1.6 raeburn 1117: }
1.168 raeburn 1118: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1119: $datatable .= '</tr></table></td></tr>';
1120: } elsif ($caller eq 'help') {
1121: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1122: my $switchserver = &check_switchserver($dom,$confname);
1123: my $itemcount = 1;
1124: $defaulturl = '/adm/loginproblems.html';
1125: $defaulttype = 'default';
1126: %lt = &Apache::lonlocal::texthash (
1127: del => 'Delete?',
1128: rep => 'Replace:',
1129: upl => 'Upload:',
1130: default => 'Default',
1131: custom => 'Custom',
1132: );
1133: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1134: my @currlangs;
1135: if (ref($settings) eq 'HASH') {
1136: if (ref($settings->{'helpurl'}) eq 'HASH') {
1137: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1138: next if ($settings->{'helpurl'}{$key} eq '');
1139: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1140: $type{$key} = 'custom';
1141: unless ($key eq 'nolang') {
1142: push(@currlangs,$key);
1143: }
1144: }
1145: } elsif ($settings->{'helpurl'} ne '') {
1146: $type{'nolang'} = 'custom';
1147: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1148: }
1149: }
1.168 raeburn 1150: foreach my $lang ('nolang',sort(@currlangs)) {
1151: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1152: $datatable .= '<tr'.$css_class.'>';
1153: if ($url{$lang} eq '') {
1154: $url{$lang} = $defaulturl;
1155: }
1156: if ($type{$lang} eq '') {
1157: $type{$lang} = $defaulttype;
1158: }
1159: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1160: if ($lang eq 'nolang') {
1161: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1162: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1163: } else {
1164: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1165: $langchoices{$lang},
1166: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1167: }
1168: $datatable .= '</span></td>'."\n".
1169: '<td class="LC_left_item">';
1170: if ($type{$lang} eq 'custom') {
1171: $datatable .= '<span class="LC_nobreak"><label>'.
1172: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1173: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1174: } else {
1175: $datatable .= $lt{'upl'};
1176: }
1177: $datatable .='<br />';
1178: if ($switchserver) {
1179: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1180: } else {
1181: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1182: }
1.168 raeburn 1183: $datatable .= '</td></tr>';
1184: $itemcount ++;
1.6 raeburn 1185: }
1.168 raeburn 1186: my @addlangs;
1187: foreach my $lang (sort(keys(%langchoices))) {
1188: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1189: push(@addlangs,$lang);
1190: }
1191: if (@addlangs > 0) {
1192: my %toadd;
1193: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1194: $toadd{''} = &mt('Select');
1195: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1196: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1197: &mt('Add log-in help page for a specific language:').' '.
1198: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1199: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1200: if ($switchserver) {
1201: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1202: } else {
1203: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1204: }
1.168 raeburn 1205: $datatable .= '</td></tr>';
1.169 raeburn 1206: $itemcount ++;
1.6 raeburn 1207: }
1.169 raeburn 1208: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1209: } elsif ($caller eq 'headtag') {
1210: my %domservers = &Apache::lonnet::get_servers($dom);
1211: my $choice = $choices{'headtag'};
1212: $css_class = ' class="LC_odd_row"';
1213: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1214: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1215: '<th>'.$choices{'current'}.'</th>'.
1216: '<th>'.$choices{'action'}.'</th>'.
1217: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1218: my (%currurls,%currexempt);
1219: if (ref($settings) eq 'HASH') {
1220: if (ref($settings->{'headtag'}) eq 'HASH') {
1221: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1222: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1223: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1224: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1225: }
1226: }
1227: }
1228: }
1229: my %lt = &Apache::lonlocal::texthash(
1230: del => 'Delete?',
1231: rep => 'Replace:',
1232: upl => 'Upload:',
1233: curr => 'View contents',
1234: none => 'None',
1235: );
1236: my $switchserver = &check_switchserver($dom,$confname);
1237: foreach my $lonhost (sort(keys(%domservers))) {
1238: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1239: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1240: if ($currurls{$lonhost}) {
1241: $datatable .= '<td class="LC_right_item"><a href="'.
1242: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1243: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1244: '">'.$lt{'curr'}.'</a></td>'.
1245: '<td><span class="LC_nobreak"><label>'.
1246: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1247: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1248: } else {
1249: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1250: }
1251: $datatable .='<br />';
1252: if ($switchserver) {
1253: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1254: } else {
1255: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1256: }
1257: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1258: }
1259: $datatable .= '</table></td></tr>';
1.1 raeburn 1260: }
1.6 raeburn 1261: return $datatable;
1262: }
1263:
1264: sub login_choices {
1265: my %choices =
1266: &Apache::lonlocal::texthash (
1.116 bisitz 1267: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1268: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1269: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1270: disallowlogin => "Login page requests redirected",
1271: hostid => "Server",
1.128 raeburn 1272: server => "Redirect to:",
1273: serverpath => "Path",
1274: custompath => "Custom",
1275: exempt => "Exempt IP(s)",
1.110 raeburn 1276: directlogin => "No redirect",
1277: newuser => "Link to create a user account",
1278: img => "Header",
1279: logo => "Main Logo",
1280: domlogo => "Domain Logo",
1281: login => "Log-in Header",
1282: textcol => "Text color",
1283: bgcol => "Box color",
1284: bgs => "Background colors",
1285: links => "Link colors",
1286: font => "Font color",
1287: pgbg => "Header",
1288: mainbg => "Page",
1289: sidebg => "Login box",
1290: link => "Link",
1291: alink => "Active link",
1292: vlink => "Visited link",
1.256 raeburn 1293: headtag => "Custom markup",
1294: action => "Action",
1295: current => "Current",
1.6 raeburn 1296: );
1297: return %choices;
1298: }
1299:
1300: sub print_rolecolors {
1.30 raeburn 1301: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1302: my %choices = &color_font_choices();
1303: my @bgs = ('pgbg','tabbg','sidebg');
1304: my @links = ('link','alink','vlink');
1305: my @images = ('img');
1306: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1307: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1308: my %defaultdesign = %Apache::loncommon::defaultdesign;
1309: my (%is_custom,%designs);
1.200 raeburn 1310: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1311: if (ref($settings) eq 'HASH') {
1312: if (ref($settings->{$role}) eq 'HASH') {
1313: if ($settings->{$role}->{'img'} ne '') {
1314: $designs{'img'} = $settings->{$role}->{'img'};
1315: $is_custom{'img'} = 1;
1316: }
1317: if ($settings->{$role}->{'font'} ne '') {
1318: $designs{'font'} = $settings->{$role}->{'font'};
1319: $is_custom{'font'} = 1;
1320: }
1.97 tempelho 1321: if ($settings->{$role}->{'fontmenu'} ne '') {
1322: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1323: $is_custom{'fontmenu'} = 1;
1324: }
1.6 raeburn 1325: foreach my $item (@bgs) {
1326: if ($settings->{$role}->{$item} ne '') {
1327: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1328: $is_custom{$item} = 1;
1329: }
1330: }
1331: foreach my $item (@links) {
1332: if ($settings->{$role}->{$item} ne '') {
1333: $designs{'links'}{$item} = $settings->{$role}->{$item};
1334: $is_custom{$item} = 1;
1335: }
1336: }
1337: }
1338: } else {
1339: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1340: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1341: $is_custom{'img'} = 1;
1342: }
1.97 tempelho 1343: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1344: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1345: $is_custom{'fontmenu'} = 1;
1346: }
1.6 raeburn 1347: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1348: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1349: $is_custom{'font'} = 1;
1350: }
1351: foreach my $item (@bgs) {
1352: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1353: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1354: $is_custom{$item} = 1;
1355:
1356: }
1357: }
1358: foreach my $item (@links) {
1359: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1360: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1361: $is_custom{$item} = 1;
1362: }
1363: }
1364: }
1365: my $itemcount = 1;
1.30 raeburn 1366: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1367: $datatable .= '</tr></table></td></tr>';
1368: return $datatable;
1369: }
1370:
1.200 raeburn 1371: sub role_defaults {
1372: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1373: my %defaults;
1374: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1375: return %defaults;
1376: }
1377: my %defaultdesign = %Apache::loncommon::defaultdesign;
1378: if ($role eq 'login') {
1379: %defaults = (
1380: font => $defaultdesign{$role.'.font'},
1381: );
1382: if (ref($logintext) eq 'ARRAY') {
1383: foreach my $item (@{$logintext}) {
1384: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1385: }
1386: }
1387: foreach my $item (@{$images}) {
1388: $defaults{'showlogo'}{$item} = 1;
1389: }
1390: } else {
1391: %defaults = (
1392: img => $defaultdesign{$role.'.img'},
1393: font => $defaultdesign{$role.'.font'},
1394: fontmenu => $defaultdesign{$role.'.fontmenu'},
1395: );
1396: }
1397: foreach my $item (@{$bgs}) {
1398: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1399: }
1400: foreach my $item (@{$links}) {
1401: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1402: }
1403: foreach my $item (@{$images}) {
1404: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1405: }
1406: return %defaults;
1407: }
1408:
1.6 raeburn 1409: sub display_color_options {
1.9 raeburn 1410: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1411: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1412: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1413: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1414: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1415: '<td>'.$choices->{'font'}.'</td>';
1416: if (!$is_custom->{'font'}) {
1.30 raeburn 1417: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1418: } else {
1419: $datatable .= '<td> </td>';
1420: }
1.174 foxr 1421: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1422:
1.8 raeburn 1423: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1424: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1425: ' value="'.$current_color.'" /> '.
1.174 foxr 1426: ' </td></tr>';
1.107 raeburn 1427: unless ($role eq 'login') {
1428: $datatable .= '<tr'.$css_class.'>'.
1429: '<td>'.$choices->{'fontmenu'}.'</td>';
1430: if (!$is_custom->{'fontmenu'}) {
1431: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1432: } else {
1433: $datatable .= '<td> </td>';
1434: }
1.202 raeburn 1435: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1436: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1437: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1438: '<input class="colorchooser" type="text" size="10" name="'
1439: .$role.'_fontmenu"'.
1440: ' value="'.$current_color.'" /> '.
1441: ' </td></tr>';
1.97 tempelho 1442: }
1.9 raeburn 1443: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1444: foreach my $img (@{$images}) {
1.18 albertel 1445: $itemcount ++;
1.6 raeburn 1446: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1447: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1448: '<td>'.$choices->{$img};
1.41 raeburn 1449: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1450: if ($role eq 'login') {
1451: if ($img eq 'login') {
1452: $login_hdr_pick =
1.135 bisitz 1453: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1454: $logincolors =
1455: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1456: $designs,$defaults);
1.70 raeburn 1457: } elsif ($img ne 'domlogo') {
1458: $datatable.= &logo_display_options($img,$defaults,$designs);
1459: }
1460: }
1461: $datatable .= '</td>';
1.6 raeburn 1462: if ($designs->{$img} ne '') {
1463: $imgfile = $designs->{$img};
1.18 albertel 1464: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1465: } else {
1466: $imgfile = $defaults->{$img};
1467: }
1468: if ($imgfile) {
1.9 raeburn 1469: my ($showfile,$fullsize);
1470: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1471: my $urldir = $1;
1472: my $filename = $2;
1473: my @info = &Apache::lonnet::stat_file($designs->{$img});
1474: if (@info) {
1475: my $thumbfile = 'tn-'.$filename;
1476: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1477: if (@thumb) {
1478: $showfile = $urldir.'/'.$thumbfile;
1479: } else {
1480: $showfile = $imgfile;
1481: }
1482: } else {
1483: $showfile = '';
1484: }
1485: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1486: $showfile = $imgfile;
1.6 raeburn 1487: my $imgdir = $1;
1488: my $filename = $2;
1.159 raeburn 1489: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1490: $showfile = "/$imgdir/tn-".$filename;
1491: } else {
1.159 raeburn 1492: my $input = $londocroot.$imgfile;
1493: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1494: if (!-e $output) {
1.9 raeburn 1495: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1496: my ($fullwidth,$fullheight) = &check_dimensions($input);
1497: if ($fullwidth ne '' && $fullheight ne '') {
1498: if ($fullwidth > $width && $fullheight > $height) {
1499: my $size = $width.'x'.$height;
1500: system("convert -sample $size $input $output");
1.159 raeburn 1501: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1502: }
1503: }
1.6 raeburn 1504: }
1505: }
1.16 raeburn 1506: }
1.6 raeburn 1507: if ($showfile) {
1.40 raeburn 1508: if ($showfile =~ m{^/(adm|res)/}) {
1509: if ($showfile =~ m{^/res/}) {
1510: my $local_showfile =
1511: &Apache::lonnet::filelocation('',$showfile);
1512: &Apache::lonnet::repcopy($local_showfile);
1513: }
1514: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1515: }
1516: if ($imgfile) {
1517: if ($imgfile =~ m{^/(adm|res)/}) {
1518: if ($imgfile =~ m{^/res/}) {
1519: my $local_imgfile =
1520: &Apache::lonnet::filelocation('',$imgfile);
1521: &Apache::lonnet::repcopy($local_imgfile);
1522: }
1523: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1524: } else {
1525: $fullsize = $imgfile;
1526: }
1527: }
1.41 raeburn 1528: $datatable .= '<td>';
1529: if ($img eq 'login') {
1.135 bisitz 1530: $datatable .= $login_hdr_pick;
1531: }
1.41 raeburn 1532: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1533: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1534: } else {
1.201 raeburn 1535: $datatable .= '<td> </td><td class="LC_left_item">'.
1536: &mt('Upload:').'<br />';
1.6 raeburn 1537: }
1538: } else {
1.201 raeburn 1539: $datatable .= '<td> </td><td class="LC_left_item">'.
1540: &mt('Upload:').'<br />';
1.6 raeburn 1541: }
1.9 raeburn 1542: if ($switchserver) {
1543: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1544: } else {
1.135 bisitz 1545: if ($img ne 'login') { # suppress file selection for Log-in header
1546: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1547: }
1.9 raeburn 1548: }
1549: $datatable .= '</td></tr>';
1.6 raeburn 1550: }
1551: $itemcount ++;
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .= '<tr'.$css_class.'>'.
1554: '<td>'.$choices->{'bgs'}.'</td>';
1555: my $bgs_def;
1556: foreach my $item (@{$bgs}) {
1557: if (!$is_custom->{$item}) {
1.70 raeburn 1558: $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 1559: }
1560: }
1561: if ($bgs_def) {
1.8 raeburn 1562: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1563: } else {
1564: $datatable .= '<td> </td>';
1565: }
1566: $datatable .= '<td class="LC_right_item">'.
1567: '<table border="0"><tr>';
1.174 foxr 1568:
1.6 raeburn 1569: foreach my $item (@{$bgs}) {
1.201 raeburn 1570: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1571: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1572: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1573: $datatable .= ' ';
1.6 raeburn 1574: }
1.174 foxr 1575: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1576: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1577: }
1578: $datatable .= '</tr></table></td></tr>';
1579: $itemcount ++;
1580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1581: $datatable .= '<tr'.$css_class.'>'.
1582: '<td>'.$choices->{'links'}.'</td>';
1583: my $links_def;
1584: foreach my $item (@{$links}) {
1585: if (!$is_custom->{$item}) {
1.30 raeburn 1586: $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 1587: }
1588: }
1589: if ($links_def) {
1.8 raeburn 1590: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1594: $datatable .= '<td class="LC_right_item">'.
1595: '<table border="0"><tr>';
1596: foreach my $item (@{$links}) {
1.234 raeburn 1597: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1598: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1599: if ($designs->{'links'}{$item}) {
1.174 foxr 1600: $datatable.=' ';
1.6 raeburn 1601: }
1.174 foxr 1602: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1603: '" /></td>';
1604: }
1.30 raeburn 1605: $$rowtotal += $itemcount;
1.3 raeburn 1606: return $datatable;
1607: }
1608:
1.70 raeburn 1609: sub logo_display_options {
1610: my ($img,$defaults,$designs) = @_;
1611: my $checkedon;
1612: if (ref($defaults) eq 'HASH') {
1613: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1614: if ($defaults->{'showlogo'}{$img}) {
1615: $checkedon = 'checked="checked" ';
1616: }
1617: }
1618: }
1619: if (ref($designs) eq 'HASH') {
1620: if (ref($designs->{'showlogo'}) eq 'HASH') {
1621: if (defined($designs->{'showlogo'}{$img})) {
1622: if ($designs->{'showlogo'}{$img} == 0) {
1623: $checkedon = '';
1624: } elsif ($designs->{'showlogo'}{$img} == 1) {
1625: $checkedon = 'checked="checked" ';
1626: }
1627: }
1628: }
1629: }
1630: return '<br /><label> <input type="checkbox" name="'.
1631: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1632: &mt('show').'</label>'."\n";
1633: }
1634:
1.41 raeburn 1635: sub login_header_options {
1.135 bisitz 1636: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1637: my $output = '';
1.41 raeburn 1638: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1639: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1640: if (!$is_custom->{'textcol'}) {
1641: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1642: ' ';
1643: }
1644: if (!$is_custom->{'bgcol'}) {
1645: $output .= $choices->{'bgcol'}.': '.
1646: '<span id="css_'.$role.'_font" style="background-color: '.
1647: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1648: }
1649: $output .= '<br />';
1650: }
1651: $output .='<br />';
1652: return $output;
1653: }
1654:
1655: sub login_text_colors {
1.201 raeburn 1656: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1657: my $color_menu = '<table border="0"><tr>';
1658: foreach my $item (@{$logintext}) {
1.201 raeburn 1659: $color_menu .= '<td align="center">'.$choices->{$item};
1660: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1661: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1662: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1663: }
1664: $color_menu .= '</tr></table><br />';
1665: return $color_menu;
1666: }
1667:
1668: sub image_changes {
1669: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1670: my $output;
1.135 bisitz 1671: if ($img eq 'login') {
1672: # suppress image for Log-in header
1673: } elsif (!$is_custom) {
1.70 raeburn 1674: if ($img ne 'domlogo') {
1.41 raeburn 1675: $output .= &mt('Default image:').'<br />';
1676: } else {
1677: $output .= &mt('Default in use:').'<br />';
1678: }
1679: }
1.135 bisitz 1680: if ($img eq 'login') { # suppress image for Log-in header
1681: $output .= '<td>'.$logincolors;
1.41 raeburn 1682: } else {
1.135 bisitz 1683: if ($img_import) {
1684: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1685: }
1686: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1687: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1688: if ($is_custom) {
1689: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1690: '<input type="checkbox" name="'.
1691: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1692: '</label> '.&mt('Replace:').'</span><br />';
1693: } else {
1.201 raeburn 1694: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1695: }
1.41 raeburn 1696: }
1697: return $output;
1698: }
1699:
1.3 raeburn 1700: sub print_quotas {
1.86 raeburn 1701: my ($dom,$settings,$rowtotal,$action) = @_;
1702: my $context;
1703: if ($action eq 'quotas') {
1704: $context = 'tools';
1705: } else {
1706: $context = $action;
1707: }
1.197 raeburn 1708: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1709: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1710: my $typecount = 0;
1.101 raeburn 1711: my ($css_class,%titles);
1.86 raeburn 1712: if ($context eq 'requestcourses') {
1.216 raeburn 1713: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1714: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1715: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1716: %titles = &courserequest_titles();
1.163 raeburn 1717: } elsif ($context eq 'requestauthor') {
1718: @usertools = ('author');
1719: @options = ('norequest','approval','automatic');
1.210 raeburn 1720: %titles = &authorrequest_titles();
1.86 raeburn 1721: } else {
1.162 raeburn 1722: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1723: %titles = &tool_titles();
1.86 raeburn 1724: }
1.26 raeburn 1725: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1726: foreach my $type (@{$types}) {
1.197 raeburn 1727: my ($currdefquota,$currauthorquota);
1.163 raeburn 1728: unless (($context eq 'requestcourses') ||
1729: ($context eq 'requestauthor')) {
1.86 raeburn 1730: if (ref($settings) eq 'HASH') {
1731: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1732: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1733: } else {
1734: $currdefquota = $settings->{$type};
1735: }
1.197 raeburn 1736: if (ref($settings->{authorquota}) eq 'HASH') {
1737: $currauthorquota = $settings->{authorquota}->{$type};
1738: }
1.78 raeburn 1739: }
1.72 raeburn 1740: }
1.3 raeburn 1741: if (defined($usertypes->{$type})) {
1742: $typecount ++;
1743: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1744: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1745: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1746: '<td class="LC_left_item">';
1.101 raeburn 1747: if ($context eq 'requestcourses') {
1748: $datatable .= '<table><tr>';
1749: }
1750: my %cell;
1.72 raeburn 1751: foreach my $item (@usertools) {
1.101 raeburn 1752: if ($context eq 'requestcourses') {
1753: my ($curroption,$currlimit);
1754: if (ref($settings) eq 'HASH') {
1755: if (ref($settings->{$item}) eq 'HASH') {
1756: $curroption = $settings->{$item}->{$type};
1757: if ($curroption =~ /^autolimit=(\d*)$/) {
1758: $currlimit = $1;
1759: }
1760: }
1761: }
1762: if (!$curroption) {
1763: $curroption = 'norequest';
1764: }
1765: $datatable .= '<th>'.$titles{$item}.'</th>';
1766: foreach my $option (@options) {
1767: my $val = $option;
1768: if ($option eq 'norequest') {
1769: $val = 0;
1770: }
1771: if ($option eq 'validate') {
1772: my $canvalidate = 0;
1773: if (ref($validations{$item}) eq 'HASH') {
1774: if ($validations{$item}{$type}) {
1775: $canvalidate = 1;
1776: }
1777: }
1778: next if (!$canvalidate);
1779: }
1780: my $checked = '';
1781: if ($option eq $curroption) {
1782: $checked = ' checked="checked"';
1783: } elsif ($option eq 'autolimit') {
1784: if ($curroption =~ /^autolimit/) {
1785: $checked = ' checked="checked"';
1786: }
1787: }
1788: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1789: '<input type="radio" name="crsreq_'.$item.
1790: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1791: $titles{$option}.'</label>';
1.101 raeburn 1792: if ($option eq 'autolimit') {
1.127 raeburn 1793: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1794: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1795: 'value="'.$currlimit.'" />';
1.101 raeburn 1796: }
1.127 raeburn 1797: $cell{$item} .= '</span> ';
1.103 raeburn 1798: if ($option eq 'autolimit') {
1.127 raeburn 1799: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1800: }
1.101 raeburn 1801: }
1.163 raeburn 1802: } elsif ($context eq 'requestauthor') {
1803: my $curroption;
1804: if (ref($settings) eq 'HASH') {
1805: $curroption = $settings->{$type};
1806: }
1807: if (!$curroption) {
1808: $curroption = 'norequest';
1809: }
1810: foreach my $option (@options) {
1811: my $val = $option;
1812: if ($option eq 'norequest') {
1813: $val = 0;
1814: }
1815: my $checked = '';
1816: if ($option eq $curroption) {
1817: $checked = ' checked="checked"';
1818: }
1819: $datatable .= '<span class="LC_nobreak"><label>'.
1820: '<input type="radio" name="authorreq_'.$type.
1821: '" value="'.$val.'"'.$checked.' />'.
1822: $titles{$option}.'</label></span> ';
1823: }
1.101 raeburn 1824: } else {
1825: my $checked = 'checked="checked" ';
1826: if (ref($settings) eq 'HASH') {
1827: if (ref($settings->{$item}) eq 'HASH') {
1828: if ($settings->{$item}->{$type} == 0) {
1829: $checked = '';
1830: } elsif ($settings->{$item}->{$type} == 1) {
1831: $checked = 'checked="checked" ';
1832: }
1.78 raeburn 1833: }
1.72 raeburn 1834: }
1.101 raeburn 1835: $datatable .= '<span class="LC_nobreak"><label>'.
1836: '<input type="checkbox" name="'.$context.'_'.$item.
1837: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1838: '</label></span> ';
1.72 raeburn 1839: }
1.101 raeburn 1840: }
1841: if ($context eq 'requestcourses') {
1842: $datatable .= '</tr><tr>';
1843: foreach my $item (@usertools) {
1.106 raeburn 1844: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1845: }
1846: $datatable .= '</tr></table>';
1.72 raeburn 1847: }
1.86 raeburn 1848: $datatable .= '</td>';
1.163 raeburn 1849: unless (($context eq 'requestcourses') ||
1850: ($context eq 'requestauthor')) {
1.86 raeburn 1851: $datatable .=
1.197 raeburn 1852: '<td class="LC_right_item">'.
1853: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1854: '<input type="text" name="quota_'.$type.
1.72 raeburn 1855: '" value="'.$currdefquota.
1.197 raeburn 1856: '" size="5" /></span>'.(' ' x 2).
1857: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1858: '<input type="text" name="authorquota_'.$type.
1859: '" value="'.$currauthorquota.
1860: '" size="5" /></span></td>';
1.86 raeburn 1861: }
1862: $datatable .= '</tr>';
1.3 raeburn 1863: }
1864: }
1865: }
1.163 raeburn 1866: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1867: $defaultquota = '20';
1.197 raeburn 1868: $authorquota = '500';
1.86 raeburn 1869: if (ref($settings) eq 'HASH') {
1870: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1871: $defaultquota = $settings->{'defaultquota'}->{'default'};
1872: } elsif (defined($settings->{'default'})) {
1873: $defaultquota = $settings->{'default'};
1874: }
1.197 raeburn 1875: if (ref($settings->{'authorquota'}) eq 'HASH') {
1876: $authorquota = $settings->{'authorquota'}->{'default'};
1877: }
1.3 raeburn 1878: }
1879: }
1880: $typecount ++;
1881: $css_class = $typecount%2?' class="LC_odd_row"':'';
1882: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1883: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1884: '<td class="LC_left_item">';
1.101 raeburn 1885: if ($context eq 'requestcourses') {
1886: $datatable .= '<table><tr>';
1887: }
1888: my %defcell;
1.72 raeburn 1889: foreach my $item (@usertools) {
1.101 raeburn 1890: if ($context eq 'requestcourses') {
1891: my ($curroption,$currlimit);
1892: if (ref($settings) eq 'HASH') {
1893: if (ref($settings->{$item}) eq 'HASH') {
1894: $curroption = $settings->{$item}->{'default'};
1895: if ($curroption =~ /^autolimit=(\d*)$/) {
1896: $currlimit = $1;
1897: }
1898: }
1899: }
1900: if (!$curroption) {
1901: $curroption = 'norequest';
1902: }
1903: $datatable .= '<th>'.$titles{$item}.'</th>';
1904: foreach my $option (@options) {
1905: my $val = $option;
1906: if ($option eq 'norequest') {
1907: $val = 0;
1908: }
1909: if ($option eq 'validate') {
1910: my $canvalidate = 0;
1911: if (ref($validations{$item}) eq 'HASH') {
1912: if ($validations{$item}{'default'}) {
1913: $canvalidate = 1;
1914: }
1915: }
1916: next if (!$canvalidate);
1917: }
1918: my $checked = '';
1919: if ($option eq $curroption) {
1920: $checked = ' checked="checked"';
1921: } elsif ($option eq 'autolimit') {
1922: if ($curroption =~ /^autolimit/) {
1923: $checked = ' checked="checked"';
1924: }
1925: }
1926: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1927: '<input type="radio" name="crsreq_'.$item.
1928: '_default" value="'.$val.'"'.$checked.' />'.
1929: $titles{$option}.'</label>';
1930: if ($option eq 'autolimit') {
1.127 raeburn 1931: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1932: $item.'_limit_default" size="1" '.
1933: 'value="'.$currlimit.'" />';
1934: }
1.127 raeburn 1935: $defcell{$item} .= '</span> ';
1.104 raeburn 1936: if ($option eq 'autolimit') {
1.127 raeburn 1937: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1938: }
1.101 raeburn 1939: }
1.163 raeburn 1940: } elsif ($context eq 'requestauthor') {
1941: my $curroption;
1942: if (ref($settings) eq 'HASH') {
1.172 raeburn 1943: $curroption = $settings->{'default'};
1.163 raeburn 1944: }
1945: if (!$curroption) {
1946: $curroption = 'norequest';
1947: }
1948: foreach my $option (@options) {
1949: my $val = $option;
1950: if ($option eq 'norequest') {
1951: $val = 0;
1952: }
1953: my $checked = '';
1954: if ($option eq $curroption) {
1955: $checked = ' checked="checked"';
1956: }
1957: $datatable .= '<span class="LC_nobreak"><label>'.
1958: '<input type="radio" name="authorreq_default"'.
1959: ' value="'.$val.'"'.$checked.' />'.
1960: $titles{$option}.'</label></span> ';
1961: }
1.101 raeburn 1962: } else {
1963: my $checked = 'checked="checked" ';
1964: if (ref($settings) eq 'HASH') {
1965: if (ref($settings->{$item}) eq 'HASH') {
1966: if ($settings->{$item}->{'default'} == 0) {
1967: $checked = '';
1968: } elsif ($settings->{$item}->{'default'} == 1) {
1969: $checked = 'checked="checked" ';
1970: }
1.78 raeburn 1971: }
1.72 raeburn 1972: }
1.101 raeburn 1973: $datatable .= '<span class="LC_nobreak"><label>'.
1974: '<input type="checkbox" name="'.$context.'_'.$item.
1975: '" value="default" '.$checked.'/>'.$titles{$item}.
1976: '</label></span> ';
1977: }
1978: }
1979: if ($context eq 'requestcourses') {
1980: $datatable .= '</tr><tr>';
1981: foreach my $item (@usertools) {
1.106 raeburn 1982: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1983: }
1.101 raeburn 1984: $datatable .= '</tr></table>';
1.72 raeburn 1985: }
1.86 raeburn 1986: $datatable .= '</td>';
1.163 raeburn 1987: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1988: $datatable .= '<td class="LC_right_item">'.
1989: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1990: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1991: $defaultquota.'" size="5" /></span>'.(' ' x2).
1992: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1993: '<input type="text" name="authorquota" value="'.
1994: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1995: }
1996: $datatable .= '</tr>';
1.72 raeburn 1997: $typecount ++;
1998: $css_class = $typecount%2?' class="LC_odd_row"':'';
1999: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2000: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2001: if ($context eq 'requestcourses') {
1.109 raeburn 2002: $datatable .= &mt('(overrides affiliation, if set)').
2003: '</td>'.
2004: '<td class="LC_left_item">'.
2005: '<table><tr>';
1.101 raeburn 2006: } else {
1.109 raeburn 2007: $datatable .= &mt('(overrides affiliation, if checked)').
2008: '</td>'.
2009: '<td class="LC_left_item" colspan="2">'.
2010: '<br />';
1.101 raeburn 2011: }
2012: my %advcell;
1.72 raeburn 2013: foreach my $item (@usertools) {
1.101 raeburn 2014: if ($context eq 'requestcourses') {
2015: my ($curroption,$currlimit);
2016: if (ref($settings) eq 'HASH') {
2017: if (ref($settings->{$item}) eq 'HASH') {
2018: $curroption = $settings->{$item}->{'_LC_adv'};
2019: if ($curroption =~ /^autolimit=(\d*)$/) {
2020: $currlimit = $1;
2021: }
2022: }
2023: }
2024: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2025: my $checked = '';
2026: if ($curroption eq '') {
2027: $checked = ' checked="checked"';
2028: }
2029: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2030: '<input type="radio" name="crsreq_'.$item.
2031: '__LC_adv" value=""'.$checked.' />'.
2032: &mt('No override set').'</label></span> ';
1.101 raeburn 2033: foreach my $option (@options) {
2034: my $val = $option;
2035: if ($option eq 'norequest') {
2036: $val = 0;
2037: }
2038: if ($option eq 'validate') {
2039: my $canvalidate = 0;
2040: if (ref($validations{$item}) eq 'HASH') {
2041: if ($validations{$item}{'_LC_adv'}) {
2042: $canvalidate = 1;
2043: }
2044: }
2045: next if (!$canvalidate);
2046: }
2047: my $checked = '';
1.104 raeburn 2048: if ($val eq $curroption) {
1.101 raeburn 2049: $checked = ' checked="checked"';
2050: } elsif ($option eq 'autolimit') {
2051: if ($curroption =~ /^autolimit/) {
2052: $checked = ' checked="checked"';
2053: }
2054: }
2055: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2056: '<input type="radio" name="crsreq_'.$item.
2057: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2058: $titles{$option}.'</label>';
2059: if ($option eq 'autolimit') {
1.127 raeburn 2060: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2061: $item.'_limit__LC_adv" size="1" '.
2062: 'value="'.$currlimit.'" />';
2063: }
1.127 raeburn 2064: $advcell{$item} .= '</span> ';
1.104 raeburn 2065: if ($option eq 'autolimit') {
1.127 raeburn 2066: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2067: }
1.101 raeburn 2068: }
1.163 raeburn 2069: } elsif ($context eq 'requestauthor') {
2070: my $curroption;
2071: if (ref($settings) eq 'HASH') {
2072: $curroption = $settings->{'_LC_adv'};
2073: }
2074: my $checked = '';
2075: if ($curroption eq '') {
2076: $checked = ' checked="checked"';
2077: }
2078: $datatable .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="authorreq__LC_adv"'.
2080: ' value=""'.$checked.' />'.
2081: &mt('No override set').'</label></span> ';
2082: foreach my $option (@options) {
2083: my $val = $option;
2084: if ($option eq 'norequest') {
2085: $val = 0;
2086: }
2087: my $checked = '';
2088: if ($val eq $curroption) {
2089: $checked = ' checked="checked"';
2090: }
2091: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2092: '<input type="radio" name="authorreq__LC_adv"'.
2093: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2094: $titles{$option}.'</label></span> ';
2095: }
1.101 raeburn 2096: } else {
2097: my $checked = 'checked="checked" ';
2098: if (ref($settings) eq 'HASH') {
2099: if (ref($settings->{$item}) eq 'HASH') {
2100: if ($settings->{$item}->{'_LC_adv'} == 0) {
2101: $checked = '';
2102: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2103: $checked = 'checked="checked" ';
2104: }
1.79 raeburn 2105: }
1.72 raeburn 2106: }
1.101 raeburn 2107: $datatable .= '<span class="LC_nobreak"><label>'.
2108: '<input type="checkbox" name="'.$context.'_'.$item.
2109: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2110: '</label></span> ';
2111: }
2112: }
2113: if ($context eq 'requestcourses') {
2114: $datatable .= '</tr><tr>';
2115: foreach my $item (@usertools) {
1.106 raeburn 2116: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2117: }
1.101 raeburn 2118: $datatable .= '</tr></table>';
1.72 raeburn 2119: }
1.98 raeburn 2120: $datatable .= '</td></tr>';
1.30 raeburn 2121: $$rowtotal += $typecount;
1.3 raeburn 2122: return $datatable;
2123: }
2124:
1.163 raeburn 2125: sub print_requestmail {
2126: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2127: my ($now,$datatable,%currapp);
1.102 raeburn 2128: $now = time;
2129: if (ref($settings) eq 'HASH') {
2130: if (ref($settings->{'notify'}) eq 'HASH') {
2131: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2132: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2133: }
2134: }
2135: }
1.191 raeburn 2136: my $numinrow = 2;
1.224 raeburn 2137: my $css_class;
2138: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2139: my $text;
2140: if ($action eq 'requestcourses') {
2141: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2142: } elsif ($action eq 'requestauthor') {
2143: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2144: } else {
1.224 raeburn 2145: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2146: }
1.224 raeburn 2147: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2148: ' <td>'.$text.'</td>'.
1.102 raeburn 2149: ' <td class="LC_left_item">';
1.191 raeburn 2150: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2151: $action.'notifyapproval',%currapp);
1.191 raeburn 2152: if ($numdc > 0) {
2153: $datatable .= $table;
1.102 raeburn 2154: } else {
2155: $datatable .= &mt('There are no active Domain Coordinators');
2156: }
2157: $datatable .='</td></tr>';
2158: return $datatable;
2159: }
2160:
1.216 raeburn 2161: sub print_studentcode {
2162: my ($settings,$rowtotal) = @_;
2163: my $rownum = 0;
1.218 raeburn 2164: my ($output,%current);
2165: my @crstypes = ('official','unofficial','community','textbook');
1.248 raeburn 2166: if (ref($settings) eq 'HASH') {
2167: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2168: foreach my $type (@crstypes) {
2169: $current{$type} = $settings->{'uniquecode'}{$type};
2170: }
1.218 raeburn 2171: }
2172: }
2173: $output .= '<tr>'.
2174: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2175: '<td class="LC_left_item">';
2176: foreach my $type (@crstypes) {
2177: my $check = ' ';
2178: if ($current{$type}) {
2179: $check = ' checked="checked" ';
2180: }
2181: $output .= '<span class="LC_nobreak"><label>'.
2182: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2183: &mt($type).'</label></span>'.(' 'x2).' ';
2184: }
2185: $output .= '</td></tr>';
2186: $$rowtotal ++;
2187: return $output;
1.216 raeburn 2188: }
2189:
2190: sub print_textbookcourses {
1.242 raeburn 2191: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2192: my $rownum = 0;
2193: my $css_class;
2194: my $itemcount = 1;
2195: my $maxnum = 0;
2196: my $bookshash;
2197: if (ref($settings) eq 'HASH') {
1.242 raeburn 2198: $bookshash = $settings->{$type};
1.216 raeburn 2199: }
2200: my %ordered;
2201: if (ref($bookshash) eq 'HASH') {
2202: foreach my $item (keys(%{$bookshash})) {
2203: if (ref($bookshash->{$item}) eq 'HASH') {
2204: my $num = $bookshash->{$item}{'order'};
2205: $ordered{$num} = $item;
2206: }
2207: }
2208: }
2209: my $confname = $dom.'-domainconfig';
2210: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2211: my $maxnum = scalar(keys(%ordered));
2212: my $datatable;
1.216 raeburn 2213: if (keys(%ordered)) {
2214: my @items = sort { $a <=> $b } keys(%ordered);
2215: for (my $i=0; $i<@items; $i++) {
2216: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2217: my $key = $ordered{$items[$i]};
2218: my %coursehash=&Apache::lonnet::coursedescription($key);
2219: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2220: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2221: if (ref($bookshash->{$key}) eq 'HASH') {
2222: $subject = $bookshash->{$key}->{'subject'};
2223: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2224: if ($type eq 'textbooks') {
1.243 raeburn 2225: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2226: $author = $bookshash->{$key}->{'author'};
2227: $image = $bookshash->{$key}->{'image'};
2228: if ($image ne '') {
2229: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2230: my $imagethumb = "$path/tn-".$imagefile;
2231: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2232: }
1.216 raeburn 2233: }
2234: }
1.242 raeburn 2235: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2236: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2237: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2238: for (my $k=0; $k<=$maxnum; $k++) {
2239: my $vpos = $k+1;
2240: my $selstr;
2241: if ($k == $i) {
2242: $selstr = ' selected="selected" ';
2243: }
2244: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2245: }
2246: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2247: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2248: &mt('Delete?').'</label></span></td>'.
2249: '<td colspan="2">'.
1.242 raeburn 2250: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2251: (' 'x2).
1.242 raeburn 2252: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2253: if ($type eq 'textbooks') {
2254: $datatable .= (' 'x2).
1.243 raeburn 2255: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2256: (' 'x2).
1.242 raeburn 2257: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2258: (' 'x2).
2259: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2260: if ($image) {
2261: $datatable .= '<span class="LC_nobreak">'.
2262: $imgsrc.
2263: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2264: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2265: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2266: }
2267: if ($switchserver) {
2268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2269: } else {
2270: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2271: }
1.216 raeburn 2272: }
1.242 raeburn 2273: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2274: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2275: $coursetitle.'</span></td></tr>'."\n";
2276: $itemcount ++;
2277: }
2278: }
2279: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2280: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2281: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2282: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2283: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2284: for (my $k=0; $k<$maxnum+1; $k++) {
2285: my $vpos = $k+1;
2286: my $selstr;
2287: if ($k == $maxnum) {
2288: $selstr = ' selected="selected" ';
2289: }
2290: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2291: }
2292: $datatable .= '</select> '."\n".
1.242 raeburn 2293: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2294: '<td colspan="2">'.
1.242 raeburn 2295: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2296: (' 'x2).
1.242 raeburn 2297: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2298: (' 'x2);
2299: if ($type eq 'textbooks') {
1.243 raeburn 2300: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2301: (' 'x2).
2302: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2303: (' 'x2).
2304: '<span class="LC_nobreak">'.&mt('Image:').' ';
2305: if ($switchserver) {
2306: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2307: } else {
2308: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2309: }
1.216 raeburn 2310: }
2311: $datatable .= '</span>'."\n".
2312: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2313: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2314: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2315: &Apache::loncommon::selectcourse_link
1.242 raeburn 2316: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2317: '</span></td>'."\n".
2318: '</tr>'."\n";
2319: $itemcount ++;
2320: return $datatable;
2321: }
2322:
1.217 raeburn 2323: sub textbookcourses_javascript {
1.242 raeburn 2324: my ($settings) = @_;
2325: return unless(ref($settings) eq 'HASH');
2326: my (%ordered,%total,%jstext);
2327: foreach my $type ('textbooks','templates') {
2328: $total{$type} = 0;
2329: if (ref($settings->{$type}) eq 'HASH') {
2330: foreach my $item (keys(%{$settings->{$type}})) {
2331: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2332: my $num = $settings->{$type}->{$item}{'order'};
2333: $ordered{$type}{$num} = $item;
2334: }
2335: }
2336: $total{$type} = scalar(keys(%{$settings->{$type}}));
2337: }
2338: my @jsarray = ();
2339: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2340: push(@jsarray,$ordered{$type}{$item});
2341: }
2342: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2343: }
2344: return <<"ENDSCRIPT";
2345: <script type="text/javascript">
2346: // <![CDATA[
1.242 raeburn 2347: function reorderBooks(form,item,caller) {
1.217 raeburn 2348: var changedVal;
1.242 raeburn 2349: $jstext{'textbooks'};
2350: $jstext{'templates'};
2351: var newpos;
2352: var maxh;
2353: if (caller == 'textbooks') {
2354: newpos = 'textbooks_addbook_pos';
2355: maxh = 1 + $total{'textbooks'};
2356: } else {
2357: newpos = 'templates_addbook_pos';
2358: maxh = 1 + $total{'templates'};
2359: }
1.217 raeburn 2360: var current = new Array;
2361: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2362: if (item == newpos) {
2363: changedVal = newitemVal;
2364: } else {
2365: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2366: current[newitemVal] = newpos;
2367: }
1.242 raeburn 2368: if (caller == 'textbooks') {
2369: for (var i=0; i<textbooks.length; i++) {
2370: var elementName = 'textbooks_'+textbooks[i];
2371: if (elementName != item) {
2372: if (form.elements[elementName]) {
2373: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2374: current[currVal] = elementName;
2375: }
2376: }
2377: }
2378: }
2379: if (caller == 'templates') {
2380: for (var i=0; i<templates.length; i++) {
2381: var elementName = 'templates_'+templates[i];
2382: if (elementName != item) {
2383: if (form.elements[elementName]) {
2384: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2385: current[currVal] = elementName;
2386: }
1.217 raeburn 2387: }
2388: }
2389: }
2390: var oldVal;
2391: for (var j=0; j<maxh; j++) {
2392: if (current[j] == undefined) {
2393: oldVal = j;
2394: }
2395: }
2396: if (oldVal < changedVal) {
2397: for (var k=oldVal+1; k<=changedVal ; k++) {
2398: var elementName = current[k];
2399: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2400: }
2401: } else {
2402: for (var k=changedVal; k<oldVal; k++) {
2403: var elementName = current[k];
2404: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2405: }
2406: }
2407: return;
2408: }
2409:
2410: // ]]>
2411: </script>
2412:
2413: ENDSCRIPT
2414: }
2415:
1.3 raeburn 2416: sub print_autoenroll {
1.30 raeburn 2417: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2418: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2419: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2420: if (ref($settings) eq 'HASH') {
2421: if (exists($settings->{'run'})) {
2422: if ($settings->{'run'} eq '0') {
2423: $runoff = ' checked="checked" ';
2424: $runon = ' ';
2425: } else {
2426: $runon = ' checked="checked" ';
2427: $runoff = ' ';
2428: }
2429: } else {
2430: if ($autorun) {
2431: $runon = ' checked="checked" ';
2432: $runoff = ' ';
2433: } else {
2434: $runoff = ' checked="checked" ';
2435: $runon = ' ';
2436: }
2437: }
1.129 raeburn 2438: if (exists($settings->{'co-owners'})) {
2439: if ($settings->{'co-owners'} eq '0') {
2440: $coownersoff = ' checked="checked" ';
2441: $coownerson = ' ';
2442: } else {
2443: $coownerson = ' checked="checked" ';
2444: $coownersoff = ' ';
2445: }
2446: } else {
2447: $coownersoff = ' checked="checked" ';
2448: $coownerson = ' ';
2449: }
1.3 raeburn 2450: if (exists($settings->{'sender_domain'})) {
2451: $defdom = $settings->{'sender_domain'};
2452: }
1.14 raeburn 2453: } else {
2454: if ($autorun) {
2455: $runon = ' checked="checked" ';
2456: $runoff = ' ';
2457: } else {
2458: $runoff = ' checked="checked" ';
2459: $runon = ' ';
2460: }
1.3 raeburn 2461: }
2462: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2463: my $notif_sender;
2464: if (ref($settings) eq 'HASH') {
2465: $notif_sender = $settings->{'sender_uname'};
2466: }
1.3 raeburn 2467: my $datatable='<tr class="LC_odd_row">'.
2468: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2469: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2470: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2471: $runon.' value="1" />'.&mt('Yes').'</label> '.
2472: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2473: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2474: '</tr><tr>'.
2475: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2476: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2477: &mt('username').': '.
2478: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2479: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2480: ': '.$domform.'</span></td></tr>'.
2481: '<tr class="LC_odd_row">'.
2482: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2483: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2484: '<input type="radio" name="autoassign_coowners"'.
2485: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2486: '<label><input type="radio" name="autoassign_coowners"'.
2487: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2488: '</tr>';
2489: $$rowtotal += 3;
1.3 raeburn 2490: return $datatable;
2491: }
2492:
2493: sub print_autoupdate {
1.30 raeburn 2494: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2495: my $datatable;
2496: if ($position eq 'top') {
2497: my $updateon = ' ';
2498: my $updateoff = ' checked="checked" ';
2499: my $classlistson = ' ';
2500: my $classlistsoff = ' checked="checked" ';
2501: if (ref($settings) eq 'HASH') {
2502: if ($settings->{'run'} eq '1') {
2503: $updateon = $updateoff;
2504: $updateoff = ' ';
2505: }
2506: if ($settings->{'classlists'} eq '1') {
2507: $classlistson = $classlistsoff;
2508: $classlistsoff = ' ';
2509: }
2510: }
2511: my %title = (
2512: run => 'Auto-update active?',
2513: classlists => 'Update information in classlists?',
2514: );
2515: $datatable = '<tr class="LC_odd_row">'.
2516: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2517: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2518: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2519: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2520: '<label><input type="radio" name="autoupdate_run"'.
2521: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2522: '</tr><tr>'.
2523: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2524: '<td class="LC_right_item"><span class="LC_nobreak">'.
2525: '<label><input type="radio" name="classlists"'.
2526: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2527: '<label><input type="radio" name="classlists"'.
2528: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2529: '</tr>';
1.30 raeburn 2530: $$rowtotal += 2;
1.131 raeburn 2531: } elsif ($position eq 'middle') {
2532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2533: my $numinrow = 3;
2534: my $locknamesettings;
2535: $datatable .= &insttypes_row($settings,$types,$usertypes,
2536: $dom,$numinrow,$othertitle,
2537: 'lockablenames');
2538: $$rowtotal ++;
1.3 raeburn 2539: } else {
1.44 raeburn 2540: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2541: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2542: 'permanentemail','id');
1.33 raeburn 2543: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2544: my $numrows = 0;
1.26 raeburn 2545: if (ref($types) eq 'ARRAY') {
2546: if (@{$types} > 0) {
2547: $datatable =
2548: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2549: \@fields,$types,\$numrows);
1.30 raeburn 2550: $$rowtotal += @{$types};
1.26 raeburn 2551: }
1.3 raeburn 2552: }
2553: $datatable .=
2554: &usertype_update_row($settings,{'default' => $othertitle},
2555: \%fieldtitles,\@fields,['default'],
2556: \$numrows);
1.30 raeburn 2557: $$rowtotal ++;
1.3 raeburn 2558: }
2559: return $datatable;
2560: }
2561:
1.125 raeburn 2562: sub print_autocreate {
2563: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2564: my (%createon,%createoff,%currhash);
1.125 raeburn 2565: my @types = ('xml','req');
2566: if (ref($settings) eq 'HASH') {
2567: foreach my $item (@types) {
2568: $createoff{$item} = ' checked="checked" ';
2569: $createon{$item} = ' ';
2570: if (exists($settings->{$item})) {
2571: if ($settings->{$item}) {
2572: $createon{$item} = ' checked="checked" ';
2573: $createoff{$item} = ' ';
2574: }
2575: }
2576: }
1.210 raeburn 2577: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2578: $currhash{$settings->{'xmldc'}} = 1;
2579: }
1.125 raeburn 2580: } else {
2581: foreach my $item (@types) {
2582: $createoff{$item} = ' checked="checked" ';
2583: $createon{$item} = ' ';
2584: }
2585: }
2586: $$rowtotal += 2;
1.191 raeburn 2587: my $numinrow = 2;
1.125 raeburn 2588: my $datatable='<tr class="LC_odd_row">'.
2589: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2590: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2591: '<input type="radio" name="autocreate_xml"'.
2592: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2593: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2594: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2595: '</td></tr><tr>'.
2596: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2597: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2598: '<input type="radio" name="autocreate_req"'.
2599: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2600: '<label><input type="radio" name="autocreate_req"'.
2601: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2602: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2603: 'autocreate_xmldc',%currhash);
1.247 raeburn 2604: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2605: if ($numdc > 1) {
1.247 raeburn 2606: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2607: '</td><td class="LC_left_item">';
1.125 raeburn 2608: } else {
1.247 raeburn 2609: $datatable .= &mt('Course creation processed as:').
2610: '</td><td class="LC_right_item">';
1.125 raeburn 2611: }
1.247 raeburn 2612: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2613: $$rowtotal += $rows;
1.125 raeburn 2614: return $datatable;
2615: }
2616:
1.23 raeburn 2617: sub print_directorysrch {
1.30 raeburn 2618: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2619: my $srchon = ' ';
2620: my $srchoff = ' checked="checked" ';
1.25 raeburn 2621: my ($exacton,$containson,$beginson);
1.24 raeburn 2622: my $localon = ' ';
2623: my $localoff = ' checked="checked" ';
1.23 raeburn 2624: if (ref($settings) eq 'HASH') {
2625: if ($settings->{'available'} eq '1') {
2626: $srchon = $srchoff;
2627: $srchoff = ' ';
2628: }
1.24 raeburn 2629: if ($settings->{'localonly'} eq '1') {
2630: $localon = $localoff;
2631: $localoff = ' ';
2632: }
1.25 raeburn 2633: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2634: foreach my $type (@{$settings->{'searchtypes'}}) {
2635: if ($type eq 'exact') {
2636: $exacton = ' checked="checked" ';
2637: } elsif ($type eq 'contains') {
2638: $containson = ' checked="checked" ';
2639: } elsif ($type eq 'begins') {
2640: $beginson = ' checked="checked" ';
2641: }
2642: }
2643: } else {
2644: if ($settings->{'searchtypes'} eq 'exact') {
2645: $exacton = ' checked="checked" ';
2646: } elsif ($settings->{'searchtypes'} eq 'contains') {
2647: $containson = ' checked="checked" ';
2648: } elsif ($settings->{'searchtypes'} eq 'specify') {
2649: $exacton = ' checked="checked" ';
2650: $containson = ' checked="checked" ';
2651: }
1.23 raeburn 2652: }
2653: }
2654: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2655: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2656:
2657: my $numinrow = 4;
1.26 raeburn 2658: my $cansrchrow = 0;
1.23 raeburn 2659: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2660: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2661: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2662: '<input type="radio" name="dirsrch_available"'.
2663: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2664: '<label><input type="radio" name="dirsrch_available"'.
2665: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2666: '</tr><tr>'.
1.30 raeburn 2667: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2668: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2669: '<input type="radio" name="dirsrch_localonly"'.
2670: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2671: '<label><input type="radio" name="dirsrch_localonly"'.
2672: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2673: '</tr>';
1.30 raeburn 2674: $$rowtotal += 2;
1.26 raeburn 2675: if (ref($usertypes) eq 'HASH') {
2676: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2677: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2678: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2679: $cansrchrow = 1;
2680: }
2681: }
2682: if ($cansrchrow) {
1.30 raeburn 2683: $$rowtotal ++;
1.26 raeburn 2684: $datatable .= '<tr>';
2685: } else {
2686: $datatable .= '<tr class="LC_odd_row">';
2687: }
1.30 raeburn 2688: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2689: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2690: foreach my $title (@{$titleorder}) {
2691: if (defined($searchtitles->{$title})) {
2692: my $check = ' ';
1.93 raeburn 2693: if (ref($settings) eq 'HASH') {
1.39 raeburn 2694: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2695: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2696: $check = ' checked="checked" ';
2697: }
1.25 raeburn 2698: }
2699: }
2700: $datatable .= '<td class="LC_left_item">'.
2701: '<span class="LC_nobreak"><label>'.
2702: '<input type="checkbox" name="searchby" '.
2703: 'value="'.$title.'"'.$check.'/>'.
2704: $searchtitles->{$title}.'</label></span></td>';
2705: }
2706: }
1.26 raeburn 2707: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2708: $$rowtotal ++;
1.26 raeburn 2709: if ($cansrchrow) {
2710: $datatable .= '<tr class="LC_odd_row">';
2711: } else {
2712: $datatable .= '<tr>';
2713: }
1.30 raeburn 2714: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2715: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2716: '<span class="LC_nobreak"><label>'.
2717: '<input type="checkbox" name="searchtypes" '.
2718: $exacton.' value="exact" />'.&mt('Exact match').
2719: '</label> '.
2720: '<label><input type="checkbox" name="searchtypes" '.
2721: $beginson.' value="begins" />'.&mt('Begins with').
2722: '</label> '.
2723: '<label><input type="checkbox" name="searchtypes" '.
2724: $containson.' value="contains" />'.&mt('Contains').
2725: '</label></span></td></tr>';
1.30 raeburn 2726: $$rowtotal ++;
1.25 raeburn 2727: return $datatable;
2728: }
2729:
1.28 raeburn 2730: sub print_contacts {
1.30 raeburn 2731: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2732: my $datatable;
2733: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2734: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2735: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2736: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2737: foreach my $type (@mailings) {
2738: $otheremails{$type} = '';
2739: }
1.134 raeburn 2740: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2741: if (ref($settings) eq 'HASH') {
2742: foreach my $item (@contacts) {
2743: if (exists($settings->{$item})) {
2744: $to{$item} = $settings->{$item};
2745: }
2746: }
2747: foreach my $type (@mailings) {
2748: if (exists($settings->{$type})) {
2749: if (ref($settings->{$type}) eq 'HASH') {
2750: foreach my $item (@contacts) {
2751: if ($settings->{$type}{$item}) {
2752: $checked{$type}{$item} = ' checked="checked" ';
2753: }
2754: }
2755: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2756: if ($type eq 'helpdeskmail') {
2757: $bccemails{$type} = $settings->{$type}{'bcc'};
2758: }
1.28 raeburn 2759: }
1.89 raeburn 2760: } elsif ($type eq 'lonstatusmail') {
2761: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2762: }
2763: }
2764: } else {
2765: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2766: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2767: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2768: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2769: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2770: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2771: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2772: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2773: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2774: }
2775: my ($titles,$short_titles) = &contact_titles();
2776: my $rownum = 0;
2777: my $css_class;
2778: foreach my $item (@contacts) {
1.69 raeburn 2779: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2780: $datatable .= '<tr'.$css_class.'>'.
2781: '<td><span class="LC_nobreak">'.$titles->{$item}.
2782: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2783: '<input type="text" name="'.$item.'" value="'.
2784: $to{$item}.'" /></td></tr>';
1.203 raeburn 2785: $rownum ++;
1.28 raeburn 2786: }
2787: foreach my $type (@mailings) {
1.69 raeburn 2788: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2789: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2790: '<td><span class="LC_nobreak">'.
2791: $titles->{$type}.': </span></td>'.
1.28 raeburn 2792: '<td class="LC_left_item">'.
2793: '<span class="LC_nobreak">';
2794: foreach my $item (@contacts) {
2795: $datatable .= '<label>'.
2796: '<input type="checkbox" name="'.$type.'"'.
2797: $checked{$type}{$item}.
2798: ' value="'.$item.'" />'.$short_titles->{$item}.
2799: '</label> ';
2800: }
2801: $datatable .= '</span><br />'.&mt('Others').': '.
2802: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2803: 'value="'.$otheremails{$type}.'" />';
2804: if ($type eq 'helpdeskmail') {
1.136 raeburn 2805: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2806: '<input type="text" name="'.$type.'_bcc" '.
2807: 'value="'.$bccemails{$type}.'" />';
2808: }
2809: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2810: $rownum ++;
1.28 raeburn 2811: }
1.203 raeburn 2812: my %choices;
2813: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2814: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2815: &mt('LON-CAPA core group - MSU'),600,500));
2816: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2817: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2818: &mt('LON-CAPA core group - MSU'),600,500));
2819: my @toggles = ('reporterrors','reportupdates');
2820: my %defaultchecked = ('reporterrors' => 'on',
2821: 'reportupdates' => 'on');
2822: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2823: \%choices,$rownum);
2824: $datatable .= $reports;
1.30 raeburn 2825: $$rowtotal += $rownum;
1.28 raeburn 2826: return $datatable;
2827: }
2828:
1.118 jms 2829: sub print_helpsettings {
1.168 raeburn 2830: my ($dom,$confname,$settings,$rowtotal) = @_;
2831: my ($datatable,$itemcount);
1.166 raeburn 2832: $itemcount = 1;
1.168 raeburn 2833: my (%choices,%defaultchecked,@toggles);
2834: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2835: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2836: &mt('LON-CAPA bug tracker'),600,500));
2837: %defaultchecked = ('submitbugs' => 'on');
2838: @toggles = ('submitbugs',);
1.166 raeburn 2839:
1.168 raeburn 2840: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2841: \%choices,$itemcount);
1.166 raeburn 2842: return $datatable;
1.121 raeburn 2843: }
2844:
2845: sub radiobutton_prefs {
1.192 raeburn 2846: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2847: $additional,$align) = @_;
1.121 raeburn 2848: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2849: (ref($choices) eq 'HASH'));
2850:
1.170 raeburn 2851: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2852:
2853: foreach my $item (@{$toggles}) {
2854: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2855: $checkedon{$item} = ' checked="checked" ';
2856: $checkedoff{$item} = ' ';
1.121 raeburn 2857: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2858: $checkedoff{$item} = ' checked="checked" ';
2859: $checkedon{$item} = ' ';
2860: }
2861: }
2862: if (ref($settings) eq 'HASH') {
1.121 raeburn 2863: foreach my $item (@{$toggles}) {
1.118 jms 2864: if ($settings->{$item} eq '1') {
2865: $checkedon{$item} = ' checked="checked" ';
2866: $checkedoff{$item} = ' ';
2867: } elsif ($settings->{$item} eq '0') {
2868: $checkedoff{$item} = ' checked="checked" ';
2869: $checkedon{$item} = ' ';
2870: }
2871: }
1.121 raeburn 2872: }
1.192 raeburn 2873: if ($onclick) {
2874: $onclick = ' onclick="'.$onclick.'"';
2875: }
1.121 raeburn 2876: foreach my $item (@{$toggles}) {
1.118 jms 2877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2878: $datatable .=
1.192 raeburn 2879: '<tr'.$css_class.'><td valign="top">'.
2880: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 2881: '</span></td>';
2882: if ($align eq 'left') {
2883: $datatable .= '<td class="LC_left_item">';
2884: } else {
2885: $datatable .= '<td class="LC_right_item">';
2886: }
2887: $datatable .=
2888: '<span class="LC_nobreak">'.
1.118 jms 2889: '<label><input type="radio" name="'.
1.192 raeburn 2890: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2891: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2892: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2893: '</span>'.$additional.
2894: '</td>'.
1.118 jms 2895: '</tr>';
2896: $itemcount ++;
1.121 raeburn 2897: }
2898: return ($datatable,$itemcount);
2899: }
2900:
2901: sub print_coursedefaults {
1.139 raeburn 2902: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2903: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2904: my $itemcount = 1;
1.192 raeburn 2905: my %choices = &Apache::lonlocal::texthash (
2906: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2907: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2908: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2909: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 2910: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
2911: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
2912: postsubmit => 'Disable submit button/keypress following student submission',
1.192 raeburn 2913: );
1.198 raeburn 2914: my %staticdefaults = (
2915: anonsurvey_threshold => 10,
2916: uploadquota => 500,
1.257 raeburn 2917: postsubmit => 60,
1.198 raeburn 2918: );
1.139 raeburn 2919: if ($position eq 'top') {
1.257 raeburn 2920: %defaultchecked = (
2921: 'canuse_pdfforms' => 'off',
2922: 'uselcmath' => 'on',
2923: 'usejsme' => 'on',
2924: );
2925: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 2926: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 2927: \%choices,$itemcount);
1.139 raeburn 2928: } else {
2929: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.257 raeburn 2930: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.192 raeburn 2931: my $currusecredits = 0;
1.257 raeburn 2932: my $postsubmitclient = 1;
1.216 raeburn 2933: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2934: if (ref($settings) eq 'HASH') {
2935: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2936: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2937: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2938: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2939: }
2940: }
1.192 raeburn 2941: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 2942: foreach my $type (@types) {
2943: next if ($type eq 'community');
2944: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
2945: if ($defcredits{$type} ne '') {
2946: $currusecredits = 1;
2947: }
2948: }
2949: }
2950: if (ref($settings->{'postsubmit'}) eq 'HASH') {
2951: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
2952: $postsubmitclient = 0;
2953: foreach my $type (@types) {
2954: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2955: }
2956: } else {
2957: foreach my $type (@types) {
2958: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
2959: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
2960: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
2961: } else {
2962: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2963: }
2964: } else {
2965: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2966: }
2967: }
2968: }
2969: } else {
2970: foreach my $type (@types) {
2971: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 2972: }
2973: }
1.258 raeburn 2974: } else {
2975: foreach my $type (@types) {
2976: $deftimeout{$type} = $staticdefaults{'postsubmit'};
2977: }
1.139 raeburn 2978: }
2979: if (!$currdefresponder) {
1.198 raeburn 2980: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2981: } elsif ($currdefresponder < 1) {
2982: $currdefresponder = 1;
2983: }
1.198 raeburn 2984: foreach my $type (@types) {
2985: if ($curruploadquota{$type} eq '') {
2986: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2987: }
2988: }
1.139 raeburn 2989: $datatable .=
1.192 raeburn 2990: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2991: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2992: '</span></td>'.
2993: '<td class="LC_right_item"><span class="LC_nobreak">'.
2994: '<input type="text" name="anonsurvey_threshold"'.
2995: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2996: '</td></tr>'."\n";
2997: $itemcount ++;
2998: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2999: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3000: $choices{'uploadquota'}.
3001: '</span></td>'.
3002: '<td align="right" class="LC_right_item">'.
3003: '<table><tr>';
1.198 raeburn 3004: foreach my $type (@types) {
3005: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3006: '<input type="text" name="uploadquota_'.$type.'"'.
3007: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3008: }
3009: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3010: $itemcount ++;
1.236 raeburn 3011: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3012: my $display = 'none';
1.192 raeburn 3013: if ($currusecredits) {
3014: $display = 'block';
3015: }
3016: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3017: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3018: foreach my $type (@types) {
3019: next if ($type eq 'community');
3020: $additional .= '<td align="center">'.&mt($type).'<br />'.
3021: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3022: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3023: }
3024: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3025: %defaultchecked = ('coursecredits' => 'off');
3026: @toggles = ('coursecredits');
3027: my $current = {
3028: 'coursecredits' => $currusecredits,
3029: };
3030: (my $table,$itemcount) =
3031: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3032: \%choices,$itemcount,$onclick,$additional,'left');
3033: $datatable .= $table;
3034: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3035: my $display = 'none';
3036: if ($postsubmitclient) {
3037: $display = 'block';
3038: }
3039: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3040: &mt('Number of seconds submit is disabled').'<br />'.
3041: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3042: '<table><tr>';
1.257 raeburn 3043: foreach my $type (@types) {
3044: $additional .= '<td align="center">'.&mt($type).'<br />'.
3045: '<input type="text" name="'.$type.'_timeout" value="'.
3046: $deftimeout{$type}.'" size="5" /></td>';
3047: }
3048: $additional .= '</tr></table></div>'."\n";
3049: %defaultchecked = ('postsubmit' => 'on');
3050: @toggles = ('postsubmit');
3051: my $current = {
3052: 'postsubmit' => $postsubmitclient,
3053: };
3054: ($table,$itemcount) =
3055: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3056: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3057: $datatable .= $table;
1.139 raeburn 3058: }
1.192 raeburn 3059: $$rowtotal += $itemcount;
1.121 raeburn 3060: return $datatable;
1.118 jms 3061: }
3062:
1.231 raeburn 3063: sub print_selfenrollment {
3064: my ($position,$dom,$settings,$rowtotal) = @_;
3065: my ($css_class,$datatable);
3066: my $itemcount = 1;
3067: my @types = ('official','unofficial','community','textbook');
3068: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3069: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3070: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3071: my @rows;
3072: my $key;
3073: if ($position eq 'top') {
3074: $key = 'admin';
3075: if (ref($rowsref) eq 'ARRAY') {
3076: @rows = @{$rowsref};
3077: }
3078: } elsif ($position eq 'middle') {
3079: $key = 'default';
3080: @rows = ('types','registered','approval','limit');
3081: }
3082: foreach my $row (@rows) {
3083: if (defined($titlesref->{$row})) {
3084: $itemcount ++;
3085: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3086: $datatable .= '<tr'.$css_class.'>'.
3087: '<td>'.$titlesref->{$row}.'</td>'.
3088: '<td class="LC_left_item">'.
3089: '<table><tr>';
3090: my (%current,%currentcap);
3091: if (ref($settings) eq 'HASH') {
3092: if (ref($settings->{$key}) eq 'HASH') {
3093: foreach my $type (@types) {
3094: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3095: $current{$type} = $settings->{$key}->{$type}->{$row};
3096: }
3097: if (($row eq 'limit') && ($key eq 'default')) {
3098: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3099: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3100: }
3101: }
3102: }
3103: }
3104: }
3105: my %roles = (
3106: '0' => &Apache::lonnet::plaintext('dc'),
3107: );
3108:
3109: foreach my $type (@types) {
3110: unless (($row eq 'registered') && ($key eq 'default')) {
3111: $datatable .= '<th>'.&mt($type).'</th>';
3112: }
3113: }
3114: unless (($row eq 'registered') && ($key eq 'default')) {
3115: $datatable .= '</tr><tr>';
3116: }
3117: foreach my $type (@types) {
3118: if ($type eq 'community') {
3119: $roles{'1'} = &mt('Community personnel');
3120: } else {
3121: $roles{'1'} = &mt('Course personnel');
3122: }
3123: $datatable .= '<td style="vertical-align: top">';
3124: if ($position eq 'top') {
3125: my %checked;
3126: if ($current{$type} eq '0') {
3127: $checked{'0'} = ' checked="checked"';
3128: } else {
3129: $checked{'1'} = ' checked="checked"';
3130: }
3131: foreach my $role ('1','0') {
3132: $datatable .= '<span class="LC_nobreak"><label>'.
3133: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3134: 'value="'.$role.'"'.$checked{$role}.' />'.
3135: $roles{$role}.'</label></span> ';
3136: }
3137: } else {
3138: if ($row eq 'types') {
3139: my %checked;
3140: if ($current{$type} =~ /^(all|dom)$/) {
3141: $checked{$1} = ' checked="checked"';
3142: } else {
3143: $checked{''} = ' checked="checked"';
3144: }
3145: foreach my $val ('','dom','all') {
3146: $datatable .= '<span class="LC_nobreak"><label>'.
3147: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3148: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3149: }
3150: } elsif ($row eq 'registered') {
3151: my %checked;
3152: if ($current{$type} eq '1') {
3153: $checked{'1'} = ' checked="checked"';
3154: } else {
3155: $checked{'0'} = ' checked="checked"';
3156: }
3157: foreach my $val ('0','1') {
3158: $datatable .= '<span class="LC_nobreak"><label>'.
3159: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3160: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3161: }
3162: } elsif ($row eq 'approval') {
3163: my %checked;
3164: if ($current{$type} =~ /^([12])$/) {
3165: $checked{$1} = ' checked="checked"';
3166: } else {
3167: $checked{'0'} = ' checked="checked"';
3168: }
3169: for my $val (0..2) {
3170: $datatable .= '<span class="LC_nobreak"><label>'.
3171: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3172: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3173: }
3174: } elsif ($row eq 'limit') {
3175: my %checked;
3176: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3177: $checked{$1} = ' checked="checked"';
3178: } else {
3179: $checked{'none'} = ' checked="checked"';
3180: }
3181: my $cap;
3182: if ($currentcap{$type} =~ /^\d+$/) {
3183: $cap = $currentcap{$type};
3184: }
3185: foreach my $val ('none','allstudents','selfenrolled') {
3186: $datatable .= '<span class="LC_nobreak"><label>'.
3187: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3188: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3189: }
3190: $datatable .= '<br />'.
3191: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3192: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3193: '</span>';
3194: }
3195: }
3196: $datatable .= '</td>';
3197: }
3198: $datatable .= '</tr>';
3199: }
3200: $datatable .= '</table></td></tr>';
3201: }
3202: } elsif ($position eq 'bottom') {
1.235 raeburn 3203: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3204: }
3205: $$rowtotal += $itemcount;
3206: return $datatable;
3207: }
3208:
3209: sub print_validation_rows {
3210: my ($caller,$dom,$settings,$rowtotal) = @_;
3211: my ($itemsref,$namesref,$fieldsref);
3212: if ($caller eq 'selfenroll') {
3213: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3214: } elsif ($caller eq 'requestcourses') {
3215: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3216: }
3217: my %currvalidation;
3218: if (ref($settings) eq 'HASH') {
3219: if (ref($settings->{'validation'}) eq 'HASH') {
3220: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3221: }
1.235 raeburn 3222: }
3223: my $datatable;
3224: my $itemcount = 0;
3225: foreach my $item (@{$itemsref}) {
3226: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3227: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3228: $namesref->{$item}.
3229: '</span></td>'.
3230: '<td class="LC_left_item">';
3231: if (($item eq 'url') || ($item eq 'button')) {
3232: $datatable .= '<span class="LC_nobreak">'.
3233: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3234: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3235: } elsif ($item eq 'fields') {
3236: my @currfields;
3237: if (ref($currvalidation{$item}) eq 'ARRAY') {
3238: @currfields = @{$currvalidation{$item}};
3239: }
3240: foreach my $field (@{$fieldsref}) {
3241: my $check = '';
3242: if (grep(/^\Q$field\E$/,@currfields)) {
3243: $check = ' checked="checked"';
3244: }
3245: $datatable .= '<span class="LC_nobreak"><label>'.
3246: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3247: ' value="'.$field.'"'.$check.' />'.$field.
3248: '</label></span> ';
3249: }
3250: } elsif ($item eq 'markup') {
3251: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3252: $currvalidation{$item}.
1.231 raeburn 3253: '</textarea>';
1.235 raeburn 3254: }
3255: $datatable .= '</td></tr>'."\n";
3256: if (ref($rowtotal)) {
1.231 raeburn 3257: $itemcount ++;
3258: }
3259: }
1.235 raeburn 3260: if ($caller eq 'requestcourses') {
3261: my %currhash;
1.248 raeburn 3262: if (ref($settings) eq 'HASH') {
3263: if (ref($settings->{'validation'}) eq 'HASH') {
3264: if ($settings->{'validation'}{'dc'} ne '') {
3265: $currhash{$settings->{'validation'}{'dc'}} = 1;
3266: }
1.235 raeburn 3267: }
3268: }
3269: my $numinrow = 2;
3270: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3271: 'validationdc',%currhash);
1.247 raeburn 3272: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3273: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3274: if ($numdc > 1) {
1.247 raeburn 3275: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3276: } else {
1.247 raeburn 3277: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3278: }
1.247 raeburn 3279: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3280: $itemcount ++;
3281: }
3282: if (ref($rowtotal)) {
3283: $$rowtotal += $itemcount;
3284: }
1.231 raeburn 3285: return $datatable;
3286: }
3287:
1.137 raeburn 3288: sub print_usersessions {
3289: my ($position,$dom,$settings,$rowtotal) = @_;
3290: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3291: my (%by_ip,%by_location,@intdoms);
3292: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3293:
3294: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3295: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3296: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3297: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3298: my $itemcount = 1;
3299: if ($position eq 'top') {
1.152 raeburn 3300: if (keys(%serverhomes) > 1) {
1.145 raeburn 3301: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3302: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3303: } else {
1.140 raeburn 3304: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3305: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3306: }
1.137 raeburn 3307: } else {
1.145 raeburn 3308: if (keys(%by_location) == 0) {
3309: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3310: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3311: } else {
3312: my %lt = &usersession_titles();
3313: my $numinrow = 5;
3314: my $prefix;
3315: my @types;
3316: if ($position eq 'bottom') {
3317: $prefix = 'remote';
3318: @types = ('version','excludedomain','includedomain');
3319: } else {
3320: $prefix = 'hosted';
3321: @types = ('excludedomain','includedomain');
3322: }
3323: my (%current,%checkedon,%checkedoff);
3324: my @lcversions = &Apache::lonnet::all_loncaparevs();
3325: my @locations = sort(keys(%by_location));
3326: foreach my $type (@types) {
3327: $checkedon{$type} = '';
3328: $checkedoff{$type} = ' checked="checked"';
3329: }
3330: if (ref($settings) eq 'HASH') {
3331: if (ref($settings->{$prefix}) eq 'HASH') {
3332: foreach my $key (keys(%{$settings->{$prefix}})) {
3333: $current{$key} = $settings->{$prefix}{$key};
3334: if ($key eq 'version') {
3335: if ($current{$key} ne '') {
3336: $checkedon{$key} = ' checked="checked"';
3337: $checkedoff{$key} = '';
3338: }
3339: } elsif (ref($current{$key}) eq 'ARRAY') {
3340: $checkedon{$key} = ' checked="checked"';
3341: $checkedoff{$key} = '';
3342: }
1.137 raeburn 3343: }
3344: }
3345: }
1.145 raeburn 3346: foreach my $type (@types) {
3347: next if ($type ne 'version' && !@locations);
3348: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3349: $datatable .= '<tr'.$css_class.'>
3350: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3351: <span class="LC_nobreak">
3352: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3353: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3354: if ($type eq 'version') {
3355: my $selector = '<select name="'.$prefix.'_version">';
3356: foreach my $version (@lcversions) {
3357: my $selected = '';
3358: if ($current{'version'} eq $version) {
3359: $selected = ' selected="selected"';
3360: }
3361: $selector .= ' <option value="'.$version.'"'.
3362: $selected.'>'.$version.'</option>';
3363: }
3364: $selector .= '</select> ';
3365: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3366: } else {
3367: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3368: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3369: ' />'.(' 'x2).
3370: '<input type="button" value="'.&mt('uncheck all').'" '.
3371: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3372: "\n".
3373: '</div><div><table>';
3374: my $rem;
3375: for (my $i=0; $i<@locations; $i++) {
3376: my ($showloc,$value,$checkedtype);
3377: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3378: my $ip = $by_location{$locations[$i]}->[0];
3379: if (ref($by_ip{$ip}) eq 'ARRAY') {
3380: $value = join(':',@{$by_ip{$ip}});
3381: $showloc = join(', ',@{$by_ip{$ip}});
3382: if (ref($current{$type}) eq 'ARRAY') {
3383: foreach my $loc (@{$by_ip{$ip}}) {
3384: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3385: $checkedtype = ' checked="checked"';
3386: last;
3387: }
3388: }
1.138 raeburn 3389: }
3390: }
3391: }
1.145 raeburn 3392: $rem = $i%($numinrow);
3393: if ($rem == 0) {
3394: if ($i > 0) {
3395: $datatable .= '</tr>';
3396: }
3397: $datatable .= '<tr>';
3398: }
3399: $datatable .= '<td class="LC_left_item">'.
3400: '<span class="LC_nobreak"><label>'.
3401: '<input type="checkbox" name="'.$prefix.'_'.$type.
3402: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3403: '</label></span></td>';
1.137 raeburn 3404: }
1.145 raeburn 3405: $rem = @locations%($numinrow);
3406: my $colsleft = $numinrow - $rem;
3407: if ($colsleft > 1 ) {
3408: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3409: ' </td>';
3410: } elsif ($colsleft == 1) {
3411: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3412: }
1.145 raeburn 3413: $datatable .= '</tr></table>';
1.137 raeburn 3414: }
1.145 raeburn 3415: $datatable .= '</td></tr>';
3416: $itemcount ++;
1.137 raeburn 3417: }
3418: }
3419: }
3420: $$rowtotal += $itemcount;
3421: return $datatable;
3422: }
3423:
1.138 raeburn 3424: sub build_location_hashes {
3425: my ($intdoms,$by_ip,$by_location) = @_;
3426: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3427: (ref($by_location) eq 'HASH'));
3428: my %iphost = &Apache::lonnet::get_iphost();
3429: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3430: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3431: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3432: foreach my $id (@{$iphost{$primary_ip}}) {
3433: my $intdom = &Apache::lonnet::internet_dom($id);
3434: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3435: push(@{$intdoms},$intdom);
3436: }
3437: }
3438: }
3439: foreach my $ip (keys(%iphost)) {
3440: if (ref($iphost{$ip}) eq 'ARRAY') {
3441: foreach my $id (@{$iphost{$ip}}) {
3442: my $location = &Apache::lonnet::internet_dom($id);
3443: if ($location) {
3444: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3445: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3446: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3447: push(@{$by_ip->{$ip}},$location);
3448: }
3449: } else {
3450: $by_ip->{$ip} = [$location];
3451: }
3452: }
3453: }
3454: }
3455: }
3456: foreach my $ip (sort(keys(%{$by_ip}))) {
3457: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3458: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3459: my $first = $by_ip->{$ip}->[0];
3460: if (ref($by_location->{$first}) eq 'ARRAY') {
3461: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3462: push(@{$by_location->{$first}},$ip);
3463: }
3464: } else {
3465: $by_location->{$first} = [$ip];
3466: }
3467: }
3468: }
3469: return;
3470: }
3471:
1.145 raeburn 3472: sub current_offloads_to {
3473: my ($dom,$settings,$servers) = @_;
3474: my (%spareid,%otherdomconfigs);
1.152 raeburn 3475: if (ref($servers) eq 'HASH') {
1.145 raeburn 3476: foreach my $lonhost (sort(keys(%{$servers}))) {
3477: my $gotspares;
1.152 raeburn 3478: if (ref($settings) eq 'HASH') {
3479: if (ref($settings->{'spares'}) eq 'HASH') {
3480: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3481: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3482: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3483: $gotspares = 1;
3484: }
1.145 raeburn 3485: }
3486: }
3487: unless ($gotspares) {
3488: my $gotspares;
3489: my $serverhomeID =
3490: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3491: my $serverhomedom =
3492: &Apache::lonnet::host_domain($serverhomeID);
3493: if ($serverhomedom ne $dom) {
3494: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3495: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3496: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3497: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3498: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3499: $gotspares = 1;
3500: }
3501: }
3502: } else {
3503: $otherdomconfigs{$serverhomedom} =
3504: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3505: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3506: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3507: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3508: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3509: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3510: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3511: $gotspares = 1;
3512: }
3513: }
3514: }
3515: }
3516: }
3517: }
3518: }
3519: unless ($gotspares) {
3520: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3521: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3522: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3523: } else {
3524: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3525: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3526: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3527: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3528: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3529: } else {
1.150 raeburn 3530: my %what = (
3531: spareid => 1,
3532: );
3533: my ($result,$returnhash) =
3534: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3535: if ($result eq 'ok') {
3536: if (ref($returnhash) eq 'HASH') {
3537: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3538: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3539: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3540: }
3541: }
1.145 raeburn 3542: }
3543: }
3544: }
3545: }
3546: }
3547: }
3548: return %spareid;
3549: }
3550:
3551: sub spares_row {
1.152 raeburn 3552: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3553: my $css_class;
3554: my $numinrow = 4;
3555: my $itemcount = 1;
3556: my $datatable;
1.152 raeburn 3557: my %typetitles = &sparestype_titles();
3558: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3559: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3560: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3561: my ($othercontrol,$serverdom);
3562: if ($serverhome ne $server) {
3563: $serverdom = &Apache::lonnet::host_domain($serverhome);
3564: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3565: } else {
3566: $serverdom = &Apache::lonnet::host_domain($server);
3567: if ($serverdom ne $dom) {
3568: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3569: }
3570: }
3571: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3572: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3573: $datatable .= '<tr'.$css_class.'>
3574: <td rowspan="2">
1.183 bisitz 3575: <span class="LC_nobreak">'.
3576: &mt('[_1] when busy, offloads to:'
3577: ,'<b>'.$server.'</b>').
3578: "\n";
1.145 raeburn 3579: my (%current,%canselect);
1.152 raeburn 3580: my @choices =
3581: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3582: foreach my $type ('primary','default') {
3583: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3584: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3585: my @spares = @{$spareid->{$server}{$type}};
3586: if (@spares > 0) {
1.152 raeburn 3587: if ($othercontrol) {
3588: $current{$type} = join(', ',@spares);
3589: } else {
3590: $current{$type} .= '<table>';
3591: my $numspares = scalar(@spares);
3592: for (my $i=0; $i<@spares; $i++) {
3593: my $rem = $i%($numinrow);
3594: if ($rem == 0) {
3595: if ($i > 0) {
3596: $current{$type} .= '</tr>';
3597: }
3598: $current{$type} .= '<tr>';
1.145 raeburn 3599: }
1.152 raeburn 3600: $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'".');" /> '.
3601: $spareid->{$server}{$type}[$i].
3602: '</label></td>'."\n";
3603: }
3604: my $rem = @spares%($numinrow);
3605: my $colsleft = $numinrow - $rem;
3606: if ($colsleft > 1 ) {
3607: $current{$type} .= '<td colspan="'.$colsleft.
3608: '" class="LC_left_item">'.
3609: ' </td>';
3610: } elsif ($colsleft == 1) {
3611: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3612: }
1.152 raeburn 3613: $current{$type} .= '</tr></table>';
1.150 raeburn 3614: }
1.145 raeburn 3615: }
3616: }
3617: if ($current{$type} eq '') {
3618: $current{$type} = &mt('None specified');
3619: }
1.152 raeburn 3620: if ($othercontrol) {
3621: if ($type eq 'primary') {
3622: $canselect{$type} = $othercontrol;
3623: }
3624: } else {
3625: $canselect{$type} =
3626: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3627: '<select name="newspare_'.$type.'_'.$server.'" '.
3628: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3629: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3630: if (@choices > 0) {
3631: foreach my $lonhost (@choices) {
3632: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3633: }
3634: }
3635: $canselect{$type} .= '</select>'."\n";
3636: }
3637: } else {
3638: $current{$type} = &mt('Could not be determined');
3639: if ($type eq 'primary') {
3640: $canselect{$type} = $othercontrol;
3641: }
1.145 raeburn 3642: }
1.152 raeburn 3643: if ($type eq 'default') {
3644: $datatable .= '<tr'.$css_class.'>';
3645: }
3646: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3647: '<td>'.$current{$type}.'</td>'."\n".
3648: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3649: }
3650: $itemcount ++;
3651: }
3652: }
3653: $$rowtotal += $itemcount;
3654: return $datatable;
3655: }
3656:
1.152 raeburn 3657: sub possible_newspares {
3658: my ($server,$currspares,$serverhomes,$altids) = @_;
3659: my $serverhostname = &Apache::lonnet::hostname($server);
3660: my %excluded;
3661: if ($serverhostname ne '') {
3662: %excluded = (
3663: $serverhostname => 1,
3664: );
3665: }
3666: if (ref($currspares) eq 'HASH') {
3667: foreach my $type (keys(%{$currspares})) {
3668: if (ref($currspares->{$type}) eq 'ARRAY') {
3669: if (@{$currspares->{$type}} > 0) {
3670: foreach my $curr (@{$currspares->{$type}}) {
3671: my $hostname = &Apache::lonnet::hostname($curr);
3672: $excluded{$hostname} = 1;
3673: }
3674: }
3675: }
3676: }
3677: }
3678: my @choices;
3679: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3680: if (keys(%{$serverhomes}) > 1) {
3681: foreach my $name (sort(keys(%{$serverhomes}))) {
3682: unless ($excluded{$name}) {
3683: if (exists($altids->{$serverhomes->{$name}})) {
3684: push(@choices,$altids->{$serverhomes->{$name}});
3685: } else {
3686: push(@choices,$serverhomes->{$name});
1.145 raeburn 3687: }
3688: }
3689: }
3690: }
3691: }
1.152 raeburn 3692: return sort(@choices);
1.145 raeburn 3693: }
3694:
1.150 raeburn 3695: sub print_loadbalancing {
3696: my ($dom,$settings,$rowtotal) = @_;
3697: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3698: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3699: my $numinrow = 1;
3700: my $datatable;
3701: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3702: my (%currbalancer,%currtargets,%currrules,%existing);
3703: if (ref($settings) eq 'HASH') {
3704: %existing = %{$settings};
3705: }
3706: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3707: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3708: \%currtargets,\%currrules);
1.150 raeburn 3709: } else {
3710: return;
3711: }
3712: my ($othertitle,$usertypes,$types) =
3713: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3714: my $rownum = 8;
1.150 raeburn 3715: if (ref($types) eq 'ARRAY') {
3716: $rownum += scalar(@{$types});
3717: }
1.171 raeburn 3718: my @css_class = ('LC_odd_row','LC_even_row');
3719: my $balnum = 0;
3720: my $islast;
3721: my (@toshow,$disabledtext);
3722: if (keys(%currbalancer) > 0) {
3723: @toshow = sort(keys(%currbalancer));
3724: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3725: push(@toshow,'');
3726: }
3727: } else {
3728: @toshow = ('');
3729: $disabledtext = &mt('No existing load balancer');
3730: }
3731: foreach my $lonhost (@toshow) {
3732: if ($balnum == scalar(@toshow)-1) {
3733: $islast = 1;
3734: } else {
3735: $islast = 0;
3736: }
3737: my $cssidx = $balnum%2;
3738: my $targets_div_style = 'display: none';
3739: my $disabled_div_style = 'display: block';
3740: my $homedom_div_style = 'display: none';
3741: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3742: '<td rowspan="'.$rownum.'" valign="top">'.
3743: '<p>';
3744: if ($lonhost eq '') {
1.210 raeburn 3745: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3746: if (keys(%currbalancer) > 0) {
3747: $datatable .= &mt('Add balancer:');
3748: } else {
3749: $datatable .= &mt('Enable balancer:');
3750: }
3751: $datatable .= ' '.
3752: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3753: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3754: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3755: '<option value="" selected="selected">'.&mt('None').
3756: '</option>'."\n";
3757: foreach my $server (sort(keys(%servers))) {
3758: next if ($currbalancer{$server});
3759: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3760: }
1.210 raeburn 3761: $datatable .=
1.171 raeburn 3762: '</select>'."\n".
3763: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3764: } else {
3765: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3766: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3767: &mt('Stop balancing').'</label>'.
3768: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3769: $targets_div_style = 'display: block';
3770: $disabled_div_style = 'display: none';
3771: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3772: $homedom_div_style = 'display: block';
3773: }
3774: }
3775: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3776: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3777: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3778: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3779: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3780: my @sparestypes = ('primary','default');
3781: my %typetitles = &sparestype_titles();
3782: foreach my $sparetype (@sparestypes) {
3783: my $targettable;
3784: for (my $i=0; $i<$numspares; $i++) {
3785: my $checked;
3786: if (ref($currtargets{$lonhost}) eq 'HASH') {
3787: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3788: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3789: $checked = ' checked="checked"';
3790: }
3791: }
3792: }
3793: my ($chkboxval,$disabled);
3794: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3795: $chkboxval = $spares[$i];
3796: }
3797: if (exists($currbalancer{$spares[$i]})) {
3798: $disabled = ' disabled="disabled"';
3799: }
1.210 raeburn 3800: $targettable .=
1.253 raeburn 3801: '<td><span class="LC_nobreak"><label>'.
3802: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 3803: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 3804: '</span></label></span></td>';
1.171 raeburn 3805: my $rem = $i%($numinrow);
3806: if ($rem == 0) {
3807: if (($i > 0) && ($i < $numspares-1)) {
3808: $targettable .= '</tr>';
3809: }
3810: if ($i < $numspares-1) {
3811: $targettable .= '<tr>';
1.150 raeburn 3812: }
3813: }
3814: }
1.171 raeburn 3815: if ($targettable ne '') {
3816: my $rem = $numspares%($numinrow);
3817: my $colsleft = $numinrow - $rem;
3818: if ($colsleft > 1 ) {
3819: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3820: ' </td>';
3821: } elsif ($colsleft == 1) {
3822: $targettable .= '<td class="LC_left_item"> </td>';
3823: }
3824: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3825: '<table><tr>'.$targettable.'</tr></table><br />';
3826: }
3827: }
3828: $datatable .= '</div></td></tr>'.
3829: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3830: $othertitle,$usertypes,$types,\%servers,
3831: \%currbalancer,$lonhost,
3832: $targets_div_style,$homedom_div_style,
3833: $css_class[$cssidx],$balnum,$islast);
3834: $$rowtotal += $rownum;
3835: $balnum ++;
3836: }
3837: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3838: return $datatable;
3839: }
3840:
3841: sub get_loadbalancers_config {
3842: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3843: return unless ((ref($servers) eq 'HASH') &&
3844: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3845: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3846: if (keys(%{$existing}) > 0) {
3847: my $oldlonhost;
3848: foreach my $key (sort(keys(%{$existing}))) {
3849: if ($key eq 'lonhost') {
3850: $oldlonhost = $existing->{'lonhost'};
3851: $currbalancer->{$oldlonhost} = 1;
3852: } elsif ($key eq 'targets') {
3853: if ($oldlonhost) {
3854: $currtargets->{$oldlonhost} = $existing->{'targets'};
3855: }
3856: } elsif ($key eq 'rules') {
3857: if ($oldlonhost) {
3858: $currrules->{$oldlonhost} = $existing->{'rules'};
3859: }
3860: } elsif (ref($existing->{$key}) eq 'HASH') {
3861: $currbalancer->{$key} = 1;
3862: $currtargets->{$key} = $existing->{$key}{'targets'};
3863: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3864: }
3865: }
1.171 raeburn 3866: } else {
3867: my ($balancerref,$targetsref) =
3868: &Apache::lonnet::get_lonbalancer_config($servers);
3869: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3870: foreach my $server (sort(keys(%{$balancerref}))) {
3871: $currbalancer->{$server} = 1;
3872: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3873: }
3874: }
3875: }
1.171 raeburn 3876: return;
1.150 raeburn 3877: }
3878:
3879: sub loadbalancing_rules {
3880: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3881: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3882: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3883: my $output;
1.171 raeburn 3884: my $num = 0;
1.210 raeburn 3885: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3886: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3887: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3888: foreach my $type (@{$alltypes}) {
1.171 raeburn 3889: $num ++;
1.150 raeburn 3890: my $current;
3891: if (ref($currrules) eq 'HASH') {
3892: $current = $currrules->{$type};
3893: }
1.253 raeburn 3894: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3895: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3896: $current = '';
3897: }
3898: }
3899: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3900: $servers,$currbalancer,$lonhost,$dom,
3901: $targets_div_style,$homedom_div_style,
3902: $css_class,$balnum,$num,$islast);
1.150 raeburn 3903: }
3904: }
3905: return $output;
3906: }
3907:
3908: sub loadbalancing_titles {
3909: my ($dom,$intdom,$usertypes,$types) = @_;
3910: my %othertypes = (
3911: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3912: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3913: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3914: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3915: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3916: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3917: );
1.209 raeburn 3918: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3919: if (ref($types) eq 'ARRAY') {
3920: unshift(@alltypes,@{$types},'default');
3921: }
3922: my %titles;
3923: foreach my $type (@alltypes) {
3924: if ($type =~ /^_LC_/) {
3925: $titles{$type} = $othertypes{$type};
3926: } elsif ($type eq 'default') {
3927: $titles{$type} = &mt('All users from [_1]',$dom);
3928: if (ref($types) eq 'ARRAY') {
3929: if (@{$types} > 0) {
3930: $titles{$type} = &mt('Other users from [_1]',$dom);
3931: }
3932: }
3933: } elsif (ref($usertypes) eq 'HASH') {
3934: $titles{$type} = $usertypes->{$type};
3935: }
3936: }
3937: return (\@alltypes,\%othertypes,\%titles);
3938: }
3939:
3940: sub loadbalance_rule_row {
1.171 raeburn 3941: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3942: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3943: my @rulenames;
1.150 raeburn 3944: my %ruletitles = &offloadtype_text();
1.209 raeburn 3945: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 3946: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3947: } else {
1.209 raeburn 3948: @rulenames = ('default','homeserver');
3949: if ($type eq '_LC_external') {
3950: push(@rulenames,'externalbalancer');
3951: } else {
3952: push(@rulenames,'specific');
3953: }
3954: push(@rulenames,'none');
1.150 raeburn 3955: }
3956: my $style = $targets_div_style;
1.253 raeburn 3957: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3958: $style = $homedom_div_style;
3959: }
1.171 raeburn 3960: my $space;
3961: if ($islast && $num == 1) {
3962: $space = '<div display="inline-block"> </div>';
3963: }
1.210 raeburn 3964: my $output =
1.171 raeburn 3965: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3966: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3967: '<td valaign="top">'.$space.
3968: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3969: for (my $i=0; $i<@rulenames; $i++) {
3970: my $rule = $rulenames[$i];
3971: my ($checked,$extra);
3972: if ($rulenames[$i] eq 'default') {
3973: $rule = '';
3974: }
3975: if ($rulenames[$i] eq 'specific') {
3976: if (ref($servers) eq 'HASH') {
3977: my $default;
3978: if (($current ne '') && (exists($servers->{$current}))) {
3979: $checked = ' checked="checked"';
3980: }
3981: unless ($checked) {
3982: $default = ' selected="selected"';
3983: }
1.210 raeburn 3984: $extra =
1.171 raeburn 3985: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3986: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3987: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3988: '<option value=""'.$default.'></option>'."\n";
3989: foreach my $server (sort(keys(%{$servers}))) {
3990: if (ref($currbalancer) eq 'HASH') {
3991: next if (exists($currbalancer->{$server}));
3992: }
1.150 raeburn 3993: my $selected;
1.171 raeburn 3994: if ($server eq $current) {
1.150 raeburn 3995: $selected = ' selected="selected"';
3996: }
1.171 raeburn 3997: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3998: }
3999: $extra .= '</select>';
4000: }
4001: } elsif ($rule eq $current) {
4002: $checked = ' checked="checked"';
4003: }
4004: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4005: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4006: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4007: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4008: ')"'.$checked.' /> ';
4009: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4010: $output .= $ruletitles{'particular'};
4011: } else {
4012: $output .= $ruletitles{$rulenames[$i]};
4013: }
4014: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4015: }
4016: $output .= '</div></td></tr>'."\n";
4017: return $output;
4018: }
4019:
4020: sub offloadtype_text {
4021: my %ruletitles = &Apache::lonlocal::texthash (
4022: 'default' => 'Offloads to default destinations',
4023: 'homeserver' => "Offloads to user's home server",
4024: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4025: 'specific' => 'Offloads to specific server',
1.161 raeburn 4026: 'none' => 'No offload',
1.209 raeburn 4027: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4028: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4029: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4030: );
4031: return %ruletitles;
4032: }
4033:
4034: sub sparestype_titles {
4035: my %typestitles = &Apache::lonlocal::texthash (
4036: 'primary' => 'primary',
4037: 'default' => 'default',
4038: );
4039: return %typestitles;
4040: }
4041:
1.28 raeburn 4042: sub contact_titles {
4043: my %titles = &Apache::lonlocal::texthash (
4044: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4045: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4046: 'errormail' => 'Error reports to be e-mailed to',
4047: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4048: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4049: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4050: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4051: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4052: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4053: );
4054: my %short_titles = &Apache::lonlocal::texthash (
4055: adminemail => 'Admin E-mail address',
4056: supportemail => 'Support E-mail',
4057: );
4058: return (\%titles,\%short_titles);
4059: }
4060:
1.72 raeburn 4061: sub tool_titles {
4062: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4063: aboutme => 'Personal web page',
1.86 raeburn 4064: blog => 'Blog',
1.162 raeburn 4065: webdav => 'WebDAV',
1.86 raeburn 4066: portfolio => 'Portfolio',
1.88 bisitz 4067: official => 'Official courses (with institutional codes)',
4068: unofficial => 'Unofficial courses',
1.98 raeburn 4069: community => 'Communities',
1.216 raeburn 4070: textbook => 'Textbook courses',
1.86 raeburn 4071: );
1.72 raeburn 4072: return %titles;
4073: }
4074:
1.101 raeburn 4075: sub courserequest_titles {
4076: my %titles = &Apache::lonlocal::texthash (
4077: official => 'Official',
4078: unofficial => 'Unofficial',
4079: community => 'Communities',
1.216 raeburn 4080: textbook => 'Textbook',
1.101 raeburn 4081: norequest => 'Not allowed',
1.104 raeburn 4082: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4083: validate => 'With validation',
4084: autolimit => 'Numerical limit',
1.103 raeburn 4085: unlimited => '(blank for unlimited)',
1.101 raeburn 4086: );
4087: return %titles;
4088: }
4089:
1.163 raeburn 4090: sub authorrequest_titles {
4091: my %titles = &Apache::lonlocal::texthash (
4092: norequest => 'Not allowed',
4093: approval => 'Approval by Dom. Coord.',
4094: automatic => 'Automatic approval',
4095: );
4096: return %titles;
1.210 raeburn 4097: }
1.163 raeburn 4098:
1.101 raeburn 4099: sub courserequest_conditions {
4100: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4101: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4102: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4103: );
4104: return %conditions;
4105: }
4106:
4107:
1.27 raeburn 4108: sub print_usercreation {
1.30 raeburn 4109: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4110: my $numinrow = 4;
1.28 raeburn 4111: my $datatable;
4112: if ($position eq 'top') {
1.30 raeburn 4113: $$rowtotal ++;
1.34 raeburn 4114: my $rowcount = 0;
1.32 raeburn 4115: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4116: if (ref($rules) eq 'HASH') {
4117: if (keys(%{$rules}) > 0) {
1.32 raeburn 4118: $datatable .= &user_formats_row('username',$settings,$rules,
4119: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4120: $$rowtotal ++;
1.32 raeburn 4121: $rowcount ++;
4122: }
4123: }
4124: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4125: if (ref($idrules) eq 'HASH') {
4126: if (keys(%{$idrules}) > 0) {
4127: $datatable .= &user_formats_row('id',$settings,$idrules,
4128: $idruleorder,$numinrow,$rowcount);
4129: $$rowtotal ++;
4130: $rowcount ++;
1.28 raeburn 4131: }
4132: }
1.39 raeburn 4133: if ($rowcount == 0) {
4134: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4135: $$rowtotal ++;
4136: $rowcount ++;
4137: }
1.34 raeburn 4138: } elsif ($position eq 'middle') {
1.224 raeburn 4139: my @creators = ('author','course','requestcrs');
1.37 raeburn 4140: my ($rules,$ruleorder) =
4141: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4142: my %lt = &usercreation_types();
4143: my %checked;
4144: if (ref($settings) eq 'HASH') {
4145: if (ref($settings->{'cancreate'}) eq 'HASH') {
4146: foreach my $item (@creators) {
4147: $checked{$item} = $settings->{'cancreate'}{$item};
4148: }
4149: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4150: foreach my $item (@creators) {
4151: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4152: $checked{$item} = 'none';
4153: }
4154: }
4155: }
4156: }
4157: my $rownum = 0;
4158: foreach my $item (@creators) {
4159: $rownum ++;
1.224 raeburn 4160: if ($checked{$item} eq '') {
4161: $checked{$item} = 'any';
1.34 raeburn 4162: }
4163: my $css_class;
4164: if ($rownum%2) {
4165: $css_class = '';
4166: } else {
4167: $css_class = ' class="LC_odd_row" ';
4168: }
4169: $datatable .= '<tr'.$css_class.'>'.
4170: '<td><span class="LC_nobreak">'.$lt{$item}.
4171: '</span></td><td align="right">';
1.224 raeburn 4172: my @options = ('any');
4173: if (ref($rules) eq 'HASH') {
4174: if (keys(%{$rules}) > 0) {
4175: push(@options,('official','unofficial'));
1.37 raeburn 4176: }
4177: }
1.224 raeburn 4178: push(@options,'none');
1.37 raeburn 4179: foreach my $option (@options) {
1.50 raeburn 4180: my $type = 'radio';
1.34 raeburn 4181: my $check = ' ';
1.224 raeburn 4182: if ($checked{$item} eq $option) {
4183: $check = ' checked="checked" ';
1.34 raeburn 4184: }
4185: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4186: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4187: $item.'" value="'.$option.'"'.$check.'/> '.
4188: $lt{$option}.'</label> </span>';
4189: }
4190: $datatable .= '</td></tr>';
4191: }
1.28 raeburn 4192: } else {
4193: my @contexts = ('author','course','domain');
4194: my @authtypes = ('int','krb4','krb5','loc');
4195: my %checked;
4196: if (ref($settings) eq 'HASH') {
4197: if (ref($settings->{'authtypes'}) eq 'HASH') {
4198: foreach my $item (@contexts) {
4199: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4200: foreach my $auth (@authtypes) {
4201: if ($settings->{'authtypes'}{$item}{$auth}) {
4202: $checked{$item}{$auth} = ' checked="checked" ';
4203: }
4204: }
4205: }
4206: }
1.27 raeburn 4207: }
1.35 raeburn 4208: } else {
4209: foreach my $item (@contexts) {
1.36 raeburn 4210: foreach my $auth (@authtypes) {
1.35 raeburn 4211: $checked{$item}{$auth} = ' checked="checked" ';
4212: }
4213: }
1.27 raeburn 4214: }
1.28 raeburn 4215: my %title = &context_names();
4216: my %authname = &authtype_names();
4217: my $rownum = 0;
4218: my $css_class;
4219: foreach my $item (@contexts) {
4220: if ($rownum%2) {
4221: $css_class = '';
4222: } else {
4223: $css_class = ' class="LC_odd_row" ';
4224: }
1.30 raeburn 4225: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4226: '<td>'.$title{$item}.
4227: '</td><td class="LC_left_item">'.
4228: '<span class="LC_nobreak">';
4229: foreach my $auth (@authtypes) {
4230: $datatable .= '<label>'.
4231: '<input type="checkbox" name="'.$item.'_auth" '.
4232: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4233: $authname{$auth}.'</label> ';
4234: }
4235: $datatable .= '</span></td></tr>';
4236: $rownum ++;
1.27 raeburn 4237: }
1.30 raeburn 4238: $$rowtotal += $rownum;
1.27 raeburn 4239: }
4240: return $datatable;
4241: }
4242:
1.224 raeburn 4243: sub print_selfcreation {
4244: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4245: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4246: if (ref($settings) eq 'HASH') {
4247: if (ref($settings->{'cancreate'}) eq 'HASH') {
4248: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4249: if (ref($createsettings) eq 'HASH') {
4250: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4251: @selfcreate = @{$createsettings->{'selfcreate'}};
4252: } elsif ($createsettings->{'selfcreate'} ne '') {
4253: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4254: @selfcreate = ('email','login','sso');
4255: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4256: @selfcreate = ($createsettings->{'selfcreate'});
4257: }
4258: }
4259: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4260: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4261: }
4262: }
4263: }
4264: }
4265: my %radiohash;
4266: my $numinrow = 4;
4267: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4268: if ($position eq 'top') {
4269: my %choices = &Apache::lonlocal::texthash (
4270: cancreate_login => 'Institutional Login',
4271: cancreate_sso => 'Institutional Single Sign On',
4272: );
4273: my @toggles = sort(keys(%choices));
4274: my %defaultchecked = (
4275: 'cancreate_login' => 'off',
4276: 'cancreate_sso' => 'off',
4277: );
1.228 raeburn 4278: my ($onclick,$itemcount);
1.224 raeburn 4279: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4280: \%choices,$itemcount,$onclick);
1.228 raeburn 4281: $$rowtotal += $itemcount;
4282:
1.224 raeburn 4283: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4284:
4285: if (ref($usertypes) eq 'HASH') {
4286: if (keys(%{$usertypes}) > 0) {
4287: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4288: $dom,$numinrow,$othertitle,
1.228 raeburn 4289: 'statustocreate',$$rowtotal);
1.224 raeburn 4290: $$rowtotal ++;
4291: }
4292: }
1.240 raeburn 4293: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4294: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4295: $fieldtitles{'inststatus'} = &mt('Institutional status');
4296: my $rem;
4297: my $numperrow = 2;
4298: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4299: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4300: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4301: '<td class="LC_left_item">'."\n".
4302: '<table><tr><td>'."\n";
4303: for (my $i=0; $i<@fields; $i++) {
4304: $rem = $i%($numperrow);
4305: if ($rem == 0) {
4306: if ($i > 0) {
4307: $datatable .= '</tr>';
4308: }
4309: $datatable .= '<tr>';
4310: }
4311: my $currval;
1.248 raeburn 4312: if (ref($createsettings) eq 'HASH') {
4313: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4314: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4315: }
1.240 raeburn 4316: }
4317: $datatable .= '<td class="LC_left_item">'.
4318: '<span class="LC_nobreak">'.
4319: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4320: 'value="'.$currval.'" size="10" /> '.
4321: $fieldtitles{$fields[$i]}.'</span></td>';
4322: }
4323: my $colsleft = $numperrow - $rem;
4324: if ($colsleft > 1 ) {
4325: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4326: ' </td>';
4327: } elsif ($colsleft == 1) {
4328: $datatable .= '<td class="LC_left_item"> </td>';
4329: }
4330: $datatable .= '</tr></table></td></tr>';
4331: $$rowtotal ++;
1.224 raeburn 4332: } elsif ($position eq 'middle') {
4333: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4334: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4335: $usertypes->{'default'} = $othertitle;
4336: if (ref($types) eq 'ARRAY') {
4337: push(@{$types},'default');
4338: $usertypes->{'default'} = $othertitle;
4339: foreach my $status (@{$types}) {
4340: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4341: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4342: $$rowtotal ++;
1.224 raeburn 4343: }
4344: }
4345: } else {
1.236 raeburn 4346: my %choices = &Apache::lonlocal::texthash (
4347: cancreate_email => 'E-mail address as username',
4348: );
4349: my @toggles = sort(keys(%choices));
4350: my %defaultchecked = (
4351: 'cancreate_email' => 'off',
4352: );
4353: my $itemcount = 0;
4354: my $display = 'none';
4355: if (grep(/^\Qemail\E$/,@selfcreate)) {
4356: $display = 'block';
4357: }
4358: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4359: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4360: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4361: my $usertypes = {};
4362: my $order = [];
4363: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4364: $usertypes = $domdefaults{'inststatustypes'};
4365: $order = $domdefaults{'inststatusguest'};
4366: }
4367: if (ref($order) eq 'ARRAY') {
4368: push(@{$order},'default');
4369: if (@{$order} > 1) {
4370: $usertypes->{'default'} = &mt('Other users');
4371: $additional .= '<table><tr>';
4372: foreach my $status (@{$order}) {
4373: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4374: }
4375: $additional .= '</tr><tr>';
4376: foreach my $status (@{$order}) {
4377: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4378: }
1.236 raeburn 4379: $additional .= '</tr></table>';
1.224 raeburn 4380: } else {
1.236 raeburn 4381: $usertypes->{'default'} = &mt('All users');
4382: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4383: }
4384: }
1.236 raeburn 4385: $additional .= '</div>'."\n";
4386:
4387: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4388: \%choices,$$rowtotal,$onclick,$additional);
4389: $$rowtotal ++;
1.236 raeburn 4390: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4391: $$rowtotal ++;
1.224 raeburn 4392: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4393: $numinrow = 1;
1.236 raeburn 4394: if (ref($order) eq 'ARRAY') {
4395: foreach my $status (@{$order}) {
1.228 raeburn 4396: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4397: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4398: $$rowtotal ++;
4399: }
4400: }
1.224 raeburn 4401: my ($emailrules,$emailruleorder) =
4402: &Apache::lonnet::inst_userrules($dom,'email');
4403: if (ref($emailrules) eq 'HASH') {
4404: if (keys(%{$emailrules}) > 0) {
4405: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4406: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4407: $$rowtotal ++;
4408: }
4409: }
1.228 raeburn 4410: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4411: }
4412: return $datatable;
4413: }
4414:
1.236 raeburn 4415: sub email_as_username {
4416: my ($rowtotal,$processing,$type) = @_;
4417: my %choices =
4418: &Apache::lonlocal::texthash (
4419: automatic => 'Automatic approval',
4420: approval => 'Queued for approval',
4421: );
4422: my $output;
4423: foreach my $option ('automatic','approval') {
4424: my $checked;
4425: if (ref($processing) eq 'HASH') {
4426: if ($type eq '') {
4427: if (!exists($processing->{'default'})) {
4428: if ($option eq 'automatic') {
4429: $checked = ' checked="checked"';
4430: }
4431: } else {
4432: if ($processing->{'default'} eq $option) {
4433: $checked = ' checked="checked"';
4434: }
4435: }
4436: } else {
4437: if (!exists($processing->{$type})) {
4438: if ($option eq 'automatic') {
4439: $checked = ' checked="checked"';
4440: }
4441: } else {
4442: if ($processing->{$type} eq $option) {
4443: $checked = ' checked="checked"';
4444: }
4445: }
4446: }
4447: } elsif ($option eq 'automatic') {
4448: $checked = ' checked="checked"';
4449: }
4450: my $name = 'cancreate_emailprocess';
4451: if (($type ne '') && ($type ne 'default')) {
4452: $name .= '_'.$type;
4453: }
4454: $output .= '<span class="LC_nobreak"><label>'.
4455: '<input type="radio" name="'.$name.'"'.
4456: $checked.' value="'.$option.'" />'.
4457: $choices{$option}.'</label></span>';
4458: if ($type eq '') {
4459: $output .= ' ';
4460: } else {
4461: $output .= '<br />';
4462: }
4463: }
4464: $$rowtotal ++;
4465: return $output;
4466: }
4467:
1.165 raeburn 4468: sub captcha_choice {
1.169 raeburn 4469: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4470: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4471: my %lt = &captcha_phrases();
4472: $keyentry = 'hidden';
4473: if ($context eq 'cancreate') {
1.224 raeburn 4474: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4475: } elsif ($context eq 'login') {
4476: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4477: }
4478: if (ref($settings) eq 'HASH') {
4479: if ($settings->{'captcha'}) {
4480: $checked{$settings->{'captcha'}} = ' checked="checked"';
4481: } else {
4482: $checked{'original'} = ' checked="checked"';
4483: }
4484: if ($settings->{'captcha'} eq 'recaptcha') {
4485: $pubtext = $lt{'pub'};
4486: $privtext = $lt{'priv'};
4487: $keyentry = 'text';
4488: }
4489: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4490: $currpub = $settings->{'recaptchakeys'}{'public'};
4491: $currpriv = $settings->{'recaptchakeys'}{'private'};
4492: }
4493: } else {
4494: $checked{'original'} = ' checked="checked"';
4495: }
1.169 raeburn 4496: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4497: my $output = '<tr'.$css_class.'>'.
4498: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4499: '<table><tr><td>'."\n";
4500: foreach my $option ('original','recaptcha','notused') {
4501: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4502: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4503: $lt{$option}.'</label></span>';
4504: unless ($option eq 'notused') {
4505: $output .= (' 'x2)."\n";
4506: }
4507: }
4508: #
4509: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4510: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4511: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4512: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4513: #
1.165 raeburn 4514: $output .= '</td></tr>'."\n".
4515: '<tr><td>'."\n".
4516: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4517: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4518: $currpub.'" size="40" /></span><br />'."\n".
4519: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4520: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4521: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4522: '</td></tr>';
4523: return $output;
4524: }
4525:
1.32 raeburn 4526: sub user_formats_row {
4527: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4528: my $output;
4529: my %text = (
4530: 'username' => 'new usernames',
4531: 'id' => 'IDs',
1.45 raeburn 4532: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4533: );
4534: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4535: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4536: '<td><span class="LC_nobreak">';
4537: if ($type eq 'email') {
4538: $output .= &mt("Formats disallowed for $text{$type}: ");
4539: } else {
4540: $output .= &mt("Format rules to check for $text{$type}: ");
4541: }
4542: $output .= '</span></td>'.
4543: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4544: my $rem;
4545: if (ref($ruleorder) eq 'ARRAY') {
4546: for (my $i=0; $i<@{$ruleorder}; $i++) {
4547: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4548: my $rem = $i%($numinrow);
4549: if ($rem == 0) {
4550: if ($i > 0) {
4551: $output .= '</tr>';
4552: }
4553: $output .= '<tr>';
4554: }
4555: my $check = ' ';
1.39 raeburn 4556: if (ref($settings) eq 'HASH') {
4557: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4558: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4559: $check = ' checked="checked" ';
4560: }
1.27 raeburn 4561: }
4562: }
4563: $output .= '<td class="LC_left_item">'.
4564: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4565: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4566: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4567: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4568: }
4569: }
4570: $rem = @{$ruleorder}%($numinrow);
4571: }
4572: my $colsleft = $numinrow - $rem;
4573: if ($colsleft > 1 ) {
4574: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4575: ' </td>';
4576: } elsif ($colsleft == 1) {
4577: $output .= '<td class="LC_left_item"> </td>';
4578: }
4579: $output .= '</tr></table></td></tr>';
4580: return $output;
4581: }
4582:
1.34 raeburn 4583: sub usercreation_types {
4584: my %lt = &Apache::lonlocal::texthash (
4585: author => 'When adding a co-author',
4586: course => 'When adding a user to a course',
1.100 raeburn 4587: requestcrs => 'When requesting a course',
1.34 raeburn 4588: any => 'Any',
4589: official => 'Institutional only ',
4590: unofficial => 'Non-institutional only',
4591: none => 'None',
4592: );
4593: return %lt;
1.48 raeburn 4594: }
1.34 raeburn 4595:
1.224 raeburn 4596: sub selfcreation_types {
4597: my %lt = &Apache::lonlocal::texthash (
4598: selfcreate => 'User creates own account',
4599: any => 'Any',
4600: official => 'Institutional only ',
4601: unofficial => 'Non-institutional only',
4602: email => 'E-mail address',
4603: login => 'Institutional Login',
4604: sso => 'SSO',
4605: );
4606: }
4607:
1.28 raeburn 4608: sub authtype_names {
4609: my %lt = &Apache::lonlocal::texthash(
4610: int => 'Internal',
4611: krb4 => 'Kerberos 4',
4612: krb5 => 'Kerberos 5',
4613: loc => 'Local',
4614: );
4615: return %lt;
4616: }
4617:
4618: sub context_names {
4619: my %context_title = &Apache::lonlocal::texthash(
4620: author => 'Creating users when an Author',
4621: course => 'Creating users when in a course',
4622: domain => 'Creating users when a Domain Coordinator',
4623: );
4624: return %context_title;
4625: }
4626:
1.33 raeburn 4627: sub print_usermodification {
4628: my ($position,$dom,$settings,$rowtotal) = @_;
4629: my $numinrow = 4;
4630: my ($context,$datatable,$rowcount);
4631: if ($position eq 'top') {
4632: $rowcount = 0;
4633: $context = 'author';
4634: foreach my $role ('ca','aa') {
4635: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4636: $numinrow,$rowcount);
4637: $$rowtotal ++;
4638: $rowcount ++;
4639: }
1.230 raeburn 4640: } elsif ($position eq 'bottom') {
1.33 raeburn 4641: $context = 'course';
4642: $rowcount = 0;
4643: foreach my $role ('st','ep','ta','in','cr') {
4644: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4645: $numinrow,$rowcount);
4646: $$rowtotal ++;
4647: $rowcount ++;
4648: }
4649: }
4650: return $datatable;
4651: }
4652:
1.43 raeburn 4653: sub print_defaults {
1.236 raeburn 4654: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4655: my $rownum = 0;
4656: my ($datatable,$css_class);
1.236 raeburn 4657: if ($position eq 'top') {
4658: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4659: 'datelocale_def','portal_def');
4660: my %defaults;
4661: if (ref($settings) eq 'HASH') {
4662: %defaults = %{$settings};
1.43 raeburn 4663: } else {
1.236 raeburn 4664: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4665: foreach my $item (@items) {
4666: $defaults{$item} = $domdefaults{$item};
4667: }
1.43 raeburn 4668: }
1.236 raeburn 4669: my $titles = &defaults_titles($dom);
4670: foreach my $item (@items) {
4671: if ($rownum%2) {
4672: $css_class = '';
4673: } else {
4674: $css_class = ' class="LC_odd_row" ';
4675: }
4676: $datatable .= '<tr'.$css_class.'>'.
4677: '<td><span class="LC_nobreak">'.$titles->{$item}.
4678: '</span></td><td class="LC_right_item" colspan="3">';
4679: if ($item eq 'auth_def') {
4680: my @authtypes = ('internal','krb4','krb5','localauth');
4681: my %shortauth = (
4682: internal => 'int',
4683: krb4 => 'krb4',
4684: krb5 => 'krb5',
4685: localauth => 'loc'
4686: );
4687: my %authnames = &authtype_names();
4688: foreach my $auth (@authtypes) {
4689: my $checked = ' ';
4690: if ($defaults{$item} eq $auth) {
4691: $checked = ' checked="checked" ';
4692: }
4693: $datatable .= '<label><input type="radio" name="'.$item.
4694: '" value="'.$auth.'"'.$checked.'/>'.
4695: $authnames{$shortauth{$auth}}.'</label> ';
4696: }
4697: } elsif ($item eq 'timezone_def') {
4698: my $includeempty = 1;
4699: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4700: } elsif ($item eq 'datelocale_def') {
4701: my $includeempty = 1;
4702: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4703: } elsif ($item eq 'lang_def') {
4704: my %langchoices = &get_languages_hash();
4705: $langchoices{''} = 'No language preference';
4706: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4707: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4708: \%langchoices);
4709: } else {
4710: my $size;
4711: if ($item eq 'portal_def') {
4712: $size = ' size="25"';
4713: }
4714: $datatable .= '<input type="text" name="'.$item.'" value="'.
4715: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4716: }
1.236 raeburn 4717: $datatable .= '</td></tr>';
4718: $rownum ++;
4719: }
4720: } else {
4721: my (%defaults);
4722: if (ref($settings) eq 'HASH') {
4723: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4724: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4725: my $maxnum = @{$settings->{'inststatusorder'}};
4726: for (my $i=0; $i<$maxnum; $i++) {
4727: $css_class = $rownum%2?' class="LC_odd_row"':'';
4728: my $item = $settings->{'inststatusorder'}->[$i];
4729: my $title = $settings->{'inststatustypes'}->{$item};
4730: my $guestok;
4731: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4732: $guestok = 1;
4733: }
4734: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4735: $datatable .= '<tr'.$css_class.'>'.
4736: '<td><span class="LC_nobreak">'.
4737: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4738: for (my $k=0; $k<=$maxnum; $k++) {
4739: my $vpos = $k+1;
4740: my $selstr;
4741: if ($k == $i) {
4742: $selstr = ' selected="selected" ';
4743: }
4744: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4745: }
4746: my ($checkedon,$checkedoff);
4747: $checkedoff = ' checked="checked"';
4748: if ($guestok) {
4749: $checkedon = $checkedoff;
4750: $checkedoff = '';
4751: }
4752: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4753: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4754: &mt('delete').'</span></td>'.
4755: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4756: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4757: '</span></td>'.
4758: '<td class="LC_right_item"><span class="LC_nobreak">'.
4759: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4760: &mt('Yes').'</label>'.(' 'x2).
4761: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4762: &mt('No').'</label></span></td></tr>';
4763: }
4764: $css_class = $rownum%2?' class="LC_odd_row"':'';
4765: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4766: $datatable .= '<tr '.$css_class.'>'.
4767: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4768: for (my $k=0; $k<=$maxnum; $k++) {
4769: my $vpos = $k+1;
4770: my $selstr;
4771: if ($k == $maxnum) {
4772: $selstr = ' selected="selected" ';
4773: }
4774: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4775: }
4776: $datatable .= '</select> '.&mt('Internal ID:').
4777: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4778: ' '.&mt('(new)').
4779: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4780: &mt('Name displayed:').
4781: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4782: '<td class="LC_right_item"><span class="LC_nobreak">'.
4783: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4784: &mt('Yes').'</label>'.(' 'x2).
4785: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4786: &mt('No').'</label></span></td></tr>';
4787: '</tr>'."\n";
4788: $rownum ++;
1.141 raeburn 4789: }
1.43 raeburn 4790: }
4791: }
4792: $$rowtotal += $rownum;
4793: return $datatable;
4794: }
4795:
1.168 raeburn 4796: sub get_languages_hash {
4797: my %langchoices;
4798: foreach my $id (&Apache::loncommon::languageids()) {
4799: my $code = &Apache::loncommon::supportedlanguagecode($id);
4800: if ($code ne '') {
4801: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4802: }
4803: }
4804: return %langchoices;
4805: }
4806:
1.43 raeburn 4807: sub defaults_titles {
1.141 raeburn 4808: my ($dom) = @_;
1.43 raeburn 4809: my %titles = &Apache::lonlocal::texthash (
4810: 'auth_def' => 'Default authentication type',
4811: 'auth_arg_def' => 'Default authentication argument',
4812: 'lang_def' => 'Default language',
1.54 raeburn 4813: 'timezone_def' => 'Default timezone',
1.68 raeburn 4814: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4815: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4816: );
1.141 raeburn 4817: if ($dom) {
4818: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4819: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4820: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4821: $protocol = 'http' if ($protocol ne 'https');
4822: if ($uint_dom) {
4823: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4824: $uint_dom);
4825: }
4826: }
1.43 raeburn 4827: return (\%titles);
4828: }
4829:
1.46 raeburn 4830: sub print_scantronformat {
4831: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4832: my $itemcount = 1;
1.60 raeburn 4833: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4834: %confhash);
1.46 raeburn 4835: my $switchserver = &check_switchserver($dom,$confname);
4836: my %lt = &Apache::lonlocal::texthash (
1.95 www 4837: default => 'Default bubblesheet format file error',
4838: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4839: );
4840: my %scantronfiles = (
4841: default => 'default.tab',
4842: custom => 'custom.tab',
4843: );
4844: foreach my $key (keys(%scantronfiles)) {
4845: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4846: .$scantronfiles{$key};
4847: }
4848: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4849: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4850: if (!$switchserver) {
4851: my $servadm = $r->dir_config('lonAdmEMail');
4852: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4853: if ($configuserok eq 'ok') {
4854: if ($author_ok eq 'ok') {
4855: my %legacyfile = (
4856: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4857: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4858: );
4859: my %md5chk;
4860: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4861: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4862: chomp($md5chk{$type});
1.46 raeburn 4863: }
4864: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4865: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4866: ($scantronurls{$type},my $error) =
1.46 raeburn 4867: &legacy_scantronformat($r,$dom,$confname,
4868: $type,$legacyfile{$type},
4869: $scantronurls{$type},
4870: $scantronfiles{$type});
1.60 raeburn 4871: if ($error ne '') {
4872: $error{$type} = $error;
4873: }
4874: }
4875: if (keys(%error) == 0) {
4876: $is_custom = 1;
4877: $confhash{'scantron'}{'scantronformat'} =
4878: $scantronurls{'custom'};
4879: my $putresult =
4880: &Apache::lonnet::put_dom('configuration',
4881: \%confhash,$dom);
4882: if ($putresult ne 'ok') {
4883: $error{'custom'} =
4884: '<span class="LC_error">'.
4885: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4886: }
1.46 raeburn 4887: }
4888: } else {
1.60 raeburn 4889: ($scantronurls{'default'},my $error) =
1.46 raeburn 4890: &legacy_scantronformat($r,$dom,$confname,
4891: 'default',$legacyfile{'default'},
4892: $scantronurls{'default'},
4893: $scantronfiles{'default'});
1.60 raeburn 4894: if ($error eq '') {
4895: $confhash{'scantron'}{'scantronformat'} = '';
4896: my $putresult =
4897: &Apache::lonnet::put_dom('configuration',
4898: \%confhash,$dom);
4899: if ($putresult ne 'ok') {
4900: $error{'default'} =
4901: '<span class="LC_error">'.
4902: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4903: }
4904: } else {
4905: $error{'default'} = $error;
4906: }
1.46 raeburn 4907: }
4908: }
4909: }
4910: } else {
1.95 www 4911: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4912: }
4913: }
4914: if (ref($settings) eq 'HASH') {
4915: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4916: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4917: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4918: $scantronurl = '';
4919: } else {
4920: $scantronurl = $settings->{'scantronformat'};
4921: }
4922: $is_custom = 1;
4923: } else {
4924: $scantronurl = $scantronurls{'default'};
4925: }
4926: } else {
1.60 raeburn 4927: if ($is_custom) {
4928: $scantronurl = $scantronurls{'custom'};
4929: } else {
4930: $scantronurl = $scantronurls{'default'};
4931: }
1.46 raeburn 4932: }
4933: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4934: $datatable .= '<tr'.$css_class.'>';
4935: if (!$is_custom) {
1.65 raeburn 4936: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4937: '<span class="LC_nobreak">';
1.46 raeburn 4938: if ($scantronurl) {
1.199 raeburn 4939: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4940: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4941: } else {
4942: $datatable = &mt('File unavailable for display');
4943: }
1.65 raeburn 4944: $datatable .= '</span></td>';
1.60 raeburn 4945: if (keys(%error) == 0) {
4946: $datatable .= '<td valign="bottom">';
4947: if (!$switchserver) {
4948: $datatable .= &mt('Upload:').'<br />';
4949: }
4950: } else {
4951: my $errorstr;
4952: foreach my $key (sort(keys(%error))) {
4953: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4954: }
4955: $datatable .= '<td>'.$errorstr;
4956: }
1.46 raeburn 4957: } else {
4958: if (keys(%error) > 0) {
4959: my $errorstr;
4960: foreach my $key (sort(keys(%error))) {
4961: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4962: }
1.60 raeburn 4963: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4964: } elsif ($scantronurl) {
1.199 raeburn 4965: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4966: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4967: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4968: $link.
4969: '<label><input type="checkbox" name="scantronformat_del"'.
4970: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4971: '<td><span class="LC_nobreak"> '.
4972: &mt('Replace:').'</span><br />';
1.46 raeburn 4973: }
4974: }
4975: if (keys(%error) == 0) {
4976: if ($switchserver) {
4977: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4978: } else {
1.65 raeburn 4979: $datatable .='<span class="LC_nobreak"> '.
4980: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4981: }
4982: }
4983: $datatable .= '</td></tr>';
4984: $$rowtotal ++;
4985: return $datatable;
4986: }
4987:
4988: sub legacy_scantronformat {
4989: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4990: my ($url,$error);
4991: my @statinfo = &Apache::lonnet::stat_file($newurl);
4992: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4993: (my $result,$url) =
4994: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4995: '','',$newfile);
4996: if ($result ne 'ok') {
1.130 raeburn 4997: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4998: }
4999: }
5000: return ($url,$error);
5001: }
1.43 raeburn 5002:
1.49 raeburn 5003: sub print_coursecategories {
1.57 raeburn 5004: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5005: my $datatable;
5006: if ($position eq 'top') {
1.238 raeburn 5007: my (%checked);
5008: my @catitems = ('unauth','auth');
5009: my @cattypes = ('std','domonly','codesrch','none');
5010: $checked{'unauth'} = 'std';
5011: $checked{'auth'} = 'std';
5012: if (ref($settings) eq 'HASH') {
5013: foreach my $type (@cattypes) {
5014: if ($type eq $settings->{'unauth'}) {
5015: $checked{'unauth'} = $type;
5016: }
5017: if ($type eq $settings->{'auth'}) {
5018: $checked{'auth'} = $type;
5019: }
5020: }
5021: }
5022: my %lt = &Apache::lonlocal::texthash (
5023: unauth => 'Catalog type for unauthenticated users',
5024: auth => 'Catalog type for authenticated users',
5025: none => 'No catalog',
5026: std => 'Standard catalog',
5027: domonly => 'Domain-only catalog',
5028: codesrch => "Code search form",
5029: );
5030: my $itemcount = 0;
5031: foreach my $item (@catitems) {
5032: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5033: $datatable .= '<tr '.$css_class.'>'.
5034: '<td>'.$lt{$item}.'</td>'.
5035: '<td class="LC_right_item"><span class="LC_nobreak">';
5036: foreach my $type (@cattypes) {
5037: my $ischecked;
5038: if ($checked{$item} eq $type) {
5039: $ischecked=' checked="checked"';
5040: }
5041: $datatable .= '<label>'.
5042: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5043: ' />'.$lt{$type}.'</label> ';
5044: }
5045: $datatable .= '</td></tr>';
5046: $itemcount ++;
5047: }
5048: $$rowtotal += $itemcount;
5049: } elsif ($position eq 'middle') {
1.57 raeburn 5050: my $toggle_cats_crs = ' ';
5051: my $toggle_cats_dom = ' checked="checked" ';
5052: my $can_cat_crs = ' ';
5053: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5054: my $toggle_catscomm_comm = ' ';
5055: my $toggle_catscomm_dom = ' checked="checked" ';
5056: my $can_catcomm_comm = ' ';
5057: my $can_catcomm_dom = ' checked="checked" ';
5058:
1.57 raeburn 5059: if (ref($settings) eq 'HASH') {
5060: if ($settings->{'togglecats'} eq 'crs') {
5061: $toggle_cats_crs = $toggle_cats_dom;
5062: $toggle_cats_dom = ' ';
5063: }
5064: if ($settings->{'categorize'} eq 'crs') {
5065: $can_cat_crs = $can_cat_dom;
5066: $can_cat_dom = ' ';
5067: }
1.120 raeburn 5068: if ($settings->{'togglecatscomm'} eq 'comm') {
5069: $toggle_catscomm_comm = $toggle_catscomm_dom;
5070: $toggle_catscomm_dom = ' ';
5071: }
5072: if ($settings->{'categorizecomm'} eq 'comm') {
5073: $can_catcomm_comm = $can_catcomm_dom;
5074: $can_catcomm_dom = ' ';
5075: }
1.57 raeburn 5076: }
5077: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5078: togglecats => 'Show/Hide a course in catalog',
5079: togglecatscomm => 'Show/Hide a community in catalog',
5080: categorize => 'Assign a category to a course',
5081: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5082: );
5083: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5084: dom => 'Set in Domain',
5085: crs => 'Set in Course',
5086: comm => 'Set in Community',
1.57 raeburn 5087: );
5088: $datatable = '<tr class="LC_odd_row">'.
5089: '<td>'.$title{'togglecats'}.'</td>'.
5090: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5091: '<input type="radio" name="togglecats"'.
5092: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5093: '<label><input type="radio" name="togglecats"'.
5094: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5095: '</tr><tr>'.
5096: '<td>'.$title{'categorize'}.'</td>'.
5097: '<td class="LC_right_item"><span class="LC_nobreak">'.
5098: '<label><input type="radio" name="categorize"'.
5099: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5100: '<label><input type="radio" name="categorize"'.
5101: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5102: '</tr><tr class="LC_odd_row">'.
5103: '<td>'.$title{'togglecatscomm'}.'</td>'.
5104: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5105: '<input type="radio" name="togglecatscomm"'.
5106: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5107: '<label><input type="radio" name="togglecatscomm"'.
5108: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5109: '</tr><tr>'.
5110: '<td>'.$title{'categorizecomm'}.'</td>'.
5111: '<td class="LC_right_item"><span class="LC_nobreak">'.
5112: '<label><input type="radio" name="categorizecomm"'.
5113: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5114: '<label><input type="radio" name="categorizecomm"'.
5115: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5116: '</tr>';
1.120 raeburn 5117: $$rowtotal += 4;
1.57 raeburn 5118: } else {
5119: my $css_class;
5120: my $itemcount = 1;
5121: my $cathash;
5122: if (ref($settings) eq 'HASH') {
5123: $cathash = $settings->{'cats'};
5124: }
5125: if (ref($cathash) eq 'HASH') {
5126: my (@cats,@trails,%allitems,%idx,@jsarray);
5127: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5128: \%allitems,\%idx,\@jsarray);
5129: my $maxdepth = scalar(@cats);
5130: my $colattrib = '';
5131: if ($maxdepth > 2) {
5132: $colattrib = ' colspan="2" ';
5133: }
5134: my @path;
5135: if (@cats > 0) {
5136: if (ref($cats[0]) eq 'ARRAY') {
5137: my $numtop = @{$cats[0]};
5138: my $maxnum = $numtop;
1.120 raeburn 5139: my %default_names = (
5140: instcode => &mt('Official courses'),
5141: communities => &mt('Communities'),
5142: );
5143:
5144: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5145: ($cathash->{'instcode::0'} eq '') ||
5146: (!grep(/^communities$/,@{$cats[0]})) ||
5147: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5148: $maxnum ++;
5149: }
5150: my $lastidx;
5151: for (my $i=0; $i<$numtop; $i++) {
5152: my $parent = $cats[0][$i];
5153: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5154: my $item = &escape($parent).'::0';
5155: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5156: $lastidx = $idx{$item};
5157: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5158: .'<select name="'.$item.'"'.$chgstr.'>';
5159: for (my $k=0; $k<=$maxnum; $k++) {
5160: my $vpos = $k+1;
5161: my $selstr;
5162: if ($k == $i) {
5163: $selstr = ' selected="selected" ';
5164: }
5165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5166: }
1.214 raeburn 5167: $datatable .= '</select></span></td><td>';
1.120 raeburn 5168: if ($parent eq 'instcode' || $parent eq 'communities') {
5169: $datatable .= '<span class="LC_nobreak">'
5170: .$default_names{$parent}.'</span>';
5171: if ($parent eq 'instcode') {
5172: $datatable .= '<br /><span class="LC_nobreak">('
5173: .&mt('with institutional codes')
5174: .')</span></td><td'.$colattrib.'>';
5175: } else {
5176: $datatable .= '<table><tr><td>';
5177: }
5178: $datatable .= '<span class="LC_nobreak">'
5179: .'<label><input type="radio" name="'
5180: .$parent.'" value="1" checked="checked" />'
5181: .&mt('Display').'</label>';
5182: if ($parent eq 'instcode') {
5183: $datatable .= ' ';
5184: } else {
5185: $datatable .= '</span></td></tr><tr><td>'
5186: .'<span class="LC_nobreak">';
5187: }
5188: $datatable .= '<label><input type="radio" name="'
5189: .$parent.'" value="0" />'
5190: .&mt('Do not display').'</label></span>';
5191: if ($parent eq 'communities') {
5192: $datatable .= '</td></tr></table>';
5193: }
5194: $datatable .= '</td>';
1.57 raeburn 5195: } else {
5196: $datatable .= $parent
1.214 raeburn 5197: .' <span class="LC_nobreak"><label>'
5198: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5199: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5200: }
5201: my $depth = 1;
5202: push(@path,$parent);
5203: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5204: pop(@path);
5205: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5206: $itemcount ++;
5207: }
1.48 raeburn 5208: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5209: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5210: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5211: for (my $k=0; $k<=$maxnum; $k++) {
5212: my $vpos = $k+1;
5213: my $selstr;
1.57 raeburn 5214: if ($k == $numtop) {
1.48 raeburn 5215: $selstr = ' selected="selected" ';
5216: }
5217: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5218: }
1.59 bisitz 5219: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5220: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5221: .'</tr>'."\n";
1.48 raeburn 5222: $itemcount ++;
1.120 raeburn 5223: foreach my $default ('instcode','communities') {
5224: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5225: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5226: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5227: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5228: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5229: for (my $k=0; $k<=$maxnum; $k++) {
5230: my $vpos = $k+1;
5231: my $selstr;
5232: if ($k == $maxnum) {
5233: $selstr = ' selected="selected" ';
5234: }
5235: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5236: }
1.120 raeburn 5237: $datatable .= '</select></span></td>'.
5238: '<td><span class="LC_nobreak">'.
5239: $default_names{$default}.'</span>';
5240: if ($default eq 'instcode') {
5241: $datatable .= '<br /><span class="LC_nobreak">('
5242: .&mt('with institutional codes').')</span>';
5243: }
5244: $datatable .= '</td>'
5245: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5246: .&mt('Display').'</label> '
5247: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5248: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5249: }
5250: }
5251: }
1.57 raeburn 5252: } else {
5253: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5254: }
5255: } else {
1.238 raeburn 5256: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5257: .&initialize_categories($itemcount);
1.48 raeburn 5258: }
1.57 raeburn 5259: $$rowtotal += $itemcount;
1.48 raeburn 5260: }
5261: return $datatable;
5262: }
5263:
1.69 raeburn 5264: sub print_serverstatuses {
5265: my ($dom,$settings,$rowtotal) = @_;
5266: my $datatable;
5267: my @pages = &serverstatus_pages();
5268: my (%namedaccess,%machineaccess);
5269: foreach my $type (@pages) {
5270: $namedaccess{$type} = '';
5271: $machineaccess{$type}= '';
5272: }
5273: if (ref($settings) eq 'HASH') {
5274: foreach my $type (@pages) {
5275: if (exists($settings->{$type})) {
5276: if (ref($settings->{$type}) eq 'HASH') {
5277: foreach my $key (keys(%{$settings->{$type}})) {
5278: if ($key eq 'namedusers') {
5279: $namedaccess{$type} = $settings->{$type}->{$key};
5280: } elsif ($key eq 'machines') {
5281: $machineaccess{$type} = $settings->{$type}->{$key};
5282: }
5283: }
5284: }
5285: }
5286: }
5287: }
1.81 raeburn 5288: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5289: my $rownum = 0;
5290: my $css_class;
5291: foreach my $type (@pages) {
5292: $rownum ++;
5293: $css_class = $rownum%2?' class="LC_odd_row"':'';
5294: $datatable .= '<tr'.$css_class.'>'.
5295: '<td><span class="LC_nobreak">'.
5296: $titles->{$type}.'</span></td>'.
5297: '<td class="LC_left_item">'.
5298: '<input type="text" name="'.$type.'_namedusers" '.
5299: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5300: '<td class="LC_right_item">'.
5301: '<span class="LC_nobreak">'.
5302: '<input type="text" name="'.$type.'_machines" '.
5303: 'value="'.$machineaccess{$type}.'" size="10" />'.
5304: '</td></tr>'."\n";
5305: }
5306: $$rowtotal += $rownum;
5307: return $datatable;
5308: }
5309:
5310: sub serverstatus_pages {
5311: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5312: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5313: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5314: 'uniquecodes','diskusage');
1.69 raeburn 5315: }
5316:
1.236 raeburn 5317: sub defaults_javascript {
5318: my ($settings) = @_;
1.248 raeburn 5319: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5320: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5321: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5322: if ($maxnum eq '') {
5323: $maxnum = 0;
5324: }
5325: $maxnum ++;
1.249 raeburn 5326: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5327: return <<"ENDSCRIPT";
5328: <script type="text/javascript">
5329: // <![CDATA[
5330: function reorderTypes(form,caller) {
5331: var changedVal;
5332: $jstext
5333: var newpos = 'addinststatus_pos';
5334: var current = new Array;
5335: var maxh = $maxnum;
5336: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5337: var oldVal;
5338: if (caller == newpos) {
5339: changedVal = newitemVal;
5340: } else {
5341: var curritem = 'inststatus_pos_'+caller;
5342: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5343: current[newitemVal] = newpos;
5344: }
5345: for (var i=0; i<inststatuses.length; i++) {
5346: if (inststatuses[i] != caller) {
5347: var elementName = 'inststatus_pos_'+inststatuses[i];
5348: if (form.elements[elementName]) {
5349: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5350: current[currVal] = elementName;
5351: }
5352: }
5353: }
5354: for (var j=0; j<maxh; j++) {
5355: if (current[j] == undefined) {
5356: oldVal = j;
5357: }
5358: }
5359: if (oldVal < changedVal) {
5360: for (var k=oldVal+1; k<=changedVal ; k++) {
5361: var elementName = current[k];
5362: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5363: }
5364: } else {
5365: for (var k=changedVal; k<oldVal; k++) {
5366: var elementName = current[k];
5367: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5368: }
5369: }
5370: return;
5371: }
5372:
5373: // ]]>
5374: </script>
5375:
5376: ENDSCRIPT
5377: }
5378: }
5379:
1.49 raeburn 5380: sub coursecategories_javascript {
5381: my ($settings) = @_;
1.57 raeburn 5382: my ($output,$jstext,$cathash);
1.49 raeburn 5383: if (ref($settings) eq 'HASH') {
1.57 raeburn 5384: $cathash = $settings->{'cats'};
5385: }
5386: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5387: my (@cats,@jsarray,%idx);
1.57 raeburn 5388: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5389: if (@jsarray > 0) {
5390: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5391: for (my $i=0; $i<@jsarray; $i++) {
5392: if (ref($jsarray[$i]) eq 'ARRAY') {
5393: my $catstr = join('","',@{$jsarray[$i]});
5394: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5395: }
5396: }
5397: }
5398: } else {
5399: $jstext = ' var categories = Array(1);'."\n".
5400: ' categories[0] = Array("instcode_pos");'."\n";
5401: }
1.237 bisitz 5402: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5403: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5404: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5405: $output = <<"ENDSCRIPT";
5406: <script type="text/javascript">
1.109 raeburn 5407: // <![CDATA[
1.49 raeburn 5408: function reorderCats(form,parent,item,idx) {
5409: var changedVal;
5410: $jstext
5411: var newpos = 'addcategory_pos';
5412: if (parent == '') {
5413: var has_instcode = 0;
5414: var maxtop = categories[idx].length;
5415: for (var j=0; j<maxtop; j++) {
5416: if (categories[idx][j] == 'instcode::0') {
5417: has_instcode == 1;
5418: }
5419: }
5420: if (has_instcode == 0) {
5421: categories[idx][maxtop] = 'instcode_pos';
5422: }
5423: } else {
5424: newpos += '_'+parent;
5425: }
5426: var maxh = 1 + categories[idx].length;
5427: var current = new Array;
5428: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5429: if (item == newpos) {
5430: changedVal = newitemVal;
5431: } else {
5432: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5433: current[newitemVal] = newpos;
5434: }
5435: for (var i=0; i<categories[idx].length; i++) {
5436: var elementName = categories[idx][i];
5437: if (elementName != item) {
5438: if (form.elements[elementName]) {
5439: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5440: current[currVal] = elementName;
5441: }
5442: }
5443: }
5444: var oldVal;
5445: for (var j=0; j<maxh; j++) {
5446: if (current[j] == undefined) {
5447: oldVal = j;
5448: }
5449: }
5450: if (oldVal < changedVal) {
5451: for (var k=oldVal+1; k<=changedVal ; k++) {
5452: var elementName = current[k];
5453: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5454: }
5455: } else {
5456: for (var k=changedVal; k<oldVal; k++) {
5457: var elementName = current[k];
5458: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5459: }
5460: }
5461: return;
5462: }
1.120 raeburn 5463:
5464: function categoryCheck(form) {
5465: if (form.elements['addcategory_name'].value == 'instcode') {
5466: alert('$instcode_reserved\\n$choose_again');
5467: return false;
5468: }
5469: if (form.elements['addcategory_name'].value == 'communities') {
5470: alert('$communities_reserved\\n$choose_again');
5471: return false;
5472: }
5473: return true;
5474: }
5475:
1.109 raeburn 5476: // ]]>
1.49 raeburn 5477: </script>
5478:
5479: ENDSCRIPT
5480: return $output;
5481: }
5482:
1.48 raeburn 5483: sub initialize_categories {
5484: my ($itemcount) = @_;
1.120 raeburn 5485: my ($datatable,$css_class,$chgstr);
5486: my %default_names = (
5487: instcode => 'Official courses (with institutional codes)',
5488: communities => 'Communities',
5489: );
5490: my $select0 = ' selected="selected"';
5491: my $select1 = '';
5492: foreach my $default ('instcode','communities') {
5493: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5494: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5495: if ($default eq 'communities') {
5496: $select1 = $select0;
5497: $select0 = '';
5498: }
5499: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5500: .'<select name="'.$default.'_pos">'
5501: .'<option value="0"'.$select0.'>1</option>'
5502: .'<option value="1"'.$select1.'>2</option>'
5503: .'<option value="2">3</option></select> '
5504: .$default_names{$default}
5505: .'</span></td><td><span class="LC_nobreak">'
5506: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5507: .&mt('Display').'</label> <label>'
5508: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5509: .'</label></span></td></tr>';
1.120 raeburn 5510: $itemcount ++;
5511: }
1.48 raeburn 5512: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5513: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5514: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5515: .'<select name="addcategory_pos"'.$chgstr.'>'
5516: .'<option value="0">1</option>'
5517: .'<option value="1">2</option>'
5518: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5519: .&mt('Add category').'</td><td>'.&mt('Name:')
5520: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5521: return $datatable;
5522: }
5523:
5524: sub build_category_rows {
1.49 raeburn 5525: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5526: my ($text,$name,$item,$chgstr);
1.48 raeburn 5527: if (ref($cats) eq 'ARRAY') {
5528: my $maxdepth = scalar(@{$cats});
5529: if (ref($cats->[$depth]) eq 'HASH') {
5530: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5531: my $numchildren = @{$cats->[$depth]{$parent}};
5532: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5533: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5534: my ($idxnum,$parent_name,$parent_item);
5535: my $higher = $depth - 1;
5536: if ($higher == 0) {
5537: $parent_name = &escape($parent).'::'.$higher;
5538: } else {
5539: if (ref($path) eq 'ARRAY') {
5540: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5541: }
5542: }
5543: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5544: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5545: if ($j < $numchildren) {
1.48 raeburn 5546: $name = $cats->[$depth]{$parent}[$j];
5547: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5548: $idxnum = $idx->{$item};
5549: } else {
5550: $name = $parent_name;
5551: $item = $parent_item;
1.48 raeburn 5552: }
1.49 raeburn 5553: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5554: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5555: for (my $i=0; $i<=$numchildren; $i++) {
5556: my $vpos = $i+1;
5557: my $selstr;
5558: if ($j == $i) {
5559: $selstr = ' selected="selected" ';
5560: }
5561: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5562: }
5563: $text .= '</select> ';
5564: if ($j < $numchildren) {
5565: my $deeper = $depth+1;
5566: $text .= $name.' '
5567: .'<label><input type="checkbox" name="deletecategory" value="'
5568: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5569: if(ref($path) eq 'ARRAY') {
5570: push(@{$path},$name);
1.49 raeburn 5571: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5572: pop(@{$path});
5573: }
5574: } else {
1.59 bisitz 5575: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5576: if ($j == $numchildren) {
5577: $text .= $name;
5578: } else {
5579: $text .= $item;
5580: }
5581: $text .= '" value="" />';
5582: }
5583: $text .= '</td></tr>';
5584: }
5585: $text .= '</table></td>';
5586: } else {
5587: my $higher = $depth-1;
5588: if ($higher == 0) {
5589: $name = &escape($parent).'::'.$higher;
5590: } else {
5591: if (ref($path) eq 'ARRAY') {
5592: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5593: }
5594: }
5595: my $colspan;
5596: if ($parent ne 'instcode') {
5597: $colspan = $maxdepth - $depth - 1;
5598: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5599: }
5600: }
5601: }
5602: }
5603: return $text;
5604: }
5605:
1.33 raeburn 5606: sub modifiable_userdata_row {
1.228 raeburn 5607: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5608: my ($role,$rolename,$statustype);
5609: $role = $item;
1.224 raeburn 5610: if ($context eq 'cancreate') {
1.228 raeburn 5611: if ($item =~ /^emailusername_(.+)$/) {
5612: $statustype = $1;
5613: $role = 'emailusername';
5614: if (ref($usertypes) eq 'HASH') {
5615: if ($usertypes->{$statustype}) {
5616: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5617: } else {
5618: $rolename = &mt('Data provided by user');
5619: }
5620: }
1.224 raeburn 5621: }
5622: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5623: if (ref($usertypes) eq 'HASH') {
5624: $rolename = $usertypes->{$role};
5625: } else {
5626: $rolename = $role;
5627: }
1.33 raeburn 5628: } else {
1.63 raeburn 5629: if ($role eq 'cr') {
5630: $rolename = &mt('Custom role');
5631: } else {
5632: $rolename = &Apache::lonnet::plaintext($role);
5633: }
1.33 raeburn 5634: }
1.224 raeburn 5635: my (@fields,%fieldtitles);
5636: if (ref($fieldsref) eq 'ARRAY') {
5637: @fields = @{$fieldsref};
5638: } else {
5639: @fields = ('lastname','firstname','middlename','generation',
5640: 'permanentemail','id');
5641: }
5642: if ((ref($titlesref) eq 'HASH')) {
5643: %fieldtitles = %{$titlesref};
5644: } else {
5645: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5646: }
1.33 raeburn 5647: my $output;
5648: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5649: $output = '<tr '.$css_class.'>'.
5650: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5651: '<td class="LC_left_item" colspan="2"><table>';
5652: my $rem;
5653: my %checks;
5654: if (ref($settings) eq 'HASH') {
5655: if (ref($settings->{$context}) eq 'HASH') {
5656: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5657: my $hashref = $settings->{$context}->{$role};
5658: if ($role eq 'emailusername') {
5659: if ($statustype) {
5660: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5661: $hashref = $settings->{$context}->{$role}->{$statustype};
5662: if (ref($hashref) eq 'HASH') {
5663: foreach my $field (@fields) {
5664: if ($hashref->{$field}) {
5665: $checks{$field} = $hashref->{$field};
5666: }
5667: }
5668: }
5669: }
5670: }
5671: } else {
5672: if (ref($hashref) eq 'HASH') {
5673: foreach my $field (@fields) {
5674: if ($hashref->{$field}) {
5675: $checks{$field} = ' checked="checked" ';
5676: }
5677: }
1.33 raeburn 5678: }
5679: }
5680: }
5681: }
5682: }
1.228 raeburn 5683:
1.33 raeburn 5684: for (my $i=0; $i<@fields; $i++) {
5685: my $rem = $i%($numinrow);
5686: if ($rem == 0) {
5687: if ($i > 0) {
5688: $output .= '</tr>';
5689: }
5690: $output .= '<tr>';
5691: }
5692: my $check = ' ';
1.228 raeburn 5693: unless ($role eq 'emailusername') {
5694: if (exists($checks{$fields[$i]})) {
5695: $check = $checks{$fields[$i]}
5696: } else {
5697: if ($role eq 'st') {
5698: if (ref($settings) ne 'HASH') {
5699: $check = ' checked="checked" ';
5700: }
1.33 raeburn 5701: }
5702: }
5703: }
5704: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5705: '<span class="LC_nobreak">';
5706: if ($role eq 'emailusername') {
5707: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5708: $checks{$fields[$i]} = 'omit';
5709: }
5710: foreach my $option ('required','optional','omit') {
5711: my $checked='';
5712: if ($checks{$fields[$i]} eq $option) {
5713: $checked='checked="checked" ';
5714: }
5715: $output .= '<label>'.
5716: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5717: &mt($option).'</label>'.(' ' x2);
5718: }
5719: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5720: } else {
5721: $output .= '<label>'.
5722: '<input type="checkbox" name="canmodify_'.$role.'" '.
5723: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5724: '</label>';
5725: }
5726: $output .= '</span></td>';
1.33 raeburn 5727: $rem = @fields%($numinrow);
5728: }
5729: my $colsleft = $numinrow - $rem;
5730: if ($colsleft > 1 ) {
5731: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5732: ' </td>';
5733: } elsif ($colsleft == 1) {
5734: $output .= '<td class="LC_left_item"> </td>';
5735: }
5736: $output .= '</tr></table></td></tr>';
5737: return $output;
5738: }
1.28 raeburn 5739:
1.93 raeburn 5740: sub insttypes_row {
1.224 raeburn 5741: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5742: my %lt = &Apache::lonlocal::texthash (
5743: cansearch => 'Users allowed to search',
5744: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5745: lockablenames => 'User preference to lock name',
1.93 raeburn 5746: );
5747: my $showdom;
5748: if ($context eq 'cansearch') {
5749: $showdom = ' ('.$dom.')';
5750: }
1.165 raeburn 5751: my $class = 'LC_left_item';
5752: if ($context eq 'statustocreate') {
5753: $class = 'LC_right_item';
5754: }
1.224 raeburn 5755: my $css_class = ' class="LC_odd_row"';
5756: if ($rownum ne '') {
5757: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5758: }
5759: my $output = '<tr'.$css_class.'>'.
5760: '<td>'.$lt{$context}.$showdom.
5761: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5762: my $rem;
5763: if (ref($types) eq 'ARRAY') {
5764: for (my $i=0; $i<@{$types}; $i++) {
5765: if (defined($usertypes->{$types->[$i]})) {
5766: my $rem = $i%($numinrow);
5767: if ($rem == 0) {
5768: if ($i > 0) {
5769: $output .= '</tr>';
5770: }
5771: $output .= '<tr>';
1.23 raeburn 5772: }
1.26 raeburn 5773: my $check = ' ';
1.99 raeburn 5774: if (ref($settings) eq 'HASH') {
5775: if (ref($settings->{$context}) eq 'ARRAY') {
5776: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5777: $check = ' checked="checked" ';
5778: }
5779: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5780: $check = ' checked="checked" ';
5781: }
1.23 raeburn 5782: }
1.26 raeburn 5783: $output .= '<td class="LC_left_item">'.
5784: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5785: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5786: 'value="'.$types->[$i].'"'.$check.'/>'.
5787: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5788: }
5789: }
1.26 raeburn 5790: $rem = @{$types}%($numinrow);
1.23 raeburn 5791: }
5792: my $colsleft = $numinrow - $rem;
1.131 raeburn 5793: if (($rem == 0) && (@{$types} > 0)) {
5794: $output .= '<tr>';
5795: }
1.23 raeburn 5796: if ($colsleft > 1) {
1.25 raeburn 5797: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5798: } else {
1.25 raeburn 5799: $output .= '<td class="LC_left_item">';
1.23 raeburn 5800: }
5801: my $defcheck = ' ';
1.99 raeburn 5802: if (ref($settings) eq 'HASH') {
5803: if (ref($settings->{$context}) eq 'ARRAY') {
5804: if (grep(/^default$/,@{$settings->{$context}})) {
5805: $defcheck = ' checked="checked" ';
5806: }
5807: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5808: $defcheck = ' checked="checked" ';
5809: }
1.23 raeburn 5810: }
1.25 raeburn 5811: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5812: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5813: 'value="default"'.$defcheck.'/>'.
5814: $othertitle.'</label></span></td>'.
5815: '</tr></table></td></tr>';
5816: return $output;
1.23 raeburn 5817: }
5818:
5819: sub sorted_searchtitles {
5820: my %searchtitles = &Apache::lonlocal::texthash(
5821: 'uname' => 'username',
5822: 'lastname' => 'last name',
5823: 'lastfirst' => 'last name, first name',
5824: );
5825: my @titleorder = ('uname','lastname','lastfirst');
5826: return (\%searchtitles,\@titleorder);
5827: }
5828:
1.25 raeburn 5829: sub sorted_searchtypes {
5830: my %srchtypes_desc = (
5831: exact => 'is exact match',
5832: contains => 'contains ..',
5833: begins => 'begins with ..',
5834: );
5835: my @srchtypeorder = ('exact','begins','contains');
5836: return (\%srchtypes_desc,\@srchtypeorder);
5837: }
5838:
1.3 raeburn 5839: sub usertype_update_row {
5840: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5841: my $datatable;
5842: my $numinrow = 4;
5843: foreach my $type (@{$types}) {
5844: if (defined($usertypes->{$type})) {
5845: $$rownums ++;
5846: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5847: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5848: '</td><td class="LC_left_item"><table>';
5849: for (my $i=0; $i<@{$fields}; $i++) {
5850: my $rem = $i%($numinrow);
5851: if ($rem == 0) {
5852: if ($i > 0) {
5853: $datatable .= '</tr>';
5854: }
5855: $datatable .= '<tr>';
5856: }
5857: my $check = ' ';
1.39 raeburn 5858: if (ref($settings) eq 'HASH') {
5859: if (ref($settings->{'fields'}) eq 'HASH') {
5860: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5861: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5862: $check = ' checked="checked" ';
5863: }
1.3 raeburn 5864: }
5865: }
5866: }
5867:
5868: if ($i == @{$fields}-1) {
5869: my $colsleft = $numinrow - $rem;
5870: if ($colsleft > 1) {
5871: $datatable .= '<td colspan="'.$colsleft.'">';
5872: } else {
5873: $datatable .= '<td>';
5874: }
5875: } else {
5876: $datatable .= '<td>';
5877: }
1.8 raeburn 5878: $datatable .= '<span class="LC_nobreak"><label>'.
5879: '<input type="checkbox" name="updateable_'.$type.
5880: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5881: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5882: }
5883: $datatable .= '</tr></table></td></tr>';
5884: }
5885: }
5886: return $datatable;
1.1 raeburn 5887: }
5888:
5889: sub modify_login {
1.205 raeburn 5890: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5891: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5892: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5893: %title = ( coursecatalog => 'Display course catalog',
5894: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5895: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5896: newuser => 'Link for visitors to create a user account',
5897: loginheader => 'Log-in box header');
5898: @offon = ('off','on');
1.112 raeburn 5899: if (ref($domconfig{login}) eq 'HASH') {
5900: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5901: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5902: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5903: }
5904: }
5905: }
1.9 raeburn 5906: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5907: \%domconfig,\%loginhash);
1.188 raeburn 5908: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5909: foreach my $item (@toggles) {
5910: $loginhash{login}{$item} = $env{'form.'.$item};
5911: }
1.41 raeburn 5912: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5913: if (ref($colchanges{'login'}) eq 'HASH') {
5914: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5915: \%loginhash);
5916: }
1.110 raeburn 5917:
1.149 raeburn 5918: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 5919: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5920: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5921: if (keys(%servers) > 1) {
5922: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5923: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5924: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5925: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5926: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5927: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5928: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5929: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5930: $changes{'loginvia'}{$lonhost} = 1;
5931: } else {
5932: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5933: $changes{'loginvia'}{$lonhost} = 1;
5934: }
5935: } else {
5936: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5937: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5938: $changes{'loginvia'}{$lonhost} = 1;
5939: }
5940: }
5941: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5942: foreach my $item (@loginvia_attribs) {
5943: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5944: }
5945: } else {
5946: foreach my $item (@loginvia_attribs) {
5947: my $new = $env{'form.'.$lonhost.'_'.$item};
5948: if (($item eq 'serverpath') && ($new eq 'custom')) {
5949: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5950: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5951: $new = '/';
5952: }
5953: }
5954: if (($item eq 'custompath') &&
5955: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5956: $new = '';
5957: }
5958: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5959: $changes{'loginvia'}{$lonhost} = 1;
5960: }
5961: if ($item eq 'exempt') {
1.256 raeburn 5962: $new = &check_exempt_addresses($new);
1.128 raeburn 5963: }
5964: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5965: }
5966: }
1.112 raeburn 5967: } else {
1.128 raeburn 5968: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5969: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5970: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5971: foreach my $item (@loginvia_attribs) {
5972: my $new = $env{'form.'.$lonhost.'_'.$item};
5973: if (($item eq 'serverpath') && ($new eq 'custom')) {
5974: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5975: $new = '/';
5976: }
5977: }
5978: if (($item eq 'custompath') &&
5979: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5980: $new = '';
5981: }
5982: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5983: }
1.110 raeburn 5984: }
5985: }
5986: }
5987: }
1.119 raeburn 5988:
1.168 raeburn 5989: my $servadm = $r->dir_config('lonAdmEMail');
5990: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5991: if (ref($domconfig{'login'}) eq 'HASH') {
5992: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5993: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5994: if ($lang eq 'nolang') {
5995: push(@currlangs,$lang);
5996: } elsif (defined($langchoices{$lang})) {
5997: push(@currlangs,$lang);
5998: } else {
5999: next;
6000: }
6001: }
6002: }
6003: }
6004: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6005: if (@currlangs > 0) {
6006: foreach my $lang (@currlangs) {
6007: if (grep(/^\Q$lang\E$/,@delurls)) {
6008: $changes{'helpurl'}{$lang} = 1;
6009: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6010: $changes{'helpurl'}{$lang} = 1;
6011: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6012: push(@newlangs,$lang);
6013: } else {
6014: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6015: }
6016: }
6017: }
6018: unless (grep(/^nolang$/,@currlangs)) {
6019: if ($env{'form.loginhelpurl_nolang.filename'}) {
6020: $changes{'helpurl'}{'nolang'} = 1;
6021: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6022: push(@newlangs,'nolang');
6023: }
6024: }
6025: if ($env{'form.loginhelpurl_add_lang'}) {
6026: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6027: ($env{'form.loginhelpurl_add_file.filename'})) {
6028: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6029: $addedfile = $env{'form.loginhelpurl_add_lang'};
6030: }
6031: }
6032: if ((@newlangs > 0) || ($addedfile)) {
6033: my $error;
6034: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6035: if ($configuserok eq 'ok') {
6036: if ($switchserver) {
6037: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6038: } elsif ($author_ok eq 'ok') {
6039: my @allnew = @newlangs;
6040: if ($addedfile ne '') {
6041: push(@allnew,$addedfile);
6042: }
6043: foreach my $lang (@allnew) {
6044: my $formelem = 'loginhelpurl_'.$lang;
6045: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6046: $formelem = 'loginhelpurl_add_file';
6047: }
6048: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6049: "help/$lang",'','',$newfile{$lang});
6050: if ($result eq 'ok') {
6051: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6052: $changes{'helpurl'}{$lang} = 1;
6053: } else {
6054: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6055: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6056: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6057: (!grep(/^\Q$lang\E$/,@delurls))) {
6058: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6059: }
6060: }
6061: }
6062: } else {
6063: $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);
6064: }
6065: } else {
6066: $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);
6067: }
6068: if ($error) {
6069: &Apache::lonnet::logthis($error);
6070: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6071: }
6072: }
1.256 raeburn 6073:
6074: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6075: if (ref($domconfig{'login'}) eq 'HASH') {
6076: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6077: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6078: if ($domservers{$lonhost}) {
6079: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6080: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
6081: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
6082: }
6083: }
6084: }
6085: }
6086: }
6087: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6088: foreach my $lonhost (sort(keys(%domservers))) {
6089: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6090: $changes{'headtag'}{$lonhost} = 1;
6091: } else {
6092: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6093: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6094: }
6095: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6096: push(@newhosts,$lonhost);
6097: } elsif ($currheadtagurls{$lonhost}) {
6098: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6099: if ($currexempt{$lonhost}) {
6100: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6101: $changes{'headtag'}{$lonhost} = 1;
6102: }
6103: } elsif ($possexempt{$lonhost}) {
6104: $changes{'headtag'}{$lonhost} = 1;
6105: }
6106: if ($possexempt{$lonhost}) {
6107: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6108: }
6109: }
6110: }
6111: }
6112: if (@newhosts) {
6113: my $error;
6114: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6115: if ($configuserok eq 'ok') {
6116: if ($switchserver) {
6117: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6118: } elsif ($author_ok eq 'ok') {
6119: foreach my $lonhost (@newhosts) {
6120: my $formelem = 'loginheadtag_'.$lonhost;
6121: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6122: "login/headtag/$lonhost",'','',
6123: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6124: if ($result eq 'ok') {
6125: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6126: $changes{'headtag'}{$lonhost} = 1;
6127: if ($possexempt{$lonhost}) {
6128: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6129: }
6130: } else {
6131: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6132: $newheadtagurls{$lonhost},$result);
6133: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6134: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6135: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6136: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6137: }
6138: }
6139: }
6140: } else {
6141: $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
6142: }
6143: } else {
6144: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
6145: }
6146: if ($error) {
6147: &Apache::lonnet::logthis($error);
6148: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6149: }
6150: }
1.169 raeburn 6151: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6152:
6153: my $defaulthelpfile = '/adm/loginproblems.html';
6154: my $defaulttext = &mt('Default in use');
6155:
1.1 raeburn 6156: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6157: $dom);
6158: if ($putresult eq 'ok') {
1.188 raeburn 6159: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6160: my %defaultchecked = (
6161: 'coursecatalog' => 'on',
1.188 raeburn 6162: 'helpdesk' => 'on',
1.42 raeburn 6163: 'adminmail' => 'off',
1.43 raeburn 6164: 'newuser' => 'off',
1.42 raeburn 6165: );
1.55 raeburn 6166: if (ref($domconfig{'login'}) eq 'HASH') {
6167: foreach my $item (@toggles) {
6168: if ($defaultchecked{$item} eq 'on') {
6169: if (($domconfig{'login'}{$item} eq '0') &&
6170: ($env{'form.'.$item} eq '1')) {
6171: $changes{$item} = 1;
6172: } elsif (($domconfig{'login'}{$item} eq '' ||
6173: $domconfig{'login'}{$item} eq '1') &&
6174: ($env{'form.'.$item} eq '0')) {
6175: $changes{$item} = 1;
6176: }
6177: } elsif ($defaultchecked{$item} eq 'off') {
6178: if (($domconfig{'login'}{$item} eq '1') &&
6179: ($env{'form.'.$item} eq '0')) {
6180: $changes{$item} = 1;
6181: } elsif (($domconfig{'login'}{$item} eq '' ||
6182: $domconfig{'login'}{$item} eq '0') &&
6183: ($env{'form.'.$item} eq '1')) {
6184: $changes{$item} = 1;
6185: }
1.42 raeburn 6186: }
6187: }
1.41 raeburn 6188: }
1.6 raeburn 6189: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6190: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6191: if (ref($lastactref) eq 'HASH') {
6192: $lastactref->{'domainconfig'} = 1;
6193: }
1.1 raeburn 6194: $resulttext = &mt('Changes made:').'<ul>';
6195: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6196: if ($item eq 'loginvia') {
1.112 raeburn 6197: if (ref($changes{$item}) eq 'HASH') {
6198: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6199: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6200: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6201: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6202: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6203: $protocol = 'http' if ($protocol ne 'https');
6204: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6205:
6206: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6207: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6208: } else {
6209: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6210: }
6211: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6212: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6213: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6214: }
6215: $resulttext .= '</li>';
6216: } else {
6217: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6218: }
1.112 raeburn 6219: } else {
1.128 raeburn 6220: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6221: }
6222: }
1.128 raeburn 6223: $resulttext .= '</ul></li>';
1.112 raeburn 6224: }
1.168 raeburn 6225: } elsif ($item eq 'helpurl') {
6226: if (ref($changes{$item}) eq 'HASH') {
6227: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6228: if (grep(/^\Q$lang\E$/,@delurls)) {
6229: my ($chg,$link);
6230: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6231: if ($lang eq 'nolang') {
6232: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6233: } else {
6234: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6235: }
6236: $resulttext .= '<li>'.$chg.'</li>';
6237: } else {
6238: my $chg;
6239: if ($lang eq 'nolang') {
6240: $chg = &mt('custom log-in help file for no preferred language');
6241: } else {
6242: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6243: }
6244: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6245: $loginhash{'login'}{'helpurl'}{$lang}.
6246: '?inhibitmenu=yes',$chg,600,500).
6247: '</li>';
6248: }
6249: }
6250: }
1.256 raeburn 6251: } elsif ($item eq 'headtag') {
6252: if (ref($changes{$item}) eq 'HASH') {
6253: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6254: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6255: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6256: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6257: $resulttext .= '<li><a href="'.
6258: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6259: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6260: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6261: if ($possexempt{$lonhost}) {
6262: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6263: } else {
6264: $resulttext .= &mt('included for any client IP');
6265: }
6266: $resulttext .= '</li>';
6267: }
6268: }
6269: }
1.169 raeburn 6270: } elsif ($item eq 'captcha') {
6271: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6272: my $chgtxt;
1.169 raeburn 6273: if ($loginhash{'login'}{$item} eq 'notused') {
6274: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6275: } else {
6276: my %captchas = &captcha_phrases();
6277: if ($captchas{$loginhash{'login'}{$item}}) {
6278: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6279: } else {
6280: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6281: }
6282: }
6283: $resulttext .= '<li>'.$chgtxt.'</li>';
6284: }
6285: } elsif ($item eq 'recaptchakeys') {
6286: if (ref($loginhash{'login'}) eq 'HASH') {
6287: my ($privkey,$pubkey);
6288: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6289: $pubkey = $loginhash{'login'}{$item}{'public'};
6290: $privkey = $loginhash{'login'}{$item}{'private'};
6291: }
6292: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6293: if (!$pubkey) {
6294: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6295: } else {
6296: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6297: }
6298: if (!$privkey) {
6299: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6300: } else {
1.251 raeburn 6301: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6302: }
6303: $chgtxt .= '</ul>';
6304: $resulttext .= '<li>'.$chgtxt.'</li>';
6305: }
1.41 raeburn 6306: } else {
6307: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6308: }
1.1 raeburn 6309: }
1.6 raeburn 6310: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6311: } else {
6312: $resulttext = &mt('No changes made to log-in page settings');
6313: }
6314: } else {
1.11 albertel 6315: $resulttext = '<span class="LC_error">'.
6316: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6317: }
1.6 raeburn 6318: if ($errors) {
1.9 raeburn 6319: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6320: $errors.'</ul>';
6321: }
6322: return $resulttext;
6323: }
6324:
1.256 raeburn 6325:
6326: sub check_exempt_addresses {
6327: my ($iplist) = @_;
6328: $iplist =~ s/^\s+//;
6329: $iplist =~ s/\s+$//;
6330: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6331: my (@okips,$new);
6332: foreach my $ip (@poss_ips) {
6333: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6334: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6335: push(@okips,$ip);
6336: }
6337: }
6338: }
6339: if (@okips > 0) {
6340: $new = join(',',@okips);
6341: } else {
6342: $new = '';
6343: }
6344: return $new;
6345: }
6346:
1.6 raeburn 6347: sub color_font_choices {
6348: my %choices =
6349: &Apache::lonlocal::texthash (
6350: img => "Header",
6351: bgs => "Background colors",
6352: links => "Link colors",
1.55 raeburn 6353: images => "Images",
1.6 raeburn 6354: font => "Font color",
1.201 raeburn 6355: fontmenu => "Font menu",
1.76 raeburn 6356: pgbg => "Page",
1.6 raeburn 6357: tabbg => "Header",
6358: sidebg => "Border",
6359: link => "Link",
6360: alink => "Active link",
6361: vlink => "Visited link",
6362: );
6363: return %choices;
6364: }
6365:
6366: sub modify_rolecolors {
1.205 raeburn 6367: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6368: my ($resulttext,%rolehash);
6369: $rolehash{'rolecolors'} = {};
1.55 raeburn 6370: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6371: if ($domconfig{'rolecolors'} eq '') {
6372: $domconfig{'rolecolors'} = {};
6373: }
6374: }
1.9 raeburn 6375: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6376: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6377: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6378: $dom);
6379: if ($putresult eq 'ok') {
6380: if (keys(%changes) > 0) {
1.41 raeburn 6381: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6382: if (ref($lastactref) eq 'HASH') {
6383: $lastactref->{'domainconfig'} = 1;
6384: }
1.6 raeburn 6385: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6386: $rolehash{'rolecolors'});
6387: } else {
6388: $resulttext = &mt('No changes made to default color schemes');
6389: }
6390: } else {
1.11 albertel 6391: $resulttext = '<span class="LC_error">'.
6392: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6393: }
6394: if ($errors) {
6395: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6396: $errors.'</ul>';
6397: }
6398: return $resulttext;
6399: }
6400:
6401: sub modify_colors {
1.9 raeburn 6402: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6403: my (%changes,%choices);
1.51 raeburn 6404: my @bgs;
1.6 raeburn 6405: my @links = ('link','alink','vlink');
1.41 raeburn 6406: my @logintext;
1.6 raeburn 6407: my @images;
6408: my $servadm = $r->dir_config('lonAdmEMail');
6409: my $errors;
1.200 raeburn 6410: my %defaults;
1.6 raeburn 6411: foreach my $role (@{$roles}) {
6412: if ($role eq 'login') {
1.12 raeburn 6413: %choices = &login_choices();
1.41 raeburn 6414: @logintext = ('textcol','bgcol');
1.12 raeburn 6415: } else {
6416: %choices = &color_font_choices();
6417: }
6418: if ($role eq 'login') {
1.41 raeburn 6419: @images = ('img','logo','domlogo','login');
1.51 raeburn 6420: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6421: } else {
6422: @images = ('img');
1.200 raeburn 6423: @bgs = ('pgbg','tabbg','sidebg');
6424: }
6425: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6426: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6427: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6428: }
6429: if ($role eq 'login') {
6430: foreach my $item (@logintext) {
1.234 raeburn 6431: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6432: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6433: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6434: }
6435: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6436: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6437: }
6438: }
6439: } else {
1.234 raeburn 6440: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6441: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6442: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6443: }
6444: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6445: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6446: }
1.6 raeburn 6447: }
1.200 raeburn 6448: foreach my $item (@bgs) {
1.234 raeburn 6449: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6450: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6451: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6452: }
6453: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6454: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6455: }
6456: }
6457: foreach my $item (@links) {
1.234 raeburn 6458: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6459: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6460: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6461: }
6462: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6463: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6464: }
1.6 raeburn 6465: }
1.46 raeburn 6466: my ($configuserok,$author_ok,$switchserver) =
6467: &config_check($dom,$confname,$servadm);
1.9 raeburn 6468: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6469: if (ref($domconfig->{$role}) ne 'HASH') {
6470: $domconfig->{$role} = {};
6471: }
1.8 raeburn 6472: foreach my $img (@images) {
1.70 raeburn 6473: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6474: if (defined($env{'form.login_showlogo_'.$img})) {
6475: $confhash->{$role}{'showlogo'}{$img} = 1;
6476: } else {
6477: $confhash->{$role}{'showlogo'}{$img} = 0;
6478: }
6479: }
1.18 albertel 6480: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6481: && !defined($domconfig->{$role}{$img})
6482: && !$env{'form.'.$role.'_del_'.$img}
6483: && $env{'form.'.$role.'_import_'.$img}) {
6484: # import the old configured image from the .tab setting
6485: # if they haven't provided a new one
6486: $domconfig->{$role}{$img} =
6487: $env{'form.'.$role.'_import_'.$img};
6488: }
1.6 raeburn 6489: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6490: my $error;
1.6 raeburn 6491: if ($configuserok eq 'ok') {
1.9 raeburn 6492: if ($switchserver) {
1.12 raeburn 6493: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6494: } else {
6495: if ($author_ok eq 'ok') {
6496: my ($result,$logourl) =
6497: &publishlogo($r,'upload',$role.'_'.$img,
6498: $dom,$confname,$img,$width,$height);
6499: if ($result eq 'ok') {
6500: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6501: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6502: } else {
1.12 raeburn 6503: $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 6504: }
6505: } else {
1.46 raeburn 6506: $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 6507: }
6508: }
6509: } else {
1.46 raeburn 6510: $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 6511: }
6512: if ($error) {
1.8 raeburn 6513: &Apache::lonnet::logthis($error);
1.11 albertel 6514: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6515: }
6516: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6517: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6518: my $error;
6519: if ($configuserok eq 'ok') {
6520: # is confname an author?
6521: if ($switchserver eq '') {
6522: if ($author_ok eq 'ok') {
6523: my ($result,$logourl) =
6524: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6525: $dom,$confname,$img,$width,$height);
6526: if ($result eq 'ok') {
6527: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6528: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6529: }
6530: }
6531: }
6532: }
1.6 raeburn 6533: }
6534: }
6535: }
6536: if (ref($domconfig) eq 'HASH') {
6537: if (ref($domconfig->{$role}) eq 'HASH') {
6538: foreach my $img (@images) {
6539: if ($domconfig->{$role}{$img} ne '') {
6540: if ($env{'form.'.$role.'_del_'.$img}) {
6541: $confhash->{$role}{$img} = '';
1.12 raeburn 6542: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6543: } else {
1.9 raeburn 6544: if ($confhash->{$role}{$img} eq '') {
6545: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6546: }
1.6 raeburn 6547: }
6548: } else {
6549: if ($env{'form.'.$role.'_del_'.$img}) {
6550: $confhash->{$role}{$img} = '';
1.12 raeburn 6551: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6552: }
6553: }
1.70 raeburn 6554: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6555: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6556: if ($confhash->{$role}{'showlogo'}{$img} ne
6557: $domconfig->{$role}{'showlogo'}{$img}) {
6558: $changes{$role}{'showlogo'}{$img} = 1;
6559: }
6560: } else {
6561: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6562: $changes{$role}{'showlogo'}{$img} = 1;
6563: }
6564: }
6565: }
6566: }
1.6 raeburn 6567: if ($domconfig->{$role}{'font'} ne '') {
6568: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6569: $changes{$role}{'font'} = 1;
6570: }
6571: } else {
6572: if ($confhash->{$role}{'font'}) {
6573: $changes{$role}{'font'} = 1;
6574: }
6575: }
1.107 raeburn 6576: if ($role ne 'login') {
6577: if ($domconfig->{$role}{'fontmenu'} ne '') {
6578: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6579: $changes{$role}{'fontmenu'} = 1;
6580: }
6581: } else {
6582: if ($confhash->{$role}{'fontmenu'}) {
6583: $changes{$role}{'fontmenu'} = 1;
6584: }
1.97 tempelho 6585: }
6586: }
1.6 raeburn 6587: foreach my $item (@bgs) {
6588: if ($domconfig->{$role}{$item} ne '') {
6589: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6590: $changes{$role}{'bgs'}{$item} = 1;
6591: }
6592: } else {
6593: if ($confhash->{$role}{$item}) {
6594: $changes{$role}{'bgs'}{$item} = 1;
6595: }
6596: }
6597: }
6598: foreach my $item (@links) {
6599: if ($domconfig->{$role}{$item} ne '') {
6600: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6601: $changes{$role}{'links'}{$item} = 1;
6602: }
6603: } else {
6604: if ($confhash->{$role}{$item}) {
6605: $changes{$role}{'links'}{$item} = 1;
6606: }
6607: }
6608: }
1.41 raeburn 6609: foreach my $item (@logintext) {
6610: if ($domconfig->{$role}{$item} ne '') {
6611: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6612: $changes{$role}{'logintext'}{$item} = 1;
6613: }
6614: } else {
6615: if ($confhash->{$role}{$item}) {
6616: $changes{$role}{'logintext'}{$item} = 1;
6617: }
6618: }
6619: }
1.6 raeburn 6620: } else {
6621: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6622: \@logintext,$confhash,\%changes);
1.6 raeburn 6623: }
6624: } else {
6625: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6626: \@logintext,$confhash,\%changes);
1.6 raeburn 6627: }
6628: }
6629: return ($errors,%changes);
6630: }
6631:
1.46 raeburn 6632: sub config_check {
6633: my ($dom,$confname,$servadm) = @_;
6634: my ($configuserok,$author_ok,$switchserver,%currroles);
6635: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6636: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6637: $confname,$servadm);
6638: if ($configuserok eq 'ok') {
6639: $switchserver = &check_switchserver($dom,$confname);
6640: if ($switchserver eq '') {
6641: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6642: }
6643: }
6644: return ($configuserok,$author_ok,$switchserver);
6645: }
6646:
1.6 raeburn 6647: sub default_change_checker {
1.41 raeburn 6648: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6649: foreach my $item (@{$links}) {
6650: if ($confhash->{$role}{$item}) {
6651: $changes->{$role}{'links'}{$item} = 1;
6652: }
6653: }
6654: foreach my $item (@{$bgs}) {
6655: if ($confhash->{$role}{$item}) {
6656: $changes->{$role}{'bgs'}{$item} = 1;
6657: }
6658: }
1.41 raeburn 6659: foreach my $item (@{$logintext}) {
6660: if ($confhash->{$role}{$item}) {
6661: $changes->{$role}{'logintext'}{$item} = 1;
6662: }
6663: }
1.6 raeburn 6664: foreach my $img (@{$images}) {
6665: if ($env{'form.'.$role.'_del_'.$img}) {
6666: $confhash->{$role}{$img} = '';
1.12 raeburn 6667: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6668: }
1.70 raeburn 6669: if ($role eq 'login') {
6670: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6671: $changes->{$role}{'showlogo'}{$img} = 1;
6672: }
6673: }
1.6 raeburn 6674: }
6675: if ($confhash->{$role}{'font'}) {
6676: $changes->{$role}{'font'} = 1;
6677: }
1.48 raeburn 6678: }
1.6 raeburn 6679:
6680: sub display_colorchgs {
6681: my ($dom,$changes,$roles,$confhash) = @_;
6682: my (%choices,$resulttext);
6683: if (!grep(/^login$/,@{$roles})) {
6684: $resulttext = &mt('Changes made:').'<br />';
6685: }
6686: foreach my $role (@{$roles}) {
6687: if ($role eq 'login') {
6688: %choices = &login_choices();
6689: } else {
6690: %choices = &color_font_choices();
6691: }
6692: if (ref($changes->{$role}) eq 'HASH') {
6693: if ($role ne 'login') {
6694: $resulttext .= '<h4>'.&mt($role).'</h4>';
6695: }
6696: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6697: if ($role ne 'login') {
6698: $resulttext .= '<ul>';
6699: }
6700: if (ref($changes->{$role}{$key}) eq 'HASH') {
6701: if ($role ne 'login') {
6702: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6703: }
6704: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6705: if (($role eq 'login') && ($key eq 'showlogo')) {
6706: if ($confhash->{$role}{$key}{$item}) {
6707: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6708: } else {
6709: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6710: }
6711: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6712: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6713: } else {
1.12 raeburn 6714: my $newitem = $confhash->{$role}{$item};
6715: if ($key eq 'images') {
6716: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6717: }
6718: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6719: }
6720: }
6721: if ($role ne 'login') {
6722: $resulttext .= '</ul></li>';
6723: }
6724: } else {
6725: if ($confhash->{$role}{$key} eq '') {
6726: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6727: } else {
6728: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6729: }
6730: }
6731: if ($role ne 'login') {
6732: $resulttext .= '</ul>';
6733: }
6734: }
6735: }
6736: }
1.3 raeburn 6737: return $resulttext;
1.1 raeburn 6738: }
6739:
1.9 raeburn 6740: sub thumb_dimensions {
6741: return ('200','50');
6742: }
6743:
1.16 raeburn 6744: sub check_dimensions {
6745: my ($inputfile) = @_;
6746: my ($fullwidth,$fullheight);
6747: if ($inputfile =~ m|^[/\w.\-]+$|) {
6748: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6749: my $imageinfo = <PIPE>;
6750: if (!close(PIPE)) {
6751: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6752: }
6753: chomp($imageinfo);
6754: my ($fullsize) =
1.21 raeburn 6755: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6756: if ($fullsize) {
6757: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6758: }
6759: }
6760: }
6761: return ($fullwidth,$fullheight);
6762: }
6763:
1.9 raeburn 6764: sub check_configuser {
6765: my ($uhome,$dom,$confname,$servadm) = @_;
6766: my ($configuserok,%currroles);
6767: if ($uhome eq 'no_host') {
6768: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6769: my $configpass = &LONCAPA::Enrollment::create_password();
6770: $configuserok =
6771: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6772: $configpass,'','','','','',undef,$servadm);
6773: } else {
6774: $configuserok = 'ok';
6775: %currroles =
6776: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6777: }
6778: return ($configuserok,%currroles);
6779: }
6780:
6781: sub check_authorstatus {
6782: my ($dom,$confname,%currroles) = @_;
6783: my $author_ok;
1.40 raeburn 6784: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6785: my $start = time;
6786: my $end = 0;
6787: $author_ok =
6788: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6789: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6790: } else {
6791: $author_ok = 'ok';
6792: }
6793: return $author_ok;
6794: }
6795:
6796: sub publishlogo {
1.46 raeburn 6797: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6798: my ($output,$fname,$logourl);
6799: if ($action eq 'upload') {
6800: $fname=$env{'form.'.$formname.'.filename'};
6801: chop($env{'form.'.$formname});
6802: } else {
6803: ($fname) = ($formname =~ /([^\/]+)$/);
6804: }
1.46 raeburn 6805: if ($savefileas ne '') {
6806: $fname = $savefileas;
6807: }
1.9 raeburn 6808: $fname=&Apache::lonnet::clean_filename($fname);
6809: # See if there is anything left
6810: unless ($fname) { return ('error: no uploaded file'); }
6811: $fname="$subdir/$fname";
1.210 raeburn 6812: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6813: my $filepath="$docroot/priv";
6814: my $relpath = "$dom/$confname";
1.9 raeburn 6815: my ($fnamepath,$file,$fetchthumb);
6816: $file=$fname;
6817: if ($fname=~m|/|) {
6818: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6819: }
1.164 raeburn 6820: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6821: my $count;
1.164 raeburn 6822: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6823: $filepath.="/$parts[$count]";
6824: if ((-e $filepath)!=1) {
6825: mkdir($filepath,02770);
6826: }
6827: }
6828: # Check for bad extension and disallow upload
6829: if ($file=~/\.(\w+)$/ &&
6830: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6831: $output =
1.207 bisitz 6832: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6833: } elsif ($file=~/\.(\w+)$/ &&
6834: !defined(&Apache::loncommon::fileembstyle($1))) {
6835: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6836: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6837: $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 6838: } elsif (-d "$filepath/$file") {
1.195 bisitz 6839: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6840: } else {
6841: my $source = $filepath.'/'.$file;
6842: my $logfile;
6843: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6844: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6845: }
6846: print $logfile
6847: "\n================= Publish ".localtime()." ================\n".
6848: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6849: # Save the file
6850: if (!open(FH,'>'.$source)) {
6851: &Apache::lonnet::logthis('Failed to create '.$source);
6852: return (&mt('Failed to create file'));
6853: }
6854: if ($action eq 'upload') {
6855: if (!print FH ($env{'form.'.$formname})) {
6856: &Apache::lonnet::logthis('Failed to write to '.$source);
6857: return (&mt('Failed to write file'));
6858: }
6859: } else {
6860: my $original = &Apache::lonnet::filelocation('',$formname);
6861: if(!copy($original,$source)) {
6862: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6863: return (&mt('Failed to write file'));
6864: }
6865: }
6866: close(FH);
6867: chmod(0660, $source); # Permissions to rw-rw---.
6868:
6869: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6870: my $copyfile=$targetdir.'/'.$file;
6871:
6872: my @parts=split(/\//,$targetdir);
6873: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6874: for (my $count=5;$count<=$#parts;$count++) {
6875: $path.="/$parts[$count]";
6876: if (!-e $path) {
6877: print $logfile "\nCreating directory ".$path;
6878: mkdir($path,02770);
6879: }
6880: }
6881: my $versionresult;
6882: if (-e $copyfile) {
6883: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6884: } else {
6885: $versionresult = 'ok';
6886: }
6887: if ($versionresult eq 'ok') {
6888: if (copy($source,$copyfile)) {
6889: print $logfile "\nCopied original source to ".$copyfile."\n";
6890: $output = 'ok';
6891: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6892: push(@{$modified_urls},[$copyfile,$source]);
6893: my $metaoutput =
6894: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6895: unless ($registered_cleanup) {
6896: my $handlers = $r->get_handlers('PerlCleanupHandler');
6897: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6898: $registered_cleanup=1;
6899: }
1.9 raeburn 6900: } else {
6901: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6902: $output = &mt('Failed to copy file to RES space').", $!";
6903: }
6904: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6905: my $inputfile = $filepath.'/'.$file;
6906: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6907: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6908: if ($fullwidth ne '' && $fullheight ne '') {
6909: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6910: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6911: system("convert -sample $thumbsize $inputfile $outfile");
6912: chmod(0660, $filepath.'/tn-'.$file);
6913: if (-e $outfile) {
6914: my $copyfile=$targetdir.'/tn-'.$file;
6915: if (copy($outfile,$copyfile)) {
6916: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6917: my $thumb_metaoutput =
6918: &write_metadata($dom,$confname,$formname,
6919: $targetdir,'tn-'.$file,$logfile);
6920: push(@{$modified_urls},[$copyfile,$outfile]);
6921: unless ($registered_cleanup) {
6922: my $handlers = $r->get_handlers('PerlCleanupHandler');
6923: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6924: $registered_cleanup=1;
6925: }
1.16 raeburn 6926: } else {
6927: print $logfile "\nUnable to write ".$copyfile.
6928: ':'.$!."\n";
6929: }
6930: }
1.9 raeburn 6931: }
6932: }
6933: }
6934: } else {
6935: $output = $versionresult;
6936: }
6937: }
6938: return ($output,$logourl);
6939: }
6940:
6941: sub logo_versioning {
6942: my ($targetdir,$file,$logfile) = @_;
6943: my $target = $targetdir.'/'.$file;
6944: my ($maxversion,$fn,$extn,$output);
6945: $maxversion = 0;
6946: if ($file =~ /^(.+)\.(\w+)$/) {
6947: $fn=$1;
6948: $extn=$2;
6949: }
6950: opendir(DIR,$targetdir);
6951: while (my $filename=readdir(DIR)) {
6952: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6953: $maxversion=($1>$maxversion)?$1:$maxversion;
6954: }
6955: }
6956: $maxversion++;
6957: print $logfile "\nCreating old version ".$maxversion."\n";
6958: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6959: if (copy($target,$copyfile)) {
6960: print $logfile "Copied old target to ".$copyfile."\n";
6961: $copyfile=$copyfile.'.meta';
6962: if (copy($target.'.meta',$copyfile)) {
6963: print $logfile "Copied old target metadata to ".$copyfile."\n";
6964: $output = 'ok';
6965: } else {
6966: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6967: $output = &mt('Failed to copy old meta').", $!, ";
6968: }
6969: } else {
6970: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6971: $output = &mt('Failed to copy old target').", $!, ";
6972: }
6973: return $output;
6974: }
6975:
6976: sub write_metadata {
6977: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6978: my (%metadatafields,%metadatakeys,$output);
6979: $metadatafields{'title'}=$formname;
6980: $metadatafields{'creationdate'}=time;
6981: $metadatafields{'lastrevisiondate'}=time;
6982: $metadatafields{'copyright'}='public';
6983: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6984: $env{'user.domain'};
6985: $metadatafields{'authorspace'}=$confname.':'.$dom;
6986: $metadatafields{'domain'}=$dom;
6987: {
6988: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6989: my $mfh;
1.155 raeburn 6990: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6991: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6992: unless ($_=~/\./) {
6993: my $unikey=$_;
6994: $unikey=~/^([A-Za-z]+)/;
6995: my $tag=$1;
6996: $tag=~tr/A-Z/a-z/;
6997: print $mfh "\n\<$tag";
6998: foreach (split(/\,/,$metadatakeys{$unikey})) {
6999: my $value=$metadatafields{$unikey.'.'.$_};
7000: $value=~s/\"/\'\'/g;
7001: print $mfh ' '.$_.'="'.$value.'"';
7002: }
7003: print $mfh '>'.
7004: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7005: .'</'.$tag.'>';
7006: }
7007: }
7008: $output = 'ok';
7009: print $logfile "\nWrote metadata";
7010: close($mfh);
7011: } else {
7012: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7013: $output = &mt('Could not write metadata');
7014: }
7015: }
1.155 raeburn 7016: return $output;
7017: }
7018:
7019: sub notifysubscribed {
7020: foreach my $targetsource (@{$modified_urls}){
7021: next unless (ref($targetsource) eq 'ARRAY');
7022: my ($target,$source)=@{$targetsource};
7023: if ($source ne '') {
7024: if (open(my $logfh,'>>'.$source.'.log')) {
7025: print $logfh "\nCleanup phase: Notifications\n";
7026: my @subscribed=&subscribed_hosts($target);
7027: foreach my $subhost (@subscribed) {
7028: print $logfh "\nNotifying host ".$subhost.':';
7029: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7030: print $logfh $reply;
7031: }
7032: my @subscribedmeta=&subscribed_hosts("$target.meta");
7033: foreach my $subhost (@subscribedmeta) {
7034: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7035: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7036: $subhost);
7037: print $logfh $reply;
7038: }
7039: print $logfh "\n============ Done ============\n";
1.160 raeburn 7040: close($logfh);
1.155 raeburn 7041: }
7042: }
7043: }
7044: return OK;
7045: }
7046:
7047: sub subscribed_hosts {
7048: my ($target) = @_;
7049: my @subscribed;
7050: if (open(my $fh,"<$target.subscription")) {
7051: while (my $subline=<$fh>) {
7052: if ($subline =~ /^($match_lonid):/) {
7053: my $host = $1;
7054: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7055: unless (grep(/^\Q$host\E$/,@subscribed)) {
7056: push(@subscribed,$host);
7057: }
7058: }
7059: }
7060: }
7061: }
7062: return @subscribed;
1.9 raeburn 7063: }
7064:
7065: sub check_switchserver {
7066: my ($dom,$confname) = @_;
7067: my ($allowed,$switchserver);
7068: my $home = &Apache::lonnet::homeserver($confname,$dom);
7069: if ($home eq 'no_host') {
7070: $home = &Apache::lonnet::domain($dom,'primary');
7071: }
7072: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7073: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7074: if (!$allowed) {
1.180 raeburn 7075: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7076: }
7077: return $switchserver;
7078: }
7079:
1.1 raeburn 7080: sub modify_quotas {
1.216 raeburn 7081: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7082: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7083: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7084: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7085: $validationfieldsref);
1.86 raeburn 7086: if ($action eq 'quotas') {
7087: $context = 'tools';
1.163 raeburn 7088: } else {
1.86 raeburn 7089: $context = $action;
7090: }
7091: if ($context eq 'requestcourses') {
1.216 raeburn 7092: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7093: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7094: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7095: %titles = &courserequest_titles();
7096: $toolregexp = join('|',@usertools);
7097: %conditions = &courserequest_conditions();
1.216 raeburn 7098: $confname = $dom.'-domainconfig';
7099: my $servadm = $r->dir_config('lonAdmEMail');
7100: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7101: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7102: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7103: } elsif ($context eq 'requestauthor') {
7104: @usertools = ('author');
7105: %titles = &authorrequest_titles();
1.86 raeburn 7106: } else {
1.162 raeburn 7107: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7108: %titles = &tool_titles();
1.86 raeburn 7109: }
1.212 raeburn 7110: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7111: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7112: foreach my $key (keys(%env)) {
1.101 raeburn 7113: if ($context eq 'requestcourses') {
7114: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7115: my $item = $1;
7116: my $type = $2;
7117: if ($type =~ /^limit_(.+)/) {
7118: $limithash{$item}{$1} = $env{$key};
7119: } else {
7120: $confhash{$item}{$type} = $env{$key};
7121: }
7122: }
1.163 raeburn 7123: } elsif ($context eq 'requestauthor') {
7124: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7125: $confhash{$1} = $env{$key};
7126: }
1.101 raeburn 7127: } else {
1.86 raeburn 7128: if ($key =~ /^form\.quota_(.+)$/) {
7129: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7130: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7131: $confhash{'authorquota'}{$1} = $env{$key};
7132: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7133: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7134: }
1.72 raeburn 7135: }
7136: }
1.163 raeburn 7137: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7138: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7139: @approvalnotify = sort(@approvalnotify);
7140: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 7141: my @crstypes = ('official','unofficial','community','textbook');
7142: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7143: foreach my $type (@hasuniquecode) {
7144: if (grep(/^\Q$type\E$/,@crstypes)) {
7145: $confhash{'uniquecode'}{$type} = 1;
7146: }
1.216 raeburn 7147: }
1.242 raeburn 7148: my (%newbook,%allpos);
1.216 raeburn 7149: if ($context eq 'requestcourses') {
1.242 raeburn 7150: foreach my $type ('textbooks','templates') {
7151: @{$allpos{$type}} = ();
7152: my $invalid;
7153: if ($type eq 'textbooks') {
7154: $invalid = &mt('Invalid LON-CAPA course for textbook');
7155: } else {
7156: $invalid = &mt('Invalid LON-CAPA course for template');
7157: }
7158: if ($env{'form.'.$type.'_addbook'}) {
7159: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7160: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7161: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7162: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7163: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7164: } else {
7165: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7166: my $position = $env{'form.'.$type.'_addbook_pos'};
7167: $position =~ s/\D+//g;
7168: if ($position ne '') {
7169: $allpos{$type}[$position] = $newbook{$type};
7170: }
1.216 raeburn 7171: }
1.242 raeburn 7172: } else {
7173: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7174: }
7175: }
1.242 raeburn 7176: }
1.216 raeburn 7177: }
1.102 raeburn 7178: if (ref($domconfig{$action}) eq 'HASH') {
7179: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7180: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7181: $changes{'notify'}{'approval'} = 1;
7182: }
7183: } else {
1.144 raeburn 7184: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7185: $changes{'notify'}{'approval'} = 1;
7186: }
7187: }
1.218 raeburn 7188: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7189: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7190: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7191: unless ($confhash{'uniquecode'}{$crstype}) {
7192: $changes{'uniquecode'} = 1;
7193: }
7194: }
7195: unless ($changes{'uniquecode'}) {
7196: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7197: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7198: $changes{'uniquecode'} = 1;
7199: }
7200: }
7201: }
7202: } else {
7203: $changes{'uniquecode'} = 1;
7204: }
7205: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7206: $changes{'uniquecode'} = 1;
1.216 raeburn 7207: }
7208: if ($context eq 'requestcourses') {
1.242 raeburn 7209: foreach my $type ('textbooks','templates') {
7210: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7211: my %deletions;
7212: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7213: if (@todelete) {
7214: map { $deletions{$_} = 1; } @todelete;
7215: }
7216: my %imgdeletions;
7217: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7218: if (@todeleteimages) {
7219: map { $imgdeletions{$_} = 1; } @todeleteimages;
7220: }
7221: my $maxnum = $env{'form.'.$type.'_maxnum'};
7222: for (my $i=0; $i<=$maxnum; $i++) {
7223: my $itemid = $env{'form.'.$type.'_id_'.$i};
7224: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7225: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7226: if ($deletions{$key}) {
7227: if ($domconfig{$action}{$type}{$key}{'image'}) {
7228: #FIXME need to obsolete item in RES space
7229: }
7230: next;
7231: } else {
7232: my $newpos = $env{'form.'.$itemid};
7233: $newpos =~ s/\D+//g;
1.243 raeburn 7234: foreach my $item ('subject','title','publisher','author') {
7235: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7236: ($type eq 'templates'));
1.242 raeburn 7237: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7238: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7239: $changes{$type}{$key} = 1;
7240: }
7241: }
7242: $allpos{$type}[$newpos] = $key;
7243: }
7244: if ($imgdeletions{$key}) {
7245: $changes{$type}{$key} = 1;
1.216 raeburn 7246: #FIXME need to obsolete item in RES space
1.242 raeburn 7247: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7248: my ($cdom,$cnum) = split(/_/,$key);
7249: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7250: $cdom,$cnum,$type,$configuserok,
7251: $switchserver,$author_ok);
7252: if ($imgurl) {
7253: $confhash{$type}{$key}{'image'} = $imgurl;
7254: $changes{$type}{$key} = 1;
1.216 raeburn 7255: }
1.242 raeburn 7256: if ($error) {
7257: &Apache::lonnet::logthis($error);
7258: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7259: }
7260: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7261: $confhash{$type}{$key}{'image'} =
7262: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7263: }
7264: }
7265: }
7266: }
7267: }
7268: }
1.102 raeburn 7269: } else {
1.144 raeburn 7270: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7271: $changes{'notify'}{'approval'} = 1;
7272: }
1.218 raeburn 7273: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7274: $changes{'uniquecode'} = 1;
7275: }
7276: }
7277: if ($context eq 'requestcourses') {
1.242 raeburn 7278: foreach my $type ('textbooks','templates') {
7279: if ($newbook{$type}) {
7280: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7281: foreach my $item ('subject','title','publisher','author') {
7282: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7283: ($type eq 'template'));
1.242 raeburn 7284: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7285: if ($env{'form.'.$type.'_addbook_'.$item}) {
7286: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7287: }
7288: }
7289: if ($type eq 'textbooks') {
7290: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7291: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7292: my ($imageurl,$error) =
7293: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7294: $configuserok,$switchserver,$author_ok);
7295: if ($imageurl) {
7296: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7297: }
7298: if ($error) {
7299: &Apache::lonnet::logthis($error);
7300: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7301: }
7302: }
1.216 raeburn 7303: }
7304: }
1.242 raeburn 7305: if (@{$allpos{$type}} > 0) {
7306: my $idx = 0;
7307: foreach my $item (@{$allpos{$type}}) {
7308: if ($item ne '') {
7309: $confhash{$type}{$item}{'order'} = $idx;
7310: if (ref($domconfig{$action}) eq 'HASH') {
7311: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7312: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7313: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7314: $changes{$type}{$item} = 1;
7315: }
1.216 raeburn 7316: }
7317: }
7318: }
1.242 raeburn 7319: $idx ++;
1.216 raeburn 7320: }
7321: }
7322: }
7323: }
1.235 raeburn 7324: if (ref($validationitemsref) eq 'ARRAY') {
7325: foreach my $item (@{$validationitemsref}) {
7326: if ($item eq 'fields') {
7327: my @changed;
7328: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7329: if (@{$confhash{'validation'}{$item}} > 0) {
7330: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7331: }
7332: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7333: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7334: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7335: $domconfig{'requestcourses'}{'validation'}{$item});
7336: } else {
7337: @changed = @{$confhash{'validation'}{$item}};
7338: }
7339: } else {
7340: @changed = @{$confhash{'validation'}{$item}};
7341: }
7342: if (@changed) {
7343: if ($confhash{'validation'}{$item}) {
7344: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7345: } else {
7346: $changes{'validation'}{$item} = &mt('None');
7347: }
7348: }
7349: } else {
7350: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7351: if ($item eq 'markup') {
7352: if ($env{'form.requestcourses_validation_'.$item}) {
7353: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7354: }
7355: }
7356: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7357: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7358: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7359: }
7360: } else {
7361: if ($confhash{'validation'}{$item} ne '') {
7362: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7363: }
7364: }
7365: }
7366: }
7367: }
7368: if ($env{'form.validationdc'}) {
7369: my $newval = $env{'form.validationdc'};
7370: my %domcoords = &get_active_dcs($dom);
7371: if (exists($domcoords{$newval})) {
7372: $confhash{'validation'}{'dc'} = $newval;
7373: }
7374: }
7375: if (ref($confhash{'validation'}) eq 'HASH') {
7376: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7377: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7378: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7379: if ($confhash{'validation'}{'dc'} eq '') {
7380: $changes{'validation'}{'dc'} = &mt('None');
7381: } else {
7382: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7383: }
7384: }
7385: } elsif ($confhash{'validation'}{'dc'} ne '') {
7386: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7387: }
7388: } elsif ($confhash{'validation'}{'dc'} ne '') {
7389: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7390: }
7391: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7392: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7393: $changes{'validation'}{'dc'} = &mt('None');
7394: }
7395: }
1.102 raeburn 7396: }
7397: } else {
1.86 raeburn 7398: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7399: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7400: }
1.72 raeburn 7401: foreach my $item (@usertools) {
7402: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7403: my $unset;
1.101 raeburn 7404: if ($context eq 'requestcourses') {
1.104 raeburn 7405: $unset = '0';
7406: if ($type eq '_LC_adv') {
7407: $unset = '';
7408: }
1.101 raeburn 7409: if ($confhash{$item}{$type} eq 'autolimit') {
7410: $confhash{$item}{$type} .= '=';
7411: unless ($limithash{$item}{$type} =~ /\D/) {
7412: $confhash{$item}{$type} .= $limithash{$item}{$type};
7413: }
7414: }
1.163 raeburn 7415: } elsif ($context eq 'requestauthor') {
7416: $unset = '0';
7417: if ($type eq '_LC_adv') {
7418: $unset = '';
7419: }
1.72 raeburn 7420: } else {
1.101 raeburn 7421: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7422: $confhash{$item}{$type} = 1;
7423: } else {
7424: $confhash{$item}{$type} = 0;
7425: }
1.72 raeburn 7426: }
1.86 raeburn 7427: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7428: if ($action eq 'requestauthor') {
7429: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7430: $changes{$type} = 1;
7431: }
7432: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7433: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7434: $changes{$item}{$type} = 1;
7435: }
7436: } else {
7437: if ($context eq 'requestcourses') {
1.104 raeburn 7438: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7439: $changes{$item}{$type} = 1;
7440: }
7441: } else {
7442: if (!$confhash{$item}{$type}) {
7443: $changes{$item}{$type} = 1;
7444: }
7445: }
7446: }
7447: } else {
7448: if ($context eq 'requestcourses') {
1.104 raeburn 7449: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7450: $changes{$item}{$type} = 1;
7451: }
1.163 raeburn 7452: } elsif ($context eq 'requestauthor') {
7453: if ($confhash{$type} ne $unset) {
7454: $changes{$type} = 1;
7455: }
1.72 raeburn 7456: } else {
7457: if (!$confhash{$item}{$type}) {
7458: $changes{$item}{$type} = 1;
7459: }
7460: }
7461: }
1.1 raeburn 7462: }
7463: }
1.163 raeburn 7464: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7465: if (ref($domconfig{'quotas'}) eq 'HASH') {
7466: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7467: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7468: if (exists($confhash{'defaultquota'}{$key})) {
7469: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7470: $changes{'defaultquota'}{$key} = 1;
7471: }
7472: } else {
7473: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7474: }
7475: }
1.86 raeburn 7476: } else {
7477: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7478: if (exists($confhash{'defaultquota'}{$key})) {
7479: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7480: $changes{'defaultquota'}{$key} = 1;
7481: }
7482: } else {
7483: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7484: }
1.1 raeburn 7485: }
7486: }
1.197 raeburn 7487: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7488: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7489: if (exists($confhash{'authorquota'}{$key})) {
7490: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7491: $changes{'authorquota'}{$key} = 1;
7492: }
7493: } else {
7494: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7495: }
7496: }
7497: }
1.1 raeburn 7498: }
1.86 raeburn 7499: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7500: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7501: if (ref($domconfig{'quotas'}) eq 'HASH') {
7502: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7503: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7504: $changes{'defaultquota'}{$key} = 1;
7505: }
7506: } else {
7507: if (!exists($domconfig{'quotas'}{$key})) {
7508: $changes{'defaultquota'}{$key} = 1;
7509: }
1.72 raeburn 7510: }
7511: } else {
1.86 raeburn 7512: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7513: }
1.1 raeburn 7514: }
7515: }
1.197 raeburn 7516: if (ref($confhash{'authorquota'}) eq 'HASH') {
7517: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7518: if (ref($domconfig{'quotas'}) eq 'HASH') {
7519: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7520: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7521: $changes{'authorquota'}{$key} = 1;
7522: }
7523: } else {
7524: $changes{'authorquota'}{$key} = 1;
7525: }
7526: } else {
7527: $changes{'authorquota'}{$key} = 1;
7528: }
7529: }
7530: }
1.1 raeburn 7531: }
1.72 raeburn 7532:
1.163 raeburn 7533: if ($context eq 'requestauthor') {
7534: $domdefaults{'requestauthor'} = \%confhash;
7535: } else {
7536: foreach my $key (keys(%confhash)) {
1.242 raeburn 7537: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7538: $domdefaults{$key} = $confhash{$key};
7539: }
1.163 raeburn 7540: }
1.72 raeburn 7541: }
1.163 raeburn 7542:
1.1 raeburn 7543: my %quotahash = (
1.86 raeburn 7544: $action => { %confhash }
1.1 raeburn 7545: );
7546: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7547: $dom);
7548: if ($putresult eq 'ok') {
7549: if (keys(%changes) > 0) {
1.72 raeburn 7550: my $cachetime = 24*60*60;
7551: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7552: if (ref($lastactref) eq 'HASH') {
7553: $lastactref->{'domdefaults'} = 1;
7554: }
1.1 raeburn 7555: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7556: unless (($context eq 'requestcourses') ||
1.163 raeburn 7557: ($context eq 'requestauthor')) {
1.86 raeburn 7558: if (ref($changes{'defaultquota'}) eq 'HASH') {
7559: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7560: foreach my $type (@{$types},'default') {
7561: if (defined($changes{'defaultquota'}{$type})) {
7562: my $typetitle = $usertypes->{$type};
7563: if ($type eq 'default') {
7564: $typetitle = $othertitle;
7565: }
1.213 raeburn 7566: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7567: }
7568: }
1.86 raeburn 7569: $resulttext .= '</ul></li>';
1.72 raeburn 7570: }
1.197 raeburn 7571: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7572: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7573: foreach my $type (@{$types},'default') {
7574: if (defined($changes{'authorquota'}{$type})) {
7575: my $typetitle = $usertypes->{$type};
7576: if ($type eq 'default') {
7577: $typetitle = $othertitle;
7578: }
1.213 raeburn 7579: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7580: }
7581: }
7582: $resulttext .= '</ul></li>';
7583: }
1.72 raeburn 7584: }
1.80 raeburn 7585: my %newenv;
1.72 raeburn 7586: foreach my $item (@usertools) {
1.163 raeburn 7587: my (%haschgs,%inconf);
7588: if ($context eq 'requestauthor') {
7589: %haschgs = %changes;
1.210 raeburn 7590: %inconf = %confhash;
1.163 raeburn 7591: } else {
7592: if (ref($changes{$item}) eq 'HASH') {
7593: %haschgs = %{$changes{$item}};
7594: }
7595: if (ref($confhash{$item}) eq 'HASH') {
7596: %inconf = %{$confhash{$item}};
7597: }
7598: }
7599: if (keys(%haschgs) > 0) {
1.80 raeburn 7600: my $newacc =
7601: &Apache::lonnet::usertools_access($env{'user.name'},
7602: $env{'user.domain'},
1.86 raeburn 7603: $item,'reload',$context);
1.210 raeburn 7604: if (($context eq 'requestcourses') ||
1.163 raeburn 7605: ($context eq 'requestauthor')) {
1.108 raeburn 7606: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7607: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7608: }
7609: } else {
7610: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7611: $newenv{'environment.availabletools.'.$item} = $newacc;
7612: }
1.80 raeburn 7613: }
1.163 raeburn 7614: unless ($context eq 'requestauthor') {
7615: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7616: }
1.72 raeburn 7617: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7618: if ($haschgs{$type}) {
1.72 raeburn 7619: my $typetitle = $usertypes->{$type};
7620: if ($type eq 'default') {
7621: $typetitle = $othertitle;
7622: } elsif ($type eq '_LC_adv') {
7623: $typetitle = 'LON-CAPA Advanced Users';
7624: }
1.163 raeburn 7625: if ($inconf{$type}) {
1.101 raeburn 7626: if ($context eq 'requestcourses') {
7627: my $cond;
1.163 raeburn 7628: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7629: if ($1 eq '') {
7630: $cond = &mt('(Automatic processing of any request).');
7631: } else {
7632: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7633: }
7634: } else {
1.163 raeburn 7635: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7636: }
7637: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7638: } elsif ($context eq 'requestauthor') {
7639: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7640: $titles{$inconf{$type}},$typetitle);
7641:
1.101 raeburn 7642: } else {
7643: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7644: }
1.72 raeburn 7645: } else {
1.104 raeburn 7646: if ($type eq '_LC_adv') {
1.163 raeburn 7647: if ($inconf{$type} eq '0') {
1.104 raeburn 7648: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7649: } else {
7650: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7651: }
7652: } else {
7653: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7654: }
1.72 raeburn 7655: }
7656: }
1.26 raeburn 7657: }
1.163 raeburn 7658: unless ($context eq 'requestauthor') {
7659: $resulttext .= '</ul></li>';
7660: }
1.26 raeburn 7661: }
1.1 raeburn 7662: }
1.163 raeburn 7663: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7664: if (ref($changes{'notify'}) eq 'HASH') {
7665: if ($changes{'notify'}{'approval'}) {
7666: if (ref($confhash{'notify'}) eq 'HASH') {
7667: if ($confhash{'notify'}{'approval'}) {
7668: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7669: } else {
1.163 raeburn 7670: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7671: }
7672: }
7673: }
7674: }
7675: }
1.216 raeburn 7676: if ($action eq 'requestcourses') {
7677: my @offon = ('off','on');
7678: if ($changes{'uniquecode'}) {
1.218 raeburn 7679: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7680: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7681: $resulttext .= '<li>'.
7682: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7683: '</li>';
7684: } else {
7685: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7686: '</li>';
7687: }
1.216 raeburn 7688: }
1.242 raeburn 7689: foreach my $type ('textbooks','templates') {
7690: if (ref($changes{$type}) eq 'HASH') {
7691: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7692: foreach my $key (sort(keys(%{$changes{$type}}))) {
7693: my %coursehash = &Apache::lonnet::coursedescription($key);
7694: my $coursetitle = $coursehash{'description'};
7695: my $position = $confhash{$type}{$key}{'order'} + 1;
7696: $resulttext .= '<li>';
1.243 raeburn 7697: foreach my $item ('subject','title','publisher','author') {
7698: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7699: ($type eq 'templates'));
1.242 raeburn 7700: my $name = $item.':';
7701: $name =~ s/^(\w)/\U$1/;
7702: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7703: }
7704: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7705: if ($type eq 'textbooks') {
7706: if ($confhash{$type}{$key}{'image'}) {
7707: $resulttext .= ' '.&mt('Image: [_1]',
7708: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7709: ' alt="Textbook cover" />').'<br />';
7710: }
7711: }
7712: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7713: }
1.242 raeburn 7714: $resulttext .= '</ul></li>';
1.216 raeburn 7715: }
7716: }
1.235 raeburn 7717: if (ref($changes{'validation'}) eq 'HASH') {
7718: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7719: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7720: foreach my $item (@{$validationitemsref}) {
7721: if (exists($changes{'validation'}{$item})) {
7722: if ($item eq 'markup') {
7723: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7724: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7725: } else {
7726: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7727: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7728: }
7729: }
7730: }
7731: if (exists($changes{'validation'}{'dc'})) {
7732: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7733: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7734: }
7735: }
7736: }
1.216 raeburn 7737: }
1.1 raeburn 7738: $resulttext .= '</ul>';
1.80 raeburn 7739: if (keys(%newenv)) {
7740: &Apache::lonnet::appenv(\%newenv);
7741: }
1.1 raeburn 7742: } else {
1.86 raeburn 7743: if ($context eq 'requestcourses') {
7744: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7745: } elsif ($context eq 'requestauthor') {
7746: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7747: } else {
1.90 weissno 7748: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7749: }
1.1 raeburn 7750: }
7751: } else {
1.11 albertel 7752: $resulttext = '<span class="LC_error">'.
7753: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7754: }
1.216 raeburn 7755: if ($errors) {
7756: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7757: '<ul>'.$errors.'</ul></p>';
7758: }
1.3 raeburn 7759: return $resulttext;
1.1 raeburn 7760: }
7761:
1.216 raeburn 7762: sub process_textbook_image {
1.242 raeburn 7763: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7764: my $filename = $env{'form.'.$caller.'.filename'};
7765: my ($error,$url);
7766: my ($width,$height) = (50,50);
7767: if ($configuserok eq 'ok') {
7768: if ($switchserver) {
7769: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7770: $switchserver);
7771: } elsif ($author_ok eq 'ok') {
7772: my ($result,$imageurl) =
7773: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7774: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7775: if ($result eq 'ok') {
7776: $url = $imageurl;
7777: } else {
7778: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7779: }
7780: } else {
7781: $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);
7782: }
7783: } else {
7784: $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);
7785: }
7786: return ($url,$error);
7787: }
7788:
1.3 raeburn 7789: sub modify_autoenroll {
1.205 raeburn 7790: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7791: my ($resulttext,%changes);
7792: my %currautoenroll;
7793: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7794: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7795: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7796: }
7797: }
7798: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7799: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7800: sender => 'Sender for notification messages',
7801: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7802: my @offon = ('off','on');
1.17 raeburn 7803: my $sender_uname = $env{'form.sender_uname'};
7804: my $sender_domain = $env{'form.sender_domain'};
7805: if ($sender_domain eq '') {
7806: $sender_uname = '';
7807: } elsif ($sender_uname eq '') {
7808: $sender_domain = '';
7809: }
1.129 raeburn 7810: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7811: my %autoenrollhash = (
1.129 raeburn 7812: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7813: 'sender_uname' => $sender_uname,
7814: 'sender_domain' => $sender_domain,
7815: 'co-owners' => $coowners,
1.1 raeburn 7816: }
7817: );
1.4 raeburn 7818: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7819: $dom);
1.1 raeburn 7820: if ($putresult eq 'ok') {
7821: if (exists($currautoenroll{'run'})) {
7822: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7823: $changes{'run'} = 1;
7824: }
7825: } elsif ($autorun) {
7826: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7827: $changes{'run'} = 1;
1.1 raeburn 7828: }
7829: }
1.17 raeburn 7830: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7831: $changes{'sender'} = 1;
7832: }
1.17 raeburn 7833: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7834: $changes{'sender'} = 1;
7835: }
1.129 raeburn 7836: if ($currautoenroll{'co-owners'} ne '') {
7837: if ($currautoenroll{'co-owners'} ne $coowners) {
7838: $changes{'coowners'} = 1;
7839: }
7840: } elsif ($coowners) {
7841: $changes{'coowners'} = 1;
7842: }
1.1 raeburn 7843: if (keys(%changes) > 0) {
7844: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7845: if ($changes{'run'}) {
1.1 raeburn 7846: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7847: }
7848: if ($changes{'sender'}) {
1.17 raeburn 7849: if ($sender_uname eq '' || $sender_domain eq '') {
7850: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7851: } else {
7852: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7853: }
1.1 raeburn 7854: }
1.129 raeburn 7855: if ($changes{'coowners'}) {
7856: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7857: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7858: if (ref($lastactref) eq 'HASH') {
7859: $lastactref->{'domainconfig'} = 1;
7860: }
1.129 raeburn 7861: }
1.1 raeburn 7862: $resulttext .= '</ul>';
7863: } else {
7864: $resulttext = &mt('No changes made to auto-enrollment settings');
7865: }
7866: } else {
1.11 albertel 7867: $resulttext = '<span class="LC_error">'.
7868: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7869: }
1.3 raeburn 7870: return $resulttext;
1.1 raeburn 7871: }
7872:
7873: sub modify_autoupdate {
1.3 raeburn 7874: my ($dom,%domconfig) = @_;
1.1 raeburn 7875: my ($resulttext,%currautoupdate,%fields,%changes);
7876: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7877: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7878: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7879: }
7880: }
7881: my @offon = ('off','on');
7882: my %title = &Apache::lonlocal::texthash (
7883: run => 'Auto-update:',
7884: classlists => 'Updates to user information in classlists?'
7885: );
1.44 raeburn 7886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7887: my %fieldtitles = &Apache::lonlocal::texthash (
7888: id => 'Student/Employee ID',
1.20 raeburn 7889: permanentemail => 'E-mail address',
1.1 raeburn 7890: lastname => 'Last Name',
7891: firstname => 'First Name',
7892: middlename => 'Middle Name',
1.132 raeburn 7893: generation => 'Generation',
1.1 raeburn 7894: );
1.142 raeburn 7895: $othertitle = &mt('All users');
1.1 raeburn 7896: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7897: $othertitle = &mt('Other users');
1.1 raeburn 7898: }
7899: foreach my $key (keys(%env)) {
7900: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7901: my ($usertype,$item) = ($1,$2);
7902: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7903: if ($usertype eq 'default') {
7904: push(@{$fields{$1}},$2);
7905: } elsif (ref($types) eq 'ARRAY') {
7906: if (grep(/^\Q$usertype\E$/,@{$types})) {
7907: push(@{$fields{$1}},$2);
7908: }
7909: }
7910: }
1.1 raeburn 7911: }
7912: }
1.131 raeburn 7913: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7914: @lockablenames = sort(@lockablenames);
7915: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7916: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7917: if (@changed) {
7918: $changes{'lockablenames'} = 1;
7919: }
7920: } else {
7921: if (@lockablenames) {
7922: $changes{'lockablenames'} = 1;
7923: }
7924: }
1.1 raeburn 7925: my %updatehash = (
7926: autoupdate => { run => $env{'form.autoupdate_run'},
7927: classlists => $env{'form.classlists'},
7928: fields => {%fields},
1.131 raeburn 7929: lockablenames => \@lockablenames,
1.1 raeburn 7930: }
7931: );
7932: foreach my $key (keys(%currautoupdate)) {
7933: if (($key eq 'run') || ($key eq 'classlists')) {
7934: if (exists($updatehash{autoupdate}{$key})) {
7935: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7936: $changes{$key} = 1;
7937: }
7938: }
7939: } elsif ($key eq 'fields') {
7940: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7941: foreach my $item (@{$types},'default') {
1.1 raeburn 7942: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7943: my $change = 0;
7944: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7945: if (!exists($fields{$item})) {
7946: $change = 1;
1.132 raeburn 7947: last;
1.1 raeburn 7948: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7949: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7950: $change = 1;
1.132 raeburn 7951: last;
1.1 raeburn 7952: }
7953: }
7954: }
7955: if ($change) {
7956: push(@{$changes{$key}},$item);
7957: }
1.26 raeburn 7958: }
1.1 raeburn 7959: }
7960: }
1.131 raeburn 7961: } elsif ($key eq 'lockablenames') {
7962: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7963: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7964: if (@changed) {
7965: $changes{'lockablenames'} = 1;
7966: }
7967: } else {
7968: if (@lockablenames) {
7969: $changes{'lockablenames'} = 1;
7970: }
7971: }
7972: }
7973: }
7974: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7975: if (@lockablenames) {
7976: $changes{'lockablenames'} = 1;
1.1 raeburn 7977: }
7978: }
1.26 raeburn 7979: foreach my $item (@{$types},'default') {
7980: if (defined($fields{$item})) {
7981: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7982: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7983: my $change = 0;
7984: if (ref($fields{$item}) eq 'ARRAY') {
7985: foreach my $type (@{$fields{$item}}) {
7986: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7987: $change = 1;
7988: last;
7989: }
7990: }
7991: }
7992: if ($change) {
7993: push(@{$changes{'fields'}},$item);
7994: }
7995: } else {
1.26 raeburn 7996: push(@{$changes{'fields'}},$item);
7997: }
7998: } else {
7999: push(@{$changes{'fields'}},$item);
1.1 raeburn 8000: }
8001: }
8002: }
8003: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8004: $dom);
8005: if ($putresult eq 'ok') {
8006: if (keys(%changes) > 0) {
8007: $resulttext = &mt('Changes made:').'<ul>';
8008: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8009: if ($key eq 'lockablenames') {
8010: $resulttext .= '<li>';
8011: if (@lockablenames) {
8012: $usertypes->{'default'} = $othertitle;
8013: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8014: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8015: } else {
8016: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8017: }
8018: $resulttext .= '</li>';
8019: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8020: foreach my $item (@{$changes{$key}}) {
8021: my @newvalues;
8022: foreach my $type (@{$fields{$item}}) {
8023: push(@newvalues,$fieldtitles{$type});
8024: }
1.3 raeburn 8025: my $newvaluestr;
8026: if (@newvalues > 0) {
8027: $newvaluestr = join(', ',@newvalues);
8028: } else {
8029: $newvaluestr = &mt('none');
1.6 raeburn 8030: }
1.1 raeburn 8031: if ($item eq 'default') {
1.26 raeburn 8032: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8033: } else {
1.26 raeburn 8034: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8035: }
8036: }
8037: } else {
8038: my $newvalue;
8039: if ($key eq 'run') {
8040: $newvalue = $offon[$env{'form.autoupdate_run'}];
8041: } else {
8042: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8043: }
1.1 raeburn 8044: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8045: }
8046: }
8047: $resulttext .= '</ul>';
8048: } else {
1.3 raeburn 8049: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8050: }
8051: } else {
1.11 albertel 8052: $resulttext = '<span class="LC_error">'.
8053: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8054: }
1.3 raeburn 8055: return $resulttext;
1.1 raeburn 8056: }
8057:
1.125 raeburn 8058: sub modify_autocreate {
8059: my ($dom,%domconfig) = @_;
8060: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8061: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8062: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8063: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8064: }
8065: }
8066: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8067: req => 'Auto-creation of validated requests for official courses',
8068: xmldc => 'Identity of course creator of courses from XML files',
8069: );
8070: my @types = ('xml','req');
8071: foreach my $item (@types) {
8072: $newvals{$item} = $env{'form.autocreate_'.$item};
8073: $newvals{$item} =~ s/\D//g;
8074: $newvals{$item} = 0 if ($newvals{$item} eq '');
8075: }
8076: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8077: my %domcoords = &get_active_dcs($dom);
8078: unless (exists($domcoords{$newvals{'xmldc'}})) {
8079: $newvals{'xmldc'} = '';
8080: }
8081: %autocreatehash = (
8082: autocreate => { xml => $newvals{'xml'},
8083: req => $newvals{'req'},
8084: }
8085: );
8086: if ($newvals{'xmldc'} ne '') {
8087: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8088: }
8089: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8090: $dom);
8091: if ($putresult eq 'ok') {
8092: my @items = @types;
8093: if ($newvals{'xml'}) {
8094: push(@items,'xmldc');
8095: }
8096: foreach my $item (@items) {
8097: if (exists($currautocreate{$item})) {
8098: if ($currautocreate{$item} ne $newvals{$item}) {
8099: $changes{$item} = 1;
8100: }
8101: } elsif ($newvals{$item}) {
8102: $changes{$item} = 1;
8103: }
8104: }
8105: if (keys(%changes) > 0) {
8106: my @offon = ('off','on');
8107: $resulttext = &mt('Changes made:').'<ul>';
8108: foreach my $item (@types) {
8109: if ($changes{$item}) {
8110: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 8111: $resulttext .= '<li>'.
8112: &mt("$title{$item} set to [_1]$newtxt [_2]",
8113: '<b>','</b>').
8114: '</li>';
1.125 raeburn 8115: }
8116: }
8117: if ($changes{'xmldc'}) {
8118: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8119: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 8120: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8121: }
8122: $resulttext .= '</ul>';
8123: } else {
8124: $resulttext = &mt('No changes made to auto-creation settings');
8125: }
8126: } else {
8127: $resulttext = '<span class="LC_error">'.
8128: &mt('An error occurred: [_1]',$putresult).'</span>';
8129: }
8130: return $resulttext;
8131: }
8132:
1.23 raeburn 8133: sub modify_directorysrch {
8134: my ($dom,%domconfig) = @_;
8135: my ($resulttext,%changes);
8136: my %currdirsrch;
8137: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8138: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8139: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8140: }
8141: }
8142: my %title = ( available => 'Directory search available',
1.24 raeburn 8143: localonly => 'Other domains can search',
1.23 raeburn 8144: searchby => 'Search types',
8145: searchtypes => 'Search latitude');
8146: my @offon = ('off','on');
1.24 raeburn 8147: my @otherdoms = ('Yes','No');
1.23 raeburn 8148:
1.25 raeburn 8149: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8150: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8151: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8152:
1.44 raeburn 8153: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8154: if (keys(%{$usertypes}) == 0) {
8155: @cansearch = ('default');
8156: } else {
8157: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8158: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8159: if (!grep(/^\Q$type\E$/,@cansearch)) {
8160: push(@{$changes{'cansearch'}},$type);
8161: }
1.23 raeburn 8162: }
1.26 raeburn 8163: foreach my $type (@cansearch) {
8164: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8165: push(@{$changes{'cansearch'}},$type);
8166: }
1.23 raeburn 8167: }
1.26 raeburn 8168: } else {
8169: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8170: }
8171: }
8172:
8173: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8174: foreach my $by (@{$currdirsrch{'searchby'}}) {
8175: if (!grep(/^\Q$by\E$/,@searchby)) {
8176: push(@{$changes{'searchby'}},$by);
8177: }
8178: }
8179: foreach my $by (@searchby) {
8180: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8181: push(@{$changes{'searchby'}},$by);
8182: }
8183: }
8184: } else {
8185: push(@{$changes{'searchby'}},@searchby);
8186: }
1.25 raeburn 8187:
8188: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8189: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8190: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8191: push(@{$changes{'searchtypes'}},$type);
8192: }
8193: }
8194: foreach my $type (@searchtypes) {
8195: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8196: push(@{$changes{'searchtypes'}},$type);
8197: }
8198: }
8199: } else {
8200: if (exists($currdirsrch{'searchtypes'})) {
8201: foreach my $type (@searchtypes) {
8202: if ($type ne $currdirsrch{'searchtypes'}) {
8203: push(@{$changes{'searchtypes'}},$type);
8204: }
8205: }
8206: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8207: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8208: }
8209: } else {
8210: push(@{$changes{'searchtypes'}},@searchtypes);
8211: }
8212: }
8213:
1.23 raeburn 8214: my %dirsrch_hash = (
8215: directorysrch => { available => $env{'form.dirsrch_available'},
8216: cansearch => \@cansearch,
1.24 raeburn 8217: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8218: searchby => \@searchby,
1.25 raeburn 8219: searchtypes => \@searchtypes,
1.23 raeburn 8220: }
8221: );
8222: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8223: $dom);
8224: if ($putresult eq 'ok') {
8225: if (exists($currdirsrch{'available'})) {
8226: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8227: $changes{'available'} = 1;
8228: }
8229: } else {
8230: if ($env{'form.dirsrch_available'} eq '1') {
8231: $changes{'available'} = 1;
8232: }
8233: }
1.24 raeburn 8234: if (exists($currdirsrch{'localonly'})) {
8235: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8236: $changes{'localonly'} = 1;
8237: }
8238: } else {
8239: if ($env{'form.dirsrch_localonly'} eq '1') {
8240: $changes{'localonly'} = 1;
8241: }
8242: }
1.23 raeburn 8243: if (keys(%changes) > 0) {
8244: $resulttext = &mt('Changes made:').'<ul>';
8245: if ($changes{'available'}) {
8246: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8247: }
1.24 raeburn 8248: if ($changes{'localonly'}) {
8249: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8250: }
8251:
1.23 raeburn 8252: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8253: my $chgtext;
1.26 raeburn 8254: if (ref($usertypes) eq 'HASH') {
8255: if (keys(%{$usertypes}) > 0) {
8256: foreach my $type (@{$types}) {
8257: if (grep(/^\Q$type\E$/,@cansearch)) {
8258: $chgtext .= $usertypes->{$type}.'; ';
8259: }
8260: }
8261: if (grep(/^default$/,@cansearch)) {
8262: $chgtext .= $othertitle;
8263: } else {
8264: $chgtext =~ s/\; $//;
8265: }
1.210 raeburn 8266: $resulttext .=
1.178 raeburn 8267: '<li>'.
8268: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8269: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8270: '</li>';
1.23 raeburn 8271: }
8272: }
8273: }
8274: if (ref($changes{'searchby'}) eq 'ARRAY') {
8275: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8276: my $chgtext;
8277: foreach my $type (@{$titleorder}) {
8278: if (grep(/^\Q$type\E$/,@searchby)) {
8279: if (defined($searchtitles->{$type})) {
8280: $chgtext .= $searchtitles->{$type}.'; ';
8281: }
8282: }
8283: }
8284: $chgtext =~ s/\; $//;
8285: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8286: }
1.25 raeburn 8287: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8288: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8289: my $chgtext;
8290: foreach my $type (@{$srchtypeorder}) {
8291: if (grep(/^\Q$type\E$/,@searchtypes)) {
8292: if (defined($srchtypes_desc->{$type})) {
8293: $chgtext .= $srchtypes_desc->{$type}.'; ';
8294: }
8295: }
8296: }
8297: $chgtext =~ s/\; $//;
1.178 raeburn 8298: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8299: }
8300: $resulttext .= '</ul>';
8301: } else {
8302: $resulttext = &mt('No changes made to institution directory search settings');
8303: }
8304: } else {
8305: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8306: &mt('An error occurred: [_1]',$putresult).'</span>';
8307: }
8308: return $resulttext;
8309: }
8310:
1.28 raeburn 8311: sub modify_contacts {
1.205 raeburn 8312: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8313: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8314: if (ref($domconfig{'contacts'}) eq 'HASH') {
8315: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8316: $currsetting{$key} = $domconfig{'contacts'}{$key};
8317: }
8318: }
1.134 raeburn 8319: my (%others,%to,%bcc);
1.28 raeburn 8320: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8321: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8322: 'requestsmail','updatesmail','idconflictsmail');
8323: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8324: foreach my $type (@mailings) {
8325: @{$newsetting{$type}} =
8326: &Apache::loncommon::get_env_multiple('form.'.$type);
8327: foreach my $item (@contacts) {
8328: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8329: $contacts_hash{contacts}{$type}{$item} = 1;
8330: } else {
8331: $contacts_hash{contacts}{$type}{$item} = 0;
8332: }
8333: }
8334: $others{$type} = $env{'form.'.$type.'_others'};
8335: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8336: if ($type eq 'helpdeskmail') {
8337: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8338: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8339: }
1.28 raeburn 8340: }
8341: foreach my $item (@contacts) {
8342: $to{$item} = $env{'form.'.$item};
8343: $contacts_hash{'contacts'}{$item} = $to{$item};
8344: }
1.203 raeburn 8345: foreach my $item (@toggles) {
8346: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8347: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8348: }
8349: }
1.28 raeburn 8350: if (keys(%currsetting) > 0) {
8351: foreach my $item (@contacts) {
8352: if ($to{$item} ne $currsetting{$item}) {
8353: $changes{$item} = 1;
8354: }
8355: }
8356: foreach my $type (@mailings) {
8357: foreach my $item (@contacts) {
8358: if (ref($currsetting{$type}) eq 'HASH') {
8359: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8360: push(@{$changes{$type}},$item);
8361: }
8362: } else {
8363: push(@{$changes{$type}},@{$newsetting{$type}});
8364: }
8365: }
8366: if ($others{$type} ne $currsetting{$type}{'others'}) {
8367: push(@{$changes{$type}},'others');
8368: }
1.134 raeburn 8369: if ($type eq 'helpdeskmail') {
8370: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8371: push(@{$changes{$type}},'bcc');
8372: }
8373: }
1.28 raeburn 8374: }
8375: } else {
8376: my %default;
8377: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8378: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8379: $default{'errormail'} = 'adminemail';
8380: $default{'packagesmail'} = 'adminemail';
8381: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8382: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8383: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8384: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8385: foreach my $item (@contacts) {
8386: if ($to{$item} ne $default{$item}) {
8387: $changes{$item} = 1;
1.203 raeburn 8388: }
1.28 raeburn 8389: }
8390: foreach my $type (@mailings) {
8391: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8392:
8393: push(@{$changes{$type}},@{$newsetting{$type}});
8394: }
8395: if ($others{$type} ne '') {
8396: push(@{$changes{$type}},'others');
1.134 raeburn 8397: }
8398: if ($type eq 'helpdeskmail') {
8399: if ($bcc{$type} ne '') {
8400: push(@{$changes{$type}},'bcc');
8401: }
8402: }
1.28 raeburn 8403: }
8404: }
1.203 raeburn 8405: foreach my $item (@toggles) {
8406: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8407: $changes{$item} = 1;
8408: } elsif ((!$env{'form.'.$item}) &&
8409: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8410: $changes{$item} = 1;
8411: }
8412: }
1.28 raeburn 8413: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8414: $dom);
8415: if ($putresult eq 'ok') {
8416: if (keys(%changes) > 0) {
1.205 raeburn 8417: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8418: if (ref($lastactref) eq 'HASH') {
8419: $lastactref->{'domainconfig'} = 1;
8420: }
1.28 raeburn 8421: my ($titles,$short_titles) = &contact_titles();
8422: $resulttext = &mt('Changes made:').'<ul>';
8423: foreach my $item (@contacts) {
8424: if ($changes{$item}) {
8425: $resulttext .= '<li>'.$titles->{$item}.
8426: &mt(' set to: ').
8427: '<span class="LC_cusr_emph">'.
8428: $to{$item}.'</span></li>';
8429: }
8430: }
8431: foreach my $type (@mailings) {
8432: if (ref($changes{$type}) eq 'ARRAY') {
8433: $resulttext .= '<li>'.$titles->{$type}.': ';
8434: my @text;
8435: foreach my $item (@{$newsetting{$type}}) {
8436: push(@text,$short_titles->{$item});
8437: }
8438: if ($others{$type} ne '') {
8439: push(@text,$others{$type});
8440: }
8441: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8442: join(', ',@text).'</span>';
8443: if ($type eq 'helpdeskmail') {
8444: if ($bcc{$type} ne '') {
8445: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8446: }
8447: }
8448: $resulttext .= '</li>';
1.28 raeburn 8449: }
8450: }
1.203 raeburn 8451: my @offon = ('off','on');
8452: if ($changes{'reporterrors'}) {
8453: $resulttext .= '<li>'.
8454: &mt('E-mail error reports to [_1] set to "'.
8455: $offon[$env{'form.reporterrors'}].'".',
8456: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8457: &mt('LON-CAPA core group - MSU'),600,500)).
8458: '</li>';
8459: }
8460: if ($changes{'reportupdates'}) {
8461: $resulttext .= '<li>'.
8462: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8463: $offon[$env{'form.reportupdates'}].'".',
8464: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8465: &mt('LON-CAPA core group - MSU'),600,500)).
8466: '</li>';
8467: }
1.28 raeburn 8468: $resulttext .= '</ul>';
8469: } else {
1.34 raeburn 8470: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8471: }
8472: } else {
8473: $resulttext = '<span class="LC_error">'.
8474: &mt('An error occurred: [_1].',$putresult).'</span>';
8475: }
8476: return $resulttext;
8477: }
8478:
8479: sub modify_usercreation {
1.27 raeburn 8480: my ($dom,%domconfig) = @_;
1.224 raeburn 8481: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8482: my $warningmsg;
1.27 raeburn 8483: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8484: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8485: if ($key eq 'cancreate') {
8486: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8487: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8488: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8489: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8490: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8491: } else {
8492: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8493: }
8494: }
8495: }
8496: } elsif ($key eq 'email_rule') {
8497: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8498: } else {
8499: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8500: }
1.27 raeburn 8501: }
8502: }
8503: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8504: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8505: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8506: foreach my $item(@contexts) {
1.224 raeburn 8507: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8508: }
1.34 raeburn 8509: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8510: foreach my $item (@contexts) {
1.224 raeburn 8511: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8512: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8513: }
1.27 raeburn 8514: }
1.34 raeburn 8515: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8516: foreach my $item (@contexts) {
1.43 raeburn 8517: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8518: if ($cancreate{$item} ne 'any') {
8519: push(@{$changes{'cancreate'}},$item);
8520: }
8521: } else {
8522: if ($cancreate{$item} ne 'none') {
8523: push(@{$changes{'cancreate'}},$item);
8524: }
1.27 raeburn 8525: }
8526: }
8527: } else {
1.43 raeburn 8528: foreach my $item (@contexts) {
1.34 raeburn 8529: push(@{$changes{'cancreate'}},$item);
8530: }
1.27 raeburn 8531: }
1.34 raeburn 8532:
1.27 raeburn 8533: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8534: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8535: if (!grep(/^\Q$type\E$/,@username_rule)) {
8536: push(@{$changes{'username_rule'}},$type);
8537: }
8538: }
8539: foreach my $type (@username_rule) {
8540: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8541: push(@{$changes{'username_rule'}},$type);
8542: }
8543: }
8544: } else {
8545: push(@{$changes{'username_rule'}},@username_rule);
8546: }
8547:
1.32 raeburn 8548: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8549: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8550: if (!grep(/^\Q$type\E$/,@id_rule)) {
8551: push(@{$changes{'id_rule'}},$type);
8552: }
8553: }
8554: foreach my $type (@id_rule) {
8555: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8556: push(@{$changes{'id_rule'}},$type);
8557: }
8558: }
8559: } else {
8560: push(@{$changes{'id_rule'}},@id_rule);
8561: }
8562:
1.43 raeburn 8563: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8564: my @authtypes = ('int','krb4','krb5','loc');
8565: my %authhash;
1.43 raeburn 8566: foreach my $item (@authen_contexts) {
1.28 raeburn 8567: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8568: foreach my $auth (@authtypes) {
8569: if (grep(/^\Q$auth\E$/,@authallowed)) {
8570: $authhash{$item}{$auth} = 1;
8571: } else {
8572: $authhash{$item}{$auth} = 0;
8573: }
8574: }
8575: }
8576: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8577: foreach my $item (@authen_contexts) {
1.28 raeburn 8578: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8579: foreach my $auth (@authtypes) {
8580: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8581: push(@{$changes{'authtypes'}},$item);
8582: last;
8583: }
8584: }
8585: }
8586: }
8587: } else {
1.43 raeburn 8588: foreach my $item (@authen_contexts) {
1.28 raeburn 8589: push(@{$changes{'authtypes'}},$item);
8590: }
8591: }
8592:
1.224 raeburn 8593: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8594: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8595: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8596: $save_usercreate{'id_rule'} = \@id_rule;
8597: $save_usercreate{'username_rule'} = \@username_rule,
8598: $save_usercreate{'authtypes'} = \%authhash;
8599:
1.27 raeburn 8600: my %usercreation_hash = (
1.224 raeburn 8601: usercreation => \%save_usercreate,
8602: );
1.27 raeburn 8603:
8604: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8605: $dom);
1.50 raeburn 8606:
1.224 raeburn 8607: if ($putresult eq 'ok') {
8608: if (keys(%changes) > 0) {
8609: $resulttext = &mt('Changes made:').'<ul>';
8610: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8611: my %lt = &usercreation_types();
8612: foreach my $type (@{$changes{'cancreate'}}) {
8613: my $chgtext = $lt{$type}.', ';
8614: if ($cancreate{$type} eq 'none') {
8615: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8616: } elsif ($cancreate{$type} eq 'any') {
8617: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8618: } elsif ($cancreate{$type} eq 'official') {
8619: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8620: } elsif ($cancreate{$type} eq 'unofficial') {
8621: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8622: }
8623: $resulttext .= '<li>'.$chgtext.'</li>';
8624: }
8625: }
8626: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8627: my ($rules,$ruleorder) =
8628: &Apache::lonnet::inst_userrules($dom,'username');
8629: my $chgtext = '<ul>';
8630: foreach my $type (@username_rule) {
8631: if (ref($rules->{$type}) eq 'HASH') {
8632: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8633: }
8634: }
8635: $chgtext .= '</ul>';
8636: if (@username_rule > 0) {
8637: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8638: } else {
8639: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8640: }
8641: }
8642: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8643: my ($idrules,$idruleorder) =
8644: &Apache::lonnet::inst_userrules($dom,'id');
8645: my $chgtext = '<ul>';
8646: foreach my $type (@id_rule) {
8647: if (ref($idrules->{$type}) eq 'HASH') {
8648: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8649: }
8650: }
8651: $chgtext .= '</ul>';
8652: if (@id_rule > 0) {
8653: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8654: } else {
8655: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8656: }
8657: }
8658: my %authname = &authtype_names();
8659: my %context_title = &context_names();
8660: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8661: my $chgtext = '<ul>';
8662: foreach my $type (@{$changes{'authtypes'}}) {
8663: my @allowed;
8664: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8665: foreach my $auth (@authtypes) {
8666: if ($authhash{$type}{$auth}) {
8667: push(@allowed,$authname{$auth});
8668: }
8669: }
8670: if (@allowed > 0) {
8671: $chgtext .= join(', ',@allowed).'</li>';
8672: } else {
8673: $chgtext .= &mt('none').'</li>';
8674: }
8675: }
8676: $chgtext .= '</ul>';
8677: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8678: $resulttext .= '</li>';
8679: }
8680: $resulttext .= '</ul>';
8681: } else {
8682: $resulttext = &mt('No changes made to user creation settings');
8683: }
8684: } else {
8685: $resulttext = '<span class="LC_error">'.
8686: &mt('An error occurred: [_1]',$putresult).'</span>';
8687: }
8688: if ($warningmsg ne '') {
8689: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8690: }
8691: return $resulttext;
8692: }
8693:
8694: sub modify_selfcreation {
8695: my ($dom,%domconfig) = @_;
8696: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8697: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8698: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8699: if (ref($types) eq 'ARRAY') {
8700: $usertypes->{'default'} = $othertitle;
8701: push(@{$types},'default');
8702: }
1.224 raeburn 8703: #
8704: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8705: #
8706: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8707: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8708: if ($key eq 'cancreate') {
8709: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8710: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8711: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8712: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8713: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8714: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8715: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8716: } else {
8717: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8718: }
8719: }
8720: }
8721: } elsif ($key eq 'email_rule') {
8722: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8723: } else {
8724: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8725: }
8726: }
8727: }
8728: #
8729: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8730: #
8731: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8732: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8733: if ($key eq 'selfcreate') {
8734: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8735: } else {
8736: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8737: }
8738: }
8739: }
8740:
8741: my @contexts = ('selfcreate');
8742: @{$cancreate{'selfcreate'}} = ();
8743: %{$cancreate{'emailusername'}} = ();
8744: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8745: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8746: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8747: my %selfcreatetypes = (
8748: sso => 'users authenticated by institutional single sign on',
8749: login => 'users authenticated by institutional log-in',
1.236 raeburn 8750: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8751: );
1.224 raeburn 8752: #
8753: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8754: # is permitted.
8755: #
1.236 raeburn 8756:
8757: my @statuses;
8758: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8759: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8760: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8761: }
8762: }
8763: push(@statuses,'default');
8764:
1.228 raeburn 8765: foreach my $item ('login','sso','email') {
1.224 raeburn 8766: if ($item eq 'email') {
1.236 raeburn 8767: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8768: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8769: push(@contexts,'selfcreateprocessing');
8770: foreach my $type (@statuses) {
8771: if ($type eq 'default') {
8772: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8773: } else {
8774: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8775: }
8776: }
1.224 raeburn 8777: }
8778: } else {
8779: if ($env{'form.cancreate_'.$item}) {
8780: push(@{$cancreate{'selfcreate'}},$item);
8781: }
8782: }
8783: }
8784: my (@email_rule,%userinfo,%savecaptcha);
8785: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8786: #
1.228 raeburn 8787: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8788: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8789: #
1.236 raeburn 8790:
1.244 raeburn 8791: if ($env{'form.cancreate_email'}) {
1.228 raeburn 8792: push(@contexts,'emailusername');
8793: if (ref($types) eq 'ARRAY') {
8794: foreach my $type (@{$types}) {
8795: if (ref($infofields) eq 'ARRAY') {
8796: foreach my $field (@{$infofields}) {
8797: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8798: $cancreate{'emailusername'}{$type}{$field} = $1;
8799: }
8800: }
1.224 raeburn 8801: }
8802: }
8803: }
8804: #
8805: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8806: # queued requests for self-creation of account using e-mail address as username
8807: #
8808:
8809: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8810: @approvalnotify = sort(@approvalnotify);
8811: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8812: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8813: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8814: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8815: push(@{$changes{'cancreate'}},'notify');
8816: }
8817: } else {
8818: if ($cancreate{'notify'}{'approval'}) {
8819: push(@{$changes{'cancreate'}},'notify');
8820: }
8821: }
8822: } elsif ($cancreate{'notify'}{'approval'}) {
8823: push(@{$changes{'cancreate'}},'notify');
8824: }
8825:
8826: #
8827: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8828: #
8829: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8830: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8831: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8832: if (@{$curr_usercreation{'email_rule'}} > 0) {
8833: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8834: if (!grep(/^\Q$type\E$/,@email_rule)) {
8835: push(@{$changes{'email_rule'}},$type);
8836: }
8837: }
8838: }
8839: if (@email_rule > 0) {
8840: foreach my $type (@email_rule) {
8841: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8842: push(@{$changes{'email_rule'}},$type);
8843: }
8844: }
8845: }
8846: } elsif (@email_rule > 0) {
8847: push(@{$changes{'email_rule'}},@email_rule);
8848: }
8849: }
8850: #
1.236 raeburn 8851: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8852: # institutional log-in.
8853: #
8854: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8855: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8856: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8857: ($domdefaults{'auth_def'} eq 'localauth'))) {
8858: $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.').' '.
8859: &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.');
8860: }
8861: }
8862: my @fields = ('lastname','firstname','middlename','generation',
8863: 'permanentemail','id');
1.240 raeburn 8864: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8865: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8866: #
8867: # Where usernames may created for institutional log-in and/or institutional single sign on:
8868: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8869: # may self-create accounts
8870: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8871: # which the user may supply, if institutional data is unavailable.
8872: #
8873: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8874: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8875: if (@{$types} > 1) {
1.224 raeburn 8876: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8877: push(@contexts,'statustocreate');
8878: } else {
8879: undef($cancreate{'statustocreate'});
8880: }
8881: foreach my $type (@{$types}) {
8882: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8883: foreach my $field (@fields) {
8884: if (grep(/^\Q$field\E$/,@modifiable)) {
8885: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8886: } else {
8887: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8888: }
8889: }
8890: }
8891: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8892: foreach my $type (@{$types}) {
8893: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8894: foreach my $field (@fields) {
8895: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8896: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8897: push(@{$changes{'selfcreate'}},$type);
8898: last;
8899: }
8900: }
8901: }
8902: }
8903: } else {
8904: foreach my $type (@{$types}) {
8905: push(@{$changes{'selfcreate'}},$type);
8906: }
8907: }
8908: }
1.240 raeburn 8909: foreach my $field (@shibfields) {
8910: if ($env{'form.shibenv_'.$field} ne '') {
8911: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8912: }
8913: }
8914: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8915: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8916: foreach my $field (@shibfields) {
8917: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8918: push(@{$changes{'cancreate'}},'shibenv');
8919: }
8920: }
8921: } else {
8922: foreach my $field (@shibfields) {
8923: if ($env{'form.shibenv_'.$field}) {
8924: push(@{$changes{'cancreate'}},'shibenv');
8925: last;
8926: }
8927: }
8928: }
8929: }
1.224 raeburn 8930: }
8931: foreach my $item (@contexts) {
8932: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8933: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8934: if (ref($cancreate{$item}) eq 'ARRAY') {
8935: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8936: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8937: push(@{$changes{'cancreate'}},$item);
8938: }
8939: }
8940: }
8941: }
8942: if (ref($cancreate{$item}) eq 'ARRAY') {
8943: foreach my $type (@{$cancreate{$item}}) {
8944: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8945: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8946: push(@{$changes{'cancreate'}},$item);
8947: }
8948: }
8949: }
8950: }
8951: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8952: if (ref($cancreate{$item}) eq 'HASH') {
8953: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8954: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8955: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8956: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8957: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8958: push(@{$changes{'cancreate'}},$item);
8959: }
8960: }
8961: }
1.236 raeburn 8962: } elsif ($item eq 'selfcreateprocessing') {
8963: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8964: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8965: push(@{$changes{'cancreate'}},$item);
8966: }
8967: }
1.228 raeburn 8968: } else {
8969: if (!$cancreate{$item}{$curr}) {
8970: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8971: push(@{$changes{'cancreate'}},$item);
8972: }
1.224 raeburn 8973: }
8974: }
8975: }
8976: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8977: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8978: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8979: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8980: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8981: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8982: push(@{$changes{'cancreate'}},$item);
8983: }
8984: }
8985: } else {
8986: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8987: push(@{$changes{'cancreate'}},$item);
8988: }
8989: }
8990: }
1.236 raeburn 8991: } elsif ($item eq 'selfcreateprocessing') {
8992: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8993: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8994: push(@{$changes{'cancreate'}},$item);
8995: }
8996: }
1.228 raeburn 8997: } else {
8998: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8999: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9000: push(@{$changes{'cancreate'}},$item);
9001: }
1.224 raeburn 9002: }
9003: }
9004: }
9005: }
9006: } elsif ($curr_usercreation{'cancreate'}{$item}) {
9007: if (ref($cancreate{$item}) eq 'ARRAY') {
9008: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
9009: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9010: push(@{$changes{'cancreate'}},$item);
9011: }
9012: }
9013: } elsif (ref($cancreate{$item}) eq 'HASH') {
9014: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
9015: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9016: push(@{$changes{'cancreate'}},$item);
9017: }
9018: }
9019: }
9020: } elsif ($item eq 'emailusername') {
1.228 raeburn 9021: if (ref($cancreate{$item}) eq 'HASH') {
9022: foreach my $type (keys(%{$cancreate{$item}})) {
9023: if (ref($cancreate{$item}{$type}) eq 'HASH') {
9024: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
9025: if ($cancreate{$item}{$type}{$field}) {
9026: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9027: push(@{$changes{'cancreate'}},$item);
9028: }
9029: last;
9030: }
9031: }
9032: }
9033: }
1.224 raeburn 9034: }
9035: }
9036: }
9037: #
9038: # Populate %save_usercreate hash with updates to self-creation configuration.
9039: #
9040: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
9041: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
9042: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
9043: if (ref($cancreate{'notify'}) eq 'HASH') {
9044: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
9045: }
1.236 raeburn 9046: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
9047: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
9048: }
1.224 raeburn 9049: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9050: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
9051: }
1.240 raeburn 9052: if (ref($cancreate{'shibenv'}) eq 'HASH') {
9053: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
9054: }
1.224 raeburn 9055: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
9056: $save_usercreate{'emailrule'} = \@email_rule;
9057:
9058: my %userconfig_hash = (
9059: usercreation => \%save_usercreate,
9060: usermodification => \%save_usermodify,
9061: );
9062: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9063: $dom);
9064: #
9065: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9066: #
1.27 raeburn 9067: if ($putresult eq 'ok') {
9068: if (keys(%changes) > 0) {
9069: $resulttext = &mt('Changes made:').'<ul>';
9070: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 9071: my %lt = &selfcreation_types();
1.34 raeburn 9072: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9073: my $chgtext;
1.45 raeburn 9074: if ($type eq 'selfcreate') {
1.50 raeburn 9075: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 9076: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9077: } else {
1.224 raeburn 9078: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9079: '<ul>';
1.50 raeburn 9080: foreach my $case (@{$cancreate{$type}}) {
9081: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9082: }
9083: $chgtext .= '</ul>';
1.100 raeburn 9084: if (ref($cancreate{$type}) eq 'ARRAY') {
9085: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9086: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9087: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 9088: $chgtext .= '<br />'.
9089: '<span class="LC_warning">'.
9090: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9091: '</span>';
1.100 raeburn 9092: }
9093: }
9094: }
9095: }
1.43 raeburn 9096: }
1.240 raeburn 9097: } elsif ($type eq 'shibenv') {
9098: if (keys(%{$cancreate{$type}}) == 0) {
9099: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9100: } else {
9101: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9102: '<ul>';
9103: foreach my $field (@shibfields) {
9104: next if ($cancreate{$type}{$field} eq '');
9105: if ($field eq 'inststatus') {
9106: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9107: } else {
9108: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9109: }
9110: }
9111: $chgtext .= '</ul>';
9112: }
1.93 raeburn 9113: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9114: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9115: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9116: if (@{$cancreate{'selfcreate'}} > 0) {
9117: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9118: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9119: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 9120: $chgtext .= '<br />'.
9121: '<span class="LC_warning">'.
9122: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9123: '</span>';
9124: }
1.96 raeburn 9125: } elsif (ref($usertypes) eq 'HASH') {
9126: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9127: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9128: } else {
9129: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9130: }
9131: $chgtext .= '<ul>';
9132: foreach my $case (@{$cancreate{$type}}) {
9133: if ($case eq 'default') {
9134: $chgtext .= '<li>'.$othertitle.'</li>';
9135: } else {
9136: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9137: }
9138: }
1.100 raeburn 9139: $chgtext .= '</ul>';
9140: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 9141: $chgtext .= '<br /><span class="LC_warning">'.
9142: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9143: '</span>';
1.100 raeburn 9144: }
9145: }
9146: } else {
9147: if (@{$cancreate{$type}} == 0) {
9148: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9149: } else {
9150: $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 9151: }
9152: }
9153: }
1.236 raeburn 9154: } elsif ($type eq 'selfcreateprocessing') {
9155: my %choices = &Apache::lonlocal::texthash (
9156: automatic => 'Automatic approval',
9157: approval => 'Queued for approval',
9158: );
9159: if (@statuses > 1) {
9160: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9161: '<ul>';
9162: foreach my $type (@statuses) {
9163: if ($type eq 'default') {
9164: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9165: } else {
9166: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9167: }
9168: }
9169: $chgtext .= '</ul>';
9170: } else {
9171: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9172: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9173: }
1.165 raeburn 9174: } elsif ($type eq 'captcha') {
1.224 raeburn 9175: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 9176: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9177: } else {
9178: my %captchas = &captcha_phrases();
1.224 raeburn 9179: if ($captchas{$savecaptcha{$type}}) {
9180: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 9181: } else {
1.210 raeburn 9182: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 9183: }
9184: }
9185: } elsif ($type eq 'recaptchakeys') {
9186: my ($privkey,$pubkey);
1.224 raeburn 9187: if (ref($savecaptcha{$type}) eq 'HASH') {
9188: $pubkey = $savecaptcha{$type}{'public'};
9189: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 9190: }
9191: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9192: if (!$pubkey) {
9193: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9194: } else {
9195: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9196: }
9197: if (!$privkey) {
9198: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9199: } else {
9200: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9201: }
9202: $chgtext .= '</ul>';
1.224 raeburn 9203: } elsif ($type eq 'emailusername') {
9204: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 9205: if (ref($types) eq 'ARRAY') {
9206: foreach my $type (@{$types}) {
9207: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9208: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 9209: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 9210: '<ul>';
9211: foreach my $field (@{$infofields}) {
9212: if ($cancreate{'emailusername'}{$type}{$field}) {
9213: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9214: }
9215: }
1.245 raeburn 9216: $chgtext .= '</ul>';
9217: } else {
9218: $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.228 raeburn 9219: }
9220: } else {
1.245 raeburn 9221: $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.224 raeburn 9222: }
9223: }
9224: }
9225: }
9226: } elsif ($type eq 'notify') {
9227: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9228: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9229: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9230: if ($cancreate{'notify'}{'approval'}) {
9231: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9232: }
9233: }
1.43 raeburn 9234: }
1.34 raeburn 9235: }
1.224 raeburn 9236: if ($chgtext) {
9237: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9238: }
9239: }
9240: }
1.43 raeburn 9241: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9242: my ($emailrules,$emailruleorder) =
9243: &Apache::lonnet::inst_userrules($dom,'email');
9244: my $chgtext = '<ul>';
9245: foreach my $type (@email_rule) {
9246: if (ref($emailrules->{$type}) eq 'HASH') {
9247: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9248: }
9249: }
9250: $chgtext .= '</ul>';
9251: if (@email_rule > 0) {
1.224 raeburn 9252: $resulttext .= '<li>'.
9253: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9254: $chgtext.
9255: '</li>';
1.43 raeburn 9256: } else {
1.224 raeburn 9257: $resulttext .= '<li>'.
9258: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9259: '</li>';
1.43 raeburn 9260: }
9261: }
1.224 raeburn 9262: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9263: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9264: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9265: foreach my $type (@{$changes{'selfcreate'}}) {
9266: my $typename = $type;
9267: if (ref($usertypes) eq 'HASH') {
9268: if ($usertypes->{$type} ne '') {
9269: $typename = $usertypes->{$type};
9270: }
9271: }
9272: my @modifiable;
9273: $resulttext .= '<li>'.
9274: &mt('Self-creation of account by users with status: [_1]',
9275: '<span class="LC_cusr_emph">'.$typename.'</span>').
9276: ' - '.&mt('modifiable fields (if institutional data blank): ');
9277: foreach my $field (@fields) {
9278: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9279: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9280: }
9281: }
1.224 raeburn 9282: if (@modifiable > 0) {
9283: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9284: } else {
1.224 raeburn 9285: $resulttext .= &mt('none');
1.43 raeburn 9286: }
1.224 raeburn 9287: $resulttext .= '</li>';
1.28 raeburn 9288: }
1.224 raeburn 9289: $resulttext .= '</ul></li>';
1.28 raeburn 9290: }
1.27 raeburn 9291: $resulttext .= '</ul>';
9292: } else {
1.224 raeburn 9293: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9294: }
9295: } else {
9296: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9297: &mt('An error occurred: [_1]',$putresult).'</span>';
9298: }
1.43 raeburn 9299: if ($warningmsg ne '') {
9300: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9301: }
1.23 raeburn 9302: return $resulttext;
9303: }
9304:
1.165 raeburn 9305: sub process_captcha {
9306: my ($container,$changes,$newsettings,$current) = @_;
9307: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9308: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9309: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9310: $newsettings->{'captcha'} = 'original';
9311: }
9312: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9313: if ($container eq 'cancreate') {
1.169 raeburn 9314: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9315: push(@{$changes->{'cancreate'}},'captcha');
9316: } elsif (!defined($changes->{'cancreate'})) {
9317: $changes->{'cancreate'} = ['captcha'];
9318: }
9319: } else {
9320: $changes->{'captcha'} = 1;
1.165 raeburn 9321: }
9322: }
9323: my ($newpub,$newpriv,$currpub,$currpriv);
9324: if ($newsettings->{'captcha'} eq 'recaptcha') {
9325: $newpub = $env{'form.'.$container.'_recaptchapub'};
9326: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 9327: $newpub =~ s/[^\w\-]//g;
9328: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 9329: $newsettings->{'recaptchakeys'} = {
9330: public => $newpub,
9331: private => $newpriv,
9332: };
1.165 raeburn 9333: }
9334: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9335: $currpub = $current->{'recaptchakeys'}{'public'};
9336: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9337: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9338: $newsettings->{'recaptchakeys'} = {
9339: public => '',
9340: private => '',
9341: }
9342: }
1.165 raeburn 9343: }
9344: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9345: if ($container eq 'cancreate') {
9346: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9347: push(@{$changes->{'cancreate'}},'recaptchakeys');
9348: } elsif (!defined($changes->{'cancreate'})) {
9349: $changes->{'cancreate'} = ['recaptchakeys'];
9350: }
9351: } else {
1.210 raeburn 9352: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9353: }
9354: }
9355: return;
9356: }
9357:
1.33 raeburn 9358: sub modify_usermodification {
9359: my ($dom,%domconfig) = @_;
1.224 raeburn 9360: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9361: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9362: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9363: if ($key eq 'selfcreate') {
9364: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9365: } else {
9366: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9367: }
1.33 raeburn 9368: }
9369: }
1.224 raeburn 9370: my @contexts = ('author','course');
1.33 raeburn 9371: my %context_title = (
9372: author => 'In author context',
9373: course => 'In course context',
9374: );
9375: my @fields = ('lastname','firstname','middlename','generation',
9376: 'permanentemail','id');
9377: my %roles = (
9378: author => ['ca','aa'],
9379: course => ['st','ep','ta','in','cr'],
9380: );
9381: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9382: foreach my $context (@contexts) {
9383: foreach my $role (@{$roles{$context}}) {
9384: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9385: foreach my $item (@fields) {
9386: if (grep(/^\Q$item\E$/,@modifiable)) {
9387: $modifyhash{$context}{$role}{$item} = 1;
9388: } else {
9389: $modifyhash{$context}{$role}{$item} = 0;
9390: }
9391: }
9392: }
9393: if (ref($curr_usermodification{$context}) eq 'HASH') {
9394: foreach my $role (@{$roles{$context}}) {
9395: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9396: foreach my $field (@fields) {
9397: if ($modifyhash{$context}{$role}{$field} ne
9398: $curr_usermodification{$context}{$role}{$field}) {
9399: push(@{$changes{$context}},$role);
9400: last;
9401: }
9402: }
9403: }
9404: }
9405: } else {
9406: foreach my $context (@contexts) {
9407: foreach my $role (@{$roles{$context}}) {
9408: push(@{$changes{$context}},$role);
9409: }
9410: }
9411: }
9412: }
9413: my %usermodification_hash = (
9414: usermodification => \%modifyhash,
9415: );
9416: my $putresult = &Apache::lonnet::put_dom('configuration',
9417: \%usermodification_hash,$dom);
9418: if ($putresult eq 'ok') {
9419: if (keys(%changes) > 0) {
9420: $resulttext = &mt('Changes made: ').'<ul>';
9421: foreach my $context (@contexts) {
9422: if (ref($changes{$context}) eq 'ARRAY') {
9423: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9424: if (ref($changes{$context}) eq 'ARRAY') {
9425: foreach my $role (@{$changes{$context}}) {
9426: my $rolename;
1.224 raeburn 9427: if ($role eq 'cr') {
9428: $rolename = &mt('Custom');
1.33 raeburn 9429: } else {
1.224 raeburn 9430: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9431: }
9432: my @modifiable;
1.224 raeburn 9433: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9434: foreach my $field (@fields) {
9435: if ($modifyhash{$context}{$role}{$field}) {
9436: push(@modifiable,$fieldtitles{$field});
9437: }
9438: }
9439: if (@modifiable > 0) {
9440: $resulttext .= join(', ',@modifiable);
9441: } else {
9442: $resulttext .= &mt('none');
9443: }
9444: $resulttext .= '</li>';
9445: }
9446: $resulttext .= '</ul></li>';
9447: }
9448: }
9449: }
9450: $resulttext .= '</ul>';
9451: } else {
9452: $resulttext = &mt('No changes made to user modification settings');
9453: }
9454: } else {
9455: $resulttext = '<span class="LC_error">'.
9456: &mt('An error occurred: [_1]',$putresult).'</span>';
9457: }
9458: return $resulttext;
9459: }
9460:
1.43 raeburn 9461: sub modify_defaults {
1.212 raeburn 9462: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9463: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9464: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9465: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9466: my @authtypes = ('internal','krb4','krb5','localauth');
9467: foreach my $item (@items) {
9468: $newvalues{$item} = $env{'form.'.$item};
9469: if ($item eq 'auth_def') {
9470: if ($newvalues{$item} ne '') {
9471: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9472: push(@errors,$item);
9473: }
9474: }
9475: } elsif ($item eq 'lang_def') {
9476: if ($newvalues{$item} ne '') {
9477: if ($newvalues{$item} =~ /^(\w+)/) {
9478: my $langcode = $1;
1.103 raeburn 9479: if ($langcode ne 'x_chef') {
9480: if (code2language($langcode) eq '') {
9481: push(@errors,$item);
9482: }
1.43 raeburn 9483: }
9484: } else {
9485: push(@errors,$item);
9486: }
9487: }
1.54 raeburn 9488: } elsif ($item eq 'timezone_def') {
9489: if ($newvalues{$item} ne '') {
1.62 raeburn 9490: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9491: push(@errors,$item);
9492: }
9493: }
1.68 raeburn 9494: } elsif ($item eq 'datelocale_def') {
9495: if ($newvalues{$item} ne '') {
9496: my @datelocale_ids = DateTime::Locale->ids();
9497: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9498: push(@errors,$item);
9499: }
9500: }
1.141 raeburn 9501: } elsif ($item eq 'portal_def') {
9502: if ($newvalues{$item} ne '') {
9503: 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])\/?$/) {
9504: push(@errors,$item);
9505: }
9506: }
1.43 raeburn 9507: }
9508: if (grep(/^\Q$item\E$/,@errors)) {
9509: $newvalues{$item} = $domdefaults{$item};
9510: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9511: $changes{$item} = 1;
9512: }
1.72 raeburn 9513: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9514: }
9515: my %defaults_hash = (
1.72 raeburn 9516: defaults => \%newvalues,
9517: );
1.43 raeburn 9518: my $title = &defaults_titles();
1.236 raeburn 9519:
9520: my $currinststatus;
9521: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9522: $currinststatus = $domconfig{'inststatus'};
9523: } else {
9524: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9525: $currinststatus = {
9526: inststatustypes => $usertypes,
9527: inststatusorder => $types,
9528: inststatusguest => [],
9529: };
9530: }
9531: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9532: my @allpos;
9533: my %guests;
9534: my %alltypes;
9535: my ($currtitles,$currguests,$currorder);
9536: if (ref($currinststatus) eq 'HASH') {
9537: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9538: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9539: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9540: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9541: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9542: }
9543: }
9544: unless (grep(/^\Q$type\E$/,@todelete)) {
9545: my $position = $env{'form.inststatus_pos_'.$type};
9546: $position =~ s/\D+//g;
9547: $allpos[$position] = $type;
9548: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9549: $alltypes{$type} =~ s/`//g;
9550: if ($env{'form.inststatus_guest_'.$type}) {
9551: $guests{$type} = 1;
9552: }
9553: }
9554: }
9555: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9556: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9557: }
9558: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9559: $currtitles =~ s/,$//;
9560: }
9561: }
9562: if ($env{'form.addinststatus'}) {
9563: my $newtype = $env{'form.addinststatus'};
9564: $newtype =~ s/\W//g;
9565: unless (exists($alltypes{$newtype})) {
9566: if ($env{'form.addinststatus_guest'}) {
9567: $guests{$newtype} = 1;
9568: }
9569: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9570: $alltypes{$newtype} =~ s/`//g;
9571: my $position = $env{'form.addinststatus_pos'};
9572: $position =~ s/\D+//g;
9573: if ($position ne '') {
9574: $allpos[$position] = $newtype;
9575: }
9576: }
9577: }
9578: my (@orderedstatus,@orderedguests);
9579: foreach my $type (@allpos) {
9580: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9581: push(@orderedstatus,$type);
9582: if ($guests{$type}) {
9583: push(@orderedguests,$type);
9584: }
9585: }
9586: }
9587: foreach my $type (keys(%alltypes)) {
9588: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9589: delete($alltypes{$type});
9590: }
9591: }
9592: $defaults_hash{'inststatus'} = {
9593: inststatustypes => \%alltypes,
9594: inststatusorder => \@orderedstatus,
9595: inststatusguest => \@orderedguests,
9596: };
9597: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9598: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9599: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9600: }
9601: }
9602: if ($currorder ne join(',',@orderedstatus)) {
9603: $changes{'inststatus'}{'inststatusorder'} = 1;
9604: }
9605: if ($currguests ne join(',',@orderedguests)) {
9606: $changes{'inststatus'}{'inststatusguest'} = 1;
9607: }
9608: my $newtitles;
9609: foreach my $item (@orderedstatus) {
9610: $newtitles .= $alltypes{$item}.',';
9611: }
9612: $newtitles =~ s/,$//;
9613: if ($currtitles ne $newtitles) {
9614: $changes{'inststatus'}{'inststatustypes'} = 1;
9615: }
1.43 raeburn 9616: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9617: $dom);
9618: if ($putresult eq 'ok') {
9619: if (keys(%changes) > 0) {
9620: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9621: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9622: 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";
9623: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9624: if ($item eq 'inststatus') {
9625: if (ref($changes{'inststatus'}) eq 'HASH') {
9626: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9627: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9628: foreach my $type (@orderedstatus) {
9629: $resulttext .= $alltypes{$type}.', ';
9630: }
9631: $resulttext =~ s/, $//;
9632: $resulttext .= '</li>';
9633: }
9634: if ($changes{'inststatus'}{'inststatusguest'}) {
9635: $resulttext .= '<li>';
9636: if (@orderedguests) {
9637: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9638: foreach my $type (@orderedguests) {
9639: $resulttext .= $alltypes{$type}.', ';
9640: }
9641: $resulttext =~ s/, $//;
9642: } else {
9643: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9644: }
9645: $resulttext .= '</li>';
9646: }
9647: }
9648: } else {
9649: my $value = $env{'form.'.$item};
9650: if ($value eq '') {
9651: $value = &mt('none');
9652: } elsif ($item eq 'auth_def') {
9653: my %authnames = &authtype_names();
9654: my %shortauth = (
9655: internal => 'int',
9656: krb4 => 'krb4',
9657: krb5 => 'krb5',
9658: localauth => 'loc',
9659: );
9660: $value = $authnames{$shortauth{$value}};
9661: }
9662: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9663: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9664: }
9665: }
9666: $resulttext .= '</ul>';
9667: $mailmsgtext .= "\n";
9668: my $cachetime = 24*60*60;
1.72 raeburn 9669: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9670: if (ref($lastactref) eq 'HASH') {
9671: $lastactref->{'domdefaults'} = 1;
9672: }
1.68 raeburn 9673: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9674: my $notify = 1;
9675: if (ref($domconfig{'contacts'}) eq 'HASH') {
9676: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9677: $notify = 0;
9678: }
9679: }
9680: if ($notify) {
9681: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9682: "LON-CAPA Domain Settings Change - $dom",
9683: $mailmsgtext);
9684: }
1.54 raeburn 9685: }
1.43 raeburn 9686: } else {
1.54 raeburn 9687: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9688: }
9689: } else {
9690: $resulttext = '<span class="LC_error">'.
9691: &mt('An error occurred: [_1]',$putresult).'</span>';
9692: }
9693: if (@errors > 0) {
9694: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9695: foreach my $item (@errors) {
9696: $resulttext .= ' "'.$title->{$item}.'",';
9697: }
9698: $resulttext =~ s/,$//;
9699: }
9700: return $resulttext;
9701: }
9702:
1.46 raeburn 9703: sub modify_scantron {
1.205 raeburn 9704: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9705: my ($resulttext,%confhash,%changes,$errors);
9706: my $custom = 'custom.tab';
9707: my $default = 'default.tab';
9708: my $servadm = $r->dir_config('lonAdmEMail');
9709: my ($configuserok,$author_ok,$switchserver) =
9710: &config_check($dom,$confname,$servadm);
9711: if ($env{'form.scantronformat.filename'} ne '') {
9712: my $error;
9713: if ($configuserok eq 'ok') {
9714: if ($switchserver) {
1.130 raeburn 9715: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9716: } else {
9717: if ($author_ok eq 'ok') {
9718: my ($result,$scantronurl) =
9719: &publishlogo($r,'upload','scantronformat',$dom,
9720: $confname,'scantron','','',$custom);
9721: if ($result eq 'ok') {
9722: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9723: $changes{'scantronformat'} = 1;
1.46 raeburn 9724: } else {
9725: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9726: }
9727: } else {
9728: $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);
9729: }
9730: }
9731: } else {
9732: $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);
9733: }
9734: if ($error) {
9735: &Apache::lonnet::logthis($error);
9736: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9737: }
9738: }
1.48 raeburn 9739: if (ref($domconfig{'scantron'}) eq 'HASH') {
9740: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9741: if ($env{'form.scantronformat_del'}) {
9742: $confhash{'scantron'}{'scantronformat'} = '';
9743: $changes{'scantronformat'} = 1;
1.46 raeburn 9744: }
9745: }
9746: }
9747: if (keys(%confhash) > 0) {
9748: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9749: $dom);
9750: if ($putresult eq 'ok') {
9751: if (keys(%changes) > 0) {
1.48 raeburn 9752: if (ref($confhash{'scantron'}) eq 'HASH') {
9753: $resulttext = &mt('Changes made:').'<ul>';
9754: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9755: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9756: } else {
1.130 raeburn 9757: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9758: }
1.48 raeburn 9759: $resulttext .= '</ul>';
9760: } else {
1.130 raeburn 9761: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9762: }
9763: $resulttext .= '</ul>';
9764: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9765: if (ref($lastactref) eq 'HASH') {
9766: $lastactref->{'domainconfig'} = 1;
9767: }
1.46 raeburn 9768: } else {
1.130 raeburn 9769: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9770: }
9771: } else {
9772: $resulttext = '<span class="LC_error">'.
9773: &mt('An error occurred: [_1]',$putresult).'</span>';
9774: }
9775: } else {
1.130 raeburn 9776: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9777: }
9778: if ($errors) {
9779: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9780: $errors.'</ul>';
9781: }
9782: return $resulttext;
9783: }
9784:
1.48 raeburn 9785: sub modify_coursecategories {
1.239 raeburn 9786: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9787: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9788: $cathash);
1.48 raeburn 9789: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9790: my @catitems = ('unauth','auth');
9791: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9792: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9793: $cathash = $domconfig{'coursecategories'}{'cats'};
9794: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9795: $changes{'togglecats'} = 1;
9796: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9797: }
9798: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9799: $changes{'categorize'} = 1;
9800: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9801: }
1.120 raeburn 9802: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9803: $changes{'togglecatscomm'} = 1;
9804: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9805: }
9806: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9807: $changes{'categorizecomm'} = 1;
9808: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9809: }
1.238 raeburn 9810: foreach my $item (@catitems) {
9811: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9812: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9813: $changes{$item} = 1;
9814: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9815: }
9816: }
9817: }
1.57 raeburn 9818: } else {
9819: $changes{'togglecats'} = 1;
9820: $changes{'categorize'} = 1;
1.124 raeburn 9821: $changes{'togglecatscomm'} = 1;
9822: $changes{'categorizecomm'} = 1;
1.87 raeburn 9823: $domconfig{'coursecategories'} = {
9824: togglecats => $env{'form.togglecats'},
9825: categorize => $env{'form.categorize'},
1.124 raeburn 9826: togglecatscomm => $env{'form.togglecatscomm'},
9827: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9828: };
1.238 raeburn 9829: foreach my $item (@catitems) {
9830: if ($env{'form.coursecat_'.$item} ne 'std') {
9831: $changes{$item} = 1;
9832: }
9833: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9834: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9835: }
9836: }
1.57 raeburn 9837: }
9838: if (ref($cathash) eq 'HASH') {
9839: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9840: push (@deletecategory,'instcode::0');
9841: }
1.120 raeburn 9842: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9843: push(@deletecategory,'communities::0');
9844: }
1.48 raeburn 9845: }
1.57 raeburn 9846: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9847: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9848: if (@deletecategory > 0) {
9849: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9850: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9851: foreach my $item (@deletecategory) {
1.57 raeburn 9852: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9853: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9854: $deletions{$item} = 1;
1.57 raeburn 9855: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9856: }
9857: }
9858: }
1.57 raeburn 9859: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9860: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9861: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9862: $reorderings{$item} = 1;
1.57 raeburn 9863: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9864: }
9865: if ($env{'form.addcategory_name_'.$item} ne '') {
9866: my $newcat = $env{'form.addcategory_name_'.$item};
9867: my $newdepth = $depth+1;
9868: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9869: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9870: $adds{$newitem} = 1;
9871: }
9872: if ($env{'form.subcat_'.$item} ne '') {
9873: my $newcat = $env{'form.subcat_'.$item};
9874: my $newdepth = $depth+1;
9875: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9876: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9877: $adds{$newitem} = 1;
9878: }
9879: }
9880: }
9881: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9882: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9883: my $newitem = 'instcode::0';
1.57 raeburn 9884: if ($cathash->{$newitem} eq '') {
9885: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9886: $adds{$newitem} = 1;
9887: }
9888: } else {
9889: my $newitem = 'instcode::0';
1.57 raeburn 9890: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9891: $adds{$newitem} = 1;
9892: }
9893: }
1.120 raeburn 9894: if ($env{'form.communities'} eq '1') {
9895: if (ref($cathash) eq 'HASH') {
9896: my $newitem = 'communities::0';
9897: if ($cathash->{$newitem} eq '') {
9898: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9899: $adds{$newitem} = 1;
9900: }
9901: } else {
9902: my $newitem = 'communities::0';
9903: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9904: $adds{$newitem} = 1;
9905: }
9906: }
1.48 raeburn 9907: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9908: if (($env{'form.addcategory_name'} ne 'instcode') &&
9909: ($env{'form.addcategory_name'} ne 'communities')) {
9910: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9911: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9912: $adds{$newitem} = 1;
9913: }
1.48 raeburn 9914: }
1.57 raeburn 9915: my $putresult;
1.48 raeburn 9916: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9917: if (keys(%deletions) > 0) {
9918: foreach my $key (keys(%deletions)) {
9919: if ($predelallitems{$key} ne '') {
9920: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9921: }
9922: }
9923: }
9924: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9925: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9926: if (ref($chkcats[0]) eq 'ARRAY') {
9927: my $depth = 0;
9928: my $chg = 0;
9929: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9930: my $name = $chkcats[0][$i];
9931: my $item;
9932: if ($name eq '') {
9933: $chg ++;
9934: } else {
9935: $item = &escape($name).'::0';
9936: if ($chg) {
1.57 raeburn 9937: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9938: }
9939: $depth ++;
1.57 raeburn 9940: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9941: $depth --;
9942: }
9943: }
9944: }
1.57 raeburn 9945: }
9946: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9947: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9948: if ($putresult eq 'ok') {
1.57 raeburn 9949: my %title = (
1.120 raeburn 9950: togglecats => 'Show/Hide a course in catalog',
9951: categorize => 'Assign a category to a course',
9952: togglecatscomm => 'Show/Hide a community in catalog',
9953: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9954: );
9955: my %level = (
1.120 raeburn 9956: dom => 'set in Domain ("Modify Course/Community")',
9957: crs => 'set in Course ("Course Configuration")',
9958: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9959: none => 'No catalog',
9960: std => 'Standard catalog',
9961: domonly => 'Domain-only catalog',
9962: codesrch => 'Code search form',
1.57 raeburn 9963: );
1.48 raeburn 9964: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9965: if ($changes{'togglecats'}) {
9966: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9967: }
9968: if ($changes{'categorize'}) {
9969: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9970: }
1.120 raeburn 9971: if ($changes{'togglecatscomm'}) {
9972: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9973: }
9974: if ($changes{'categorizecomm'}) {
9975: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9976: }
1.238 raeburn 9977: if ($changes{'unauth'}) {
9978: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9979: }
9980: if ($changes{'auth'}) {
9981: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9982: }
1.57 raeburn 9983: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9984: my $cathash;
9985: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9986: $cathash = $domconfig{'coursecategories'}{'cats'};
9987: } else {
9988: $cathash = {};
9989: }
9990: my (@cats,@trails,%allitems);
9991: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9992: if (keys(%deletions) > 0) {
9993: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9994: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9995: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9996: }
9997: $resulttext .= '</ul></li>';
9998: }
9999: if (keys(%reorderings) > 0) {
10000: my %sort_by_trail;
10001: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
10002: foreach my $key (keys(%reorderings)) {
10003: if ($allitems{$key} ne '') {
10004: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10005: }
1.48 raeburn 10006: }
1.57 raeburn 10007: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10008: $resulttext .= '<li>'.$trails[$trail].'</li>';
10009: }
10010: $resulttext .= '</ul></li>';
1.48 raeburn 10011: }
1.57 raeburn 10012: if (keys(%adds) > 0) {
10013: my %sort_by_trail;
10014: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
10015: foreach my $key (keys(%adds)) {
10016: if ($allitems{$key} ne '') {
10017: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
10018: }
10019: }
10020: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
10021: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 10022: }
1.57 raeburn 10023: $resulttext .= '</ul></li>';
1.48 raeburn 10024: }
10025: }
10026: $resulttext .= '</ul>';
1.239 raeburn 10027: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 10028: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10029: if ($changes{'auth'}) {
10030: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
10031: }
10032: if ($changes{'unauth'}) {
10033: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
10034: }
10035: my $cachetime = 24*60*60;
10036: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 10037: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 10038: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 10039: }
10040: }
1.48 raeburn 10041: } else {
10042: $resulttext = '<span class="LC_error">'.
1.57 raeburn 10043: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 10044: }
10045: } else {
1.120 raeburn 10046: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 10047: }
10048: return $resulttext;
10049: }
10050:
1.69 raeburn 10051: sub modify_serverstatuses {
10052: my ($dom,%domconfig) = @_;
10053: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
10054: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
10055: %currserverstatus = %{$domconfig{'serverstatuses'}};
10056: }
10057: my @pages = &serverstatus_pages();
10058: foreach my $type (@pages) {
10059: $newserverstatus{$type}{'namedusers'} = '';
10060: $newserverstatus{$type}{'machines'} = '';
10061: if (defined($env{'form.'.$type.'_namedusers'})) {
10062: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10063: my @okusers;
10064: foreach my $user (@users) {
10065: my ($uname,$udom) = split(/:/,$user);
10066: if (($udom =~ /^$match_domain$/) &&
10067: (&Apache::lonnet::domain($udom)) &&
10068: ($uname =~ /^$match_username$/)) {
10069: if (!grep(/^\Q$user\E/,@okusers)) {
10070: push(@okusers,$user);
10071: }
10072: }
10073: }
10074: if (@okusers > 0) {
10075: @okusers = sort(@okusers);
10076: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10077: }
10078: }
10079: if (defined($env{'form.'.$type.'_machines'})) {
10080: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10081: my @okmachines;
10082: foreach my $ip (@machines) {
10083: my @parts = split(/\./,$ip);
10084: next if (@parts < 4);
10085: my $badip = 0;
10086: for (my $i=0; $i<4; $i++) {
10087: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10088: $badip = 1;
10089: last;
10090: }
10091: }
10092: if (!$badip) {
10093: push(@okmachines,$ip);
10094: }
10095: }
10096: @okmachines = sort(@okmachines);
10097: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10098: }
10099: }
10100: my %serverstatushash = (
10101: serverstatuses => \%newserverstatus,
10102: );
10103: foreach my $type (@pages) {
1.83 raeburn 10104: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10105: my (@current,@new);
1.83 raeburn 10106: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10107: if ($currserverstatus{$type}{$setting} ne '') {
10108: @current = split(/,/,$currserverstatus{$type}{$setting});
10109: }
10110: }
10111: if ($newserverstatus{$type}{$setting} ne '') {
10112: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10113: }
10114: if (@current > 0) {
10115: if (@new > 0) {
10116: foreach my $item (@current) {
10117: if (!grep(/^\Q$item\E$/,@new)) {
10118: $changes{$type}{$setting} = 1;
1.82 raeburn 10119: last;
10120: }
10121: }
1.84 raeburn 10122: foreach my $item (@new) {
10123: if (!grep(/^\Q$item\E$/,@current)) {
10124: $changes{$type}{$setting} = 1;
10125: last;
1.82 raeburn 10126: }
10127: }
10128: } else {
1.83 raeburn 10129: $changes{$type}{$setting} = 1;
1.69 raeburn 10130: }
1.83 raeburn 10131: } elsif (@new > 0) {
10132: $changes{$type}{$setting} = 1;
1.69 raeburn 10133: }
10134: }
10135: }
10136: if (keys(%changes) > 0) {
1.81 raeburn 10137: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10138: my $putresult = &Apache::lonnet::put_dom('configuration',
10139: \%serverstatushash,$dom);
10140: if ($putresult eq 'ok') {
10141: $resulttext .= &mt('Changes made:').'<ul>';
10142: foreach my $type (@pages) {
1.84 raeburn 10143: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10144: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10145: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10146: if ($newserverstatus{$type}{'namedusers'} eq '') {
10147: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10148: } else {
10149: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10150: }
1.84 raeburn 10151: }
10152: if ($changes{$type}{'machines'}) {
1.69 raeburn 10153: if ($newserverstatus{$type}{'machines'} eq '') {
10154: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10155: } else {
10156: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10157: }
10158:
10159: }
10160: $resulttext .= '</ul></li>';
10161: }
10162: }
10163: $resulttext .= '</ul>';
10164: } else {
10165: $resulttext = '<span class="LC_error">'.
10166: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10167:
10168: }
10169: } else {
10170: $resulttext = &mt('No changes made to access to server status pages');
10171: }
10172: return $resulttext;
10173: }
10174:
1.118 jms 10175: sub modify_helpsettings {
1.122 jms 10176: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 10177: my ($resulttext,$errors,%changes,%helphash);
10178: my %defaultchecked = ('submitbugs' => 'on');
10179: my @offon = ('off','on');
1.118 jms 10180: my @toggles = ('submitbugs');
10181: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10182: foreach my $item (@toggles) {
1.166 raeburn 10183: if ($defaultchecked{$item} eq 'on') {
10184: if ($domconfig{'helpsettings'}{$item} eq '') {
10185: if ($env{'form.'.$item} eq '0') {
10186: $changes{$item} = 1;
10187: }
10188: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10189: $changes{$item} = 1;
10190: }
10191: } elsif ($defaultchecked{$item} eq 'off') {
10192: if ($domconfig{'helpsettings'}{$item} eq '') {
10193: if ($env{'form.'.$item} eq '1') {
10194: $changes{$item} = 1;
10195: }
10196: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10197: $changes{$item} = 1;
10198: }
10199: }
1.210 raeburn 10200: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 10201: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10202: }
10203: }
1.118 jms 10204: }
1.123 jms 10205: my $putresult;
10206: if (keys(%changes) > 0) {
1.166 raeburn 10207: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 10208: if ($putresult eq 'ok') {
1.166 raeburn 10209: $resulttext = &mt('Changes made:').'<ul>';
10210: foreach my $item (sort(keys(%changes))) {
10211: if ($item eq 'submitbugs') {
10212: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10213: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10214: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10215: }
10216: }
10217: $resulttext .= '</ul>';
10218: } else {
10219: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 10220: $errors .= '<li><span class="LC_error">'.
10221: &mt('An error occurred storing the settings: [_1]',
10222: $putresult).'</span></li>';
1.166 raeburn 10223: }
1.118 jms 10224: }
10225: if ($errors) {
1.168 raeburn 10226: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10227: $errors.'</ul>';
10228: }
10229: return $resulttext;
10230: }
10231:
1.121 raeburn 10232: sub modify_coursedefaults {
1.212 raeburn 10233: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10234: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 10235: my %defaultchecked = (
10236: 'canuse_pdfforms' => 'off',
10237: 'uselcmath' => 'on',
10238: 'usejsme' => 'on'
10239: );
10240: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 10241: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 10242: 'uploadquota_community','uploadquota_textbook');
10243: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 10244: my %staticdefaults = (
10245: anonsurvey_threshold => 10,
10246: uploadquota => 500,
1.257 raeburn 10247: postsubmit => 60,
1.198 raeburn 10248: );
1.121 raeburn 10249:
10250: $defaultshash{'coursedefaults'} = {};
10251:
10252: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10253: if ($domconfig{'coursedefaults'} eq '') {
10254: $domconfig{'coursedefaults'} = {};
10255: }
10256: }
10257:
10258: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10259: foreach my $item (@toggles) {
10260: if ($defaultchecked{$item} eq 'on') {
10261: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10262: ($env{'form.'.$item} eq '0')) {
10263: $changes{$item} = 1;
1.192 raeburn 10264: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10265: $changes{$item} = 1;
10266: }
10267: } elsif ($defaultchecked{$item} eq 'off') {
10268: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10269: ($env{'form.'.$item} eq '1')) {
10270: $changes{$item} = 1;
10271: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10272: $changes{$item} = 1;
10273: }
10274: }
10275: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10276: }
1.198 raeburn 10277: foreach my $item (@numbers) {
10278: my ($currdef,$newdef);
1.208 raeburn 10279: $newdef = $env{'form.'.$item};
1.198 raeburn 10280: if ($item eq 'anonsurvey_threshold') {
10281: $currdef = $domconfig{'coursedefaults'}{$item};
10282: $newdef =~ s/\D//g;
10283: if ($newdef eq '' || $newdef < 1) {
10284: $newdef = 1;
10285: }
10286: $defaultshash{'coursedefaults'}{$item} = $newdef;
10287: } else {
10288: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10289: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10290: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10291: }
10292: $newdef =~ s/[^\w.\-]//g;
10293: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10294: }
10295: if ($currdef ne $newdef) {
10296: my $staticdef;
10297: if ($item eq 'anonsurvey_threshold') {
10298: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10299: $changes{$item} = 1;
10300: }
10301: } else {
10302: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10303: $changes{'uploadquota'} = 1;
10304: }
10305: }
1.139 raeburn 10306: }
10307: }
1.231 raeburn 10308:
1.257 raeburn 10309: my %credits;
10310: foreach my $type (@types) {
10311: unless ($type eq 'community') {
10312: $credits{$type} = $env{'form.'.$type.'_credits'};
10313: $credits{$type} =~ s/[^\d.]+//g;
10314: }
10315: }
10316: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
10317: ($env{'form.coursecredits'} eq '1')) {
10318: $changes{'coursecredits'} = 1;
10319: foreach my $type (keys(%credits)) {
10320: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10321: }
10322: } else {
10323: if ($env{'form.coursecredits'} eq '1') {
10324: foreach my $type (@types) {
10325: unless ($type eq 'community') {
10326: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
10327: $changes{'coursecredits'} = 1;
10328: }
10329: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
10330: }
10331: }
10332: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10333: foreach my $type (@types) {
10334: unless ($type eq 'community') {
10335: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
10336: $changes{'coursecredits'} = 1;
10337: last;
10338: }
10339: }
10340: }
10341: }
10342: }
10343: if ($env{'form.postsubmit'} eq '1') {
10344: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
10345: my %currtimeout;
10346: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10347: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
10348: $changes{'postsubmit'} = 1;
10349: }
10350: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10351: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
10352: }
10353: } else {
10354: $changes{'postsubmit'} = 1;
10355: }
10356: foreach my $type (@types) {
10357: my $timeout = $env{'form.'.$type.'_timeout'};
10358: $timeout =~ s/\D//g;
10359: if ($timeout == $staticdefaults{'postsubmit'}) {
10360: $timeout = '';
10361: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
10362: $timeout = '0';
10363: }
10364: unless ($timeout eq '') {
10365: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
10366: }
10367: if (exists($currtimeout{$type})) {
10368: if ($timeout ne $currtimeout{$type}) {
10369: $changes{'postsubmit'} = 1;
10370: }
10371: } elsif ($timeout ne '') {
10372: $changes{'postsubmit'} = 1;
10373: }
10374: }
10375: } else {
10376: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
10377: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10378: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
10379: $changes{'postsubmit'} = 1;
10380: }
10381: } else {
10382: $changes{'postsubmit'} = 1;
10383: }
1.192 raeburn 10384: }
1.121 raeburn 10385: }
10386: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10387: $dom);
10388: if ($putresult eq 'ok') {
10389: if (keys(%changes) > 0) {
1.213 raeburn 10390: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 10391: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
10392: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'})) {
10393: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
10394: if ($changes{$item}) {
10395: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
10396: }
10397: }
1.192 raeburn 10398: if ($changes{'coursecredits'}) {
10399: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 10400: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
10401: $domdefaults{$type.'credits'} =
10402: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
10403: }
10404: }
10405: }
10406: if ($changes{'postsubmit'}) {
10407: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10408: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
10409: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10410: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
10411: $domdefaults{$type.'postsubtimeout'} =
10412: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10413: }
10414: }
1.192 raeburn 10415: }
10416: }
1.198 raeburn 10417: if ($changes{'uploadquota'}) {
10418: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10419: foreach my $type (@types) {
10420: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10421: }
10422: }
10423: }
1.121 raeburn 10424: my $cachetime = 24*60*60;
10425: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10426: if (ref($lastactref) eq 'HASH') {
10427: $lastactref->{'domdefaults'} = 1;
10428: }
1.121 raeburn 10429: }
10430: $resulttext = &mt('Changes made:').'<ul>';
10431: foreach my $item (sort(keys(%changes))) {
10432: if ($item eq 'canuse_pdfforms') {
10433: if ($env{'form.'.$item} eq '1') {
10434: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10435: } else {
10436: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10437: }
1.257 raeburn 10438: } elsif ($item eq 'uselcmath') {
10439: if ($env{'form.'.$item} eq '1') {
10440: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
10441: } else {
10442: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
10443: }
10444: } elsif ($item eq 'usejsme') {
10445: if ($env{'form.'.$item} eq '1') {
10446: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
10447: } else {
10448: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
10449: }
1.139 raeburn 10450: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10451: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10452: } elsif ($item eq 'uploadquota') {
10453: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10454: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10455: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10456: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10457: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10458:
1.198 raeburn 10459: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10460: '</ul>'.
10461: '</li>';
10462: } else {
10463: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10464: }
1.257 raeburn 10465: } elsif ($item eq 'postsubmit') {
10466: if ($domdefaults{'postsubmit'} eq 'off') {
10467: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
10468: } else {
10469: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
10470: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
10471: $resulttext .= &mt('durations:').'<ul>';
10472: foreach my $type (@types) {
10473: $resulttext .= '<li>';
10474: my $timeout;
10475: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
10476: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
10477: }
10478: my $display;
10479: if ($timeout eq '0') {
10480: $display = &mt('unlimited');
10481: } elsif ($timeout eq '') {
10482: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
10483: } else {
10484: $display = &mt('[quant,_1,second]',$timeout);
10485: }
10486: if ($type eq 'community') {
10487: $resulttext .= &mt('Communities');
10488: } elsif ($type eq 'official') {
10489: $resulttext .= &mt('Official courses');
10490: } elsif ($type eq 'unofficial') {
10491: $resulttext .= &mt('Unofficial courses');
10492: } elsif ($type eq 'textbook') {
10493: $resulttext .= &mt('Textbook courses');
10494: }
10495: $resulttext .= ' -- '.$display.'</li>';
10496: }
10497: $resulttext .= '</ul>';
10498: }
10499: $resulttext .= '</li>';
10500: }
1.192 raeburn 10501: } elsif ($item eq 'coursecredits') {
10502: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10503: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10504: ($domdefaults{'unofficialcredits'} eq '') &&
10505: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10506: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10507: } else {
10508: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10509: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10510: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10511: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10512: '</ul>'.
10513: '</li>';
10514: }
10515: } else {
10516: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10517: }
1.140 raeburn 10518: }
1.121 raeburn 10519: }
10520: $resulttext .= '</ul>';
10521: } else {
10522: $resulttext = &mt('No changes made to course defaults');
10523: }
10524: } else {
10525: $resulttext = '<span class="LC_error">'.
10526: &mt('An error occurred: [_1]',$putresult).'</span>';
10527: }
10528: return $resulttext;
10529: }
10530:
1.231 raeburn 10531: sub modify_selfenrollment {
10532: my ($dom,$lastactref,%domconfig) = @_;
10533: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10534: my @types = ('official','unofficial','community','textbook');
10535: my %titles = &tool_titles();
1.232 raeburn 10536: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10537: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10538: $ordered{'default'} = ['types','registered','approval','limit'];
10539:
10540: my (%roles,%shown,%toplevel);
10541: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10542:
10543: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10544: if ($domconfig{'selfenrollment'} eq '') {
10545: $domconfig{'selfenrollment'} = {};
10546: }
10547: }
10548: %toplevel = (
10549: admin => 'Configuration Rights',
10550: default => 'Default settings',
10551: validation => 'Validation of self-enrollment requests',
10552: );
1.233 raeburn 10553: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10554:
10555: if (ref($ordered{'admin'}) eq 'ARRAY') {
10556: foreach my $item (@{$ordered{'admin'}}) {
10557: foreach my $type (@types) {
10558: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10559: $selfenrollhash{'admin'}{$type}{$item} = 1;
10560: } else {
10561: $selfenrollhash{'admin'}{$type}{$item} = 0;
10562: }
10563: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10564: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10565: if ($selfenrollhash{'admin'}{$type}{$item} ne
10566: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10567: push(@{$changes{'admin'}{$type}},$item);
10568: }
10569: } else {
10570: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10571: push(@{$changes{'admin'}{$type}},$item);
10572: }
10573: }
10574: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10575: push(@{$changes{'admin'}{$type}},$item);
10576: }
10577: }
10578: }
10579: }
10580:
10581: foreach my $item (@{$ordered{'default'}}) {
10582: foreach my $type (@types) {
10583: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10584: if ($item eq 'types') {
10585: unless (($value eq 'all') || ($value eq 'dom')) {
10586: $value = '';
10587: }
10588: } elsif ($item eq 'registered') {
10589: unless ($value eq '1') {
10590: $value = 0;
10591: }
10592: } elsif ($item eq 'approval') {
10593: unless ($value =~ /^[012]$/) {
10594: $value = 0;
10595: }
10596: } else {
10597: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10598: $value = 'none';
10599: }
10600: }
10601: $selfenrollhash{'default'}{$type}{$item} = $value;
10602: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10603: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10604: if ($selfenrollhash{'default'}{$type}{$item} ne
10605: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10606: push(@{$changes{'default'}{$type}},$item);
10607: }
10608: } else {
10609: push(@{$changes{'default'}{$type}},$item);
10610: }
10611: } else {
10612: push(@{$changes{'default'}{$type}},$item);
10613: }
10614: if ($item eq 'limit') {
10615: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10616: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10617: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10618: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10619: }
10620: } else {
10621: $selfenrollhash{'default'}{$type}{'cap'} = '';
10622: }
10623: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10624: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10625: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10626: push(@{$changes{'default'}{$type}},'cap');
10627: }
10628: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10629: push(@{$changes{'default'}{$type}},'cap');
10630: }
10631: }
10632: }
10633: }
10634:
10635: foreach my $item (@{$itemsref}) {
10636: if ($item eq 'fields') {
10637: my @changed;
10638: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10639: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10640: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10641: }
10642: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10643: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10644: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10645: $domconfig{'selfenrollment'}{'validation'}{$item});
10646: } else {
10647: @changed = @{$selfenrollhash{'validation'}{$item}};
10648: }
10649: } else {
10650: @changed = @{$selfenrollhash{'validation'}{$item}};
10651: }
10652: if (@changed) {
10653: if ($selfenrollhash{'validation'}{$item}) {
10654: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10655: } else {
10656: $changes{'validation'}{$item} = &mt('None');
10657: }
10658: }
10659: } else {
10660: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10661: if ($item eq 'markup') {
10662: if ($env{'form.selfenroll_validation_'.$item}) {
10663: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10664: }
10665: }
10666: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10667: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10668: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10669: }
10670: }
10671: }
10672: }
10673:
10674: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10675: $dom);
10676: if ($putresult eq 'ok') {
10677: if (keys(%changes) > 0) {
10678: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10679: $resulttext = &mt('Changes made:').'<ul>';
10680: foreach my $key ('admin','default','validation') {
10681: if (ref($changes{$key}) eq 'HASH') {
10682: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10683: if ($key eq 'validation') {
10684: foreach my $item (@{$itemsref}) {
10685: if (exists($changes{$key}{$item})) {
10686: if ($item eq 'markup') {
10687: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10688: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10689: } else {
10690: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10691: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10692: }
10693: }
10694: }
10695: } else {
10696: foreach my $type (@types) {
10697: if ($type eq 'community') {
10698: $roles{'1'} = &mt('Community personnel');
10699: } else {
10700: $roles{'1'} = &mt('Course personnel');
10701: }
10702: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10703: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10704: if ($key eq 'admin') {
10705: my @mgrdc = ();
10706: if (ref($ordered{$key}) eq 'ARRAY') {
10707: foreach my $item (@{$ordered{'admin'}}) {
10708: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10709: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10710: push(@mgrdc,$item);
10711: }
10712: }
10713: }
10714: if (@mgrdc) {
10715: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10716: } else {
10717: delete($domdefaults{$type.'selfenrolladmdc'});
10718: }
10719: }
10720: } else {
10721: if (ref($ordered{$key}) eq 'ARRAY') {
10722: foreach my $item (@{$ordered{$key}}) {
10723: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10724: $domdefaults{$type.'selfenroll'.$item} =
10725: $selfenrollhash{$key}{$type}{$item};
10726: }
10727: }
10728: }
10729: }
10730: }
1.231 raeburn 10731: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10732: foreach my $item (@{$ordered{$key}}) {
10733: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10734: $resulttext .= '<li>';
10735: if ($key eq 'admin') {
10736: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10737: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10738: } else {
10739: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10740: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10741: }
10742: $resulttext .= '</li>';
10743: }
10744: }
10745: $resulttext .= '</ul></li>';
10746: }
10747: }
10748: $resulttext .= '</ul></li>';
10749: }
10750: }
1.232 raeburn 10751: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10752: my $cachetime = 24*60*60;
10753: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10754: if (ref($lastactref) eq 'HASH') {
10755: $lastactref->{'domdefaults'} = 1;
10756: }
10757: }
1.231 raeburn 10758: }
10759: $resulttext .= '</ul>';
10760: } else {
10761: $resulttext = &mt('No changes made to self-enrollment settings');
10762: }
10763: } else {
10764: $resulttext = '<span class="LC_error">'.
10765: &mt('An error occurred: [_1]',$putresult).'</span>';
10766: }
10767: return $resulttext;
10768: }
10769:
1.137 raeburn 10770: sub modify_usersessions {
1.212 raeburn 10771: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10772: my @hostingtypes = ('version','excludedomain','includedomain');
10773: my @offloadtypes = ('primary','default');
10774: my %types = (
10775: remote => \@hostingtypes,
10776: hosted => \@hostingtypes,
10777: spares => \@offloadtypes,
10778: );
10779: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10780: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10781: my (%by_ip,%by_location,@intdoms);
10782: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10783: my @locations = sort(keys(%by_location));
1.137 raeburn 10784: my (%defaultshash,%changes);
10785: foreach my $prefix (@prefixes) {
10786: $defaultshash{'usersessions'}{$prefix} = {};
10787: }
1.212 raeburn 10788: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10789: my $resulttext;
1.138 raeburn 10790: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10791: foreach my $prefix (@prefixes) {
1.145 raeburn 10792: next if ($prefix eq 'spares');
10793: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10794: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10795: if ($type eq 'version') {
10796: my $value = $env{'form.'.$prefix.'_'.$type};
10797: my $okvalue;
10798: if ($value ne '') {
10799: if (grep(/^\Q$value\E$/,@lcversions)) {
10800: $okvalue = $value;
10801: }
10802: }
10803: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10804: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10805: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10806: if ($inuse == 0) {
10807: $changes{$prefix}{$type} = 1;
10808: } else {
10809: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10810: $changes{$prefix}{$type} = 1;
10811: }
10812: if ($okvalue ne '') {
10813: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10814: }
10815: }
10816: } else {
10817: if (($inuse == 1) && ($okvalue ne '')) {
10818: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10819: $changes{$prefix}{$type} = 1;
10820: }
10821: }
10822: } else {
10823: if (($inuse == 1) && ($okvalue ne '')) {
10824: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10825: $changes{$prefix}{$type} = 1;
10826: }
10827: }
10828: } else {
10829: if (($inuse == 1) && ($okvalue ne '')) {
10830: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10831: $changes{$prefix}{$type} = 1;
10832: }
10833: }
10834: } else {
10835: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10836: my @okvals;
10837: foreach my $val (@vals) {
1.138 raeburn 10838: if ($val =~ /:/) {
10839: my @items = split(/:/,$val);
10840: foreach my $item (@items) {
10841: if (ref($by_location{$item}) eq 'ARRAY') {
10842: push(@okvals,$item);
10843: }
10844: }
10845: } else {
10846: if (ref($by_location{$val}) eq 'ARRAY') {
10847: push(@okvals,$val);
10848: }
1.137 raeburn 10849: }
10850: }
10851: @okvals = sort(@okvals);
10852: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10853: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10854: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10855: if ($inuse == 0) {
10856: $changes{$prefix}{$type} = 1;
10857: } else {
10858: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10859: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10860: if (@changed > 0) {
10861: $changes{$prefix}{$type} = 1;
10862: }
10863: }
10864: } else {
10865: if ($inuse == 1) {
10866: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10867: $changes{$prefix}{$type} = 1;
10868: }
10869: }
10870: } else {
10871: if ($inuse == 1) {
10872: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10873: $changes{$prefix}{$type} = 1;
10874: }
10875: }
10876: } else {
10877: if ($inuse == 1) {
10878: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10879: $changes{$prefix}{$type} = 1;
10880: }
10881: }
10882: }
10883: }
10884: }
1.145 raeburn 10885:
10886: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10887: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10888: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10889: my $savespares;
10890:
10891: foreach my $lonhost (sort(keys(%servers))) {
10892: my $serverhomeID =
10893: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10894: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10895: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10896: my %spareschg;
10897: foreach my $type (@{$types{'spares'}}) {
10898: my @okspares;
10899: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10900: foreach my $server (@checked) {
1.152 raeburn 10901: if (&Apache::lonnet::hostname($server) ne '') {
10902: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10903: unless (grep(/^\Q$server\E$/,@okspares)) {
10904: push(@okspares,$server);
10905: }
1.145 raeburn 10906: }
10907: }
10908: }
10909: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10910: my $newspare;
1.152 raeburn 10911: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10912: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10913: $newspare = $new;
10914: }
10915: }
1.152 raeburn 10916: my @spares;
10917: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10918: @spares = sort(@okspares,$newspare);
10919: } else {
10920: @spares = sort(@okspares);
10921: }
10922: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10923: if (ref($spareid{$lonhost}) eq 'HASH') {
10924: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10925: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10926: if (@diffs > 0) {
10927: $spareschg{$type} = 1;
10928: }
10929: }
10930: }
10931: }
10932: if (keys(%spareschg) > 0) {
10933: $changes{'spares'}{$lonhost} = \%spareschg;
10934: }
10935: }
10936:
10937: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10938: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10939: if (ref($changes{'spares'}) eq 'HASH') {
10940: if (keys(%{$changes{'spares'}}) > 0) {
10941: $savespares = 1;
10942: }
10943: }
10944: } else {
10945: $savespares = 1;
10946: }
10947: }
10948:
1.147 raeburn 10949: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10950: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10951: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10952: $dom);
10953: if ($putresult eq 'ok') {
10954: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10955: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10956: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10957: }
10958: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10959: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10960: }
10961: }
10962: my $cachetime = 24*60*60;
10963: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10964: if (ref($lastactref) eq 'HASH') {
10965: $lastactref->{'domdefaults'} = 1;
10966: }
1.147 raeburn 10967: if (keys(%changes) > 0) {
10968: my %lt = &usersession_titles();
10969: $resulttext = &mt('Changes made:').'<ul>';
10970: foreach my $prefix (@prefixes) {
10971: if (ref($changes{$prefix}) eq 'HASH') {
10972: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10973: if ($prefix eq 'spares') {
10974: if (ref($changes{$prefix}) eq 'HASH') {
10975: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10976: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10977: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10978: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10979: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10980: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10981: foreach my $type (@{$types{$prefix}}) {
10982: if ($changes{$prefix}{$lonhost}{$type}) {
10983: my $offloadto = &mt('None');
10984: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10985: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10986: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10987: }
1.145 raeburn 10988: }
1.147 raeburn 10989: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10990: }
1.137 raeburn 10991: }
10992: }
1.147 raeburn 10993: $resulttext .= '</li>';
1.137 raeburn 10994: }
10995: }
1.147 raeburn 10996: } else {
10997: foreach my $type (@{$types{$prefix}}) {
10998: if (defined($changes{$prefix}{$type})) {
10999: my $newvalue;
11000: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
11001: if (ref($defaultshash{'usersessions'}{$prefix})) {
11002: if ($type eq 'version') {
11003: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
11004: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11005: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
11006: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
11007: }
1.145 raeburn 11008: }
11009: }
11010: }
1.147 raeburn 11011: if ($newvalue eq '') {
11012: if ($type eq 'version') {
11013: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
11014: } else {
11015: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
11016: }
1.145 raeburn 11017: } else {
1.147 raeburn 11018: if ($type eq 'version') {
11019: $newvalue .= ' '.&mt('(or later)');
11020: }
11021: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 11022: }
1.137 raeburn 11023: }
11024: }
11025: }
1.147 raeburn 11026: $resulttext .= '</ul>';
1.137 raeburn 11027: }
11028: }
1.147 raeburn 11029: $resulttext .= '</ul>';
11030: } else {
11031: $resulttext = $nochgmsg;
1.137 raeburn 11032: }
11033: } else {
11034: $resulttext = '<span class="LC_error">'.
11035: &mt('An error occurred: [_1]',$putresult).'</span>';
11036: }
11037: } else {
1.147 raeburn 11038: $resulttext = $nochgmsg;
1.137 raeburn 11039: }
11040: return $resulttext;
11041: }
11042:
1.150 raeburn 11043: sub modify_loadbalancing {
11044: my ($dom,%domconfig) = @_;
11045: my $primary_id = &Apache::lonnet::domain($dom,'primary');
11046: my $intdom = &Apache::lonnet::internet_dom($primary_id);
11047: my ($othertitle,$usertypes,$types) =
11048: &Apache::loncommon::sorted_inst_types($dom);
11049: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 11050: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 11051: my @sparestypes = ('primary','default');
11052: my %typetitles = &sparestype_titles();
11053: my $resulttext;
1.171 raeburn 11054: my (%currbalancer,%currtargets,%currrules,%existing);
11055: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11056: %existing = %{$domconfig{'loadbalancing'}};
11057: }
11058: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
11059: \%currtargets,\%currrules);
11060: my ($saveloadbalancing,%defaultshash,%changes);
11061: my ($alltypes,$othertypes,$titles) =
11062: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
11063: my %ruletitles = &offloadtype_text();
11064: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
11065: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
11066: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
11067: if ($balancer eq '') {
11068: next;
11069: }
1.210 raeburn 11070: if (!exists($servers{$balancer})) {
1.171 raeburn 11071: if (exists($currbalancer{$balancer})) {
11072: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 11073: }
1.171 raeburn 11074: next;
11075: }
11076: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
11077: push(@{$changes{'delete'}},$balancer);
11078: next;
11079: }
11080: if (!exists($currbalancer{$balancer})) {
11081: push(@{$changes{'add'}},$balancer);
11082: }
11083: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
11084: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
11085: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
11086: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
11087: $saveloadbalancing = 1;
11088: }
11089: foreach my $sparetype (@sparestypes) {
11090: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
11091: my @offloadto;
11092: foreach my $target (@targets) {
11093: if (($servers{$target}) && ($target ne $balancer)) {
11094: if ($sparetype eq 'default') {
11095: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
11096: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 11097: }
11098: }
1.171 raeburn 11099: unless(grep(/^\Q$target\E$/,@offloadto)) {
11100: push(@offloadto,$target);
11101: }
1.150 raeburn 11102: }
1.171 raeburn 11103: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 11104: }
11105: }
1.171 raeburn 11106: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 11107: foreach my $sparetype (@sparestypes) {
1.171 raeburn 11108: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
11109: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 11110: if (@targetdiffs > 0) {
1.171 raeburn 11111: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11112: }
1.171 raeburn 11113: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11114: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11115: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 11116: }
11117: }
11118: }
11119: } else {
1.171 raeburn 11120: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 11121: foreach my $sparetype (@sparestypes) {
1.171 raeburn 11122: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11123: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11124: $changes{'curr'}{$balancer}{'targets'} = 1;
11125: }
1.150 raeburn 11126: }
11127: }
1.210 raeburn 11128: }
1.150 raeburn 11129: }
11130: my $ishomedom;
1.171 raeburn 11131: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
11132: $ishomedom = 1;
1.150 raeburn 11133: }
11134: if (ref($alltypes) eq 'ARRAY') {
11135: foreach my $type (@{$alltypes}) {
11136: my $rule;
1.210 raeburn 11137: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 11138: (!$ishomedom)) {
1.171 raeburn 11139: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
11140: }
11141: if ($rule eq 'specific') {
1.255 raeburn 11142: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
11143: if (exists($servers{$specifiedhost})) {
11144: $rule = $specifiedhost;
11145: }
1.150 raeburn 11146: }
1.171 raeburn 11147: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
11148: if (ref($currrules{$balancer}) eq 'HASH') {
11149: if ($rule ne $currrules{$balancer}{$type}) {
11150: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11151: }
11152: } elsif ($rule ne '') {
1.171 raeburn 11153: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 11154: }
11155: }
11156: }
1.171 raeburn 11157: }
11158: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
11159: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
11160: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
11161: $defaultshash{'loadbalancing'} = {};
11162: }
11163: my $putresult = &Apache::lonnet::put_dom('configuration',
11164: \%defaultshash,$dom);
11165: if ($putresult eq 'ok') {
11166: if (keys(%changes) > 0) {
1.252 raeburn 11167: my %toupdate;
1.171 raeburn 11168: if (ref($changes{'delete'}) eq 'ARRAY') {
11169: foreach my $balancer (sort(@{$changes{'delete'}})) {
11170: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 11171: $toupdate{$balancer} = 1;
1.150 raeburn 11172: }
1.171 raeburn 11173: }
11174: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 11175: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 11176: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 11177: $toupdate{$balancer} = 1;
1.171 raeburn 11178: }
11179: }
11180: if (ref($changes{'curr'}) eq 'HASH') {
11181: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 11182: $toupdate{$balancer} = 1;
1.171 raeburn 11183: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11184: if ($changes{'curr'}{$balancer}{'targets'}) {
11185: my %offloadstr;
11186: foreach my $sparetype (@sparestypes) {
11187: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11188: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11189: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11190: }
11191: }
1.150 raeburn 11192: }
1.171 raeburn 11193: if (keys(%offloadstr) == 0) {
11194: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11195: } else {
1.171 raeburn 11196: my $showoffload;
11197: foreach my $sparetype (@sparestypes) {
11198: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11199: if (defined($offloadstr{$sparetype})) {
11200: $showoffload .= $offloadstr{$sparetype};
11201: } else {
11202: $showoffload .= &mt('None');
11203: }
11204: $showoffload .= (' 'x3);
11205: }
11206: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11207: }
11208: }
11209: }
1.171 raeburn 11210: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11211: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11212: foreach my $type (@{$alltypes}) {
11213: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11214: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11215: my $balancetext;
11216: if ($rule eq '') {
11217: $balancetext = $ruletitles{'default'};
1.209 raeburn 11218: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 11219: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11220: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 11221: foreach my $sparetype (@sparestypes) {
11222: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11223: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11224: }
11225: }
1.253 raeburn 11226: foreach my $item (@{$alltypes}) {
11227: next if ($item =~ /^_LC_ipchange/);
11228: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11229: if ($hasrule eq 'homeserver') {
11230: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11231: } else {
11232: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11233: if ($servers{$hasrule}) {
11234: $toupdate{$hasrule} = 1;
11235: }
11236: }
11237: }
11238: }
1.254 raeburn 11239: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11240: $balancetext = $ruletitles{$rule};
11241: } else {
11242: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11243: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11244: if ($receiver) {
11245: $toupdate{$receiver};
11246: }
11247: }
11248: } else {
11249: $balancetext = $ruletitles{$rule};
1.252 raeburn 11250: }
1.171 raeburn 11251: } else {
11252: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11253: }
1.210 raeburn 11254: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11255: }
11256: }
11257: }
11258: }
1.252 raeburn 11259: if (keys(%toupdate)) {
11260: my %thismachine;
11261: my $updatedhere;
11262: my $cachetime = 60*60*24;
11263: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11264: foreach my $lonhost (keys(%toupdate)) {
11265: if ($thismachine{$lonhost}) {
11266: unless ($updatedhere) {
11267: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11268: $defaultshash{'loadbalancing'},
11269: $cachetime);
11270: $updatedhere = 1;
11271: }
11272: } else {
11273: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11274: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11275: }
11276: }
11277: }
1.150 raeburn 11278: }
1.171 raeburn 11279: }
11280: if ($resulttext ne '') {
11281: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11282: } else {
11283: $resulttext = $nochgmsg;
11284: }
11285: } else {
1.171 raeburn 11286: $resulttext = $nochgmsg;
1.150 raeburn 11287: }
11288: } else {
1.171 raeburn 11289: $resulttext = '<span class="LC_error">'.
11290: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11291: }
11292: } else {
1.171 raeburn 11293: $resulttext = $nochgmsg;
1.150 raeburn 11294: }
11295: return $resulttext;
11296: }
11297:
1.48 raeburn 11298: sub recurse_check {
11299: my ($chkcats,$categories,$depth,$name) = @_;
11300: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11301: my $chg = 0;
11302: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11303: my $category = $chkcats->[$depth]{$name}[$j];
11304: my $item;
11305: if ($category eq '') {
11306: $chg ++;
11307: } else {
11308: my $deeper = $depth + 1;
11309: $item = &escape($category).':'.&escape($name).':'.$depth;
11310: if ($chg) {
11311: $categories->{$item} -= $chg;
11312: }
11313: &recurse_check($chkcats,$categories,$deeper,$category);
11314: $deeper --;
11315: }
11316: }
11317: }
11318: return;
11319: }
11320:
11321: sub recurse_cat_deletes {
11322: my ($item,$coursecategories,$deletions) = @_;
11323: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11324: my $subdepth = $depth + 1;
11325: if (ref($coursecategories) eq 'HASH') {
11326: foreach my $subitem (keys(%{$coursecategories})) {
11327: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11328: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11329: delete($coursecategories->{$subitem});
11330: $deletions->{$subitem} = 1;
11331: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 11332: }
1.48 raeburn 11333: }
11334: }
11335: return;
11336: }
11337:
1.125 raeburn 11338: sub get_active_dcs {
11339: my ($dom) = @_;
1.191 raeburn 11340: my $now = time;
11341: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11342: my %domcoords;
11343: my $numdcs = 0;
11344: foreach my $server (keys(%dompersonnel)) {
11345: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11346: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 11347: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11348: }
11349: }
11350: return %domcoords;
11351: }
11352:
11353: sub active_dc_picker {
1.191 raeburn 11354: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 11355: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 11356: my @domcoord = keys(%domcoords);
11357: if (keys(%currhash)) {
11358: foreach my $dc (keys(%currhash)) {
11359: unless (exists($domcoords{$dc})) {
11360: push(@domcoord,$dc);
11361: }
11362: }
11363: }
11364: @domcoord = sort(@domcoord);
1.210 raeburn 11365: my $numdcs = scalar(@domcoord);
1.191 raeburn 11366: my $rows = 0;
11367: my $table;
1.125 raeburn 11368: if ($numdcs > 1) {
1.191 raeburn 11369: $table = '<table>';
11370: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11371: my $rem = $i%($numinrow);
11372: if ($rem == 0) {
11373: if ($i > 0) {
1.191 raeburn 11374: $table .= '</tr>';
1.125 raeburn 11375: }
1.191 raeburn 11376: $table .= '<tr>';
11377: $rows ++;
1.125 raeburn 11378: }
1.191 raeburn 11379: my $check = '';
11380: if ($inputtype eq 'radio') {
11381: if (keys(%currhash) == 0) {
11382: if (!$i) {
11383: $check = ' checked="checked"';
11384: }
11385: } elsif (exists($currhash{$domcoord[$i]})) {
11386: $check = ' checked="checked"';
11387: }
11388: } else {
11389: if (exists($currhash{$domcoord[$i]})) {
11390: $check = ' checked="checked"';
1.125 raeburn 11391: }
11392: }
1.191 raeburn 11393: if ($i == @domcoord - 1) {
1.125 raeburn 11394: my $colsleft = $numinrow - $rem;
11395: if ($colsleft > 1) {
1.191 raeburn 11396: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11397: } else {
1.191 raeburn 11398: $table .= '<td class="LC_left_item">';
1.125 raeburn 11399: }
11400: } else {
1.191 raeburn 11401: $table .= '<td class="LC_left_item">';
11402: }
11403: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11404: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11405: $table .= '<span class="LC_nobreak"><label>'.
11406: '<input type="'.$inputtype.'" name="'.$name.'"'.
11407: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11408: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 11409: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 11410: }
1.219 raeburn 11411: $table .= '</label></span></td>';
1.191 raeburn 11412: }
11413: $table .= '</tr></table>';
11414: } elsif ($numdcs == 1) {
1.219 raeburn 11415: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11416: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 11417: if ($inputtype eq 'radio') {
1.247 raeburn 11418: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 11419: if ($user ne $dcname.':'.$dcdom) {
11420: $table .= ' ('.$dcname.':'.$dcdom.')';
11421: }
1.191 raeburn 11422: } else {
11423: my $check;
11424: if (exists($currhash{$domcoord[0]})) {
11425: $check = ' checked="checked"';
1.125 raeburn 11426: }
1.247 raeburn 11427: $table = '<span class="LC_nobreak"><label>'.
11428: '<input type="checkbox" name="'.$name.'" '.
11429: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 11430: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 11431: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 11432: }
1.220 raeburn 11433: $table .= '</label></span>';
1.191 raeburn 11434: $rows ++;
1.125 raeburn 11435: }
11436: }
1.191 raeburn 11437: return ($numdcs,$table,$rows);
1.125 raeburn 11438: }
11439:
1.137 raeburn 11440: sub usersession_titles {
11441: return &Apache::lonlocal::texthash(
11442: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11443: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11444: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11445: version => 'LON-CAPA version requirement',
1.138 raeburn 11446: excludedomain => 'Allow all, but exclude specific domains',
11447: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11448: primary => 'Primary (checked first)',
1.154 raeburn 11449: default => 'Default',
1.137 raeburn 11450: );
11451: }
11452:
1.152 raeburn 11453: sub id_for_thisdom {
11454: my (%servers) = @_;
11455: my %altids;
11456: foreach my $server (keys(%servers)) {
11457: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11458: if ($serverhome ne $server) {
11459: $altids{$serverhome} = $server;
11460: }
11461: }
11462: return %altids;
11463: }
11464:
1.150 raeburn 11465: sub count_servers {
11466: my ($currbalancer,%servers) = @_;
11467: my (@spares,$numspares);
11468: foreach my $lonhost (sort(keys(%servers))) {
11469: next if ($currbalancer eq $lonhost);
11470: push(@spares,$lonhost);
11471: }
11472: if ($currbalancer) {
11473: $numspares = scalar(@spares);
11474: } else {
11475: $numspares = scalar(@spares) - 1;
11476: }
11477: return ($numspares,@spares);
11478: }
11479:
11480: sub lonbalance_targets_js {
1.171 raeburn 11481: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11482: my $select = &mt('Select');
11483: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11484: if (ref($servers) eq 'HASH') {
11485: $alltargets = join("','",sort(keys(%{$servers})));
11486: my @homedoms;
11487: foreach my $server (sort(keys(%{$servers}))) {
11488: if (&Apache::lonnet::host_domain($server) eq $dom) {
11489: push(@homedoms,'1');
11490: } else {
11491: push(@homedoms,'0');
11492: }
11493: }
11494: $allishome = join("','",@homedoms);
11495: }
11496: if (ref($types) eq 'ARRAY') {
11497: if (@{$types} > 0) {
11498: @alltypes = @{$types};
11499: }
11500: }
11501: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11502: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11503: my (%currbalancer,%currtargets,%currrules,%existing);
11504: if (ref($settings) eq 'HASH') {
11505: %existing = %{$settings};
11506: }
11507: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11508: \%currtargets,\%currrules);
1.210 raeburn 11509: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11510: return <<"END";
11511:
11512: <script type="text/javascript">
11513: // <![CDATA[
11514:
1.171 raeburn 11515: currBalancers = new Array('$balancers');
11516:
11517: function toggleTargets(balnum) {
11518: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11519: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11520: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11521: var prevbalancer = prevhostitem.value;
11522: var baltotal = document.getElementById('loadbalancing_total').value;
11523: prevhostitem.value = balancer;
11524: if (prevbalancer != '') {
11525: var prevIdx = currBalancers.indexOf(prevbalancer);
11526: if (prevIdx != -1) {
11527: currBalancers.splice(prevIdx,1);
11528: }
11529: }
1.150 raeburn 11530: if (balancer == '') {
1.171 raeburn 11531: hideSpares(balnum);
1.150 raeburn 11532: } else {
1.171 raeburn 11533: var currIdx = currBalancers.indexOf(balancer);
11534: if (currIdx == -1) {
11535: currBalancers.push(balancer);
11536: }
1.150 raeburn 11537: var homedoms = new Array('$allishome');
1.171 raeburn 11538: var ishomedom = homedoms[lonhostitem.selectedIndex];
11539: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11540: }
1.171 raeburn 11541: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11542: return;
11543: }
11544:
1.171 raeburn 11545: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11546: var alltargets = new Array('$alltargets');
11547: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11548: var offloadtypes = new Array('primary','default');
11549:
1.171 raeburn 11550: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11551: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11552:
1.151 raeburn 11553: for (var i=0; i<offloadtypes.length; i++) {
11554: var count = 0;
11555: for (var j=0; j<alltargets.length; j++) {
11556: if (alltargets[j] != balancer) {
1.171 raeburn 11557: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11558: item.value = alltargets[j];
11559: item.style.textAlign='left';
11560: item.style.textFace='normal';
11561: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11562: if (currBalancers.indexOf(alltargets[j]) == -1) {
11563: item.disabled = '';
11564: } else {
11565: item.disabled = 'disabled';
11566: item.checked = false;
11567: }
1.151 raeburn 11568: count ++;
11569: }
1.150 raeburn 11570: }
11571: }
1.151 raeburn 11572: for (var k=0; k<insttypes.length; k++) {
11573: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11574: if (ishomedom == 1) {
1.171 raeburn 11575: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11576: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11577: } else {
1.171 raeburn 11578: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11579: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11580: }
11581: } else {
1.171 raeburn 11582: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11583: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11584: }
1.151 raeburn 11585: if ((insttypes[k] != '_LC_external') &&
11586: ((insttypes[k] != '_LC_internetdom') ||
11587: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11588: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11589: item.options.length = 0;
11590: item.options[0] = new Option("","",true,true);
1.210 raeburn 11591: var idx = 0;
1.151 raeburn 11592: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11593: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11594: idx ++;
11595: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11596: }
11597: }
11598: }
11599: }
11600: return;
11601: }
11602:
1.171 raeburn 11603: function hideSpares(balnum) {
1.150 raeburn 11604: var alltargets = new Array('$alltargets');
11605: var insttypes = new Array('$allinsttypes');
11606: var offloadtypes = new Array('primary','default');
11607:
1.171 raeburn 11608: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11609: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11610:
11611: var total = alltargets.length - 1;
11612: for (var i=0; i<offloadtypes; i++) {
11613: for (var j=0; j<total; j++) {
1.171 raeburn 11614: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11615: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11616: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11617: }
1.150 raeburn 11618: }
11619: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11620: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11621: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11622: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11623: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11624: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11625: }
11626: }
11627: return;
11628: }
11629:
1.171 raeburn 11630: function checkOffloads(item,balnum,type) {
1.150 raeburn 11631: var alltargets = new Array('$alltargets');
11632: var offloadtypes = new Array('primary','default');
11633: if (item.checked) {
11634: var total = alltargets.length - 1;
11635: var other;
11636: if (type == offloadtypes[0]) {
1.151 raeburn 11637: other = offloadtypes[1];
1.150 raeburn 11638: } else {
1.151 raeburn 11639: other = offloadtypes[0];
1.150 raeburn 11640: }
11641: for (var i=0; i<total; i++) {
1.171 raeburn 11642: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11643: if (server == item.value) {
1.171 raeburn 11644: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11645: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11646: }
11647: }
11648: }
11649: }
11650: return;
11651: }
11652:
1.171 raeburn 11653: function singleServerToggle(balnum,type) {
11654: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11655: if (offloadtoSelIdx == 0) {
1.171 raeburn 11656: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11657: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11658:
11659: } else {
1.171 raeburn 11660: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11661: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11662: }
11663: return;
11664: }
11665:
1.171 raeburn 11666: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11667: if (type == '_LC_external') {
1.171 raeburn 11668: return;
1.150 raeburn 11669: }
1.171 raeburn 11670: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11671: for (var i=0; i<typesRules.length; i++) {
11672: if (formname.elements[typesRules[i]].checked) {
11673: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11674: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11675: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11676: } else {
1.171 raeburn 11677: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11678: }
11679: }
11680: }
11681: return;
11682: }
11683:
11684: function balancerDeleteChange(balnum) {
11685: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11686: var baltotal = document.getElementById('loadbalancing_total').value;
11687: var addtarget;
11688: var removetarget;
11689: var action = 'delete';
11690: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11691: var lonhost = hostitem.value;
11692: var currIdx = currBalancers.indexOf(lonhost);
11693: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11694: if (currIdx != -1) {
11695: currBalancers.splice(currIdx,1);
11696: }
11697: addtarget = lonhost;
11698: } else {
11699: if (currIdx == -1) {
11700: currBalancers.push(lonhost);
11701: }
11702: removetarget = lonhost;
11703: action = 'undelete';
11704: }
11705: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11706: }
11707: return;
11708: }
11709:
11710: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11711: if (baltotal > 1) {
11712: var offloadtypes = new Array('primary','default');
11713: var alltargets = new Array('$alltargets');
11714: var insttypes = new Array('$allinsttypes');
11715: for (var i=0; i<baltotal; i++) {
11716: if (i != balnum) {
11717: for (var j=0; j<offloadtypes.length; j++) {
11718: var total = alltargets.length - 1;
11719: for (var k=0; k<total; k++) {
11720: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11721: var server = serveritem.value;
11722: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11723: if (server == addtarget) {
11724: serveritem.disabled = '';
11725: }
11726: }
11727: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11728: if (server == removetarget) {
11729: serveritem.disabled = 'disabled';
11730: serveritem.checked = false;
11731: }
11732: }
11733: }
11734: }
11735: for (var j=0; j<insttypes.length; j++) {
11736: if (insttypes[j] != '_LC_external') {
11737: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11738: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11739: var currSel = singleserver.selectedIndex;
11740: var currVal = singleserver.options[currSel].value;
11741: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11742: var numoptions = singleserver.options.length;
11743: var needsnew = 1;
11744: for (var k=0; k<numoptions; k++) {
11745: if (singleserver.options[k] == addtarget) {
11746: needsnew = 0;
11747: break;
11748: }
11749: }
11750: if (needsnew == 1) {
11751: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11752: }
11753: }
11754: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11755: singleserver.options.length = 0;
11756: if ((currVal) && (currVal != removetarget)) {
11757: singleserver.options[0] = new Option("","",false,false);
11758: } else {
11759: singleserver.options[0] = new Option("","",true,true);
11760: }
11761: var idx = 0;
11762: for (var m=0; m<alltargets.length; m++) {
11763: if (currBalancers.indexOf(alltargets[m]) == -1) {
11764: idx ++;
11765: if (currVal == alltargets[m]) {
11766: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11767: } else {
11768: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11769: }
11770: }
11771: }
11772: }
11773: }
11774: }
11775: }
1.150 raeburn 11776: }
11777: }
11778: }
11779: return;
11780: }
11781:
1.152 raeburn 11782: // ]]>
11783: </script>
11784:
11785: END
11786: }
11787:
11788: sub new_spares_js {
11789: my @sparestypes = ('primary','default');
11790: my $types = join("','",@sparestypes);
11791: my $select = &mt('Select');
11792: return <<"END";
11793:
11794: <script type="text/javascript">
11795: // <![CDATA[
11796:
11797: function updateNewSpares(formname,lonhost) {
11798: var types = new Array('$types');
11799: var include = new Array();
11800: var exclude = new Array();
11801: for (var i=0; i<types.length; i++) {
11802: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11803: for (var j=0; j<spareboxes.length; j++) {
11804: if (formname.elements[spareboxes[j]].checked) {
11805: exclude.push(formname.elements[spareboxes[j]].value);
11806: } else {
11807: include.push(formname.elements[spareboxes[j]].value);
11808: }
11809: }
11810: }
11811: for (var i=0; i<types.length; i++) {
11812: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11813: var selIdx = newSpare.selectedIndex;
11814: var currnew = newSpare.options[selIdx].value;
11815: var okSpares = new Array();
11816: for (var j=0; j<newSpare.options.length; j++) {
11817: var possible = newSpare.options[j].value;
11818: if (possible != '') {
11819: if (exclude.indexOf(possible) == -1) {
11820: okSpares.push(possible);
11821: } else {
11822: if (currnew == possible) {
11823: selIdx = 0;
11824: }
11825: }
11826: }
11827: }
11828: for (var k=0; k<include.length; k++) {
11829: if (okSpares.indexOf(include[k]) == -1) {
11830: okSpares.push(include[k]);
11831: }
11832: }
11833: okSpares.sort();
11834: newSpare.options.length = 0;
11835: if (selIdx == 0) {
11836: newSpare.options[0] = new Option("$select","",true,true);
11837: } else {
11838: newSpare.options[0] = new Option("$select","",false,false);
11839: }
11840: for (var m=0; m<okSpares.length; m++) {
11841: var idx = m+1;
11842: var selThis = 0;
11843: if (selIdx != 0) {
11844: if (okSpares[m] == currnew) {
11845: selThis = 1;
11846: }
11847: }
11848: if (selThis == 1) {
11849: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11850: } else {
11851: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11852: }
11853: }
11854: }
11855: return;
11856: }
11857:
11858: function checkNewSpares(lonhost,type) {
11859: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11860: var chosen = newSpare.options[newSpare.selectedIndex].value;
11861: if (chosen != '') {
11862: var othertype;
11863: var othernewSpare;
11864: if (type == 'primary') {
11865: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11866: }
11867: if (type == 'default') {
11868: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11869: }
11870: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11871: othernewSpare.selectedIndex = 0;
11872: }
11873: }
11874: return;
11875: }
11876:
11877: // ]]>
11878: </script>
11879:
11880: END
11881:
11882: }
11883:
11884: sub common_domprefs_js {
11885: return <<"END";
11886:
11887: <script type="text/javascript">
11888: // <![CDATA[
11889:
1.150 raeburn 11890: function getIndicesByName(formname,item) {
1.152 raeburn 11891: var group = new Array();
1.150 raeburn 11892: for (var i=0;i<formname.elements.length;i++) {
11893: if (formname.elements[i].name == item) {
1.152 raeburn 11894: group.push(formname.elements[i].id);
1.150 raeburn 11895: }
11896: }
1.152 raeburn 11897: return group;
1.150 raeburn 11898: }
11899:
11900: // ]]>
11901: </script>
11902:
11903: END
1.152 raeburn 11904:
1.150 raeburn 11905: }
11906:
1.165 raeburn 11907: sub recaptcha_js {
11908: my %lt = &captcha_phrases();
11909: return <<"END";
11910:
11911: <script type="text/javascript">
11912: // <![CDATA[
11913:
11914: function updateCaptcha(caller,context) {
11915: var privitem;
11916: var pubitem;
11917: var privtext;
11918: var pubtext;
11919: if (document.getElementById(context+'_recaptchapub')) {
11920: pubitem = document.getElementById(context+'_recaptchapub');
11921: } else {
11922: return;
11923: }
11924: if (document.getElementById(context+'_recaptchapriv')) {
11925: privitem = document.getElementById(context+'_recaptchapriv');
11926: } else {
11927: return;
11928: }
11929: if (document.getElementById(context+'_recaptchapubtxt')) {
11930: pubtext = document.getElementById(context+'_recaptchapubtxt');
11931: } else {
11932: return;
11933: }
11934: if (document.getElementById(context+'_recaptchaprivtxt')) {
11935: privtext = document.getElementById(context+'_recaptchaprivtxt');
11936: } else {
11937: return;
11938: }
11939: if (caller.checked) {
11940: if (caller.value == 'recaptcha') {
11941: pubitem.type = 'text';
11942: privitem.type = 'text';
11943: pubitem.size = '40';
11944: privitem.size = '40';
11945: pubtext.innerHTML = "$lt{'pub'}";
11946: privtext.innerHTML = "$lt{'priv'}";
11947: } else {
11948: pubitem.type = 'hidden';
11949: privitem.type = 'hidden';
11950: pubtext.innerHTML = '';
11951: privtext.innerHTML = '';
11952: }
11953: }
11954: return;
11955: }
11956:
11957: // ]]>
11958: </script>
11959:
11960: END
11961:
11962: }
11963:
1.236 raeburn 11964: sub toggle_display_js {
1.192 raeburn 11965: return <<"END";
11966:
11967: <script type="text/javascript">
11968: // <![CDATA[
11969:
1.236 raeburn 11970: function toggleDisplay(domForm,caller) {
11971: if (document.getElementById(caller)) {
11972: var divitem = document.getElementById(caller);
11973: var optionsElement = domForm.coursecredits;
11974: if (caller == 'emailoptions') {
11975: optionsElement = domForm.cancreate_email;
11976: }
1.257 raeburn 11977: if (caller == 'studentsubmission') {
11978: optionsElement = domForm.postsubmit;
11979: }
1.236 raeburn 11980: if (optionsElement.length) {
1.192 raeburn 11981: var currval;
1.236 raeburn 11982: for (var i=0; i<optionsElement.length; i++) {
11983: if (optionsElement[i].checked) {
11984: currval = optionsElement[i].value;
1.192 raeburn 11985: }
11986: }
11987: if (currval == 1) {
1.236 raeburn 11988: divitem.style.display = 'block';
1.192 raeburn 11989: } else {
1.236 raeburn 11990: divitem.style.display = 'none';
1.192 raeburn 11991: }
11992: }
11993: }
11994: return;
11995: }
11996:
11997: // ]]>
11998: </script>
11999:
12000: END
12001:
12002: }
12003:
1.165 raeburn 12004: sub captcha_phrases {
12005: return &Apache::lonlocal::texthash (
12006: priv => 'Private key',
12007: pub => 'Public key',
12008: original => 'original (CAPTCHA)',
12009: recaptcha => 'successor (ReCAPTCHA)',
12010: notused => 'unused',
12011: );
12012: }
12013:
1.205 raeburn 12014: sub devalidate_remote_domconfs {
1.212 raeburn 12015: my ($dom,$cachekeys) = @_;
12016: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 12017: my %servers = &Apache::lonnet::internet_dom_servers($dom);
12018: my %thismachine;
12019: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 12020: my @posscached = ('domainconfig','domdefaults');
1.260 ! raeburn 12021: if (keys(%servers)) {
1.205 raeburn 12022: foreach my $server (keys(%servers)) {
12023: next if ($thismachine{$server});
1.212 raeburn 12024: my @cached;
12025: foreach my $name (@posscached) {
12026: if ($cachekeys->{$name}) {
12027: push(@cached,&escape($name).':'.&escape($dom));
12028: }
12029: }
12030: if (@cached) {
12031: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
12032: }
1.205 raeburn 12033: }
12034: }
12035: return;
12036: }
12037:
1.3 raeburn 12038: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>