Annotation of loncom/interface/domainprefs.pm, revision 1.256
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.256 ! raeburn 4: # $Id: domainprefs.pm,v 1.255 2014/10/06 21:08:03 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,
2847: $additional) = @_;
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.118 jms 2881: '</span></td>'.
2882: '<td class="LC_right_item"><span class="LC_nobreak">'.
2883: '<label><input type="radio" name="'.
1.192 raeburn 2884: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2885: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2886: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2887: '</span>'.$additional.
2888: '</td>'.
1.118 jms 2889: '</tr>';
2890: $itemcount ++;
1.121 raeburn 2891: }
2892: return ($datatable,$itemcount);
2893: }
2894:
2895: sub print_coursedefaults {
1.139 raeburn 2896: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2897: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2898: my $itemcount = 1;
1.192 raeburn 2899: my %choices = &Apache::lonlocal::texthash (
2900: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2901: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2902: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2903: coursecredits => 'Credits can be specified for courses',
2904: );
1.198 raeburn 2905: my %staticdefaults = (
2906: anonsurvey_threshold => 10,
2907: uploadquota => 500,
2908: );
1.139 raeburn 2909: if ($position eq 'top') {
2910: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2911: @toggles = ('canuse_pdfforms');
1.139 raeburn 2912: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2913: \%choices,$itemcount);
1.139 raeburn 2914: } else {
2915: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.216 raeburn 2916: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,$def_textbook_credits,
2917: %curruploadquota);
1.192 raeburn 2918: my $currusecredits = 0;
1.216 raeburn 2919: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 2920: if (ref($settings) eq 'HASH') {
2921: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2922: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2923: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2924: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2925: }
2926: }
1.192 raeburn 2927: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2928: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2929: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
1.216 raeburn 2930: $def_textbook_credits = $settings->{'coursecredits'}->{'textbook'};
2931: if (($def_official_credits ne '') || ($def_unofficial_credits ne '') ||
2932: ($def_textbook_credits ne '')) {
1.192 raeburn 2933: $currusecredits = 1;
2934: }
2935: }
1.139 raeburn 2936: }
2937: if (!$currdefresponder) {
1.198 raeburn 2938: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2939: } elsif ($currdefresponder < 1) {
2940: $currdefresponder = 1;
2941: }
1.198 raeburn 2942: foreach my $type (@types) {
2943: if ($curruploadquota{$type} eq '') {
2944: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2945: }
2946: }
1.139 raeburn 2947: $datatable .=
1.192 raeburn 2948: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2949: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2950: '</span></td>'.
2951: '<td class="LC_right_item"><span class="LC_nobreak">'.
2952: '<input type="text" name="anonsurvey_threshold"'.
2953: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 2954: '</td></tr>'."\n";
2955: $itemcount ++;
2956: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2957: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2958: $choices{'uploadquota'}.
2959: '</span></td>'.
2960: '<td align="right" class="LC_right_item">'.
2961: '<table><tr>';
1.198 raeburn 2962: foreach my $type (@types) {
2963: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2964: '<input type="text" name="uploadquota_'.$type.'"'.
2965: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2966: }
2967: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 2968: $itemcount ++;
1.236 raeburn 2969: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 2970: my $display = 'none';
1.192 raeburn 2971: if ($currusecredits) {
2972: $display = 'block';
2973: }
2974: my $additional = '<div id="credits" style="display: '.$display.'">'.
2975: '<span class="LC_nobreak">'.
2976: &mt('Default credits for official courses [_1]',
2977: '<input type="text" name="official_credits" value="'.
2978: $def_official_credits.'" size="3" />').
2979: '</span><br />'.
2980: '<span class="LC_nobreak">'.
2981: &mt('Default credits for unofficial courses [_1]',
2982: '<input type="text" name="unofficial_credits" value="'.
2983: $def_unofficial_credits.'" size="3" />').
1.216 raeburn 2984: '</span><br />'.
2985: '<span class="LC_nobreak">'.
2986: &mt('Default credits for textbook courses [_1]',
2987: '<input type="text" name="textbook_credits" value="'.
2988: $def_textbook_credits.'" size="3" />').
1.192 raeburn 2989: '</span></div>'."\n";
2990: %defaultchecked = ('coursecredits' => 'off');
2991: @toggles = ('coursecredits');
2992: my $current = {
2993: 'coursecredits' => $currusecredits,
2994: };
2995: (my $table,$itemcount) =
2996: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2997: \%choices,$itemcount,$onclick,$additional);
2998: $datatable .= $table;
1.230 raeburn 2999: $itemcount ++;
1.139 raeburn 3000: }
1.192 raeburn 3001: $$rowtotal += $itemcount;
1.121 raeburn 3002: return $datatable;
1.118 jms 3003: }
3004:
1.231 raeburn 3005: sub print_selfenrollment {
3006: my ($position,$dom,$settings,$rowtotal) = @_;
3007: my ($css_class,$datatable);
3008: my $itemcount = 1;
3009: my @types = ('official','unofficial','community','textbook');
3010: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3011: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3012: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3013: my @rows;
3014: my $key;
3015: if ($position eq 'top') {
3016: $key = 'admin';
3017: if (ref($rowsref) eq 'ARRAY') {
3018: @rows = @{$rowsref};
3019: }
3020: } elsif ($position eq 'middle') {
3021: $key = 'default';
3022: @rows = ('types','registered','approval','limit');
3023: }
3024: foreach my $row (@rows) {
3025: if (defined($titlesref->{$row})) {
3026: $itemcount ++;
3027: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3028: $datatable .= '<tr'.$css_class.'>'.
3029: '<td>'.$titlesref->{$row}.'</td>'.
3030: '<td class="LC_left_item">'.
3031: '<table><tr>';
3032: my (%current,%currentcap);
3033: if (ref($settings) eq 'HASH') {
3034: if (ref($settings->{$key}) eq 'HASH') {
3035: foreach my $type (@types) {
3036: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3037: $current{$type} = $settings->{$key}->{$type}->{$row};
3038: }
3039: if (($row eq 'limit') && ($key eq 'default')) {
3040: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3041: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3042: }
3043: }
3044: }
3045: }
3046: }
3047: my %roles = (
3048: '0' => &Apache::lonnet::plaintext('dc'),
3049: );
3050:
3051: foreach my $type (@types) {
3052: unless (($row eq 'registered') && ($key eq 'default')) {
3053: $datatable .= '<th>'.&mt($type).'</th>';
3054: }
3055: }
3056: unless (($row eq 'registered') && ($key eq 'default')) {
3057: $datatable .= '</tr><tr>';
3058: }
3059: foreach my $type (@types) {
3060: if ($type eq 'community') {
3061: $roles{'1'} = &mt('Community personnel');
3062: } else {
3063: $roles{'1'} = &mt('Course personnel');
3064: }
3065: $datatable .= '<td style="vertical-align: top">';
3066: if ($position eq 'top') {
3067: my %checked;
3068: if ($current{$type} eq '0') {
3069: $checked{'0'} = ' checked="checked"';
3070: } else {
3071: $checked{'1'} = ' checked="checked"';
3072: }
3073: foreach my $role ('1','0') {
3074: $datatable .= '<span class="LC_nobreak"><label>'.
3075: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3076: 'value="'.$role.'"'.$checked{$role}.' />'.
3077: $roles{$role}.'</label></span> ';
3078: }
3079: } else {
3080: if ($row eq 'types') {
3081: my %checked;
3082: if ($current{$type} =~ /^(all|dom)$/) {
3083: $checked{$1} = ' checked="checked"';
3084: } else {
3085: $checked{''} = ' checked="checked"';
3086: }
3087: foreach my $val ('','dom','all') {
3088: $datatable .= '<span class="LC_nobreak"><label>'.
3089: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3090: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3091: }
3092: } elsif ($row eq 'registered') {
3093: my %checked;
3094: if ($current{$type} eq '1') {
3095: $checked{'1'} = ' checked="checked"';
3096: } else {
3097: $checked{'0'} = ' checked="checked"';
3098: }
3099: foreach my $val ('0','1') {
3100: $datatable .= '<span class="LC_nobreak"><label>'.
3101: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3102: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3103: }
3104: } elsif ($row eq 'approval') {
3105: my %checked;
3106: if ($current{$type} =~ /^([12])$/) {
3107: $checked{$1} = ' checked="checked"';
3108: } else {
3109: $checked{'0'} = ' checked="checked"';
3110: }
3111: for my $val (0..2) {
3112: $datatable .= '<span class="LC_nobreak"><label>'.
3113: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3114: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3115: }
3116: } elsif ($row eq 'limit') {
3117: my %checked;
3118: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3119: $checked{$1} = ' checked="checked"';
3120: } else {
3121: $checked{'none'} = ' checked="checked"';
3122: }
3123: my $cap;
3124: if ($currentcap{$type} =~ /^\d+$/) {
3125: $cap = $currentcap{$type};
3126: }
3127: foreach my $val ('none','allstudents','selfenrolled') {
3128: $datatable .= '<span class="LC_nobreak"><label>'.
3129: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3130: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3131: }
3132: $datatable .= '<br />'.
3133: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3134: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3135: '</span>';
3136: }
3137: }
3138: $datatable .= '</td>';
3139: }
3140: $datatable .= '</tr>';
3141: }
3142: $datatable .= '</table></td></tr>';
3143: }
3144: } elsif ($position eq 'bottom') {
1.235 raeburn 3145: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3146: }
3147: $$rowtotal += $itemcount;
3148: return $datatable;
3149: }
3150:
3151: sub print_validation_rows {
3152: my ($caller,$dom,$settings,$rowtotal) = @_;
3153: my ($itemsref,$namesref,$fieldsref);
3154: if ($caller eq 'selfenroll') {
3155: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3156: } elsif ($caller eq 'requestcourses') {
3157: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3158: }
3159: my %currvalidation;
3160: if (ref($settings) eq 'HASH') {
3161: if (ref($settings->{'validation'}) eq 'HASH') {
3162: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3163: }
1.235 raeburn 3164: }
3165: my $datatable;
3166: my $itemcount = 0;
3167: foreach my $item (@{$itemsref}) {
3168: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3169: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3170: $namesref->{$item}.
3171: '</span></td>'.
3172: '<td class="LC_left_item">';
3173: if (($item eq 'url') || ($item eq 'button')) {
3174: $datatable .= '<span class="LC_nobreak">'.
3175: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3176: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3177: } elsif ($item eq 'fields') {
3178: my @currfields;
3179: if (ref($currvalidation{$item}) eq 'ARRAY') {
3180: @currfields = @{$currvalidation{$item}};
3181: }
3182: foreach my $field (@{$fieldsref}) {
3183: my $check = '';
3184: if (grep(/^\Q$field\E$/,@currfields)) {
3185: $check = ' checked="checked"';
3186: }
3187: $datatable .= '<span class="LC_nobreak"><label>'.
3188: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3189: ' value="'.$field.'"'.$check.' />'.$field.
3190: '</label></span> ';
3191: }
3192: } elsif ($item eq 'markup') {
3193: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3194: $currvalidation{$item}.
1.231 raeburn 3195: '</textarea>';
1.235 raeburn 3196: }
3197: $datatable .= '</td></tr>'."\n";
3198: if (ref($rowtotal)) {
1.231 raeburn 3199: $itemcount ++;
3200: }
3201: }
1.235 raeburn 3202: if ($caller eq 'requestcourses') {
3203: my %currhash;
1.248 raeburn 3204: if (ref($settings) eq 'HASH') {
3205: if (ref($settings->{'validation'}) eq 'HASH') {
3206: if ($settings->{'validation'}{'dc'} ne '') {
3207: $currhash{$settings->{'validation'}{'dc'}} = 1;
3208: }
1.235 raeburn 3209: }
3210: }
3211: my $numinrow = 2;
3212: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3213: 'validationdc',%currhash);
1.247 raeburn 3214: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3215: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3216: if ($numdc > 1) {
1.247 raeburn 3217: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3218: } else {
1.247 raeburn 3219: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3220: }
1.247 raeburn 3221: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3222: $itemcount ++;
3223: }
3224: if (ref($rowtotal)) {
3225: $$rowtotal += $itemcount;
3226: }
1.231 raeburn 3227: return $datatable;
3228: }
3229:
1.137 raeburn 3230: sub print_usersessions {
3231: my ($position,$dom,$settings,$rowtotal) = @_;
3232: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3233: my (%by_ip,%by_location,@intdoms);
3234: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3235:
3236: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3237: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3238: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3239: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3240: my $itemcount = 1;
3241: if ($position eq 'top') {
1.152 raeburn 3242: if (keys(%serverhomes) > 1) {
1.145 raeburn 3243: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 3244: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 3245: } else {
1.140 raeburn 3246: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3247: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3248: }
1.137 raeburn 3249: } else {
1.145 raeburn 3250: if (keys(%by_location) == 0) {
3251: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3252: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3253: } else {
3254: my %lt = &usersession_titles();
3255: my $numinrow = 5;
3256: my $prefix;
3257: my @types;
3258: if ($position eq 'bottom') {
3259: $prefix = 'remote';
3260: @types = ('version','excludedomain','includedomain');
3261: } else {
3262: $prefix = 'hosted';
3263: @types = ('excludedomain','includedomain');
3264: }
3265: my (%current,%checkedon,%checkedoff);
3266: my @lcversions = &Apache::lonnet::all_loncaparevs();
3267: my @locations = sort(keys(%by_location));
3268: foreach my $type (@types) {
3269: $checkedon{$type} = '';
3270: $checkedoff{$type} = ' checked="checked"';
3271: }
3272: if (ref($settings) eq 'HASH') {
3273: if (ref($settings->{$prefix}) eq 'HASH') {
3274: foreach my $key (keys(%{$settings->{$prefix}})) {
3275: $current{$key} = $settings->{$prefix}{$key};
3276: if ($key eq 'version') {
3277: if ($current{$key} ne '') {
3278: $checkedon{$key} = ' checked="checked"';
3279: $checkedoff{$key} = '';
3280: }
3281: } elsif (ref($current{$key}) eq 'ARRAY') {
3282: $checkedon{$key} = ' checked="checked"';
3283: $checkedoff{$key} = '';
3284: }
1.137 raeburn 3285: }
3286: }
3287: }
1.145 raeburn 3288: foreach my $type (@types) {
3289: next if ($type ne 'version' && !@locations);
3290: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3291: $datatable .= '<tr'.$css_class.'>
3292: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3293: <span class="LC_nobreak">
3294: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3295: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3296: if ($type eq 'version') {
3297: my $selector = '<select name="'.$prefix.'_version">';
3298: foreach my $version (@lcversions) {
3299: my $selected = '';
3300: if ($current{'version'} eq $version) {
3301: $selected = ' selected="selected"';
3302: }
3303: $selector .= ' <option value="'.$version.'"'.
3304: $selected.'>'.$version.'</option>';
3305: }
3306: $selector .= '</select> ';
3307: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3308: } else {
3309: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3310: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3311: ' />'.(' 'x2).
3312: '<input type="button" value="'.&mt('uncheck all').'" '.
3313: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3314: "\n".
3315: '</div><div><table>';
3316: my $rem;
3317: for (my $i=0; $i<@locations; $i++) {
3318: my ($showloc,$value,$checkedtype);
3319: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3320: my $ip = $by_location{$locations[$i]}->[0];
3321: if (ref($by_ip{$ip}) eq 'ARRAY') {
3322: $value = join(':',@{$by_ip{$ip}});
3323: $showloc = join(', ',@{$by_ip{$ip}});
3324: if (ref($current{$type}) eq 'ARRAY') {
3325: foreach my $loc (@{$by_ip{$ip}}) {
3326: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3327: $checkedtype = ' checked="checked"';
3328: last;
3329: }
3330: }
1.138 raeburn 3331: }
3332: }
3333: }
1.145 raeburn 3334: $rem = $i%($numinrow);
3335: if ($rem == 0) {
3336: if ($i > 0) {
3337: $datatable .= '</tr>';
3338: }
3339: $datatable .= '<tr>';
3340: }
3341: $datatable .= '<td class="LC_left_item">'.
3342: '<span class="LC_nobreak"><label>'.
3343: '<input type="checkbox" name="'.$prefix.'_'.$type.
3344: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3345: '</label></span></td>';
1.137 raeburn 3346: }
1.145 raeburn 3347: $rem = @locations%($numinrow);
3348: my $colsleft = $numinrow - $rem;
3349: if ($colsleft > 1 ) {
3350: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3351: ' </td>';
3352: } elsif ($colsleft == 1) {
3353: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3354: }
1.145 raeburn 3355: $datatable .= '</tr></table>';
1.137 raeburn 3356: }
1.145 raeburn 3357: $datatable .= '</td></tr>';
3358: $itemcount ++;
1.137 raeburn 3359: }
3360: }
3361: }
3362: $$rowtotal += $itemcount;
3363: return $datatable;
3364: }
3365:
1.138 raeburn 3366: sub build_location_hashes {
3367: my ($intdoms,$by_ip,$by_location) = @_;
3368: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3369: (ref($by_location) eq 'HASH'));
3370: my %iphost = &Apache::lonnet::get_iphost();
3371: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3372: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3373: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3374: foreach my $id (@{$iphost{$primary_ip}}) {
3375: my $intdom = &Apache::lonnet::internet_dom($id);
3376: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3377: push(@{$intdoms},$intdom);
3378: }
3379: }
3380: }
3381: foreach my $ip (keys(%iphost)) {
3382: if (ref($iphost{$ip}) eq 'ARRAY') {
3383: foreach my $id (@{$iphost{$ip}}) {
3384: my $location = &Apache::lonnet::internet_dom($id);
3385: if ($location) {
3386: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3387: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3388: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3389: push(@{$by_ip->{$ip}},$location);
3390: }
3391: } else {
3392: $by_ip->{$ip} = [$location];
3393: }
3394: }
3395: }
3396: }
3397: }
3398: foreach my $ip (sort(keys(%{$by_ip}))) {
3399: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3400: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3401: my $first = $by_ip->{$ip}->[0];
3402: if (ref($by_location->{$first}) eq 'ARRAY') {
3403: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3404: push(@{$by_location->{$first}},$ip);
3405: }
3406: } else {
3407: $by_location->{$first} = [$ip];
3408: }
3409: }
3410: }
3411: return;
3412: }
3413:
1.145 raeburn 3414: sub current_offloads_to {
3415: my ($dom,$settings,$servers) = @_;
3416: my (%spareid,%otherdomconfigs);
1.152 raeburn 3417: if (ref($servers) eq 'HASH') {
1.145 raeburn 3418: foreach my $lonhost (sort(keys(%{$servers}))) {
3419: my $gotspares;
1.152 raeburn 3420: if (ref($settings) eq 'HASH') {
3421: if (ref($settings->{'spares'}) eq 'HASH') {
3422: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3423: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3424: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3425: $gotspares = 1;
3426: }
1.145 raeburn 3427: }
3428: }
3429: unless ($gotspares) {
3430: my $gotspares;
3431: my $serverhomeID =
3432: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3433: my $serverhomedom =
3434: &Apache::lonnet::host_domain($serverhomeID);
3435: if ($serverhomedom ne $dom) {
3436: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3437: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3438: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3439: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3440: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3441: $gotspares = 1;
3442: }
3443: }
3444: } else {
3445: $otherdomconfigs{$serverhomedom} =
3446: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3447: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3448: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3449: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3450: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3451: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3452: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3453: $gotspares = 1;
3454: }
3455: }
3456: }
3457: }
3458: }
3459: }
3460: }
3461: unless ($gotspares) {
3462: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
3463: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3464: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3465: } else {
3466: my $server_hostname = &Apache::lonnet::hostname($lonhost);
3467: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
3468: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
3469: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
3470: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
3471: } else {
1.150 raeburn 3472: my %what = (
3473: spareid => 1,
3474: );
3475: my ($result,$returnhash) =
3476: &Apache::lonnet::get_remote_globals($lonhost,\%what);
3477: if ($result eq 'ok') {
3478: if (ref($returnhash) eq 'HASH') {
3479: if (ref($returnhash->{'spareid'}) eq 'HASH') {
3480: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
3481: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
3482: }
3483: }
1.145 raeburn 3484: }
3485: }
3486: }
3487: }
3488: }
3489: }
3490: return %spareid;
3491: }
3492:
3493: sub spares_row {
1.152 raeburn 3494: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 3495: my $css_class;
3496: my $numinrow = 4;
3497: my $itemcount = 1;
3498: my $datatable;
1.152 raeburn 3499: my %typetitles = &sparestype_titles();
3500: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 3501: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 3502: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
3503: my ($othercontrol,$serverdom);
3504: if ($serverhome ne $server) {
3505: $serverdom = &Apache::lonnet::host_domain($serverhome);
3506: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3507: } else {
3508: $serverdom = &Apache::lonnet::host_domain($server);
3509: if ($serverdom ne $dom) {
3510: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
3511: }
3512: }
3513: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 3514: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3515: $datatable .= '<tr'.$css_class.'>
3516: <td rowspan="2">
1.183 bisitz 3517: <span class="LC_nobreak">'.
3518: &mt('[_1] when busy, offloads to:'
3519: ,'<b>'.$server.'</b>').
3520: "\n";
1.145 raeburn 3521: my (%current,%canselect);
1.152 raeburn 3522: my @choices =
3523: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
3524: foreach my $type ('primary','default') {
3525: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 3526: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
3527: my @spares = @{$spareid->{$server}{$type}};
3528: if (@spares > 0) {
1.152 raeburn 3529: if ($othercontrol) {
3530: $current{$type} = join(', ',@spares);
3531: } else {
3532: $current{$type} .= '<table>';
3533: my $numspares = scalar(@spares);
3534: for (my $i=0; $i<@spares; $i++) {
3535: my $rem = $i%($numinrow);
3536: if ($rem == 0) {
3537: if ($i > 0) {
3538: $current{$type} .= '</tr>';
3539: }
3540: $current{$type} .= '<tr>';
1.145 raeburn 3541: }
1.152 raeburn 3542: $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'".');" /> '.
3543: $spareid->{$server}{$type}[$i].
3544: '</label></td>'."\n";
3545: }
3546: my $rem = @spares%($numinrow);
3547: my $colsleft = $numinrow - $rem;
3548: if ($colsleft > 1 ) {
3549: $current{$type} .= '<td colspan="'.$colsleft.
3550: '" class="LC_left_item">'.
3551: ' </td>';
3552: } elsif ($colsleft == 1) {
3553: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 3554: }
1.152 raeburn 3555: $current{$type} .= '</tr></table>';
1.150 raeburn 3556: }
1.145 raeburn 3557: }
3558: }
3559: if ($current{$type} eq '') {
3560: $current{$type} = &mt('None specified');
3561: }
1.152 raeburn 3562: if ($othercontrol) {
3563: if ($type eq 'primary') {
3564: $canselect{$type} = $othercontrol;
3565: }
3566: } else {
3567: $canselect{$type} =
3568: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
3569: '<select name="newspare_'.$type.'_'.$server.'" '.
3570: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
3571: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
3572: if (@choices > 0) {
3573: foreach my $lonhost (@choices) {
3574: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
3575: }
3576: }
3577: $canselect{$type} .= '</select>'."\n";
3578: }
3579: } else {
3580: $current{$type} = &mt('Could not be determined');
3581: if ($type eq 'primary') {
3582: $canselect{$type} = $othercontrol;
3583: }
1.145 raeburn 3584: }
1.152 raeburn 3585: if ($type eq 'default') {
3586: $datatable .= '<tr'.$css_class.'>';
3587: }
3588: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
3589: '<td>'.$current{$type}.'</td>'."\n".
3590: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 3591: }
3592: $itemcount ++;
3593: }
3594: }
3595: $$rowtotal += $itemcount;
3596: return $datatable;
3597: }
3598:
1.152 raeburn 3599: sub possible_newspares {
3600: my ($server,$currspares,$serverhomes,$altids) = @_;
3601: my $serverhostname = &Apache::lonnet::hostname($server);
3602: my %excluded;
3603: if ($serverhostname ne '') {
3604: %excluded = (
3605: $serverhostname => 1,
3606: );
3607: }
3608: if (ref($currspares) eq 'HASH') {
3609: foreach my $type (keys(%{$currspares})) {
3610: if (ref($currspares->{$type}) eq 'ARRAY') {
3611: if (@{$currspares->{$type}} > 0) {
3612: foreach my $curr (@{$currspares->{$type}}) {
3613: my $hostname = &Apache::lonnet::hostname($curr);
3614: $excluded{$hostname} = 1;
3615: }
3616: }
3617: }
3618: }
3619: }
3620: my @choices;
3621: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
3622: if (keys(%{$serverhomes}) > 1) {
3623: foreach my $name (sort(keys(%{$serverhomes}))) {
3624: unless ($excluded{$name}) {
3625: if (exists($altids->{$serverhomes->{$name}})) {
3626: push(@choices,$altids->{$serverhomes->{$name}});
3627: } else {
3628: push(@choices,$serverhomes->{$name});
1.145 raeburn 3629: }
3630: }
3631: }
3632: }
3633: }
1.152 raeburn 3634: return sort(@choices);
1.145 raeburn 3635: }
3636:
1.150 raeburn 3637: sub print_loadbalancing {
3638: my ($dom,$settings,$rowtotal) = @_;
3639: my $primary_id = &Apache::lonnet::domain($dom,'primary');
3640: my $intdom = &Apache::lonnet::internet_dom($primary_id);
3641: my $numinrow = 1;
3642: my $datatable;
3643: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 3644: my (%currbalancer,%currtargets,%currrules,%existing);
3645: if (ref($settings) eq 'HASH') {
3646: %existing = %{$settings};
3647: }
3648: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
3649: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
3650: \%currtargets,\%currrules);
1.150 raeburn 3651: } else {
3652: return;
3653: }
3654: my ($othertitle,$usertypes,$types) =
3655: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3656: my $rownum = 8;
1.150 raeburn 3657: if (ref($types) eq 'ARRAY') {
3658: $rownum += scalar(@{$types});
3659: }
1.171 raeburn 3660: my @css_class = ('LC_odd_row','LC_even_row');
3661: my $balnum = 0;
3662: my $islast;
3663: my (@toshow,$disabledtext);
3664: if (keys(%currbalancer) > 0) {
3665: @toshow = sort(keys(%currbalancer));
3666: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3667: push(@toshow,'');
3668: }
3669: } else {
3670: @toshow = ('');
3671: $disabledtext = &mt('No existing load balancer');
3672: }
3673: foreach my $lonhost (@toshow) {
3674: if ($balnum == scalar(@toshow)-1) {
3675: $islast = 1;
3676: } else {
3677: $islast = 0;
3678: }
3679: my $cssidx = $balnum%2;
3680: my $targets_div_style = 'display: none';
3681: my $disabled_div_style = 'display: block';
3682: my $homedom_div_style = 'display: none';
3683: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3684: '<td rowspan="'.$rownum.'" valign="top">'.
3685: '<p>';
3686: if ($lonhost eq '') {
1.210 raeburn 3687: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3688: if (keys(%currbalancer) > 0) {
3689: $datatable .= &mt('Add balancer:');
3690: } else {
3691: $datatable .= &mt('Enable balancer:');
3692: }
3693: $datatable .= ' '.
3694: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3695: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3696: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3697: '<option value="" selected="selected">'.&mt('None').
3698: '</option>'."\n";
3699: foreach my $server (sort(keys(%servers))) {
3700: next if ($currbalancer{$server});
3701: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3702: }
1.210 raeburn 3703: $datatable .=
1.171 raeburn 3704: '</select>'."\n".
3705: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3706: } else {
3707: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3708: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3709: &mt('Stop balancing').'</label>'.
3710: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3711: $targets_div_style = 'display: block';
3712: $disabled_div_style = 'display: none';
3713: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3714: $homedom_div_style = 'display: block';
3715: }
3716: }
3717: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3718: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3719: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3720: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3721: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3722: my @sparestypes = ('primary','default');
3723: my %typetitles = &sparestype_titles();
3724: foreach my $sparetype (@sparestypes) {
3725: my $targettable;
3726: for (my $i=0; $i<$numspares; $i++) {
3727: my $checked;
3728: if (ref($currtargets{$lonhost}) eq 'HASH') {
3729: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3730: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3731: $checked = ' checked="checked"';
3732: }
3733: }
3734: }
3735: my ($chkboxval,$disabled);
3736: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3737: $chkboxval = $spares[$i];
3738: }
3739: if (exists($currbalancer{$spares[$i]})) {
3740: $disabled = ' disabled="disabled"';
3741: }
1.210 raeburn 3742: $targettable .=
1.253 raeburn 3743: '<td><span class="LC_nobreak"><label>'.
3744: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 3745: $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 3746: '</span></label></span></td>';
1.171 raeburn 3747: my $rem = $i%($numinrow);
3748: if ($rem == 0) {
3749: if (($i > 0) && ($i < $numspares-1)) {
3750: $targettable .= '</tr>';
3751: }
3752: if ($i < $numspares-1) {
3753: $targettable .= '<tr>';
1.150 raeburn 3754: }
3755: }
3756: }
1.171 raeburn 3757: if ($targettable ne '') {
3758: my $rem = $numspares%($numinrow);
3759: my $colsleft = $numinrow - $rem;
3760: if ($colsleft > 1 ) {
3761: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3762: ' </td>';
3763: } elsif ($colsleft == 1) {
3764: $targettable .= '<td class="LC_left_item"> </td>';
3765: }
3766: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3767: '<table><tr>'.$targettable.'</tr></table><br />';
3768: }
3769: }
3770: $datatable .= '</div></td></tr>'.
3771: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3772: $othertitle,$usertypes,$types,\%servers,
3773: \%currbalancer,$lonhost,
3774: $targets_div_style,$homedom_div_style,
3775: $css_class[$cssidx],$balnum,$islast);
3776: $$rowtotal += $rownum;
3777: $balnum ++;
3778: }
3779: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3780: return $datatable;
3781: }
3782:
3783: sub get_loadbalancers_config {
3784: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3785: return unless ((ref($servers) eq 'HASH') &&
3786: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3787: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3788: if (keys(%{$existing}) > 0) {
3789: my $oldlonhost;
3790: foreach my $key (sort(keys(%{$existing}))) {
3791: if ($key eq 'lonhost') {
3792: $oldlonhost = $existing->{'lonhost'};
3793: $currbalancer->{$oldlonhost} = 1;
3794: } elsif ($key eq 'targets') {
3795: if ($oldlonhost) {
3796: $currtargets->{$oldlonhost} = $existing->{'targets'};
3797: }
3798: } elsif ($key eq 'rules') {
3799: if ($oldlonhost) {
3800: $currrules->{$oldlonhost} = $existing->{'rules'};
3801: }
3802: } elsif (ref($existing->{$key}) eq 'HASH') {
3803: $currbalancer->{$key} = 1;
3804: $currtargets->{$key} = $existing->{$key}{'targets'};
3805: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3806: }
3807: }
1.171 raeburn 3808: } else {
3809: my ($balancerref,$targetsref) =
3810: &Apache::lonnet::get_lonbalancer_config($servers);
3811: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3812: foreach my $server (sort(keys(%{$balancerref}))) {
3813: $currbalancer->{$server} = 1;
3814: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3815: }
3816: }
3817: }
1.171 raeburn 3818: return;
1.150 raeburn 3819: }
3820:
3821: sub loadbalancing_rules {
3822: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3823: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3824: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3825: my $output;
1.171 raeburn 3826: my $num = 0;
1.210 raeburn 3827: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3828: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3829: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3830: foreach my $type (@{$alltypes}) {
1.171 raeburn 3831: $num ++;
1.150 raeburn 3832: my $current;
3833: if (ref($currrules) eq 'HASH') {
3834: $current = $currrules->{$type};
3835: }
1.253 raeburn 3836: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3837: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3838: $current = '';
3839: }
3840: }
3841: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3842: $servers,$currbalancer,$lonhost,$dom,
3843: $targets_div_style,$homedom_div_style,
3844: $css_class,$balnum,$num,$islast);
1.150 raeburn 3845: }
3846: }
3847: return $output;
3848: }
3849:
3850: sub loadbalancing_titles {
3851: my ($dom,$intdom,$usertypes,$types) = @_;
3852: my %othertypes = (
3853: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3854: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3855: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3856: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3857: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3858: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3859: );
1.209 raeburn 3860: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3861: if (ref($types) eq 'ARRAY') {
3862: unshift(@alltypes,@{$types},'default');
3863: }
3864: my %titles;
3865: foreach my $type (@alltypes) {
3866: if ($type =~ /^_LC_/) {
3867: $titles{$type} = $othertypes{$type};
3868: } elsif ($type eq 'default') {
3869: $titles{$type} = &mt('All users from [_1]',$dom);
3870: if (ref($types) eq 'ARRAY') {
3871: if (@{$types} > 0) {
3872: $titles{$type} = &mt('Other users from [_1]',$dom);
3873: }
3874: }
3875: } elsif (ref($usertypes) eq 'HASH') {
3876: $titles{$type} = $usertypes->{$type};
3877: }
3878: }
3879: return (\@alltypes,\%othertypes,\%titles);
3880: }
3881:
3882: sub loadbalance_rule_row {
1.171 raeburn 3883: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3884: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3885: my @rulenames;
1.150 raeburn 3886: my %ruletitles = &offloadtype_text();
1.209 raeburn 3887: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 3888: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 3889: } else {
1.209 raeburn 3890: @rulenames = ('default','homeserver');
3891: if ($type eq '_LC_external') {
3892: push(@rulenames,'externalbalancer');
3893: } else {
3894: push(@rulenames,'specific');
3895: }
3896: push(@rulenames,'none');
1.150 raeburn 3897: }
3898: my $style = $targets_div_style;
1.253 raeburn 3899: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 3900: $style = $homedom_div_style;
3901: }
1.171 raeburn 3902: my $space;
3903: if ($islast && $num == 1) {
3904: $space = '<div display="inline-block"> </div>';
3905: }
1.210 raeburn 3906: my $output =
1.171 raeburn 3907: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3908: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3909: '<td valaign="top">'.$space.
3910: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3911: for (my $i=0; $i<@rulenames; $i++) {
3912: my $rule = $rulenames[$i];
3913: my ($checked,$extra);
3914: if ($rulenames[$i] eq 'default') {
3915: $rule = '';
3916: }
3917: if ($rulenames[$i] eq 'specific') {
3918: if (ref($servers) eq 'HASH') {
3919: my $default;
3920: if (($current ne '') && (exists($servers->{$current}))) {
3921: $checked = ' checked="checked"';
3922: }
3923: unless ($checked) {
3924: $default = ' selected="selected"';
3925: }
1.210 raeburn 3926: $extra =
1.171 raeburn 3927: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3928: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3929: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3930: '<option value=""'.$default.'></option>'."\n";
3931: foreach my $server (sort(keys(%{$servers}))) {
3932: if (ref($currbalancer) eq 'HASH') {
3933: next if (exists($currbalancer->{$server}));
3934: }
1.150 raeburn 3935: my $selected;
1.171 raeburn 3936: if ($server eq $current) {
1.150 raeburn 3937: $selected = ' selected="selected"';
3938: }
1.171 raeburn 3939: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3940: }
3941: $extra .= '</select>';
3942: }
3943: } elsif ($rule eq $current) {
3944: $checked = ' checked="checked"';
3945: }
3946: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3947: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3948: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3949: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 3950: ')"'.$checked.' /> ';
3951: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
3952: $output .= $ruletitles{'particular'};
3953: } else {
3954: $output .= $ruletitles{$rulenames[$i]};
3955: }
3956: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 3957: }
3958: $output .= '</div></td></tr>'."\n";
3959: return $output;
3960: }
3961:
3962: sub offloadtype_text {
3963: my %ruletitles = &Apache::lonlocal::texthash (
3964: 'default' => 'Offloads to default destinations',
3965: 'homeserver' => "Offloads to user's home server",
3966: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3967: 'specific' => 'Offloads to specific server',
1.161 raeburn 3968: 'none' => 'No offload',
1.209 raeburn 3969: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3970: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 3971: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 3972: );
3973: return %ruletitles;
3974: }
3975:
3976: sub sparestype_titles {
3977: my %typestitles = &Apache::lonlocal::texthash (
3978: 'primary' => 'primary',
3979: 'default' => 'default',
3980: );
3981: return %typestitles;
3982: }
3983:
1.28 raeburn 3984: sub contact_titles {
3985: my %titles = &Apache::lonlocal::texthash (
3986: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3987: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3988: 'errormail' => 'Error reports to be e-mailed to',
3989: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3990: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3991: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3992: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3993: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3994: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3995: );
3996: my %short_titles = &Apache::lonlocal::texthash (
3997: adminemail => 'Admin E-mail address',
3998: supportemail => 'Support E-mail',
3999: );
4000: return (\%titles,\%short_titles);
4001: }
4002:
1.72 raeburn 4003: sub tool_titles {
4004: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4005: aboutme => 'Personal web page',
1.86 raeburn 4006: blog => 'Blog',
1.162 raeburn 4007: webdav => 'WebDAV',
1.86 raeburn 4008: portfolio => 'Portfolio',
1.88 bisitz 4009: official => 'Official courses (with institutional codes)',
4010: unofficial => 'Unofficial courses',
1.98 raeburn 4011: community => 'Communities',
1.216 raeburn 4012: textbook => 'Textbook courses',
1.86 raeburn 4013: );
1.72 raeburn 4014: return %titles;
4015: }
4016:
1.101 raeburn 4017: sub courserequest_titles {
4018: my %titles = &Apache::lonlocal::texthash (
4019: official => 'Official',
4020: unofficial => 'Unofficial',
4021: community => 'Communities',
1.216 raeburn 4022: textbook => 'Textbook',
1.101 raeburn 4023: norequest => 'Not allowed',
1.104 raeburn 4024: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4025: validate => 'With validation',
4026: autolimit => 'Numerical limit',
1.103 raeburn 4027: unlimited => '(blank for unlimited)',
1.101 raeburn 4028: );
4029: return %titles;
4030: }
4031:
1.163 raeburn 4032: sub authorrequest_titles {
4033: my %titles = &Apache::lonlocal::texthash (
4034: norequest => 'Not allowed',
4035: approval => 'Approval by Dom. Coord.',
4036: automatic => 'Automatic approval',
4037: );
4038: return %titles;
1.210 raeburn 4039: }
1.163 raeburn 4040:
1.101 raeburn 4041: sub courserequest_conditions {
4042: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4043: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4044: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4045: );
4046: return %conditions;
4047: }
4048:
4049:
1.27 raeburn 4050: sub print_usercreation {
1.30 raeburn 4051: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4052: my $numinrow = 4;
1.28 raeburn 4053: my $datatable;
4054: if ($position eq 'top') {
1.30 raeburn 4055: $$rowtotal ++;
1.34 raeburn 4056: my $rowcount = 0;
1.32 raeburn 4057: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4058: if (ref($rules) eq 'HASH') {
4059: if (keys(%{$rules}) > 0) {
1.32 raeburn 4060: $datatable .= &user_formats_row('username',$settings,$rules,
4061: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4062: $$rowtotal ++;
1.32 raeburn 4063: $rowcount ++;
4064: }
4065: }
4066: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4067: if (ref($idrules) eq 'HASH') {
4068: if (keys(%{$idrules}) > 0) {
4069: $datatable .= &user_formats_row('id',$settings,$idrules,
4070: $idruleorder,$numinrow,$rowcount);
4071: $$rowtotal ++;
4072: $rowcount ++;
1.28 raeburn 4073: }
4074: }
1.39 raeburn 4075: if ($rowcount == 0) {
4076: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4077: $$rowtotal ++;
4078: $rowcount ++;
4079: }
1.34 raeburn 4080: } elsif ($position eq 'middle') {
1.224 raeburn 4081: my @creators = ('author','course','requestcrs');
1.37 raeburn 4082: my ($rules,$ruleorder) =
4083: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4084: my %lt = &usercreation_types();
4085: my %checked;
4086: if (ref($settings) eq 'HASH') {
4087: if (ref($settings->{'cancreate'}) eq 'HASH') {
4088: foreach my $item (@creators) {
4089: $checked{$item} = $settings->{'cancreate'}{$item};
4090: }
4091: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4092: foreach my $item (@creators) {
4093: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4094: $checked{$item} = 'none';
4095: }
4096: }
4097: }
4098: }
4099: my $rownum = 0;
4100: foreach my $item (@creators) {
4101: $rownum ++;
1.224 raeburn 4102: if ($checked{$item} eq '') {
4103: $checked{$item} = 'any';
1.34 raeburn 4104: }
4105: my $css_class;
4106: if ($rownum%2) {
4107: $css_class = '';
4108: } else {
4109: $css_class = ' class="LC_odd_row" ';
4110: }
4111: $datatable .= '<tr'.$css_class.'>'.
4112: '<td><span class="LC_nobreak">'.$lt{$item}.
4113: '</span></td><td align="right">';
1.224 raeburn 4114: my @options = ('any');
4115: if (ref($rules) eq 'HASH') {
4116: if (keys(%{$rules}) > 0) {
4117: push(@options,('official','unofficial'));
1.37 raeburn 4118: }
4119: }
1.224 raeburn 4120: push(@options,'none');
1.37 raeburn 4121: foreach my $option (@options) {
1.50 raeburn 4122: my $type = 'radio';
1.34 raeburn 4123: my $check = ' ';
1.224 raeburn 4124: if ($checked{$item} eq $option) {
4125: $check = ' checked="checked" ';
1.34 raeburn 4126: }
4127: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4128: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4129: $item.'" value="'.$option.'"'.$check.'/> '.
4130: $lt{$option}.'</label> </span>';
4131: }
4132: $datatable .= '</td></tr>';
4133: }
1.28 raeburn 4134: } else {
4135: my @contexts = ('author','course','domain');
4136: my @authtypes = ('int','krb4','krb5','loc');
4137: my %checked;
4138: if (ref($settings) eq 'HASH') {
4139: if (ref($settings->{'authtypes'}) eq 'HASH') {
4140: foreach my $item (@contexts) {
4141: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4142: foreach my $auth (@authtypes) {
4143: if ($settings->{'authtypes'}{$item}{$auth}) {
4144: $checked{$item}{$auth} = ' checked="checked" ';
4145: }
4146: }
4147: }
4148: }
1.27 raeburn 4149: }
1.35 raeburn 4150: } else {
4151: foreach my $item (@contexts) {
1.36 raeburn 4152: foreach my $auth (@authtypes) {
1.35 raeburn 4153: $checked{$item}{$auth} = ' checked="checked" ';
4154: }
4155: }
1.27 raeburn 4156: }
1.28 raeburn 4157: my %title = &context_names();
4158: my %authname = &authtype_names();
4159: my $rownum = 0;
4160: my $css_class;
4161: foreach my $item (@contexts) {
4162: if ($rownum%2) {
4163: $css_class = '';
4164: } else {
4165: $css_class = ' class="LC_odd_row" ';
4166: }
1.30 raeburn 4167: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4168: '<td>'.$title{$item}.
4169: '</td><td class="LC_left_item">'.
4170: '<span class="LC_nobreak">';
4171: foreach my $auth (@authtypes) {
4172: $datatable .= '<label>'.
4173: '<input type="checkbox" name="'.$item.'_auth" '.
4174: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4175: $authname{$auth}.'</label> ';
4176: }
4177: $datatable .= '</span></td></tr>';
4178: $rownum ++;
1.27 raeburn 4179: }
1.30 raeburn 4180: $$rowtotal += $rownum;
1.27 raeburn 4181: }
4182: return $datatable;
4183: }
4184:
1.224 raeburn 4185: sub print_selfcreation {
4186: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4187: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4188: if (ref($settings) eq 'HASH') {
4189: if (ref($settings->{'cancreate'}) eq 'HASH') {
4190: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4191: if (ref($createsettings) eq 'HASH') {
4192: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4193: @selfcreate = @{$createsettings->{'selfcreate'}};
4194: } elsif ($createsettings->{'selfcreate'} ne '') {
4195: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4196: @selfcreate = ('email','login','sso');
4197: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4198: @selfcreate = ($createsettings->{'selfcreate'});
4199: }
4200: }
4201: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4202: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4203: }
4204: }
4205: }
4206: }
4207: my %radiohash;
4208: my $numinrow = 4;
4209: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4210: if ($position eq 'top') {
4211: my %choices = &Apache::lonlocal::texthash (
4212: cancreate_login => 'Institutional Login',
4213: cancreate_sso => 'Institutional Single Sign On',
4214: );
4215: my @toggles = sort(keys(%choices));
4216: my %defaultchecked = (
4217: 'cancreate_login' => 'off',
4218: 'cancreate_sso' => 'off',
4219: );
1.228 raeburn 4220: my ($onclick,$itemcount);
1.224 raeburn 4221: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4222: \%choices,$itemcount,$onclick);
1.228 raeburn 4223: $$rowtotal += $itemcount;
4224:
1.224 raeburn 4225: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4226:
4227: if (ref($usertypes) eq 'HASH') {
4228: if (keys(%{$usertypes}) > 0) {
4229: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4230: $dom,$numinrow,$othertitle,
1.228 raeburn 4231: 'statustocreate',$$rowtotal);
1.224 raeburn 4232: $$rowtotal ++;
4233: }
4234: }
1.240 raeburn 4235: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4236: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4237: $fieldtitles{'inststatus'} = &mt('Institutional status');
4238: my $rem;
4239: my $numperrow = 2;
4240: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4241: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4242: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4243: '<td class="LC_left_item">'."\n".
4244: '<table><tr><td>'."\n";
4245: for (my $i=0; $i<@fields; $i++) {
4246: $rem = $i%($numperrow);
4247: if ($rem == 0) {
4248: if ($i > 0) {
4249: $datatable .= '</tr>';
4250: }
4251: $datatable .= '<tr>';
4252: }
4253: my $currval;
1.248 raeburn 4254: if (ref($createsettings) eq 'HASH') {
4255: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4256: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4257: }
1.240 raeburn 4258: }
4259: $datatable .= '<td class="LC_left_item">'.
4260: '<span class="LC_nobreak">'.
4261: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4262: 'value="'.$currval.'" size="10" /> '.
4263: $fieldtitles{$fields[$i]}.'</span></td>';
4264: }
4265: my $colsleft = $numperrow - $rem;
4266: if ($colsleft > 1 ) {
4267: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4268: ' </td>';
4269: } elsif ($colsleft == 1) {
4270: $datatable .= '<td class="LC_left_item"> </td>';
4271: }
4272: $datatable .= '</tr></table></td></tr>';
4273: $$rowtotal ++;
1.224 raeburn 4274: } elsif ($position eq 'middle') {
4275: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4276: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4277: $usertypes->{'default'} = $othertitle;
4278: if (ref($types) eq 'ARRAY') {
4279: push(@{$types},'default');
4280: $usertypes->{'default'} = $othertitle;
4281: foreach my $status (@{$types}) {
4282: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4283: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4284: $$rowtotal ++;
1.224 raeburn 4285: }
4286: }
4287: } else {
1.236 raeburn 4288: my %choices = &Apache::lonlocal::texthash (
4289: cancreate_email => 'E-mail address as username',
4290: );
4291: my @toggles = sort(keys(%choices));
4292: my %defaultchecked = (
4293: 'cancreate_email' => 'off',
4294: );
4295: my $itemcount = 0;
4296: my $display = 'none';
4297: if (grep(/^\Qemail\E$/,@selfcreate)) {
4298: $display = 'block';
4299: }
4300: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4301: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4303: my $usertypes = {};
4304: my $order = [];
4305: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4306: $usertypes = $domdefaults{'inststatustypes'};
4307: $order = $domdefaults{'inststatusguest'};
4308: }
4309: if (ref($order) eq 'ARRAY') {
4310: push(@{$order},'default');
4311: if (@{$order} > 1) {
4312: $usertypes->{'default'} = &mt('Other users');
4313: $additional .= '<table><tr>';
4314: foreach my $status (@{$order}) {
4315: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4316: }
4317: $additional .= '</tr><tr>';
4318: foreach my $status (@{$order}) {
4319: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4320: }
1.236 raeburn 4321: $additional .= '</tr></table>';
1.224 raeburn 4322: } else {
1.236 raeburn 4323: $usertypes->{'default'} = &mt('All users');
4324: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4325: }
4326: }
1.236 raeburn 4327: $additional .= '</div>'."\n";
4328:
4329: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4330: \%choices,$$rowtotal,$onclick,$additional);
4331: $$rowtotal ++;
1.236 raeburn 4332: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4333: $$rowtotal ++;
1.224 raeburn 4334: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4335: $numinrow = 1;
1.236 raeburn 4336: if (ref($order) eq 'ARRAY') {
4337: foreach my $status (@{$order}) {
1.228 raeburn 4338: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4339: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4340: $$rowtotal ++;
4341: }
4342: }
1.224 raeburn 4343: my ($emailrules,$emailruleorder) =
4344: &Apache::lonnet::inst_userrules($dom,'email');
4345: if (ref($emailrules) eq 'HASH') {
4346: if (keys(%{$emailrules}) > 0) {
4347: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4348: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4349: $$rowtotal ++;
4350: }
4351: }
1.228 raeburn 4352: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4353: }
4354: return $datatable;
4355: }
4356:
1.236 raeburn 4357: sub email_as_username {
4358: my ($rowtotal,$processing,$type) = @_;
4359: my %choices =
4360: &Apache::lonlocal::texthash (
4361: automatic => 'Automatic approval',
4362: approval => 'Queued for approval',
4363: );
4364: my $output;
4365: foreach my $option ('automatic','approval') {
4366: my $checked;
4367: if (ref($processing) eq 'HASH') {
4368: if ($type eq '') {
4369: if (!exists($processing->{'default'})) {
4370: if ($option eq 'automatic') {
4371: $checked = ' checked="checked"';
4372: }
4373: } else {
4374: if ($processing->{'default'} eq $option) {
4375: $checked = ' checked="checked"';
4376: }
4377: }
4378: } else {
4379: if (!exists($processing->{$type})) {
4380: if ($option eq 'automatic') {
4381: $checked = ' checked="checked"';
4382: }
4383: } else {
4384: if ($processing->{$type} eq $option) {
4385: $checked = ' checked="checked"';
4386: }
4387: }
4388: }
4389: } elsif ($option eq 'automatic') {
4390: $checked = ' checked="checked"';
4391: }
4392: my $name = 'cancreate_emailprocess';
4393: if (($type ne '') && ($type ne 'default')) {
4394: $name .= '_'.$type;
4395: }
4396: $output .= '<span class="LC_nobreak"><label>'.
4397: '<input type="radio" name="'.$name.'"'.
4398: $checked.' value="'.$option.'" />'.
4399: $choices{$option}.'</label></span>';
4400: if ($type eq '') {
4401: $output .= ' ';
4402: } else {
4403: $output .= '<br />';
4404: }
4405: }
4406: $$rowtotal ++;
4407: return $output;
4408: }
4409:
1.165 raeburn 4410: sub captcha_choice {
1.169 raeburn 4411: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 4412: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
4413: my %lt = &captcha_phrases();
4414: $keyentry = 'hidden';
4415: if ($context eq 'cancreate') {
1.224 raeburn 4416: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4417: } elsif ($context eq 'login') {
4418: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4419: }
4420: if (ref($settings) eq 'HASH') {
4421: if ($settings->{'captcha'}) {
4422: $checked{$settings->{'captcha'}} = ' checked="checked"';
4423: } else {
4424: $checked{'original'} = ' checked="checked"';
4425: }
4426: if ($settings->{'captcha'} eq 'recaptcha') {
4427: $pubtext = $lt{'pub'};
4428: $privtext = $lt{'priv'};
4429: $keyentry = 'text';
4430: }
4431: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4432: $currpub = $settings->{'recaptchakeys'}{'public'};
4433: $currpriv = $settings->{'recaptchakeys'}{'private'};
4434: }
4435: } else {
4436: $checked{'original'} = ' checked="checked"';
4437: }
1.169 raeburn 4438: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4439: my $output = '<tr'.$css_class.'>'.
4440: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4441: '<table><tr><td>'."\n";
4442: foreach my $option ('original','recaptcha','notused') {
4443: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4444: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4445: $lt{$option}.'</label></span>';
4446: unless ($option eq 'notused') {
4447: $output .= (' 'x2)."\n";
4448: }
4449: }
4450: #
4451: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
4452: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 4453: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 4454: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 4455: #
1.165 raeburn 4456: $output .= '</td></tr>'."\n".
4457: '<tr><td>'."\n".
4458: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
4459: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
4460: $currpub.'" size="40" /></span><br />'."\n".
4461: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
4462: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
4463: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
4464: '</td></tr>';
4465: return $output;
4466: }
4467:
1.32 raeburn 4468: sub user_formats_row {
4469: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
4470: my $output;
4471: my %text = (
4472: 'username' => 'new usernames',
4473: 'id' => 'IDs',
1.45 raeburn 4474: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 4475: );
4476: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4477: $output = '<tr '.$css_class.'>'.
1.63 raeburn 4478: '<td><span class="LC_nobreak">';
4479: if ($type eq 'email') {
4480: $output .= &mt("Formats disallowed for $text{$type}: ");
4481: } else {
4482: $output .= &mt("Format rules to check for $text{$type}: ");
4483: }
4484: $output .= '</span></td>'.
4485: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 4486: my $rem;
4487: if (ref($ruleorder) eq 'ARRAY') {
4488: for (my $i=0; $i<@{$ruleorder}; $i++) {
4489: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
4490: my $rem = $i%($numinrow);
4491: if ($rem == 0) {
4492: if ($i > 0) {
4493: $output .= '</tr>';
4494: }
4495: $output .= '<tr>';
4496: }
4497: my $check = ' ';
1.39 raeburn 4498: if (ref($settings) eq 'HASH') {
4499: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
4500: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
4501: $check = ' checked="checked" ';
4502: }
1.27 raeburn 4503: }
4504: }
4505: $output .= '<td class="LC_left_item">'.
4506: '<span class="LC_nobreak"><label>'.
1.32 raeburn 4507: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 4508: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
4509: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
4510: }
4511: }
4512: $rem = @{$ruleorder}%($numinrow);
4513: }
4514: my $colsleft = $numinrow - $rem;
4515: if ($colsleft > 1 ) {
4516: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4517: ' </td>';
4518: } elsif ($colsleft == 1) {
4519: $output .= '<td class="LC_left_item"> </td>';
4520: }
4521: $output .= '</tr></table></td></tr>';
4522: return $output;
4523: }
4524:
1.34 raeburn 4525: sub usercreation_types {
4526: my %lt = &Apache::lonlocal::texthash (
4527: author => 'When adding a co-author',
4528: course => 'When adding a user to a course',
1.100 raeburn 4529: requestcrs => 'When requesting a course',
1.34 raeburn 4530: any => 'Any',
4531: official => 'Institutional only ',
4532: unofficial => 'Non-institutional only',
4533: none => 'None',
4534: );
4535: return %lt;
1.48 raeburn 4536: }
1.34 raeburn 4537:
1.224 raeburn 4538: sub selfcreation_types {
4539: my %lt = &Apache::lonlocal::texthash (
4540: selfcreate => 'User creates own account',
4541: any => 'Any',
4542: official => 'Institutional only ',
4543: unofficial => 'Non-institutional only',
4544: email => 'E-mail address',
4545: login => 'Institutional Login',
4546: sso => 'SSO',
4547: );
4548: }
4549:
1.28 raeburn 4550: sub authtype_names {
4551: my %lt = &Apache::lonlocal::texthash(
4552: int => 'Internal',
4553: krb4 => 'Kerberos 4',
4554: krb5 => 'Kerberos 5',
4555: loc => 'Local',
4556: );
4557: return %lt;
4558: }
4559:
4560: sub context_names {
4561: my %context_title = &Apache::lonlocal::texthash(
4562: author => 'Creating users when an Author',
4563: course => 'Creating users when in a course',
4564: domain => 'Creating users when a Domain Coordinator',
4565: );
4566: return %context_title;
4567: }
4568:
1.33 raeburn 4569: sub print_usermodification {
4570: my ($position,$dom,$settings,$rowtotal) = @_;
4571: my $numinrow = 4;
4572: my ($context,$datatable,$rowcount);
4573: if ($position eq 'top') {
4574: $rowcount = 0;
4575: $context = 'author';
4576: foreach my $role ('ca','aa') {
4577: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4578: $numinrow,$rowcount);
4579: $$rowtotal ++;
4580: $rowcount ++;
4581: }
1.230 raeburn 4582: } elsif ($position eq 'bottom') {
1.33 raeburn 4583: $context = 'course';
4584: $rowcount = 0;
4585: foreach my $role ('st','ep','ta','in','cr') {
4586: $datatable .= &modifiable_userdata_row($context,$role,$settings,
4587: $numinrow,$rowcount);
4588: $$rowtotal ++;
4589: $rowcount ++;
4590: }
4591: }
4592: return $datatable;
4593: }
4594:
1.43 raeburn 4595: sub print_defaults {
1.236 raeburn 4596: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 4597: my $rownum = 0;
4598: my ($datatable,$css_class);
1.236 raeburn 4599: if ($position eq 'top') {
4600: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
4601: 'datelocale_def','portal_def');
4602: my %defaults;
4603: if (ref($settings) eq 'HASH') {
4604: %defaults = %{$settings};
1.43 raeburn 4605: } else {
1.236 raeburn 4606: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
4607: foreach my $item (@items) {
4608: $defaults{$item} = $domdefaults{$item};
4609: }
1.43 raeburn 4610: }
1.236 raeburn 4611: my $titles = &defaults_titles($dom);
4612: foreach my $item (@items) {
4613: if ($rownum%2) {
4614: $css_class = '';
4615: } else {
4616: $css_class = ' class="LC_odd_row" ';
4617: }
4618: $datatable .= '<tr'.$css_class.'>'.
4619: '<td><span class="LC_nobreak">'.$titles->{$item}.
4620: '</span></td><td class="LC_right_item" colspan="3">';
4621: if ($item eq 'auth_def') {
4622: my @authtypes = ('internal','krb4','krb5','localauth');
4623: my %shortauth = (
4624: internal => 'int',
4625: krb4 => 'krb4',
4626: krb5 => 'krb5',
4627: localauth => 'loc'
4628: );
4629: my %authnames = &authtype_names();
4630: foreach my $auth (@authtypes) {
4631: my $checked = ' ';
4632: if ($defaults{$item} eq $auth) {
4633: $checked = ' checked="checked" ';
4634: }
4635: $datatable .= '<label><input type="radio" name="'.$item.
4636: '" value="'.$auth.'"'.$checked.'/>'.
4637: $authnames{$shortauth{$auth}}.'</label> ';
4638: }
4639: } elsif ($item eq 'timezone_def') {
4640: my $includeempty = 1;
4641: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
4642: } elsif ($item eq 'datelocale_def') {
4643: my $includeempty = 1;
4644: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
4645: } elsif ($item eq 'lang_def') {
4646: my %langchoices = &get_languages_hash();
4647: $langchoices{''} = 'No language preference';
4648: %langchoices = &Apache::lonlocal::texthash(%langchoices);
4649: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
4650: \%langchoices);
4651: } else {
4652: my $size;
4653: if ($item eq 'portal_def') {
4654: $size = ' size="25"';
4655: }
4656: $datatable .= '<input type="text" name="'.$item.'" value="'.
4657: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 4658: }
1.236 raeburn 4659: $datatable .= '</td></tr>';
4660: $rownum ++;
4661: }
4662: } else {
4663: my (%defaults);
4664: if (ref($settings) eq 'HASH') {
4665: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
4666: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
4667: my $maxnum = @{$settings->{'inststatusorder'}};
4668: for (my $i=0; $i<$maxnum; $i++) {
4669: $css_class = $rownum%2?' class="LC_odd_row"':'';
4670: my $item = $settings->{'inststatusorder'}->[$i];
4671: my $title = $settings->{'inststatustypes'}->{$item};
4672: my $guestok;
4673: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
4674: $guestok = 1;
4675: }
4676: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
4677: $datatable .= '<tr'.$css_class.'>'.
4678: '<td><span class="LC_nobreak">'.
4679: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
4680: for (my $k=0; $k<=$maxnum; $k++) {
4681: my $vpos = $k+1;
4682: my $selstr;
4683: if ($k == $i) {
4684: $selstr = ' selected="selected" ';
4685: }
4686: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4687: }
4688: my ($checkedon,$checkedoff);
4689: $checkedoff = ' checked="checked"';
4690: if ($guestok) {
4691: $checkedon = $checkedoff;
4692: $checkedoff = '';
4693: }
4694: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
4695: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
4696: &mt('delete').'</span></td>'.
4697: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
4698: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
4699: '</span></td>'.
4700: '<td class="LC_right_item"><span class="LC_nobreak">'.
4701: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
4702: &mt('Yes').'</label>'.(' 'x2).
4703: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
4704: &mt('No').'</label></span></td></tr>';
4705: }
4706: $css_class = $rownum%2?' class="LC_odd_row"':'';
4707: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
4708: $datatable .= '<tr '.$css_class.'>'.
4709: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
4710: for (my $k=0; $k<=$maxnum; $k++) {
4711: my $vpos = $k+1;
4712: my $selstr;
4713: if ($k == $maxnum) {
4714: $selstr = ' selected="selected" ';
4715: }
4716: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4717: }
4718: $datatable .= '</select> '.&mt('Internal ID:').
4719: '<input type="text" size="10" name="addinststatus" value="" /></span>'.
4720: ' '.&mt('(new)').
4721: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
4722: &mt('Name displayed:').
4723: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
4724: '<td class="LC_right_item"><span class="LC_nobreak">'.
4725: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
4726: &mt('Yes').'</label>'.(' 'x2).
4727: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
4728: &mt('No').'</label></span></td></tr>';
4729: '</tr>'."\n";
4730: $rownum ++;
1.141 raeburn 4731: }
1.43 raeburn 4732: }
4733: }
4734: $$rowtotal += $rownum;
4735: return $datatable;
4736: }
4737:
1.168 raeburn 4738: sub get_languages_hash {
4739: my %langchoices;
4740: foreach my $id (&Apache::loncommon::languageids()) {
4741: my $code = &Apache::loncommon::supportedlanguagecode($id);
4742: if ($code ne '') {
4743: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
4744: }
4745: }
4746: return %langchoices;
4747: }
4748:
1.43 raeburn 4749: sub defaults_titles {
1.141 raeburn 4750: my ($dom) = @_;
1.43 raeburn 4751: my %titles = &Apache::lonlocal::texthash (
4752: 'auth_def' => 'Default authentication type',
4753: 'auth_arg_def' => 'Default authentication argument',
4754: 'lang_def' => 'Default language',
1.54 raeburn 4755: 'timezone_def' => 'Default timezone',
1.68 raeburn 4756: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 4757: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 4758: );
1.141 raeburn 4759: if ($dom) {
4760: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
4761: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
4762: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
4763: $protocol = 'http' if ($protocol ne 'https');
4764: if ($uint_dom) {
4765: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
4766: $uint_dom);
4767: }
4768: }
1.43 raeburn 4769: return (\%titles);
4770: }
4771:
1.46 raeburn 4772: sub print_scantronformat {
4773: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
4774: my $itemcount = 1;
1.60 raeburn 4775: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
4776: %confhash);
1.46 raeburn 4777: my $switchserver = &check_switchserver($dom,$confname);
4778: my %lt = &Apache::lonlocal::texthash (
1.95 www 4779: default => 'Default bubblesheet format file error',
4780: custom => 'Custom bubblesheet format file error',
1.46 raeburn 4781: );
4782: my %scantronfiles = (
4783: default => 'default.tab',
4784: custom => 'custom.tab',
4785: );
4786: foreach my $key (keys(%scantronfiles)) {
4787: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
4788: .$scantronfiles{$key};
4789: }
4790: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
4791: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
4792: if (!$switchserver) {
4793: my $servadm = $r->dir_config('lonAdmEMail');
4794: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
4795: if ($configuserok eq 'ok') {
4796: if ($author_ok eq 'ok') {
4797: my %legacyfile = (
4798: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
4799: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
4800: );
4801: my %md5chk;
4802: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4803: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
4804: chomp($md5chk{$type});
1.46 raeburn 4805: }
4806: if ($md5chk{'default'} ne $md5chk{'custom'}) {
4807: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 4808: ($scantronurls{$type},my $error) =
1.46 raeburn 4809: &legacy_scantronformat($r,$dom,$confname,
4810: $type,$legacyfile{$type},
4811: $scantronurls{$type},
4812: $scantronfiles{$type});
1.60 raeburn 4813: if ($error ne '') {
4814: $error{$type} = $error;
4815: }
4816: }
4817: if (keys(%error) == 0) {
4818: $is_custom = 1;
4819: $confhash{'scantron'}{'scantronformat'} =
4820: $scantronurls{'custom'};
4821: my $putresult =
4822: &Apache::lonnet::put_dom('configuration',
4823: \%confhash,$dom);
4824: if ($putresult ne 'ok') {
4825: $error{'custom'} =
4826: '<span class="LC_error">'.
4827: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4828: }
1.46 raeburn 4829: }
4830: } else {
1.60 raeburn 4831: ($scantronurls{'default'},my $error) =
1.46 raeburn 4832: &legacy_scantronformat($r,$dom,$confname,
4833: 'default',$legacyfile{'default'},
4834: $scantronurls{'default'},
4835: $scantronfiles{'default'});
1.60 raeburn 4836: if ($error eq '') {
4837: $confhash{'scantron'}{'scantronformat'} = '';
4838: my $putresult =
4839: &Apache::lonnet::put_dom('configuration',
4840: \%confhash,$dom);
4841: if ($putresult ne 'ok') {
4842: $error{'default'} =
4843: '<span class="LC_error">'.
4844: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
4845: }
4846: } else {
4847: $error{'default'} = $error;
4848: }
1.46 raeburn 4849: }
4850: }
4851: }
4852: } else {
1.95 www 4853: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 4854: }
4855: }
4856: if (ref($settings) eq 'HASH') {
4857: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
4858: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
4859: if ((!@info) || ($info[0] eq 'no_such_dir')) {
4860: $scantronurl = '';
4861: } else {
4862: $scantronurl = $settings->{'scantronformat'};
4863: }
4864: $is_custom = 1;
4865: } else {
4866: $scantronurl = $scantronurls{'default'};
4867: }
4868: } else {
1.60 raeburn 4869: if ($is_custom) {
4870: $scantronurl = $scantronurls{'custom'};
4871: } else {
4872: $scantronurl = $scantronurls{'default'};
4873: }
1.46 raeburn 4874: }
4875: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4876: $datatable .= '<tr'.$css_class.'>';
4877: if (!$is_custom) {
1.65 raeburn 4878: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
4879: '<span class="LC_nobreak">';
1.46 raeburn 4880: if ($scantronurl) {
1.199 raeburn 4881: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
4882: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 4883: } else {
4884: $datatable = &mt('File unavailable for display');
4885: }
1.65 raeburn 4886: $datatable .= '</span></td>';
1.60 raeburn 4887: if (keys(%error) == 0) {
4888: $datatable .= '<td valign="bottom">';
4889: if (!$switchserver) {
4890: $datatable .= &mt('Upload:').'<br />';
4891: }
4892: } else {
4893: my $errorstr;
4894: foreach my $key (sort(keys(%error))) {
4895: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4896: }
4897: $datatable .= '<td>'.$errorstr;
4898: }
1.46 raeburn 4899: } else {
4900: if (keys(%error) > 0) {
4901: my $errorstr;
4902: foreach my $key (sort(keys(%error))) {
4903: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
4904: }
1.60 raeburn 4905: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4906: } elsif ($scantronurl) {
1.199 raeburn 4907: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4908: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4909: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4910: $link.
4911: '<label><input type="checkbox" name="scantronformat_del"'.
4912: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4913: '<td><span class="LC_nobreak"> '.
4914: &mt('Replace:').'</span><br />';
1.46 raeburn 4915: }
4916: }
4917: if (keys(%error) == 0) {
4918: if ($switchserver) {
4919: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4920: } else {
1.65 raeburn 4921: $datatable .='<span class="LC_nobreak"> '.
4922: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4923: }
4924: }
4925: $datatable .= '</td></tr>';
4926: $$rowtotal ++;
4927: return $datatable;
4928: }
4929:
4930: sub legacy_scantronformat {
4931: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4932: my ($url,$error);
4933: my @statinfo = &Apache::lonnet::stat_file($newurl);
4934: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4935: (my $result,$url) =
4936: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4937: '','',$newfile);
4938: if ($result ne 'ok') {
1.130 raeburn 4939: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4940: }
4941: }
4942: return ($url,$error);
4943: }
1.43 raeburn 4944:
1.49 raeburn 4945: sub print_coursecategories {
1.57 raeburn 4946: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4947: my $datatable;
4948: if ($position eq 'top') {
1.238 raeburn 4949: my (%checked);
4950: my @catitems = ('unauth','auth');
4951: my @cattypes = ('std','domonly','codesrch','none');
4952: $checked{'unauth'} = 'std';
4953: $checked{'auth'} = 'std';
4954: if (ref($settings) eq 'HASH') {
4955: foreach my $type (@cattypes) {
4956: if ($type eq $settings->{'unauth'}) {
4957: $checked{'unauth'} = $type;
4958: }
4959: if ($type eq $settings->{'auth'}) {
4960: $checked{'auth'} = $type;
4961: }
4962: }
4963: }
4964: my %lt = &Apache::lonlocal::texthash (
4965: unauth => 'Catalog type for unauthenticated users',
4966: auth => 'Catalog type for authenticated users',
4967: none => 'No catalog',
4968: std => 'Standard catalog',
4969: domonly => 'Domain-only catalog',
4970: codesrch => "Code search form",
4971: );
4972: my $itemcount = 0;
4973: foreach my $item (@catitems) {
4974: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
4975: $datatable .= '<tr '.$css_class.'>'.
4976: '<td>'.$lt{$item}.'</td>'.
4977: '<td class="LC_right_item"><span class="LC_nobreak">';
4978: foreach my $type (@cattypes) {
4979: my $ischecked;
4980: if ($checked{$item} eq $type) {
4981: $ischecked=' checked="checked"';
4982: }
4983: $datatable .= '<label>'.
4984: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
4985: ' />'.$lt{$type}.'</label> ';
4986: }
4987: $datatable .= '</td></tr>';
4988: $itemcount ++;
4989: }
4990: $$rowtotal += $itemcount;
4991: } elsif ($position eq 'middle') {
1.57 raeburn 4992: my $toggle_cats_crs = ' ';
4993: my $toggle_cats_dom = ' checked="checked" ';
4994: my $can_cat_crs = ' ';
4995: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4996: my $toggle_catscomm_comm = ' ';
4997: my $toggle_catscomm_dom = ' checked="checked" ';
4998: my $can_catcomm_comm = ' ';
4999: my $can_catcomm_dom = ' checked="checked" ';
5000:
1.57 raeburn 5001: if (ref($settings) eq 'HASH') {
5002: if ($settings->{'togglecats'} eq 'crs') {
5003: $toggle_cats_crs = $toggle_cats_dom;
5004: $toggle_cats_dom = ' ';
5005: }
5006: if ($settings->{'categorize'} eq 'crs') {
5007: $can_cat_crs = $can_cat_dom;
5008: $can_cat_dom = ' ';
5009: }
1.120 raeburn 5010: if ($settings->{'togglecatscomm'} eq 'comm') {
5011: $toggle_catscomm_comm = $toggle_catscomm_dom;
5012: $toggle_catscomm_dom = ' ';
5013: }
5014: if ($settings->{'categorizecomm'} eq 'comm') {
5015: $can_catcomm_comm = $can_catcomm_dom;
5016: $can_catcomm_dom = ' ';
5017: }
1.57 raeburn 5018: }
5019: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5020: togglecats => 'Show/Hide a course in catalog',
5021: togglecatscomm => 'Show/Hide a community in catalog',
5022: categorize => 'Assign a category to a course',
5023: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5024: );
5025: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5026: dom => 'Set in Domain',
5027: crs => 'Set in Course',
5028: comm => 'Set in Community',
1.57 raeburn 5029: );
5030: $datatable = '<tr class="LC_odd_row">'.
5031: '<td>'.$title{'togglecats'}.'</td>'.
5032: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5033: '<input type="radio" name="togglecats"'.
5034: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5035: '<label><input type="radio" name="togglecats"'.
5036: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5037: '</tr><tr>'.
5038: '<td>'.$title{'categorize'}.'</td>'.
5039: '<td class="LC_right_item"><span class="LC_nobreak">'.
5040: '<label><input type="radio" name="categorize"'.
5041: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5042: '<label><input type="radio" name="categorize"'.
5043: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5044: '</tr><tr class="LC_odd_row">'.
5045: '<td>'.$title{'togglecatscomm'}.'</td>'.
5046: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5047: '<input type="radio" name="togglecatscomm"'.
5048: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5049: '<label><input type="radio" name="togglecatscomm"'.
5050: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5051: '</tr><tr>'.
5052: '<td>'.$title{'categorizecomm'}.'</td>'.
5053: '<td class="LC_right_item"><span class="LC_nobreak">'.
5054: '<label><input type="radio" name="categorizecomm"'.
5055: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5056: '<label><input type="radio" name="categorizecomm"'.
5057: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5058: '</tr>';
1.120 raeburn 5059: $$rowtotal += 4;
1.57 raeburn 5060: } else {
5061: my $css_class;
5062: my $itemcount = 1;
5063: my $cathash;
5064: if (ref($settings) eq 'HASH') {
5065: $cathash = $settings->{'cats'};
5066: }
5067: if (ref($cathash) eq 'HASH') {
5068: my (@cats,@trails,%allitems,%idx,@jsarray);
5069: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5070: \%allitems,\%idx,\@jsarray);
5071: my $maxdepth = scalar(@cats);
5072: my $colattrib = '';
5073: if ($maxdepth > 2) {
5074: $colattrib = ' colspan="2" ';
5075: }
5076: my @path;
5077: if (@cats > 0) {
5078: if (ref($cats[0]) eq 'ARRAY') {
5079: my $numtop = @{$cats[0]};
5080: my $maxnum = $numtop;
1.120 raeburn 5081: my %default_names = (
5082: instcode => &mt('Official courses'),
5083: communities => &mt('Communities'),
5084: );
5085:
5086: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5087: ($cathash->{'instcode::0'} eq '') ||
5088: (!grep(/^communities$/,@{$cats[0]})) ||
5089: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5090: $maxnum ++;
5091: }
5092: my $lastidx;
5093: for (my $i=0; $i<$numtop; $i++) {
5094: my $parent = $cats[0][$i];
5095: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5096: my $item = &escape($parent).'::0';
5097: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5098: $lastidx = $idx{$item};
5099: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5100: .'<select name="'.$item.'"'.$chgstr.'>';
5101: for (my $k=0; $k<=$maxnum; $k++) {
5102: my $vpos = $k+1;
5103: my $selstr;
5104: if ($k == $i) {
5105: $selstr = ' selected="selected" ';
5106: }
5107: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5108: }
1.214 raeburn 5109: $datatable .= '</select></span></td><td>';
1.120 raeburn 5110: if ($parent eq 'instcode' || $parent eq 'communities') {
5111: $datatable .= '<span class="LC_nobreak">'
5112: .$default_names{$parent}.'</span>';
5113: if ($parent eq 'instcode') {
5114: $datatable .= '<br /><span class="LC_nobreak">('
5115: .&mt('with institutional codes')
5116: .')</span></td><td'.$colattrib.'>';
5117: } else {
5118: $datatable .= '<table><tr><td>';
5119: }
5120: $datatable .= '<span class="LC_nobreak">'
5121: .'<label><input type="radio" name="'
5122: .$parent.'" value="1" checked="checked" />'
5123: .&mt('Display').'</label>';
5124: if ($parent eq 'instcode') {
5125: $datatable .= ' ';
5126: } else {
5127: $datatable .= '</span></td></tr><tr><td>'
5128: .'<span class="LC_nobreak">';
5129: }
5130: $datatable .= '<label><input type="radio" name="'
5131: .$parent.'" value="0" />'
5132: .&mt('Do not display').'</label></span>';
5133: if ($parent eq 'communities') {
5134: $datatable .= '</td></tr></table>';
5135: }
5136: $datatable .= '</td>';
1.57 raeburn 5137: } else {
5138: $datatable .= $parent
1.214 raeburn 5139: .' <span class="LC_nobreak"><label>'
5140: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5141: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5142: }
5143: my $depth = 1;
5144: push(@path,$parent);
5145: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5146: pop(@path);
5147: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5148: $itemcount ++;
5149: }
1.48 raeburn 5150: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5151: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5152: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5153: for (my $k=0; $k<=$maxnum; $k++) {
5154: my $vpos = $k+1;
5155: my $selstr;
1.57 raeburn 5156: if ($k == $numtop) {
1.48 raeburn 5157: $selstr = ' selected="selected" ';
5158: }
5159: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5160: }
1.59 bisitz 5161: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5162: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5163: .'</tr>'."\n";
1.48 raeburn 5164: $itemcount ++;
1.120 raeburn 5165: foreach my $default ('instcode','communities') {
5166: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5167: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5168: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5169: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5170: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5171: for (my $k=0; $k<=$maxnum; $k++) {
5172: my $vpos = $k+1;
5173: my $selstr;
5174: if ($k == $maxnum) {
5175: $selstr = ' selected="selected" ';
5176: }
5177: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5178: }
1.120 raeburn 5179: $datatable .= '</select></span></td>'.
5180: '<td><span class="LC_nobreak">'.
5181: $default_names{$default}.'</span>';
5182: if ($default eq 'instcode') {
5183: $datatable .= '<br /><span class="LC_nobreak">('
5184: .&mt('with institutional codes').')</span>';
5185: }
5186: $datatable .= '</td>'
5187: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5188: .&mt('Display').'</label> '
5189: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5190: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5191: }
5192: }
5193: }
1.57 raeburn 5194: } else {
5195: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5196: }
5197: } else {
1.238 raeburn 5198: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5199: .&initialize_categories($itemcount);
1.48 raeburn 5200: }
1.57 raeburn 5201: $$rowtotal += $itemcount;
1.48 raeburn 5202: }
5203: return $datatable;
5204: }
5205:
1.69 raeburn 5206: sub print_serverstatuses {
5207: my ($dom,$settings,$rowtotal) = @_;
5208: my $datatable;
5209: my @pages = &serverstatus_pages();
5210: my (%namedaccess,%machineaccess);
5211: foreach my $type (@pages) {
5212: $namedaccess{$type} = '';
5213: $machineaccess{$type}= '';
5214: }
5215: if (ref($settings) eq 'HASH') {
5216: foreach my $type (@pages) {
5217: if (exists($settings->{$type})) {
5218: if (ref($settings->{$type}) eq 'HASH') {
5219: foreach my $key (keys(%{$settings->{$type}})) {
5220: if ($key eq 'namedusers') {
5221: $namedaccess{$type} = $settings->{$type}->{$key};
5222: } elsif ($key eq 'machines') {
5223: $machineaccess{$type} = $settings->{$type}->{$key};
5224: }
5225: }
5226: }
5227: }
5228: }
5229: }
1.81 raeburn 5230: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5231: my $rownum = 0;
5232: my $css_class;
5233: foreach my $type (@pages) {
5234: $rownum ++;
5235: $css_class = $rownum%2?' class="LC_odd_row"':'';
5236: $datatable .= '<tr'.$css_class.'>'.
5237: '<td><span class="LC_nobreak">'.
5238: $titles->{$type}.'</span></td>'.
5239: '<td class="LC_left_item">'.
5240: '<input type="text" name="'.$type.'_namedusers" '.
5241: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5242: '<td class="LC_right_item">'.
5243: '<span class="LC_nobreak">'.
5244: '<input type="text" name="'.$type.'_machines" '.
5245: 'value="'.$machineaccess{$type}.'" size="10" />'.
5246: '</td></tr>'."\n";
5247: }
5248: $$rowtotal += $rownum;
5249: return $datatable;
5250: }
5251:
5252: sub serverstatus_pages {
5253: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5254: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5255: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.229 raeburn 5256: 'uniquecodes','diskusage');
1.69 raeburn 5257: }
5258:
1.236 raeburn 5259: sub defaults_javascript {
5260: my ($settings) = @_;
1.248 raeburn 5261: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5262: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5263: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5264: if ($maxnum eq '') {
5265: $maxnum = 0;
5266: }
5267: $maxnum ++;
1.249 raeburn 5268: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5269: return <<"ENDSCRIPT";
5270: <script type="text/javascript">
5271: // <![CDATA[
5272: function reorderTypes(form,caller) {
5273: var changedVal;
5274: $jstext
5275: var newpos = 'addinststatus_pos';
5276: var current = new Array;
5277: var maxh = $maxnum;
5278: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5279: var oldVal;
5280: if (caller == newpos) {
5281: changedVal = newitemVal;
5282: } else {
5283: var curritem = 'inststatus_pos_'+caller;
5284: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5285: current[newitemVal] = newpos;
5286: }
5287: for (var i=0; i<inststatuses.length; i++) {
5288: if (inststatuses[i] != caller) {
5289: var elementName = 'inststatus_pos_'+inststatuses[i];
5290: if (form.elements[elementName]) {
5291: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5292: current[currVal] = elementName;
5293: }
5294: }
5295: }
5296: for (var j=0; j<maxh; j++) {
5297: if (current[j] == undefined) {
5298: oldVal = j;
5299: }
5300: }
5301: if (oldVal < changedVal) {
5302: for (var k=oldVal+1; k<=changedVal ; k++) {
5303: var elementName = current[k];
5304: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5305: }
5306: } else {
5307: for (var k=changedVal; k<oldVal; k++) {
5308: var elementName = current[k];
5309: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5310: }
5311: }
5312: return;
5313: }
5314:
5315: // ]]>
5316: </script>
5317:
5318: ENDSCRIPT
5319: }
5320: }
5321:
1.49 raeburn 5322: sub coursecategories_javascript {
5323: my ($settings) = @_;
1.57 raeburn 5324: my ($output,$jstext,$cathash);
1.49 raeburn 5325: if (ref($settings) eq 'HASH') {
1.57 raeburn 5326: $cathash = $settings->{'cats'};
5327: }
5328: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5329: my (@cats,@jsarray,%idx);
1.57 raeburn 5330: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5331: if (@jsarray > 0) {
5332: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5333: for (my $i=0; $i<@jsarray; $i++) {
5334: if (ref($jsarray[$i]) eq 'ARRAY') {
5335: my $catstr = join('","',@{$jsarray[$i]});
5336: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5337: }
5338: }
5339: }
5340: } else {
5341: $jstext = ' var categories = Array(1);'."\n".
5342: ' categories[0] = Array("instcode_pos");'."\n";
5343: }
1.237 bisitz 5344: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5345: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
5346: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category.');
1.49 raeburn 5347: $output = <<"ENDSCRIPT";
5348: <script type="text/javascript">
1.109 raeburn 5349: // <![CDATA[
1.49 raeburn 5350: function reorderCats(form,parent,item,idx) {
5351: var changedVal;
5352: $jstext
5353: var newpos = 'addcategory_pos';
5354: if (parent == '') {
5355: var has_instcode = 0;
5356: var maxtop = categories[idx].length;
5357: for (var j=0; j<maxtop; j++) {
5358: if (categories[idx][j] == 'instcode::0') {
5359: has_instcode == 1;
5360: }
5361: }
5362: if (has_instcode == 0) {
5363: categories[idx][maxtop] = 'instcode_pos';
5364: }
5365: } else {
5366: newpos += '_'+parent;
5367: }
5368: var maxh = 1 + categories[idx].length;
5369: var current = new Array;
5370: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5371: if (item == newpos) {
5372: changedVal = newitemVal;
5373: } else {
5374: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5375: current[newitemVal] = newpos;
5376: }
5377: for (var i=0; i<categories[idx].length; i++) {
5378: var elementName = categories[idx][i];
5379: if (elementName != item) {
5380: if (form.elements[elementName]) {
5381: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5382: current[currVal] = elementName;
5383: }
5384: }
5385: }
5386: var oldVal;
5387: for (var j=0; j<maxh; j++) {
5388: if (current[j] == undefined) {
5389: oldVal = j;
5390: }
5391: }
5392: if (oldVal < changedVal) {
5393: for (var k=oldVal+1; k<=changedVal ; k++) {
5394: var elementName = current[k];
5395: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5396: }
5397: } else {
5398: for (var k=changedVal; k<oldVal; k++) {
5399: var elementName = current[k];
5400: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5401: }
5402: }
5403: return;
5404: }
1.120 raeburn 5405:
5406: function categoryCheck(form) {
5407: if (form.elements['addcategory_name'].value == 'instcode') {
5408: alert('$instcode_reserved\\n$choose_again');
5409: return false;
5410: }
5411: if (form.elements['addcategory_name'].value == 'communities') {
5412: alert('$communities_reserved\\n$choose_again');
5413: return false;
5414: }
5415: return true;
5416: }
5417:
1.109 raeburn 5418: // ]]>
1.49 raeburn 5419: </script>
5420:
5421: ENDSCRIPT
5422: return $output;
5423: }
5424:
1.48 raeburn 5425: sub initialize_categories {
5426: my ($itemcount) = @_;
1.120 raeburn 5427: my ($datatable,$css_class,$chgstr);
5428: my %default_names = (
5429: instcode => 'Official courses (with institutional codes)',
5430: communities => 'Communities',
5431: );
5432: my $select0 = ' selected="selected"';
5433: my $select1 = '';
5434: foreach my $default ('instcode','communities') {
5435: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5436: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5437: if ($default eq 'communities') {
5438: $select1 = $select0;
5439: $select0 = '';
5440: }
5441: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5442: .'<select name="'.$default.'_pos">'
5443: .'<option value="0"'.$select0.'>1</option>'
5444: .'<option value="1"'.$select1.'>2</option>'
5445: .'<option value="2">3</option></select> '
5446: .$default_names{$default}
5447: .'</span></td><td><span class="LC_nobreak">'
5448: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
5449: .&mt('Display').'</label> <label>'
5450: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 5451: .'</label></span></td></tr>';
1.120 raeburn 5452: $itemcount ++;
5453: }
1.48 raeburn 5454: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 5455: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 5456: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 5457: .'<select name="addcategory_pos"'.$chgstr.'>'
5458: .'<option value="0">1</option>'
5459: .'<option value="1">2</option>'
5460: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 5461: .&mt('Add category').'</td><td>'.&mt('Name:')
5462: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
5463: return $datatable;
5464: }
5465:
5466: sub build_category_rows {
1.49 raeburn 5467: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
5468: my ($text,$name,$item,$chgstr);
1.48 raeburn 5469: if (ref($cats) eq 'ARRAY') {
5470: my $maxdepth = scalar(@{$cats});
5471: if (ref($cats->[$depth]) eq 'HASH') {
5472: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
5473: my $numchildren = @{$cats->[$depth]{$parent}};
5474: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 5475: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 5476: my ($idxnum,$parent_name,$parent_item);
5477: my $higher = $depth - 1;
5478: if ($higher == 0) {
5479: $parent_name = &escape($parent).'::'.$higher;
5480: } else {
5481: if (ref($path) eq 'ARRAY') {
5482: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5483: }
5484: }
5485: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 5486: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 5487: if ($j < $numchildren) {
1.48 raeburn 5488: $name = $cats->[$depth]{$parent}[$j];
5489: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 5490: $idxnum = $idx->{$item};
5491: } else {
5492: $name = $parent_name;
5493: $item = $parent_item;
1.48 raeburn 5494: }
1.49 raeburn 5495: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
5496: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 5497: for (my $i=0; $i<=$numchildren; $i++) {
5498: my $vpos = $i+1;
5499: my $selstr;
5500: if ($j == $i) {
5501: $selstr = ' selected="selected" ';
5502: }
5503: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
5504: }
5505: $text .= '</select> ';
5506: if ($j < $numchildren) {
5507: my $deeper = $depth+1;
5508: $text .= $name.' '
5509: .'<label><input type="checkbox" name="deletecategory" value="'
5510: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
5511: if(ref($path) eq 'ARRAY') {
5512: push(@{$path},$name);
1.49 raeburn 5513: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 5514: pop(@{$path});
5515: }
5516: } else {
1.59 bisitz 5517: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 5518: if ($j == $numchildren) {
5519: $text .= $name;
5520: } else {
5521: $text .= $item;
5522: }
5523: $text .= '" value="" />';
5524: }
5525: $text .= '</td></tr>';
5526: }
5527: $text .= '</table></td>';
5528: } else {
5529: my $higher = $depth-1;
5530: if ($higher == 0) {
5531: $name = &escape($parent).'::'.$higher;
5532: } else {
5533: if (ref($path) eq 'ARRAY') {
5534: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
5535: }
5536: }
5537: my $colspan;
5538: if ($parent ne 'instcode') {
5539: $colspan = $maxdepth - $depth - 1;
5540: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
5541: }
5542: }
5543: }
5544: }
5545: return $text;
5546: }
5547:
1.33 raeburn 5548: sub modifiable_userdata_row {
1.228 raeburn 5549: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
5550: my ($role,$rolename,$statustype);
5551: $role = $item;
1.224 raeburn 5552: if ($context eq 'cancreate') {
1.228 raeburn 5553: if ($item =~ /^emailusername_(.+)$/) {
5554: $statustype = $1;
5555: $role = 'emailusername';
5556: if (ref($usertypes) eq 'HASH') {
5557: if ($usertypes->{$statustype}) {
5558: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
5559: } else {
5560: $rolename = &mt('Data provided by user');
5561: }
5562: }
1.224 raeburn 5563: }
5564: } elsif ($context eq 'selfcreate') {
1.63 raeburn 5565: if (ref($usertypes) eq 'HASH') {
5566: $rolename = $usertypes->{$role};
5567: } else {
5568: $rolename = $role;
5569: }
1.33 raeburn 5570: } else {
1.63 raeburn 5571: if ($role eq 'cr') {
5572: $rolename = &mt('Custom role');
5573: } else {
5574: $rolename = &Apache::lonnet::plaintext($role);
5575: }
1.33 raeburn 5576: }
1.224 raeburn 5577: my (@fields,%fieldtitles);
5578: if (ref($fieldsref) eq 'ARRAY') {
5579: @fields = @{$fieldsref};
5580: } else {
5581: @fields = ('lastname','firstname','middlename','generation',
5582: 'permanentemail','id');
5583: }
5584: if ((ref($titlesref) eq 'HASH')) {
5585: %fieldtitles = %{$titlesref};
5586: } else {
5587: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5588: }
1.33 raeburn 5589: my $output;
5590: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5591: $output = '<tr '.$css_class.'>'.
5592: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
5593: '<td class="LC_left_item" colspan="2"><table>';
5594: my $rem;
5595: my %checks;
5596: if (ref($settings) eq 'HASH') {
5597: if (ref($settings->{$context}) eq 'HASH') {
5598: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 5599: my $hashref = $settings->{$context}->{$role};
5600: if ($role eq 'emailusername') {
5601: if ($statustype) {
5602: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
5603: $hashref = $settings->{$context}->{$role}->{$statustype};
5604: if (ref($hashref) eq 'HASH') {
5605: foreach my $field (@fields) {
5606: if ($hashref->{$field}) {
5607: $checks{$field} = $hashref->{$field};
5608: }
5609: }
5610: }
5611: }
5612: }
5613: } else {
5614: if (ref($hashref) eq 'HASH') {
5615: foreach my $field (@fields) {
5616: if ($hashref->{$field}) {
5617: $checks{$field} = ' checked="checked" ';
5618: }
5619: }
1.33 raeburn 5620: }
5621: }
5622: }
5623: }
5624: }
1.228 raeburn 5625:
1.33 raeburn 5626: for (my $i=0; $i<@fields; $i++) {
5627: my $rem = $i%($numinrow);
5628: if ($rem == 0) {
5629: if ($i > 0) {
5630: $output .= '</tr>';
5631: }
5632: $output .= '<tr>';
5633: }
5634: my $check = ' ';
1.228 raeburn 5635: unless ($role eq 'emailusername') {
5636: if (exists($checks{$fields[$i]})) {
5637: $check = $checks{$fields[$i]}
5638: } else {
5639: if ($role eq 'st') {
5640: if (ref($settings) ne 'HASH') {
5641: $check = ' checked="checked" ';
5642: }
1.33 raeburn 5643: }
5644: }
5645: }
5646: $output .= '<td class="LC_left_item">'.
1.228 raeburn 5647: '<span class="LC_nobreak">';
5648: if ($role eq 'emailusername') {
5649: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
5650: $checks{$fields[$i]} = 'omit';
5651: }
5652: foreach my $option ('required','optional','omit') {
5653: my $checked='';
5654: if ($checks{$fields[$i]} eq $option) {
5655: $checked='checked="checked" ';
5656: }
5657: $output .= '<label>'.
5658: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
5659: &mt($option).'</label>'.(' ' x2);
5660: }
5661: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
5662: } else {
5663: $output .= '<label>'.
5664: '<input type="checkbox" name="canmodify_'.$role.'" '.
5665: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
5666: '</label>';
5667: }
5668: $output .= '</span></td>';
1.33 raeburn 5669: $rem = @fields%($numinrow);
5670: }
5671: my $colsleft = $numinrow - $rem;
5672: if ($colsleft > 1 ) {
5673: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5674: ' </td>';
5675: } elsif ($colsleft == 1) {
5676: $output .= '<td class="LC_left_item"> </td>';
5677: }
5678: $output .= '</tr></table></td></tr>';
5679: return $output;
5680: }
1.28 raeburn 5681:
1.93 raeburn 5682: sub insttypes_row {
1.224 raeburn 5683: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 5684: my %lt = &Apache::lonlocal::texthash (
5685: cansearch => 'Users allowed to search',
5686: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 5687: lockablenames => 'User preference to lock name',
1.93 raeburn 5688: );
5689: my $showdom;
5690: if ($context eq 'cansearch') {
5691: $showdom = ' ('.$dom.')';
5692: }
1.165 raeburn 5693: my $class = 'LC_left_item';
5694: if ($context eq 'statustocreate') {
5695: $class = 'LC_right_item';
5696: }
1.224 raeburn 5697: my $css_class = ' class="LC_odd_row"';
5698: if ($rownum ne '') {
5699: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
5700: }
5701: my $output = '<tr'.$css_class.'>'.
5702: '<td>'.$lt{$context}.$showdom.
5703: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 5704: my $rem;
5705: if (ref($types) eq 'ARRAY') {
5706: for (my $i=0; $i<@{$types}; $i++) {
5707: if (defined($usertypes->{$types->[$i]})) {
5708: my $rem = $i%($numinrow);
5709: if ($rem == 0) {
5710: if ($i > 0) {
5711: $output .= '</tr>';
5712: }
5713: $output .= '<tr>';
1.23 raeburn 5714: }
1.26 raeburn 5715: my $check = ' ';
1.99 raeburn 5716: if (ref($settings) eq 'HASH') {
5717: if (ref($settings->{$context}) eq 'ARRAY') {
5718: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
5719: $check = ' checked="checked" ';
5720: }
5721: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5722: $check = ' checked="checked" ';
5723: }
1.23 raeburn 5724: }
1.26 raeburn 5725: $output .= '<td class="LC_left_item">'.
5726: '<span class="LC_nobreak"><label>'.
1.93 raeburn 5727: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 5728: 'value="'.$types->[$i].'"'.$check.'/>'.
5729: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 5730: }
5731: }
1.26 raeburn 5732: $rem = @{$types}%($numinrow);
1.23 raeburn 5733: }
5734: my $colsleft = $numinrow - $rem;
1.131 raeburn 5735: if (($rem == 0) && (@{$types} > 0)) {
5736: $output .= '<tr>';
5737: }
1.23 raeburn 5738: if ($colsleft > 1) {
1.25 raeburn 5739: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 5740: } else {
1.25 raeburn 5741: $output .= '<td class="LC_left_item">';
1.23 raeburn 5742: }
5743: my $defcheck = ' ';
1.99 raeburn 5744: if (ref($settings) eq 'HASH') {
5745: if (ref($settings->{$context}) eq 'ARRAY') {
5746: if (grep(/^default$/,@{$settings->{$context}})) {
5747: $defcheck = ' checked="checked" ';
5748: }
5749: } elsif ($context eq 'statustocreate') {
1.26 raeburn 5750: $defcheck = ' checked="checked" ';
5751: }
1.23 raeburn 5752: }
1.25 raeburn 5753: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 5754: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 5755: 'value="default"'.$defcheck.'/>'.
5756: $othertitle.'</label></span></td>'.
5757: '</tr></table></td></tr>';
5758: return $output;
1.23 raeburn 5759: }
5760:
5761: sub sorted_searchtitles {
5762: my %searchtitles = &Apache::lonlocal::texthash(
5763: 'uname' => 'username',
5764: 'lastname' => 'last name',
5765: 'lastfirst' => 'last name, first name',
5766: );
5767: my @titleorder = ('uname','lastname','lastfirst');
5768: return (\%searchtitles,\@titleorder);
5769: }
5770:
1.25 raeburn 5771: sub sorted_searchtypes {
5772: my %srchtypes_desc = (
5773: exact => 'is exact match',
5774: contains => 'contains ..',
5775: begins => 'begins with ..',
5776: );
5777: my @srchtypeorder = ('exact','begins','contains');
5778: return (\%srchtypes_desc,\@srchtypeorder);
5779: }
5780:
1.3 raeburn 5781: sub usertype_update_row {
5782: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
5783: my $datatable;
5784: my $numinrow = 4;
5785: foreach my $type (@{$types}) {
5786: if (defined($usertypes->{$type})) {
5787: $$rownums ++;
5788: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
5789: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
5790: '</td><td class="LC_left_item"><table>';
5791: for (my $i=0; $i<@{$fields}; $i++) {
5792: my $rem = $i%($numinrow);
5793: if ($rem == 0) {
5794: if ($i > 0) {
5795: $datatable .= '</tr>';
5796: }
5797: $datatable .= '<tr>';
5798: }
5799: my $check = ' ';
1.39 raeburn 5800: if (ref($settings) eq 'HASH') {
5801: if (ref($settings->{'fields'}) eq 'HASH') {
5802: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
5803: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
5804: $check = ' checked="checked" ';
5805: }
1.3 raeburn 5806: }
5807: }
5808: }
5809:
5810: if ($i == @{$fields}-1) {
5811: my $colsleft = $numinrow - $rem;
5812: if ($colsleft > 1) {
5813: $datatable .= '<td colspan="'.$colsleft.'">';
5814: } else {
5815: $datatable .= '<td>';
5816: }
5817: } else {
5818: $datatable .= '<td>';
5819: }
1.8 raeburn 5820: $datatable .= '<span class="LC_nobreak"><label>'.
5821: '<input type="checkbox" name="updateable_'.$type.
5822: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
5823: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 5824: }
5825: $datatable .= '</tr></table></td></tr>';
5826: }
5827: }
5828: return $datatable;
1.1 raeburn 5829: }
5830:
5831: sub modify_login {
1.205 raeburn 5832: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 5833: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
5834: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
5835: %title = ( coursecatalog => 'Display course catalog',
5836: adminmail => 'Display administrator E-mail address',
1.188 raeburn 5837: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 5838: newuser => 'Link for visitors to create a user account',
5839: loginheader => 'Log-in box header');
5840: @offon = ('off','on');
1.112 raeburn 5841: if (ref($domconfig{login}) eq 'HASH') {
5842: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
5843: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
5844: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
5845: }
5846: }
5847: }
1.9 raeburn 5848: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
5849: \%domconfig,\%loginhash);
1.188 raeburn 5850: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 5851: foreach my $item (@toggles) {
5852: $loginhash{login}{$item} = $env{'form.'.$item};
5853: }
1.41 raeburn 5854: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 5855: if (ref($colchanges{'login'}) eq 'HASH') {
5856: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
5857: \%loginhash);
5858: }
1.110 raeburn 5859:
1.149 raeburn 5860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 ! raeburn 5861: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 5862: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 5863: if (keys(%servers) > 1) {
5864: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 5865: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
5866: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
5867: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
5868: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
5869: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
5870: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5871: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5872: $changes{'loginvia'}{$lonhost} = 1;
5873: } else {
5874: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
5875: $changes{'loginvia'}{$lonhost} = 1;
5876: }
5877: } else {
5878: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5879: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
5880: $changes{'loginvia'}{$lonhost} = 1;
5881: }
5882: }
5883: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
5884: foreach my $item (@loginvia_attribs) {
5885: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
5886: }
5887: } else {
5888: foreach my $item (@loginvia_attribs) {
5889: my $new = $env{'form.'.$lonhost.'_'.$item};
5890: if (($item eq 'serverpath') && ($new eq 'custom')) {
5891: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
5892: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5893: $new = '/';
5894: }
5895: }
5896: if (($item eq 'custompath') &&
5897: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5898: $new = '';
5899: }
5900: if ($new ne $curr_loginvia{$lonhost}{$item}) {
5901: $changes{'loginvia'}{$lonhost} = 1;
5902: }
5903: if ($item eq 'exempt') {
1.256 ! raeburn 5904: $new = &check_exempt_addresses($new);
1.128 raeburn 5905: }
5906: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5907: }
5908: }
1.112 raeburn 5909: } else {
1.128 raeburn 5910: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
5911: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 5912: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 5913: foreach my $item (@loginvia_attribs) {
5914: my $new = $env{'form.'.$lonhost.'_'.$item};
5915: if (($item eq 'serverpath') && ($new eq 'custom')) {
5916: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
5917: $new = '/';
5918: }
5919: }
5920: if (($item eq 'custompath') &&
5921: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
5922: $new = '';
5923: }
5924: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
5925: }
1.110 raeburn 5926: }
5927: }
5928: }
5929: }
1.119 raeburn 5930:
1.168 raeburn 5931: my $servadm = $r->dir_config('lonAdmEMail');
5932: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
5933: if (ref($domconfig{'login'}) eq 'HASH') {
5934: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
5935: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
5936: if ($lang eq 'nolang') {
5937: push(@currlangs,$lang);
5938: } elsif (defined($langchoices{$lang})) {
5939: push(@currlangs,$lang);
5940: } else {
5941: next;
5942: }
5943: }
5944: }
5945: }
5946: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
5947: if (@currlangs > 0) {
5948: foreach my $lang (@currlangs) {
5949: if (grep(/^\Q$lang\E$/,@delurls)) {
5950: $changes{'helpurl'}{$lang} = 1;
5951: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
5952: $changes{'helpurl'}{$lang} = 1;
5953: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
5954: push(@newlangs,$lang);
5955: } else {
5956: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
5957: }
5958: }
5959: }
5960: unless (grep(/^nolang$/,@currlangs)) {
5961: if ($env{'form.loginhelpurl_nolang.filename'}) {
5962: $changes{'helpurl'}{'nolang'} = 1;
5963: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
5964: push(@newlangs,'nolang');
5965: }
5966: }
5967: if ($env{'form.loginhelpurl_add_lang'}) {
5968: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
5969: ($env{'form.loginhelpurl_add_file.filename'})) {
5970: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
5971: $addedfile = $env{'form.loginhelpurl_add_lang'};
5972: }
5973: }
5974: if ((@newlangs > 0) || ($addedfile)) {
5975: my $error;
5976: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
5977: if ($configuserok eq 'ok') {
5978: if ($switchserver) {
5979: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
5980: } elsif ($author_ok eq 'ok') {
5981: my @allnew = @newlangs;
5982: if ($addedfile ne '') {
5983: push(@allnew,$addedfile);
5984: }
5985: foreach my $lang (@allnew) {
5986: my $formelem = 'loginhelpurl_'.$lang;
5987: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
5988: $formelem = 'loginhelpurl_add_file';
5989: }
5990: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
5991: "help/$lang",'','',$newfile{$lang});
5992: if ($result eq 'ok') {
5993: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
5994: $changes{'helpurl'}{$lang} = 1;
5995: } else {
5996: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
5997: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 5998: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 5999: (!grep(/^\Q$lang\E$/,@delurls))) {
6000: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6001: }
6002: }
6003: }
6004: } else {
6005: $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);
6006: }
6007: } else {
6008: $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);
6009: }
6010: if ($error) {
6011: &Apache::lonnet::logthis($error);
6012: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6013: }
6014: }
1.256 ! raeburn 6015:
! 6016: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
! 6017: if (ref($domconfig{'login'}) eq 'HASH') {
! 6018: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
! 6019: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
! 6020: if ($domservers{$lonhost}) {
! 6021: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
! 6022: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
! 6023: $currexempt{$lonhost} = $domconfig{'login'}{'headtagexempt'}{$lonhost}{'exempt'}
! 6024: }
! 6025: }
! 6026: }
! 6027: }
! 6028: }
! 6029: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
! 6030: foreach my $lonhost (sort(keys(%domservers))) {
! 6031: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
! 6032: $changes{'headtag'}{$lonhost} = 1;
! 6033: } else {
! 6034: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
! 6035: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
! 6036: }
! 6037: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
! 6038: push(@newhosts,$lonhost);
! 6039: } elsif ($currheadtagurls{$lonhost}) {
! 6040: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
! 6041: if ($currexempt{$lonhost}) {
! 6042: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
! 6043: $changes{'headtag'}{$lonhost} = 1;
! 6044: }
! 6045: } elsif ($possexempt{$lonhost}) {
! 6046: $changes{'headtag'}{$lonhost} = 1;
! 6047: }
! 6048: if ($possexempt{$lonhost}) {
! 6049: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
! 6050: }
! 6051: }
! 6052: }
! 6053: }
! 6054: if (@newhosts) {
! 6055: my $error;
! 6056: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
! 6057: if ($configuserok eq 'ok') {
! 6058: if ($switchserver) {
! 6059: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
! 6060: } elsif ($author_ok eq 'ok') {
! 6061: foreach my $lonhost (@newhosts) {
! 6062: my $formelem = 'loginheadtag_'.$lonhost;
! 6063: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
! 6064: "login/headtag/$lonhost",'','',
! 6065: $env{'form.loginheadtag_'.$lonhost.'.filename'});
! 6066: if ($result eq 'ok') {
! 6067: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
! 6068: $changes{'headtag'}{$lonhost} = 1;
! 6069: if ($possexempt{$lonhost}) {
! 6070: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
! 6071: }
! 6072: } else {
! 6073: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
! 6074: $newheadtagurls{$lonhost},$result);
! 6075: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
! 6076: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
! 6077: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
! 6078: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
! 6079: }
! 6080: }
! 6081: }
! 6082: } else {
! 6083: $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);
! 6084: }
! 6085: } else {
! 6086: $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);
! 6087: }
! 6088: if ($error) {
! 6089: &Apache::lonnet::logthis($error);
! 6090: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 6091: }
! 6092: }
1.169 raeburn 6093: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6094:
6095: my $defaulthelpfile = '/adm/loginproblems.html';
6096: my $defaulttext = &mt('Default in use');
6097:
1.1 raeburn 6098: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6099: $dom);
6100: if ($putresult eq 'ok') {
1.188 raeburn 6101: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6102: my %defaultchecked = (
6103: 'coursecatalog' => 'on',
1.188 raeburn 6104: 'helpdesk' => 'on',
1.42 raeburn 6105: 'adminmail' => 'off',
1.43 raeburn 6106: 'newuser' => 'off',
1.42 raeburn 6107: );
1.55 raeburn 6108: if (ref($domconfig{'login'}) eq 'HASH') {
6109: foreach my $item (@toggles) {
6110: if ($defaultchecked{$item} eq 'on') {
6111: if (($domconfig{'login'}{$item} eq '0') &&
6112: ($env{'form.'.$item} eq '1')) {
6113: $changes{$item} = 1;
6114: } elsif (($domconfig{'login'}{$item} eq '' ||
6115: $domconfig{'login'}{$item} eq '1') &&
6116: ($env{'form.'.$item} eq '0')) {
6117: $changes{$item} = 1;
6118: }
6119: } elsif ($defaultchecked{$item} eq 'off') {
6120: if (($domconfig{'login'}{$item} eq '1') &&
6121: ($env{'form.'.$item} eq '0')) {
6122: $changes{$item} = 1;
6123: } elsif (($domconfig{'login'}{$item} eq '' ||
6124: $domconfig{'login'}{$item} eq '0') &&
6125: ($env{'form.'.$item} eq '1')) {
6126: $changes{$item} = 1;
6127: }
1.42 raeburn 6128: }
6129: }
1.41 raeburn 6130: }
1.6 raeburn 6131: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6132: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6133: if (ref($lastactref) eq 'HASH') {
6134: $lastactref->{'domainconfig'} = 1;
6135: }
1.1 raeburn 6136: $resulttext = &mt('Changes made:').'<ul>';
6137: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6138: if ($item eq 'loginvia') {
1.112 raeburn 6139: if (ref($changes{$item}) eq 'HASH') {
6140: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6141: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6142: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6143: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6144: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6145: $protocol = 'http' if ($protocol ne 'https');
6146: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6147:
6148: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6149: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6150: } else {
6151: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6152: }
6153: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6154: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6155: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6156: }
6157: $resulttext .= '</li>';
6158: } else {
6159: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6160: }
1.112 raeburn 6161: } else {
1.128 raeburn 6162: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6163: }
6164: }
1.128 raeburn 6165: $resulttext .= '</ul></li>';
1.112 raeburn 6166: }
1.168 raeburn 6167: } elsif ($item eq 'helpurl') {
6168: if (ref($changes{$item}) eq 'HASH') {
6169: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6170: if (grep(/^\Q$lang\E$/,@delurls)) {
6171: my ($chg,$link);
6172: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6173: if ($lang eq 'nolang') {
6174: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6175: } else {
6176: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6177: }
6178: $resulttext .= '<li>'.$chg.'</li>';
6179: } else {
6180: my $chg;
6181: if ($lang eq 'nolang') {
6182: $chg = &mt('custom log-in help file for no preferred language');
6183: } else {
6184: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6185: }
6186: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6187: $loginhash{'login'}{'helpurl'}{$lang}.
6188: '?inhibitmenu=yes',$chg,600,500).
6189: '</li>';
6190: }
6191: }
6192: }
1.256 ! raeburn 6193: } elsif ($item eq 'headtag') {
! 6194: if (ref($changes{$item}) eq 'HASH') {
! 6195: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
! 6196: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
! 6197: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
! 6198: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
! 6199: $resulttext .= '<li><a href="'.
! 6200: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
! 6201: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
! 6202: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
! 6203: if ($possexempt{$lonhost}) {
! 6204: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
! 6205: } else {
! 6206: $resulttext .= &mt('included for any client IP');
! 6207: }
! 6208: $resulttext .= '</li>';
! 6209: }
! 6210: }
! 6211: }
1.169 raeburn 6212: } elsif ($item eq 'captcha') {
6213: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6214: my $chgtxt;
1.169 raeburn 6215: if ($loginhash{'login'}{$item} eq 'notused') {
6216: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6217: } else {
6218: my %captchas = &captcha_phrases();
6219: if ($captchas{$loginhash{'login'}{$item}}) {
6220: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6221: } else {
6222: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6223: }
6224: }
6225: $resulttext .= '<li>'.$chgtxt.'</li>';
6226: }
6227: } elsif ($item eq 'recaptchakeys') {
6228: if (ref($loginhash{'login'}) eq 'HASH') {
6229: my ($privkey,$pubkey);
6230: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6231: $pubkey = $loginhash{'login'}{$item}{'public'};
6232: $privkey = $loginhash{'login'}{$item}{'private'};
6233: }
6234: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6235: if (!$pubkey) {
6236: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6237: } else {
6238: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6239: }
6240: if (!$privkey) {
6241: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6242: } else {
1.251 raeburn 6243: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6244: }
6245: $chgtxt .= '</ul>';
6246: $resulttext .= '<li>'.$chgtxt.'</li>';
6247: }
1.41 raeburn 6248: } else {
6249: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6250: }
1.1 raeburn 6251: }
1.6 raeburn 6252: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6253: } else {
6254: $resulttext = &mt('No changes made to log-in page settings');
6255: }
6256: } else {
1.11 albertel 6257: $resulttext = '<span class="LC_error">'.
6258: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6259: }
1.6 raeburn 6260: if ($errors) {
1.9 raeburn 6261: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6262: $errors.'</ul>';
6263: }
6264: return $resulttext;
6265: }
6266:
1.256 ! raeburn 6267:
! 6268: sub check_exempt_addresses {
! 6269: my ($iplist) = @_;
! 6270: $iplist =~ s/^\s+//;
! 6271: $iplist =~ s/\s+$//;
! 6272: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
! 6273: my (@okips,$new);
! 6274: foreach my $ip (@poss_ips) {
! 6275: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
! 6276: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
! 6277: push(@okips,$ip);
! 6278: }
! 6279: }
! 6280: }
! 6281: if (@okips > 0) {
! 6282: $new = join(',',@okips);
! 6283: } else {
! 6284: $new = '';
! 6285: }
! 6286: return $new;
! 6287: }
! 6288:
1.6 raeburn 6289: sub color_font_choices {
6290: my %choices =
6291: &Apache::lonlocal::texthash (
6292: img => "Header",
6293: bgs => "Background colors",
6294: links => "Link colors",
1.55 raeburn 6295: images => "Images",
1.6 raeburn 6296: font => "Font color",
1.201 raeburn 6297: fontmenu => "Font menu",
1.76 raeburn 6298: pgbg => "Page",
1.6 raeburn 6299: tabbg => "Header",
6300: sidebg => "Border",
6301: link => "Link",
6302: alink => "Active link",
6303: vlink => "Visited link",
6304: );
6305: return %choices;
6306: }
6307:
6308: sub modify_rolecolors {
1.205 raeburn 6309: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6310: my ($resulttext,%rolehash);
6311: $rolehash{'rolecolors'} = {};
1.55 raeburn 6312: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6313: if ($domconfig{'rolecolors'} eq '') {
6314: $domconfig{'rolecolors'} = {};
6315: }
6316: }
1.9 raeburn 6317: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6318: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6319: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6320: $dom);
6321: if ($putresult eq 'ok') {
6322: if (keys(%changes) > 0) {
1.41 raeburn 6323: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6324: if (ref($lastactref) eq 'HASH') {
6325: $lastactref->{'domainconfig'} = 1;
6326: }
1.6 raeburn 6327: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6328: $rolehash{'rolecolors'});
6329: } else {
6330: $resulttext = &mt('No changes made to default color schemes');
6331: }
6332: } else {
1.11 albertel 6333: $resulttext = '<span class="LC_error">'.
6334: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6335: }
6336: if ($errors) {
6337: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6338: $errors.'</ul>';
6339: }
6340: return $resulttext;
6341: }
6342:
6343: sub modify_colors {
1.9 raeburn 6344: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6345: my (%changes,%choices);
1.51 raeburn 6346: my @bgs;
1.6 raeburn 6347: my @links = ('link','alink','vlink');
1.41 raeburn 6348: my @logintext;
1.6 raeburn 6349: my @images;
6350: my $servadm = $r->dir_config('lonAdmEMail');
6351: my $errors;
1.200 raeburn 6352: my %defaults;
1.6 raeburn 6353: foreach my $role (@{$roles}) {
6354: if ($role eq 'login') {
1.12 raeburn 6355: %choices = &login_choices();
1.41 raeburn 6356: @logintext = ('textcol','bgcol');
1.12 raeburn 6357: } else {
6358: %choices = &color_font_choices();
6359: }
6360: if ($role eq 'login') {
1.41 raeburn 6361: @images = ('img','logo','domlogo','login');
1.51 raeburn 6362: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6363: } else {
6364: @images = ('img');
1.200 raeburn 6365: @bgs = ('pgbg','tabbg','sidebg');
6366: }
6367: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6368: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6369: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6370: }
6371: if ($role eq 'login') {
6372: foreach my $item (@logintext) {
1.234 raeburn 6373: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6374: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6375: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6376: }
6377: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6378: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6379: }
6380: }
6381: } else {
1.234 raeburn 6382: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6383: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6384: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6385: }
6386: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6387: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6388: }
1.6 raeburn 6389: }
1.200 raeburn 6390: foreach my $item (@bgs) {
1.234 raeburn 6391: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6392: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6393: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6394: }
6395: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6396: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6397: }
6398: }
6399: foreach my $item (@links) {
1.234 raeburn 6400: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6401: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6402: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6403: }
6404: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6405: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6406: }
1.6 raeburn 6407: }
1.46 raeburn 6408: my ($configuserok,$author_ok,$switchserver) =
6409: &config_check($dom,$confname,$servadm);
1.9 raeburn 6410: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6411: if (ref($domconfig->{$role}) ne 'HASH') {
6412: $domconfig->{$role} = {};
6413: }
1.8 raeburn 6414: foreach my $img (@images) {
1.70 raeburn 6415: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6416: if (defined($env{'form.login_showlogo_'.$img})) {
6417: $confhash->{$role}{'showlogo'}{$img} = 1;
6418: } else {
6419: $confhash->{$role}{'showlogo'}{$img} = 0;
6420: }
6421: }
1.18 albertel 6422: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6423: && !defined($domconfig->{$role}{$img})
6424: && !$env{'form.'.$role.'_del_'.$img}
6425: && $env{'form.'.$role.'_import_'.$img}) {
6426: # import the old configured image from the .tab setting
6427: # if they haven't provided a new one
6428: $domconfig->{$role}{$img} =
6429: $env{'form.'.$role.'_import_'.$img};
6430: }
1.6 raeburn 6431: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6432: my $error;
1.6 raeburn 6433: if ($configuserok eq 'ok') {
1.9 raeburn 6434: if ($switchserver) {
1.12 raeburn 6435: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 6436: } else {
6437: if ($author_ok eq 'ok') {
6438: my ($result,$logourl) =
6439: &publishlogo($r,'upload',$role.'_'.$img,
6440: $dom,$confname,$img,$width,$height);
6441: if ($result eq 'ok') {
6442: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 6443: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6444: } else {
1.12 raeburn 6445: $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 6446: }
6447: } else {
1.46 raeburn 6448: $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 6449: }
6450: }
6451: } else {
1.46 raeburn 6452: $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 6453: }
6454: if ($error) {
1.8 raeburn 6455: &Apache::lonnet::logthis($error);
1.11 albertel 6456: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 6457: }
6458: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 6459: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
6460: my $error;
6461: if ($configuserok eq 'ok') {
6462: # is confname an author?
6463: if ($switchserver eq '') {
6464: if ($author_ok eq 'ok') {
6465: my ($result,$logourl) =
6466: &publishlogo($r,'copy',$domconfig->{$role}{$img},
6467: $dom,$confname,$img,$width,$height);
6468: if ($result eq 'ok') {
6469: $confhash->{$role}{$img} = $logourl;
1.18 albertel 6470: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 6471: }
6472: }
6473: }
6474: }
1.6 raeburn 6475: }
6476: }
6477: }
6478: if (ref($domconfig) eq 'HASH') {
6479: if (ref($domconfig->{$role}) eq 'HASH') {
6480: foreach my $img (@images) {
6481: if ($domconfig->{$role}{$img} ne '') {
6482: if ($env{'form.'.$role.'_del_'.$img}) {
6483: $confhash->{$role}{$img} = '';
1.12 raeburn 6484: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6485: } else {
1.9 raeburn 6486: if ($confhash->{$role}{$img} eq '') {
6487: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
6488: }
1.6 raeburn 6489: }
6490: } else {
6491: if ($env{'form.'.$role.'_del_'.$img}) {
6492: $confhash->{$role}{$img} = '';
1.12 raeburn 6493: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 6494: }
6495: }
1.70 raeburn 6496: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
6497: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
6498: if ($confhash->{$role}{'showlogo'}{$img} ne
6499: $domconfig->{$role}{'showlogo'}{$img}) {
6500: $changes{$role}{'showlogo'}{$img} = 1;
6501: }
6502: } else {
6503: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6504: $changes{$role}{'showlogo'}{$img} = 1;
6505: }
6506: }
6507: }
6508: }
1.6 raeburn 6509: if ($domconfig->{$role}{'font'} ne '') {
6510: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
6511: $changes{$role}{'font'} = 1;
6512: }
6513: } else {
6514: if ($confhash->{$role}{'font'}) {
6515: $changes{$role}{'font'} = 1;
6516: }
6517: }
1.107 raeburn 6518: if ($role ne 'login') {
6519: if ($domconfig->{$role}{'fontmenu'} ne '') {
6520: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
6521: $changes{$role}{'fontmenu'} = 1;
6522: }
6523: } else {
6524: if ($confhash->{$role}{'fontmenu'}) {
6525: $changes{$role}{'fontmenu'} = 1;
6526: }
1.97 tempelho 6527: }
6528: }
1.6 raeburn 6529: foreach my $item (@bgs) {
6530: if ($domconfig->{$role}{$item} ne '') {
6531: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6532: $changes{$role}{'bgs'}{$item} = 1;
6533: }
6534: } else {
6535: if ($confhash->{$role}{$item}) {
6536: $changes{$role}{'bgs'}{$item} = 1;
6537: }
6538: }
6539: }
6540: foreach my $item (@links) {
6541: if ($domconfig->{$role}{$item} ne '') {
6542: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6543: $changes{$role}{'links'}{$item} = 1;
6544: }
6545: } else {
6546: if ($confhash->{$role}{$item}) {
6547: $changes{$role}{'links'}{$item} = 1;
6548: }
6549: }
6550: }
1.41 raeburn 6551: foreach my $item (@logintext) {
6552: if ($domconfig->{$role}{$item} ne '') {
6553: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
6554: $changes{$role}{'logintext'}{$item} = 1;
6555: }
6556: } else {
6557: if ($confhash->{$role}{$item}) {
6558: $changes{$role}{'logintext'}{$item} = 1;
6559: }
6560: }
6561: }
1.6 raeburn 6562: } else {
6563: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6564: \@logintext,$confhash,\%changes);
1.6 raeburn 6565: }
6566: } else {
6567: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 6568: \@logintext,$confhash,\%changes);
1.6 raeburn 6569: }
6570: }
6571: return ($errors,%changes);
6572: }
6573:
1.46 raeburn 6574: sub config_check {
6575: my ($dom,$confname,$servadm) = @_;
6576: my ($configuserok,$author_ok,$switchserver,%currroles);
6577: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
6578: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
6579: $confname,$servadm);
6580: if ($configuserok eq 'ok') {
6581: $switchserver = &check_switchserver($dom,$confname);
6582: if ($switchserver eq '') {
6583: $author_ok = &check_authorstatus($dom,$confname,%currroles);
6584: }
6585: }
6586: return ($configuserok,$author_ok,$switchserver);
6587: }
6588:
1.6 raeburn 6589: sub default_change_checker {
1.41 raeburn 6590: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 6591: foreach my $item (@{$links}) {
6592: if ($confhash->{$role}{$item}) {
6593: $changes->{$role}{'links'}{$item} = 1;
6594: }
6595: }
6596: foreach my $item (@{$bgs}) {
6597: if ($confhash->{$role}{$item}) {
6598: $changes->{$role}{'bgs'}{$item} = 1;
6599: }
6600: }
1.41 raeburn 6601: foreach my $item (@{$logintext}) {
6602: if ($confhash->{$role}{$item}) {
6603: $changes->{$role}{'logintext'}{$item} = 1;
6604: }
6605: }
1.6 raeburn 6606: foreach my $img (@{$images}) {
6607: if ($env{'form.'.$role.'_del_'.$img}) {
6608: $confhash->{$role}{$img} = '';
1.12 raeburn 6609: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 6610: }
1.70 raeburn 6611: if ($role eq 'login') {
6612: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
6613: $changes->{$role}{'showlogo'}{$img} = 1;
6614: }
6615: }
1.6 raeburn 6616: }
6617: if ($confhash->{$role}{'font'}) {
6618: $changes->{$role}{'font'} = 1;
6619: }
1.48 raeburn 6620: }
1.6 raeburn 6621:
6622: sub display_colorchgs {
6623: my ($dom,$changes,$roles,$confhash) = @_;
6624: my (%choices,$resulttext);
6625: if (!grep(/^login$/,@{$roles})) {
6626: $resulttext = &mt('Changes made:').'<br />';
6627: }
6628: foreach my $role (@{$roles}) {
6629: if ($role eq 'login') {
6630: %choices = &login_choices();
6631: } else {
6632: %choices = &color_font_choices();
6633: }
6634: if (ref($changes->{$role}) eq 'HASH') {
6635: if ($role ne 'login') {
6636: $resulttext .= '<h4>'.&mt($role).'</h4>';
6637: }
6638: foreach my $key (sort(keys(%{$changes->{$role}}))) {
6639: if ($role ne 'login') {
6640: $resulttext .= '<ul>';
6641: }
6642: if (ref($changes->{$role}{$key}) eq 'HASH') {
6643: if ($role ne 'login') {
6644: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
6645: }
6646: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 6647: if (($role eq 'login') && ($key eq 'showlogo')) {
6648: if ($confhash->{$role}{$key}{$item}) {
6649: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
6650: } else {
6651: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
6652: }
6653: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 6654: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
6655: } else {
1.12 raeburn 6656: my $newitem = $confhash->{$role}{$item};
6657: if ($key eq 'images') {
6658: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
6659: }
6660: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 6661: }
6662: }
6663: if ($role ne 'login') {
6664: $resulttext .= '</ul></li>';
6665: }
6666: } else {
6667: if ($confhash->{$role}{$key} eq '') {
6668: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
6669: } else {
6670: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
6671: }
6672: }
6673: if ($role ne 'login') {
6674: $resulttext .= '</ul>';
6675: }
6676: }
6677: }
6678: }
1.3 raeburn 6679: return $resulttext;
1.1 raeburn 6680: }
6681:
1.9 raeburn 6682: sub thumb_dimensions {
6683: return ('200','50');
6684: }
6685:
1.16 raeburn 6686: sub check_dimensions {
6687: my ($inputfile) = @_;
6688: my ($fullwidth,$fullheight);
6689: if ($inputfile =~ m|^[/\w.\-]+$|) {
6690: if (open(PIPE,"identify $inputfile 2>&1 |")) {
6691: my $imageinfo = <PIPE>;
6692: if (!close(PIPE)) {
6693: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
6694: }
6695: chomp($imageinfo);
6696: my ($fullsize) =
1.21 raeburn 6697: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 6698: if ($fullsize) {
6699: ($fullwidth,$fullheight) = split(/x/,$fullsize);
6700: }
6701: }
6702: }
6703: return ($fullwidth,$fullheight);
6704: }
6705:
1.9 raeburn 6706: sub check_configuser {
6707: my ($uhome,$dom,$confname,$servadm) = @_;
6708: my ($configuserok,%currroles);
6709: if ($uhome eq 'no_host') {
6710: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
6711: my $configpass = &LONCAPA::Enrollment::create_password();
6712: $configuserok =
6713: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
6714: $configpass,'','','','','',undef,$servadm);
6715: } else {
6716: $configuserok = 'ok';
6717: %currroles =
6718: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
6719: }
6720: return ($configuserok,%currroles);
6721: }
6722:
6723: sub check_authorstatus {
6724: my ($dom,$confname,%currroles) = @_;
6725: my $author_ok;
1.40 raeburn 6726: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 6727: my $start = time;
6728: my $end = 0;
6729: $author_ok =
6730: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 6731: 'au',$end,$start,'','','domconfig');
1.9 raeburn 6732: } else {
6733: $author_ok = 'ok';
6734: }
6735: return $author_ok;
6736: }
6737:
6738: sub publishlogo {
1.46 raeburn 6739: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 6740: my ($output,$fname,$logourl);
6741: if ($action eq 'upload') {
6742: $fname=$env{'form.'.$formname.'.filename'};
6743: chop($env{'form.'.$formname});
6744: } else {
6745: ($fname) = ($formname =~ /([^\/]+)$/);
6746: }
1.46 raeburn 6747: if ($savefileas ne '') {
6748: $fname = $savefileas;
6749: }
1.9 raeburn 6750: $fname=&Apache::lonnet::clean_filename($fname);
6751: # See if there is anything left
6752: unless ($fname) { return ('error: no uploaded file'); }
6753: $fname="$subdir/$fname";
1.210 raeburn 6754: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 6755: my $filepath="$docroot/priv";
6756: my $relpath = "$dom/$confname";
1.9 raeburn 6757: my ($fnamepath,$file,$fetchthumb);
6758: $file=$fname;
6759: if ($fname=~m|/|) {
6760: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
6761: }
1.164 raeburn 6762: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 6763: my $count;
1.164 raeburn 6764: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 6765: $filepath.="/$parts[$count]";
6766: if ((-e $filepath)!=1) {
6767: mkdir($filepath,02770);
6768: }
6769: }
6770: # Check for bad extension and disallow upload
6771: if ($file=~/\.(\w+)$/ &&
6772: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
6773: $output =
1.207 bisitz 6774: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 6775: } elsif ($file=~/\.(\w+)$/ &&
6776: !defined(&Apache::loncommon::fileembstyle($1))) {
6777: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
6778: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 6779: $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 6780: } elsif (-d "$filepath/$file") {
1.195 bisitz 6781: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 6782: } else {
6783: my $source = $filepath.'/'.$file;
6784: my $logfile;
6785: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 6786: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 6787: }
6788: print $logfile
6789: "\n================= Publish ".localtime()." ================\n".
6790: $env{'user.name'}.':'.$env{'user.domain'}."\n";
6791: # Save the file
6792: if (!open(FH,'>'.$source)) {
6793: &Apache::lonnet::logthis('Failed to create '.$source);
6794: return (&mt('Failed to create file'));
6795: }
6796: if ($action eq 'upload') {
6797: if (!print FH ($env{'form.'.$formname})) {
6798: &Apache::lonnet::logthis('Failed to write to '.$source);
6799: return (&mt('Failed to write file'));
6800: }
6801: } else {
6802: my $original = &Apache::lonnet::filelocation('',$formname);
6803: if(!copy($original,$source)) {
6804: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
6805: return (&mt('Failed to write file'));
6806: }
6807: }
6808: close(FH);
6809: chmod(0660, $source); # Permissions to rw-rw---.
6810:
6811: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
6812: my $copyfile=$targetdir.'/'.$file;
6813:
6814: my @parts=split(/\//,$targetdir);
6815: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
6816: for (my $count=5;$count<=$#parts;$count++) {
6817: $path.="/$parts[$count]";
6818: if (!-e $path) {
6819: print $logfile "\nCreating directory ".$path;
6820: mkdir($path,02770);
6821: }
6822: }
6823: my $versionresult;
6824: if (-e $copyfile) {
6825: $versionresult = &logo_versioning($targetdir,$file,$logfile);
6826: } else {
6827: $versionresult = 'ok';
6828: }
6829: if ($versionresult eq 'ok') {
6830: if (copy($source,$copyfile)) {
6831: print $logfile "\nCopied original source to ".$copyfile."\n";
6832: $output = 'ok';
6833: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 6834: push(@{$modified_urls},[$copyfile,$source]);
6835: my $metaoutput =
6836: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
6837: unless ($registered_cleanup) {
6838: my $handlers = $r->get_handlers('PerlCleanupHandler');
6839: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6840: $registered_cleanup=1;
6841: }
1.9 raeburn 6842: } else {
6843: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
6844: $output = &mt('Failed to copy file to RES space').", $!";
6845: }
6846: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
6847: my $inputfile = $filepath.'/'.$file;
6848: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 6849: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
6850: if ($fullwidth ne '' && $fullheight ne '') {
6851: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
6852: my $thumbsize = $thumbwidth.'x'.$thumbheight;
6853: system("convert -sample $thumbsize $inputfile $outfile");
6854: chmod(0660, $filepath.'/tn-'.$file);
6855: if (-e $outfile) {
6856: my $copyfile=$targetdir.'/tn-'.$file;
6857: if (copy($outfile,$copyfile)) {
6858: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 6859: my $thumb_metaoutput =
6860: &write_metadata($dom,$confname,$formname,
6861: $targetdir,'tn-'.$file,$logfile);
6862: push(@{$modified_urls},[$copyfile,$outfile]);
6863: unless ($registered_cleanup) {
6864: my $handlers = $r->get_handlers('PerlCleanupHandler');
6865: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
6866: $registered_cleanup=1;
6867: }
1.16 raeburn 6868: } else {
6869: print $logfile "\nUnable to write ".$copyfile.
6870: ':'.$!."\n";
6871: }
6872: }
1.9 raeburn 6873: }
6874: }
6875: }
6876: } else {
6877: $output = $versionresult;
6878: }
6879: }
6880: return ($output,$logourl);
6881: }
6882:
6883: sub logo_versioning {
6884: my ($targetdir,$file,$logfile) = @_;
6885: my $target = $targetdir.'/'.$file;
6886: my ($maxversion,$fn,$extn,$output);
6887: $maxversion = 0;
6888: if ($file =~ /^(.+)\.(\w+)$/) {
6889: $fn=$1;
6890: $extn=$2;
6891: }
6892: opendir(DIR,$targetdir);
6893: while (my $filename=readdir(DIR)) {
6894: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
6895: $maxversion=($1>$maxversion)?$1:$maxversion;
6896: }
6897: }
6898: $maxversion++;
6899: print $logfile "\nCreating old version ".$maxversion."\n";
6900: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
6901: if (copy($target,$copyfile)) {
6902: print $logfile "Copied old target to ".$copyfile."\n";
6903: $copyfile=$copyfile.'.meta';
6904: if (copy($target.'.meta',$copyfile)) {
6905: print $logfile "Copied old target metadata to ".$copyfile."\n";
6906: $output = 'ok';
6907: } else {
6908: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
6909: $output = &mt('Failed to copy old meta').", $!, ";
6910: }
6911: } else {
6912: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
6913: $output = &mt('Failed to copy old target').", $!, ";
6914: }
6915: return $output;
6916: }
6917:
6918: sub write_metadata {
6919: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
6920: my (%metadatafields,%metadatakeys,$output);
6921: $metadatafields{'title'}=$formname;
6922: $metadatafields{'creationdate'}=time;
6923: $metadatafields{'lastrevisiondate'}=time;
6924: $metadatafields{'copyright'}='public';
6925: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
6926: $env{'user.domain'};
6927: $metadatafields{'authorspace'}=$confname.':'.$dom;
6928: $metadatafields{'domain'}=$dom;
6929: {
6930: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
6931: my $mfh;
1.155 raeburn 6932: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 6933: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 6934: unless ($_=~/\./) {
6935: my $unikey=$_;
6936: $unikey=~/^([A-Za-z]+)/;
6937: my $tag=$1;
6938: $tag=~tr/A-Z/a-z/;
6939: print $mfh "\n\<$tag";
6940: foreach (split(/\,/,$metadatakeys{$unikey})) {
6941: my $value=$metadatafields{$unikey.'.'.$_};
6942: $value=~s/\"/\'\'/g;
6943: print $mfh ' '.$_.'="'.$value.'"';
6944: }
6945: print $mfh '>'.
6946: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
6947: .'</'.$tag.'>';
6948: }
6949: }
6950: $output = 'ok';
6951: print $logfile "\nWrote metadata";
6952: close($mfh);
6953: } else {
6954: print $logfile "\nFailed to open metadata file";
1.9 raeburn 6955: $output = &mt('Could not write metadata');
6956: }
6957: }
1.155 raeburn 6958: return $output;
6959: }
6960:
6961: sub notifysubscribed {
6962: foreach my $targetsource (@{$modified_urls}){
6963: next unless (ref($targetsource) eq 'ARRAY');
6964: my ($target,$source)=@{$targetsource};
6965: if ($source ne '') {
6966: if (open(my $logfh,'>>'.$source.'.log')) {
6967: print $logfh "\nCleanup phase: Notifications\n";
6968: my @subscribed=&subscribed_hosts($target);
6969: foreach my $subhost (@subscribed) {
6970: print $logfh "\nNotifying host ".$subhost.':';
6971: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
6972: print $logfh $reply;
6973: }
6974: my @subscribedmeta=&subscribed_hosts("$target.meta");
6975: foreach my $subhost (@subscribedmeta) {
6976: print $logfh "\nNotifying host for metadata only ".$subhost.':';
6977: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
6978: $subhost);
6979: print $logfh $reply;
6980: }
6981: print $logfh "\n============ Done ============\n";
1.160 raeburn 6982: close($logfh);
1.155 raeburn 6983: }
6984: }
6985: }
6986: return OK;
6987: }
6988:
6989: sub subscribed_hosts {
6990: my ($target) = @_;
6991: my @subscribed;
6992: if (open(my $fh,"<$target.subscription")) {
6993: while (my $subline=<$fh>) {
6994: if ($subline =~ /^($match_lonid):/) {
6995: my $host = $1;
6996: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
6997: unless (grep(/^\Q$host\E$/,@subscribed)) {
6998: push(@subscribed,$host);
6999: }
7000: }
7001: }
7002: }
7003: }
7004: return @subscribed;
1.9 raeburn 7005: }
7006:
7007: sub check_switchserver {
7008: my ($dom,$confname) = @_;
7009: my ($allowed,$switchserver);
7010: my $home = &Apache::lonnet::homeserver($confname,$dom);
7011: if ($home eq 'no_host') {
7012: $home = &Apache::lonnet::domain($dom,'primary');
7013: }
7014: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7015: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7016: if (!$allowed) {
1.180 raeburn 7017: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7018: }
7019: return $switchserver;
7020: }
7021:
1.1 raeburn 7022: sub modify_quotas {
1.216 raeburn 7023: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7024: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7025: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7026: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7027: $validationfieldsref);
1.86 raeburn 7028: if ($action eq 'quotas') {
7029: $context = 'tools';
1.163 raeburn 7030: } else {
1.86 raeburn 7031: $context = $action;
7032: }
7033: if ($context eq 'requestcourses') {
1.216 raeburn 7034: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7035: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7036: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7037: %titles = &courserequest_titles();
7038: $toolregexp = join('|',@usertools);
7039: %conditions = &courserequest_conditions();
1.216 raeburn 7040: $confname = $dom.'-domainconfig';
7041: my $servadm = $r->dir_config('lonAdmEMail');
7042: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7043: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7044: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7045: } elsif ($context eq 'requestauthor') {
7046: @usertools = ('author');
7047: %titles = &authorrequest_titles();
1.86 raeburn 7048: } else {
1.162 raeburn 7049: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7050: %titles = &tool_titles();
1.86 raeburn 7051: }
1.212 raeburn 7052: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7053: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7054: foreach my $key (keys(%env)) {
1.101 raeburn 7055: if ($context eq 'requestcourses') {
7056: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7057: my $item = $1;
7058: my $type = $2;
7059: if ($type =~ /^limit_(.+)/) {
7060: $limithash{$item}{$1} = $env{$key};
7061: } else {
7062: $confhash{$item}{$type} = $env{$key};
7063: }
7064: }
1.163 raeburn 7065: } elsif ($context eq 'requestauthor') {
7066: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7067: $confhash{$1} = $env{$key};
7068: }
1.101 raeburn 7069: } else {
1.86 raeburn 7070: if ($key =~ /^form\.quota_(.+)$/) {
7071: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7072: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7073: $confhash{'authorquota'}{$1} = $env{$key};
7074: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7075: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7076: }
1.72 raeburn 7077: }
7078: }
1.163 raeburn 7079: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7080: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7081: @approvalnotify = sort(@approvalnotify);
7082: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.218 raeburn 7083: my @crstypes = ('official','unofficial','community','textbook');
7084: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7085: foreach my $type (@hasuniquecode) {
7086: if (grep(/^\Q$type\E$/,@crstypes)) {
7087: $confhash{'uniquecode'}{$type} = 1;
7088: }
1.216 raeburn 7089: }
1.242 raeburn 7090: my (%newbook,%allpos);
1.216 raeburn 7091: if ($context eq 'requestcourses') {
1.242 raeburn 7092: foreach my $type ('textbooks','templates') {
7093: @{$allpos{$type}} = ();
7094: my $invalid;
7095: if ($type eq 'textbooks') {
7096: $invalid = &mt('Invalid LON-CAPA course for textbook');
7097: } else {
7098: $invalid = &mt('Invalid LON-CAPA course for template');
7099: }
7100: if ($env{'form.'.$type.'_addbook'}) {
7101: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7102: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7103: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7104: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7105: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7106: } else {
7107: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7108: my $position = $env{'form.'.$type.'_addbook_pos'};
7109: $position =~ s/\D+//g;
7110: if ($position ne '') {
7111: $allpos{$type}[$position] = $newbook{$type};
7112: }
1.216 raeburn 7113: }
1.242 raeburn 7114: } else {
7115: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7116: }
7117: }
1.242 raeburn 7118: }
1.216 raeburn 7119: }
1.102 raeburn 7120: if (ref($domconfig{$action}) eq 'HASH') {
7121: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7122: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7123: $changes{'notify'}{'approval'} = 1;
7124: }
7125: } else {
1.144 raeburn 7126: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7127: $changes{'notify'}{'approval'} = 1;
7128: }
7129: }
1.218 raeburn 7130: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7131: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7132: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7133: unless ($confhash{'uniquecode'}{$crstype}) {
7134: $changes{'uniquecode'} = 1;
7135: }
7136: }
7137: unless ($changes{'uniquecode'}) {
7138: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7139: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7140: $changes{'uniquecode'} = 1;
7141: }
7142: }
7143: }
7144: } else {
7145: $changes{'uniquecode'} = 1;
7146: }
7147: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7148: $changes{'uniquecode'} = 1;
1.216 raeburn 7149: }
7150: if ($context eq 'requestcourses') {
1.242 raeburn 7151: foreach my $type ('textbooks','templates') {
7152: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7153: my %deletions;
7154: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7155: if (@todelete) {
7156: map { $deletions{$_} = 1; } @todelete;
7157: }
7158: my %imgdeletions;
7159: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7160: if (@todeleteimages) {
7161: map { $imgdeletions{$_} = 1; } @todeleteimages;
7162: }
7163: my $maxnum = $env{'form.'.$type.'_maxnum'};
7164: for (my $i=0; $i<=$maxnum; $i++) {
7165: my $itemid = $env{'form.'.$type.'_id_'.$i};
7166: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7167: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7168: if ($deletions{$key}) {
7169: if ($domconfig{$action}{$type}{$key}{'image'}) {
7170: #FIXME need to obsolete item in RES space
7171: }
7172: next;
7173: } else {
7174: my $newpos = $env{'form.'.$itemid};
7175: $newpos =~ s/\D+//g;
1.243 raeburn 7176: foreach my $item ('subject','title','publisher','author') {
7177: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7178: ($type eq 'templates'));
1.242 raeburn 7179: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7180: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7181: $changes{$type}{$key} = 1;
7182: }
7183: }
7184: $allpos{$type}[$newpos] = $key;
7185: }
7186: if ($imgdeletions{$key}) {
7187: $changes{$type}{$key} = 1;
1.216 raeburn 7188: #FIXME need to obsolete item in RES space
1.242 raeburn 7189: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7190: my ($cdom,$cnum) = split(/_/,$key);
7191: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7192: $cdom,$cnum,$type,$configuserok,
7193: $switchserver,$author_ok);
7194: if ($imgurl) {
7195: $confhash{$type}{$key}{'image'} = $imgurl;
7196: $changes{$type}{$key} = 1;
1.216 raeburn 7197: }
1.242 raeburn 7198: if ($error) {
7199: &Apache::lonnet::logthis($error);
7200: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7201: }
7202: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7203: $confhash{$type}{$key}{'image'} =
7204: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7205: }
7206: }
7207: }
7208: }
7209: }
7210: }
1.102 raeburn 7211: } else {
1.144 raeburn 7212: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7213: $changes{'notify'}{'approval'} = 1;
7214: }
1.218 raeburn 7215: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7216: $changes{'uniquecode'} = 1;
7217: }
7218: }
7219: if ($context eq 'requestcourses') {
1.242 raeburn 7220: foreach my $type ('textbooks','templates') {
7221: if ($newbook{$type}) {
7222: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7223: foreach my $item ('subject','title','publisher','author') {
7224: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7225: ($type eq 'template'));
1.242 raeburn 7226: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7227: if ($env{'form.'.$type.'_addbook_'.$item}) {
7228: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7229: }
7230: }
7231: if ($type eq 'textbooks') {
7232: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7233: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7234: my ($imageurl,$error) =
7235: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7236: $configuserok,$switchserver,$author_ok);
7237: if ($imageurl) {
7238: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7239: }
7240: if ($error) {
7241: &Apache::lonnet::logthis($error);
7242: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7243: }
7244: }
1.216 raeburn 7245: }
7246: }
1.242 raeburn 7247: if (@{$allpos{$type}} > 0) {
7248: my $idx = 0;
7249: foreach my $item (@{$allpos{$type}}) {
7250: if ($item ne '') {
7251: $confhash{$type}{$item}{'order'} = $idx;
7252: if (ref($domconfig{$action}) eq 'HASH') {
7253: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7254: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7255: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7256: $changes{$type}{$item} = 1;
7257: }
1.216 raeburn 7258: }
7259: }
7260: }
1.242 raeburn 7261: $idx ++;
1.216 raeburn 7262: }
7263: }
7264: }
7265: }
1.235 raeburn 7266: if (ref($validationitemsref) eq 'ARRAY') {
7267: foreach my $item (@{$validationitemsref}) {
7268: if ($item eq 'fields') {
7269: my @changed;
7270: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7271: if (@{$confhash{'validation'}{$item}} > 0) {
7272: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7273: }
7274: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7275: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7276: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7277: $domconfig{'requestcourses'}{'validation'}{$item});
7278: } else {
7279: @changed = @{$confhash{'validation'}{$item}};
7280: }
7281: } else {
7282: @changed = @{$confhash{'validation'}{$item}};
7283: }
7284: if (@changed) {
7285: if ($confhash{'validation'}{$item}) {
7286: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7287: } else {
7288: $changes{'validation'}{$item} = &mt('None');
7289: }
7290: }
7291: } else {
7292: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7293: if ($item eq 'markup') {
7294: if ($env{'form.requestcourses_validation_'.$item}) {
7295: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7296: }
7297: }
7298: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7299: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7300: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7301: }
7302: } else {
7303: if ($confhash{'validation'}{$item} ne '') {
7304: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7305: }
7306: }
7307: }
7308: }
7309: }
7310: if ($env{'form.validationdc'}) {
7311: my $newval = $env{'form.validationdc'};
7312: my %domcoords = &get_active_dcs($dom);
7313: if (exists($domcoords{$newval})) {
7314: $confhash{'validation'}{'dc'} = $newval;
7315: }
7316: }
7317: if (ref($confhash{'validation'}) eq 'HASH') {
7318: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7319: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7320: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7321: if ($confhash{'validation'}{'dc'} eq '') {
7322: $changes{'validation'}{'dc'} = &mt('None');
7323: } else {
7324: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7325: }
7326: }
7327: } elsif ($confhash{'validation'}{'dc'} ne '') {
7328: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7329: }
7330: } elsif ($confhash{'validation'}{'dc'} ne '') {
7331: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7332: }
7333: } elsif (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7334: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7335: $changes{'validation'}{'dc'} = &mt('None');
7336: }
7337: }
1.102 raeburn 7338: }
7339: } else {
1.86 raeburn 7340: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7341: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7342: }
1.72 raeburn 7343: foreach my $item (@usertools) {
7344: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7345: my $unset;
1.101 raeburn 7346: if ($context eq 'requestcourses') {
1.104 raeburn 7347: $unset = '0';
7348: if ($type eq '_LC_adv') {
7349: $unset = '';
7350: }
1.101 raeburn 7351: if ($confhash{$item}{$type} eq 'autolimit') {
7352: $confhash{$item}{$type} .= '=';
7353: unless ($limithash{$item}{$type} =~ /\D/) {
7354: $confhash{$item}{$type} .= $limithash{$item}{$type};
7355: }
7356: }
1.163 raeburn 7357: } elsif ($context eq 'requestauthor') {
7358: $unset = '0';
7359: if ($type eq '_LC_adv') {
7360: $unset = '';
7361: }
1.72 raeburn 7362: } else {
1.101 raeburn 7363: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7364: $confhash{$item}{$type} = 1;
7365: } else {
7366: $confhash{$item}{$type} = 0;
7367: }
1.72 raeburn 7368: }
1.86 raeburn 7369: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7370: if ($action eq 'requestauthor') {
7371: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7372: $changes{$type} = 1;
7373: }
7374: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7375: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7376: $changes{$item}{$type} = 1;
7377: }
7378: } else {
7379: if ($context eq 'requestcourses') {
1.104 raeburn 7380: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7381: $changes{$item}{$type} = 1;
7382: }
7383: } else {
7384: if (!$confhash{$item}{$type}) {
7385: $changes{$item}{$type} = 1;
7386: }
7387: }
7388: }
7389: } else {
7390: if ($context eq 'requestcourses') {
1.104 raeburn 7391: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7392: $changes{$item}{$type} = 1;
7393: }
1.163 raeburn 7394: } elsif ($context eq 'requestauthor') {
7395: if ($confhash{$type} ne $unset) {
7396: $changes{$type} = 1;
7397: }
1.72 raeburn 7398: } else {
7399: if (!$confhash{$item}{$type}) {
7400: $changes{$item}{$type} = 1;
7401: }
7402: }
7403: }
1.1 raeburn 7404: }
7405: }
1.163 raeburn 7406: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7407: if (ref($domconfig{'quotas'}) eq 'HASH') {
7408: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7409: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7410: if (exists($confhash{'defaultquota'}{$key})) {
7411: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7412: $changes{'defaultquota'}{$key} = 1;
7413: }
7414: } else {
7415: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 7416: }
7417: }
1.86 raeburn 7418: } else {
7419: foreach my $key (keys(%{$domconfig{'quotas'}})) {
7420: if (exists($confhash{'defaultquota'}{$key})) {
7421: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
7422: $changes{'defaultquota'}{$key} = 1;
7423: }
7424: } else {
7425: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 7426: }
1.1 raeburn 7427: }
7428: }
1.197 raeburn 7429: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7430: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
7431: if (exists($confhash{'authorquota'}{$key})) {
7432: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
7433: $changes{'authorquota'}{$key} = 1;
7434: }
7435: } else {
7436: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
7437: }
7438: }
7439: }
1.1 raeburn 7440: }
1.86 raeburn 7441: if (ref($confhash{'defaultquota'}) eq 'HASH') {
7442: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
7443: if (ref($domconfig{'quotas'}) eq 'HASH') {
7444: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7445: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
7446: $changes{'defaultquota'}{$key} = 1;
7447: }
7448: } else {
7449: if (!exists($domconfig{'quotas'}{$key})) {
7450: $changes{'defaultquota'}{$key} = 1;
7451: }
1.72 raeburn 7452: }
7453: } else {
1.86 raeburn 7454: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 7455: }
1.1 raeburn 7456: }
7457: }
1.197 raeburn 7458: if (ref($confhash{'authorquota'}) eq 'HASH') {
7459: foreach my $key (keys(%{$confhash{'authorquota'}})) {
7460: if (ref($domconfig{'quotas'}) eq 'HASH') {
7461: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
7462: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
7463: $changes{'authorquota'}{$key} = 1;
7464: }
7465: } else {
7466: $changes{'authorquota'}{$key} = 1;
7467: }
7468: } else {
7469: $changes{'authorquota'}{$key} = 1;
7470: }
7471: }
7472: }
1.1 raeburn 7473: }
1.72 raeburn 7474:
1.163 raeburn 7475: if ($context eq 'requestauthor') {
7476: $domdefaults{'requestauthor'} = \%confhash;
7477: } else {
7478: foreach my $key (keys(%confhash)) {
1.242 raeburn 7479: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 7480: $domdefaults{$key} = $confhash{$key};
7481: }
1.163 raeburn 7482: }
1.72 raeburn 7483: }
1.163 raeburn 7484:
1.1 raeburn 7485: my %quotahash = (
1.86 raeburn 7486: $action => { %confhash }
1.1 raeburn 7487: );
7488: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
7489: $dom);
7490: if ($putresult eq 'ok') {
7491: if (keys(%changes) > 0) {
1.72 raeburn 7492: my $cachetime = 24*60*60;
7493: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 7494: if (ref($lastactref) eq 'HASH') {
7495: $lastactref->{'domdefaults'} = 1;
7496: }
1.1 raeburn 7497: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 7498: unless (($context eq 'requestcourses') ||
1.163 raeburn 7499: ($context eq 'requestauthor')) {
1.86 raeburn 7500: if (ref($changes{'defaultquota'}) eq 'HASH') {
7501: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
7502: foreach my $type (@{$types},'default') {
7503: if (defined($changes{'defaultquota'}{$type})) {
7504: my $typetitle = $usertypes->{$type};
7505: if ($type eq 'default') {
7506: $typetitle = $othertitle;
7507: }
1.213 raeburn 7508: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 7509: }
7510: }
1.86 raeburn 7511: $resulttext .= '</ul></li>';
1.72 raeburn 7512: }
1.197 raeburn 7513: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 7514: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 7515: foreach my $type (@{$types},'default') {
7516: if (defined($changes{'authorquota'}{$type})) {
7517: my $typetitle = $usertypes->{$type};
7518: if ($type eq 'default') {
7519: $typetitle = $othertitle;
7520: }
1.213 raeburn 7521: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 7522: }
7523: }
7524: $resulttext .= '</ul></li>';
7525: }
1.72 raeburn 7526: }
1.80 raeburn 7527: my %newenv;
1.72 raeburn 7528: foreach my $item (@usertools) {
1.163 raeburn 7529: my (%haschgs,%inconf);
7530: if ($context eq 'requestauthor') {
7531: %haschgs = %changes;
1.210 raeburn 7532: %inconf = %confhash;
1.163 raeburn 7533: } else {
7534: if (ref($changes{$item}) eq 'HASH') {
7535: %haschgs = %{$changes{$item}};
7536: }
7537: if (ref($confhash{$item}) eq 'HASH') {
7538: %inconf = %{$confhash{$item}};
7539: }
7540: }
7541: if (keys(%haschgs) > 0) {
1.80 raeburn 7542: my $newacc =
7543: &Apache::lonnet::usertools_access($env{'user.name'},
7544: $env{'user.domain'},
1.86 raeburn 7545: $item,'reload',$context);
1.210 raeburn 7546: if (($context eq 'requestcourses') ||
1.163 raeburn 7547: ($context eq 'requestauthor')) {
1.108 raeburn 7548: if ($env{'environment.canrequest.'.$item} ne $newacc) {
7549: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 7550: }
7551: } else {
7552: if ($env{'environment.availabletools.'.$item} ne $newacc) {
7553: $newenv{'environment.availabletools.'.$item} = $newacc;
7554: }
1.80 raeburn 7555: }
1.163 raeburn 7556: unless ($context eq 'requestauthor') {
7557: $resulttext .= '<li>'.$titles{$item}.'<ul>';
7558: }
1.72 raeburn 7559: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 7560: if ($haschgs{$type}) {
1.72 raeburn 7561: my $typetitle = $usertypes->{$type};
7562: if ($type eq 'default') {
7563: $typetitle = $othertitle;
7564: } elsif ($type eq '_LC_adv') {
7565: $typetitle = 'LON-CAPA Advanced Users';
7566: }
1.163 raeburn 7567: if ($inconf{$type}) {
1.101 raeburn 7568: if ($context eq 'requestcourses') {
7569: my $cond;
1.163 raeburn 7570: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 7571: if ($1 eq '') {
7572: $cond = &mt('(Automatic processing of any request).');
7573: } else {
7574: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
7575: }
7576: } else {
1.163 raeburn 7577: $cond = $conditions{$inconf{$type}};
1.101 raeburn 7578: }
7579: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 7580: } elsif ($context eq 'requestauthor') {
7581: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
7582: $titles{$inconf{$type}},$typetitle);
7583:
1.101 raeburn 7584: } else {
7585: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
7586: }
1.72 raeburn 7587: } else {
1.104 raeburn 7588: if ($type eq '_LC_adv') {
1.163 raeburn 7589: if ($inconf{$type} eq '0') {
1.104 raeburn 7590: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7591: } else {
7592: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
7593: }
7594: } else {
7595: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
7596: }
1.72 raeburn 7597: }
7598: }
1.26 raeburn 7599: }
1.163 raeburn 7600: unless ($context eq 'requestauthor') {
7601: $resulttext .= '</ul></li>';
7602: }
1.26 raeburn 7603: }
1.1 raeburn 7604: }
1.163 raeburn 7605: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 7606: if (ref($changes{'notify'}) eq 'HASH') {
7607: if ($changes{'notify'}{'approval'}) {
7608: if (ref($confhash{'notify'}) eq 'HASH') {
7609: if ($confhash{'notify'}{'approval'}) {
7610: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
7611: } else {
1.163 raeburn 7612: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 7613: }
7614: }
7615: }
7616: }
7617: }
1.216 raeburn 7618: if ($action eq 'requestcourses') {
7619: my @offon = ('off','on');
7620: if ($changes{'uniquecode'}) {
1.218 raeburn 7621: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7622: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
7623: $resulttext .= '<li>'.
7624: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
7625: '</li>';
7626: } else {
7627: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
7628: '</li>';
7629: }
1.216 raeburn 7630: }
1.242 raeburn 7631: foreach my $type ('textbooks','templates') {
7632: if (ref($changes{$type}) eq 'HASH') {
7633: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
7634: foreach my $key (sort(keys(%{$changes{$type}}))) {
7635: my %coursehash = &Apache::lonnet::coursedescription($key);
7636: my $coursetitle = $coursehash{'description'};
7637: my $position = $confhash{$type}{$key}{'order'} + 1;
7638: $resulttext .= '<li>';
1.243 raeburn 7639: foreach my $item ('subject','title','publisher','author') {
7640: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7641: ($type eq 'templates'));
1.242 raeburn 7642: my $name = $item.':';
7643: $name =~ s/^(\w)/\U$1/;
7644: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
7645: }
7646: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
7647: if ($type eq 'textbooks') {
7648: if ($confhash{$type}{$key}{'image'}) {
7649: $resulttext .= ' '.&mt('Image: [_1]',
7650: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
7651: ' alt="Textbook cover" />').'<br />';
7652: }
7653: }
7654: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 7655: }
1.242 raeburn 7656: $resulttext .= '</ul></li>';
1.216 raeburn 7657: }
7658: }
1.235 raeburn 7659: if (ref($changes{'validation'}) eq 'HASH') {
7660: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
7661: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
7662: foreach my $item (@{$validationitemsref}) {
7663: if (exists($changes{'validation'}{$item})) {
7664: if ($item eq 'markup') {
7665: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7666: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
7667: } else {
7668: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
7669: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
7670: }
7671: }
7672: }
7673: if (exists($changes{'validation'}{'dc'})) {
7674: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
7675: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
7676: }
7677: }
7678: }
1.216 raeburn 7679: }
1.1 raeburn 7680: $resulttext .= '</ul>';
1.80 raeburn 7681: if (keys(%newenv)) {
7682: &Apache::lonnet::appenv(\%newenv);
7683: }
1.1 raeburn 7684: } else {
1.86 raeburn 7685: if ($context eq 'requestcourses') {
7686: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 7687: } elsif ($context eq 'requestauthor') {
7688: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 7689: } else {
1.90 weissno 7690: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 7691: }
1.1 raeburn 7692: }
7693: } else {
1.11 albertel 7694: $resulttext = '<span class="LC_error">'.
7695: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7696: }
1.216 raeburn 7697: if ($errors) {
7698: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
7699: '<ul>'.$errors.'</ul></p>';
7700: }
1.3 raeburn 7701: return $resulttext;
1.1 raeburn 7702: }
7703:
1.216 raeburn 7704: sub process_textbook_image {
1.242 raeburn 7705: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 7706: my $filename = $env{'form.'.$caller.'.filename'};
7707: my ($error,$url);
7708: my ($width,$height) = (50,50);
7709: if ($configuserok eq 'ok') {
7710: if ($switchserver) {
7711: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
7712: $switchserver);
7713: } elsif ($author_ok eq 'ok') {
7714: my ($result,$imageurl) =
7715: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 7716: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 7717: if ($result eq 'ok') {
7718: $url = $imageurl;
7719: } else {
7720: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
7721: }
7722: } else {
7723: $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);
7724: }
7725: } else {
7726: $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);
7727: }
7728: return ($url,$error);
7729: }
7730:
1.3 raeburn 7731: sub modify_autoenroll {
1.205 raeburn 7732: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 7733: my ($resulttext,%changes);
7734: my %currautoenroll;
7735: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
7736: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
7737: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
7738: }
7739: }
7740: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
7741: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 7742: sender => 'Sender for notification messages',
7743: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 7744: my @offon = ('off','on');
1.17 raeburn 7745: my $sender_uname = $env{'form.sender_uname'};
7746: my $sender_domain = $env{'form.sender_domain'};
7747: if ($sender_domain eq '') {
7748: $sender_uname = '';
7749: } elsif ($sender_uname eq '') {
7750: $sender_domain = '';
7751: }
1.129 raeburn 7752: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 7753: my %autoenrollhash = (
1.129 raeburn 7754: autoenroll => { 'run' => $env{'form.autoenroll_run'},
7755: 'sender_uname' => $sender_uname,
7756: 'sender_domain' => $sender_domain,
7757: 'co-owners' => $coowners,
1.1 raeburn 7758: }
7759: );
1.4 raeburn 7760: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
7761: $dom);
1.1 raeburn 7762: if ($putresult eq 'ok') {
7763: if (exists($currautoenroll{'run'})) {
7764: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
7765: $changes{'run'} = 1;
7766: }
7767: } elsif ($autorun) {
7768: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 7769: $changes{'run'} = 1;
1.1 raeburn 7770: }
7771: }
1.17 raeburn 7772: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 7773: $changes{'sender'} = 1;
7774: }
1.17 raeburn 7775: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 7776: $changes{'sender'} = 1;
7777: }
1.129 raeburn 7778: if ($currautoenroll{'co-owners'} ne '') {
7779: if ($currautoenroll{'co-owners'} ne $coowners) {
7780: $changes{'coowners'} = 1;
7781: }
7782: } elsif ($coowners) {
7783: $changes{'coowners'} = 1;
7784: }
1.1 raeburn 7785: if (keys(%changes) > 0) {
7786: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 7787: if ($changes{'run'}) {
1.1 raeburn 7788: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
7789: }
7790: if ($changes{'sender'}) {
1.17 raeburn 7791: if ($sender_uname eq '' || $sender_domain eq '') {
7792: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
7793: } else {
7794: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
7795: }
1.1 raeburn 7796: }
1.129 raeburn 7797: if ($changes{'coowners'}) {
7798: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
7799: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7800: if (ref($lastactref) eq 'HASH') {
7801: $lastactref->{'domainconfig'} = 1;
7802: }
1.129 raeburn 7803: }
1.1 raeburn 7804: $resulttext .= '</ul>';
7805: } else {
7806: $resulttext = &mt('No changes made to auto-enrollment settings');
7807: }
7808: } else {
1.11 albertel 7809: $resulttext = '<span class="LC_error">'.
7810: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7811: }
1.3 raeburn 7812: return $resulttext;
1.1 raeburn 7813: }
7814:
7815: sub modify_autoupdate {
1.3 raeburn 7816: my ($dom,%domconfig) = @_;
1.1 raeburn 7817: my ($resulttext,%currautoupdate,%fields,%changes);
7818: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
7819: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
7820: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
7821: }
7822: }
7823: my @offon = ('off','on');
7824: my %title = &Apache::lonlocal::texthash (
7825: run => 'Auto-update:',
7826: classlists => 'Updates to user information in classlists?'
7827: );
1.44 raeburn 7828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7829: my %fieldtitles = &Apache::lonlocal::texthash (
7830: id => 'Student/Employee ID',
1.20 raeburn 7831: permanentemail => 'E-mail address',
1.1 raeburn 7832: lastname => 'Last Name',
7833: firstname => 'First Name',
7834: middlename => 'Middle Name',
1.132 raeburn 7835: generation => 'Generation',
1.1 raeburn 7836: );
1.142 raeburn 7837: $othertitle = &mt('All users');
1.1 raeburn 7838: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 7839: $othertitle = &mt('Other users');
1.1 raeburn 7840: }
7841: foreach my $key (keys(%env)) {
7842: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 7843: my ($usertype,$item) = ($1,$2);
7844: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
7845: if ($usertype eq 'default') {
7846: push(@{$fields{$1}},$2);
7847: } elsif (ref($types) eq 'ARRAY') {
7848: if (grep(/^\Q$usertype\E$/,@{$types})) {
7849: push(@{$fields{$1}},$2);
7850: }
7851: }
7852: }
1.1 raeburn 7853: }
7854: }
1.131 raeburn 7855: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
7856: @lockablenames = sort(@lockablenames);
7857: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
7858: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7859: if (@changed) {
7860: $changes{'lockablenames'} = 1;
7861: }
7862: } else {
7863: if (@lockablenames) {
7864: $changes{'lockablenames'} = 1;
7865: }
7866: }
1.1 raeburn 7867: my %updatehash = (
7868: autoupdate => { run => $env{'form.autoupdate_run'},
7869: classlists => $env{'form.classlists'},
7870: fields => {%fields},
1.131 raeburn 7871: lockablenames => \@lockablenames,
1.1 raeburn 7872: }
7873: );
7874: foreach my $key (keys(%currautoupdate)) {
7875: if (($key eq 'run') || ($key eq 'classlists')) {
7876: if (exists($updatehash{autoupdate}{$key})) {
7877: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
7878: $changes{$key} = 1;
7879: }
7880: }
7881: } elsif ($key eq 'fields') {
7882: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 7883: foreach my $item (@{$types},'default') {
1.1 raeburn 7884: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
7885: my $change = 0;
7886: foreach my $type (@{$currautoupdate{$key}{$item}}) {
7887: if (!exists($fields{$item})) {
7888: $change = 1;
1.132 raeburn 7889: last;
1.1 raeburn 7890: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 7891: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 7892: $change = 1;
1.132 raeburn 7893: last;
1.1 raeburn 7894: }
7895: }
7896: }
7897: if ($change) {
7898: push(@{$changes{$key}},$item);
7899: }
1.26 raeburn 7900: }
1.1 raeburn 7901: }
7902: }
1.131 raeburn 7903: } elsif ($key eq 'lockablenames') {
7904: if (ref($currautoupdate{$key}) eq 'ARRAY') {
7905: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
7906: if (@changed) {
7907: $changes{'lockablenames'} = 1;
7908: }
7909: } else {
7910: if (@lockablenames) {
7911: $changes{'lockablenames'} = 1;
7912: }
7913: }
7914: }
7915: }
7916: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
7917: if (@lockablenames) {
7918: $changes{'lockablenames'} = 1;
1.1 raeburn 7919: }
7920: }
1.26 raeburn 7921: foreach my $item (@{$types},'default') {
7922: if (defined($fields{$item})) {
7923: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 7924: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
7925: my $change = 0;
7926: if (ref($fields{$item}) eq 'ARRAY') {
7927: foreach my $type (@{$fields{$item}}) {
7928: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
7929: $change = 1;
7930: last;
7931: }
7932: }
7933: }
7934: if ($change) {
7935: push(@{$changes{'fields'}},$item);
7936: }
7937: } else {
1.26 raeburn 7938: push(@{$changes{'fields'}},$item);
7939: }
7940: } else {
7941: push(@{$changes{'fields'}},$item);
1.1 raeburn 7942: }
7943: }
7944: }
7945: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
7946: $dom);
7947: if ($putresult eq 'ok') {
7948: if (keys(%changes) > 0) {
7949: $resulttext = &mt('Changes made:').'<ul>';
7950: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 7951: if ($key eq 'lockablenames') {
7952: $resulttext .= '<li>';
7953: if (@lockablenames) {
7954: $usertypes->{'default'} = $othertitle;
7955: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
7956: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
7957: } else {
7958: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
7959: }
7960: $resulttext .= '</li>';
7961: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 7962: foreach my $item (@{$changes{$key}}) {
7963: my @newvalues;
7964: foreach my $type (@{$fields{$item}}) {
7965: push(@newvalues,$fieldtitles{$type});
7966: }
1.3 raeburn 7967: my $newvaluestr;
7968: if (@newvalues > 0) {
7969: $newvaluestr = join(', ',@newvalues);
7970: } else {
7971: $newvaluestr = &mt('none');
1.6 raeburn 7972: }
1.1 raeburn 7973: if ($item eq 'default') {
1.26 raeburn 7974: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 7975: } else {
1.26 raeburn 7976: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 7977: }
7978: }
7979: } else {
7980: my $newvalue;
7981: if ($key eq 'run') {
7982: $newvalue = $offon[$env{'form.autoupdate_run'}];
7983: } else {
7984: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 7985: }
1.1 raeburn 7986: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
7987: }
7988: }
7989: $resulttext .= '</ul>';
7990: } else {
1.3 raeburn 7991: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 7992: }
7993: } else {
1.11 albertel 7994: $resulttext = '<span class="LC_error">'.
7995: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7996: }
1.3 raeburn 7997: return $resulttext;
1.1 raeburn 7998: }
7999:
1.125 raeburn 8000: sub modify_autocreate {
8001: my ($dom,%domconfig) = @_;
8002: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8003: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8004: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8005: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8006: }
8007: }
8008: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8009: req => 'Auto-creation of validated requests for official courses',
8010: xmldc => 'Identity of course creator of courses from XML files',
8011: );
8012: my @types = ('xml','req');
8013: foreach my $item (@types) {
8014: $newvals{$item} = $env{'form.autocreate_'.$item};
8015: $newvals{$item} =~ s/\D//g;
8016: $newvals{$item} = 0 if ($newvals{$item} eq '');
8017: }
8018: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
8019: my %domcoords = &get_active_dcs($dom);
8020: unless (exists($domcoords{$newvals{'xmldc'}})) {
8021: $newvals{'xmldc'} = '';
8022: }
8023: %autocreatehash = (
8024: autocreate => { xml => $newvals{'xml'},
8025: req => $newvals{'req'},
8026: }
8027: );
8028: if ($newvals{'xmldc'} ne '') {
8029: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
8030: }
8031: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
8032: $dom);
8033: if ($putresult eq 'ok') {
8034: my @items = @types;
8035: if ($newvals{'xml'}) {
8036: push(@items,'xmldc');
8037: }
8038: foreach my $item (@items) {
8039: if (exists($currautocreate{$item})) {
8040: if ($currautocreate{$item} ne $newvals{$item}) {
8041: $changes{$item} = 1;
8042: }
8043: } elsif ($newvals{$item}) {
8044: $changes{$item} = 1;
8045: }
8046: }
8047: if (keys(%changes) > 0) {
8048: my @offon = ('off','on');
8049: $resulttext = &mt('Changes made:').'<ul>';
8050: foreach my $item (@types) {
8051: if ($changes{$item}) {
8052: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 8053: $resulttext .= '<li>'.
8054: &mt("$title{$item} set to [_1]$newtxt [_2]",
8055: '<b>','</b>').
8056: '</li>';
1.125 raeburn 8057: }
8058: }
8059: if ($changes{'xmldc'}) {
8060: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
8061: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 8062: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 8063: }
8064: $resulttext .= '</ul>';
8065: } else {
8066: $resulttext = &mt('No changes made to auto-creation settings');
8067: }
8068: } else {
8069: $resulttext = '<span class="LC_error">'.
8070: &mt('An error occurred: [_1]',$putresult).'</span>';
8071: }
8072: return $resulttext;
8073: }
8074:
1.23 raeburn 8075: sub modify_directorysrch {
8076: my ($dom,%domconfig) = @_;
8077: my ($resulttext,%changes);
8078: my %currdirsrch;
8079: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
8080: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
8081: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
8082: }
8083: }
8084: my %title = ( available => 'Directory search available',
1.24 raeburn 8085: localonly => 'Other domains can search',
1.23 raeburn 8086: searchby => 'Search types',
8087: searchtypes => 'Search latitude');
8088: my @offon = ('off','on');
1.24 raeburn 8089: my @otherdoms = ('Yes','No');
1.23 raeburn 8090:
1.25 raeburn 8091: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 8092: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
8093: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
8094:
1.44 raeburn 8095: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 8096: if (keys(%{$usertypes}) == 0) {
8097: @cansearch = ('default');
8098: } else {
8099: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
8100: foreach my $type (@{$currdirsrch{'cansearch'}}) {
8101: if (!grep(/^\Q$type\E$/,@cansearch)) {
8102: push(@{$changes{'cansearch'}},$type);
8103: }
1.23 raeburn 8104: }
1.26 raeburn 8105: foreach my $type (@cansearch) {
8106: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
8107: push(@{$changes{'cansearch'}},$type);
8108: }
1.23 raeburn 8109: }
1.26 raeburn 8110: } else {
8111: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 8112: }
8113: }
8114:
8115: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
8116: foreach my $by (@{$currdirsrch{'searchby'}}) {
8117: if (!grep(/^\Q$by\E$/,@searchby)) {
8118: push(@{$changes{'searchby'}},$by);
8119: }
8120: }
8121: foreach my $by (@searchby) {
8122: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
8123: push(@{$changes{'searchby'}},$by);
8124: }
8125: }
8126: } else {
8127: push(@{$changes{'searchby'}},@searchby);
8128: }
1.25 raeburn 8129:
8130: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
8131: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
8132: if (!grep(/^\Q$type\E$/,@searchtypes)) {
8133: push(@{$changes{'searchtypes'}},$type);
8134: }
8135: }
8136: foreach my $type (@searchtypes) {
8137: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
8138: push(@{$changes{'searchtypes'}},$type);
8139: }
8140: }
8141: } else {
8142: if (exists($currdirsrch{'searchtypes'})) {
8143: foreach my $type (@searchtypes) {
8144: if ($type ne $currdirsrch{'searchtypes'}) {
8145: push(@{$changes{'searchtypes'}},$type);
8146: }
8147: }
8148: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
8149: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
8150: }
8151: } else {
8152: push(@{$changes{'searchtypes'}},@searchtypes);
8153: }
8154: }
8155:
1.23 raeburn 8156: my %dirsrch_hash = (
8157: directorysrch => { available => $env{'form.dirsrch_available'},
8158: cansearch => \@cansearch,
1.24 raeburn 8159: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 8160: searchby => \@searchby,
1.25 raeburn 8161: searchtypes => \@searchtypes,
1.23 raeburn 8162: }
8163: );
8164: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
8165: $dom);
8166: if ($putresult eq 'ok') {
8167: if (exists($currdirsrch{'available'})) {
8168: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
8169: $changes{'available'} = 1;
8170: }
8171: } else {
8172: if ($env{'form.dirsrch_available'} eq '1') {
8173: $changes{'available'} = 1;
8174: }
8175: }
1.24 raeburn 8176: if (exists($currdirsrch{'localonly'})) {
8177: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
8178: $changes{'localonly'} = 1;
8179: }
8180: } else {
8181: if ($env{'form.dirsrch_localonly'} eq '1') {
8182: $changes{'localonly'} = 1;
8183: }
8184: }
1.23 raeburn 8185: if (keys(%changes) > 0) {
8186: $resulttext = &mt('Changes made:').'<ul>';
8187: if ($changes{'available'}) {
8188: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
8189: }
1.24 raeburn 8190: if ($changes{'localonly'}) {
8191: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
8192: }
8193:
1.23 raeburn 8194: if (ref($changes{'cansearch'}) eq 'ARRAY') {
8195: my $chgtext;
1.26 raeburn 8196: if (ref($usertypes) eq 'HASH') {
8197: if (keys(%{$usertypes}) > 0) {
8198: foreach my $type (@{$types}) {
8199: if (grep(/^\Q$type\E$/,@cansearch)) {
8200: $chgtext .= $usertypes->{$type}.'; ';
8201: }
8202: }
8203: if (grep(/^default$/,@cansearch)) {
8204: $chgtext .= $othertitle;
8205: } else {
8206: $chgtext =~ s/\; $//;
8207: }
1.210 raeburn 8208: $resulttext .=
1.178 raeburn 8209: '<li>'.
8210: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
8211: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
8212: '</li>';
1.23 raeburn 8213: }
8214: }
8215: }
8216: if (ref($changes{'searchby'}) eq 'ARRAY') {
8217: my ($searchtitles,$titleorder) = &sorted_searchtitles();
8218: my $chgtext;
8219: foreach my $type (@{$titleorder}) {
8220: if (grep(/^\Q$type\E$/,@searchby)) {
8221: if (defined($searchtitles->{$type})) {
8222: $chgtext .= $searchtitles->{$type}.'; ';
8223: }
8224: }
8225: }
8226: $chgtext =~ s/\; $//;
8227: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
8228: }
1.25 raeburn 8229: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
8230: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
8231: my $chgtext;
8232: foreach my $type (@{$srchtypeorder}) {
8233: if (grep(/^\Q$type\E$/,@searchtypes)) {
8234: if (defined($srchtypes_desc->{$type})) {
8235: $chgtext .= $srchtypes_desc->{$type}.'; ';
8236: }
8237: }
8238: }
8239: $chgtext =~ s/\; $//;
1.178 raeburn 8240: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 8241: }
8242: $resulttext .= '</ul>';
8243: } else {
8244: $resulttext = &mt('No changes made to institution directory search settings');
8245: }
8246: } else {
8247: $resulttext = '<span class="LC_error">'.
1.27 raeburn 8248: &mt('An error occurred: [_1]',$putresult).'</span>';
8249: }
8250: return $resulttext;
8251: }
8252:
1.28 raeburn 8253: sub modify_contacts {
1.205 raeburn 8254: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 8255: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
8256: if (ref($domconfig{'contacts'}) eq 'HASH') {
8257: foreach my $key (keys(%{$domconfig{'contacts'}})) {
8258: $currsetting{$key} = $domconfig{'contacts'}{$key};
8259: }
8260: }
1.134 raeburn 8261: my (%others,%to,%bcc);
1.28 raeburn 8262: my @contacts = ('supportemail','adminemail');
1.102 raeburn 8263: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 8264: 'requestsmail','updatesmail','idconflictsmail');
8265: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 8266: foreach my $type (@mailings) {
8267: @{$newsetting{$type}} =
8268: &Apache::loncommon::get_env_multiple('form.'.$type);
8269: foreach my $item (@contacts) {
8270: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
8271: $contacts_hash{contacts}{$type}{$item} = 1;
8272: } else {
8273: $contacts_hash{contacts}{$type}{$item} = 0;
8274: }
8275: }
8276: $others{$type} = $env{'form.'.$type.'_others'};
8277: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 8278: if ($type eq 'helpdeskmail') {
8279: $bcc{$type} = $env{'form.'.$type.'_bcc'};
8280: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
8281: }
1.28 raeburn 8282: }
8283: foreach my $item (@contacts) {
8284: $to{$item} = $env{'form.'.$item};
8285: $contacts_hash{'contacts'}{$item} = $to{$item};
8286: }
1.203 raeburn 8287: foreach my $item (@toggles) {
8288: if ($env{'form.'.$item} =~ /^(0|1)$/) {
8289: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
8290: }
8291: }
1.28 raeburn 8292: if (keys(%currsetting) > 0) {
8293: foreach my $item (@contacts) {
8294: if ($to{$item} ne $currsetting{$item}) {
8295: $changes{$item} = 1;
8296: }
8297: }
8298: foreach my $type (@mailings) {
8299: foreach my $item (@contacts) {
8300: if (ref($currsetting{$type}) eq 'HASH') {
8301: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
8302: push(@{$changes{$type}},$item);
8303: }
8304: } else {
8305: push(@{$changes{$type}},@{$newsetting{$type}});
8306: }
8307: }
8308: if ($others{$type} ne $currsetting{$type}{'others'}) {
8309: push(@{$changes{$type}},'others');
8310: }
1.134 raeburn 8311: if ($type eq 'helpdeskmail') {
8312: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
8313: push(@{$changes{$type}},'bcc');
8314: }
8315: }
1.28 raeburn 8316: }
8317: } else {
8318: my %default;
8319: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
8320: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
8321: $default{'errormail'} = 'adminemail';
8322: $default{'packagesmail'} = 'adminemail';
8323: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 8324: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 8325: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 8326: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 8327: foreach my $item (@contacts) {
8328: if ($to{$item} ne $default{$item}) {
8329: $changes{$item} = 1;
1.203 raeburn 8330: }
1.28 raeburn 8331: }
8332: foreach my $type (@mailings) {
8333: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
8334:
8335: push(@{$changes{$type}},@{$newsetting{$type}});
8336: }
8337: if ($others{$type} ne '') {
8338: push(@{$changes{$type}},'others');
1.134 raeburn 8339: }
8340: if ($type eq 'helpdeskmail') {
8341: if ($bcc{$type} ne '') {
8342: push(@{$changes{$type}},'bcc');
8343: }
8344: }
1.28 raeburn 8345: }
8346: }
1.203 raeburn 8347: foreach my $item (@toggles) {
8348: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
8349: $changes{$item} = 1;
8350: } elsif ((!$env{'form.'.$item}) &&
8351: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
8352: $changes{$item} = 1;
8353: }
8354: }
1.28 raeburn 8355: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
8356: $dom);
8357: if ($putresult eq 'ok') {
8358: if (keys(%changes) > 0) {
1.205 raeburn 8359: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8360: if (ref($lastactref) eq 'HASH') {
8361: $lastactref->{'domainconfig'} = 1;
8362: }
1.28 raeburn 8363: my ($titles,$short_titles) = &contact_titles();
8364: $resulttext = &mt('Changes made:').'<ul>';
8365: foreach my $item (@contacts) {
8366: if ($changes{$item}) {
8367: $resulttext .= '<li>'.$titles->{$item}.
8368: &mt(' set to: ').
8369: '<span class="LC_cusr_emph">'.
8370: $to{$item}.'</span></li>';
8371: }
8372: }
8373: foreach my $type (@mailings) {
8374: if (ref($changes{$type}) eq 'ARRAY') {
8375: $resulttext .= '<li>'.$titles->{$type}.': ';
8376: my @text;
8377: foreach my $item (@{$newsetting{$type}}) {
8378: push(@text,$short_titles->{$item});
8379: }
8380: if ($others{$type} ne '') {
8381: push(@text,$others{$type});
8382: }
8383: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 8384: join(', ',@text).'</span>';
8385: if ($type eq 'helpdeskmail') {
8386: if ($bcc{$type} ne '') {
8387: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
8388: }
8389: }
8390: $resulttext .= '</li>';
1.28 raeburn 8391: }
8392: }
1.203 raeburn 8393: my @offon = ('off','on');
8394: if ($changes{'reporterrors'}) {
8395: $resulttext .= '<li>'.
8396: &mt('E-mail error reports to [_1] set to "'.
8397: $offon[$env{'form.reporterrors'}].'".',
8398: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8399: &mt('LON-CAPA core group - MSU'),600,500)).
8400: '</li>';
8401: }
8402: if ($changes{'reportupdates'}) {
8403: $resulttext .= '<li>'.
8404: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
8405: $offon[$env{'form.reportupdates'}].'".',
8406: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
8407: &mt('LON-CAPA core group - MSU'),600,500)).
8408: '</li>';
8409: }
1.28 raeburn 8410: $resulttext .= '</ul>';
8411: } else {
1.34 raeburn 8412: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 8413: }
8414: } else {
8415: $resulttext = '<span class="LC_error">'.
8416: &mt('An error occurred: [_1].',$putresult).'</span>';
8417: }
8418: return $resulttext;
8419: }
8420:
8421: sub modify_usercreation {
1.27 raeburn 8422: my ($dom,%domconfig) = @_;
1.224 raeburn 8423: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 8424: my $warningmsg;
1.27 raeburn 8425: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8426: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 8427: if ($key eq 'cancreate') {
8428: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8429: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8430: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8431: ($item eq 'captcha') || ($item eq 'recaptchakeys')) {
8432: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8433: } else {
8434: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8435: }
8436: }
8437: }
8438: } elsif ($key eq 'email_rule') {
8439: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8440: } else {
8441: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8442: }
1.27 raeburn 8443: }
8444: }
8445: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 8446: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 8447: my @contexts = ('author','course','requestcrs');
1.34 raeburn 8448: foreach my $item(@contexts) {
1.224 raeburn 8449: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 8450: }
1.34 raeburn 8451: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8452: foreach my $item (@contexts) {
1.224 raeburn 8453: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
8454: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 8455: }
1.27 raeburn 8456: }
1.34 raeburn 8457: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
8458: foreach my $item (@contexts) {
1.43 raeburn 8459: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 8460: if ($cancreate{$item} ne 'any') {
8461: push(@{$changes{'cancreate'}},$item);
8462: }
8463: } else {
8464: if ($cancreate{$item} ne 'none') {
8465: push(@{$changes{'cancreate'}},$item);
8466: }
1.27 raeburn 8467: }
8468: }
8469: } else {
1.43 raeburn 8470: foreach my $item (@contexts) {
1.34 raeburn 8471: push(@{$changes{'cancreate'}},$item);
8472: }
1.27 raeburn 8473: }
1.34 raeburn 8474:
1.27 raeburn 8475: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
8476: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
8477: if (!grep(/^\Q$type\E$/,@username_rule)) {
8478: push(@{$changes{'username_rule'}},$type);
8479: }
8480: }
8481: foreach my $type (@username_rule) {
8482: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
8483: push(@{$changes{'username_rule'}},$type);
8484: }
8485: }
8486: } else {
8487: push(@{$changes{'username_rule'}},@username_rule);
8488: }
8489:
1.32 raeburn 8490: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
8491: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
8492: if (!grep(/^\Q$type\E$/,@id_rule)) {
8493: push(@{$changes{'id_rule'}},$type);
8494: }
8495: }
8496: foreach my $type (@id_rule) {
8497: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
8498: push(@{$changes{'id_rule'}},$type);
8499: }
8500: }
8501: } else {
8502: push(@{$changes{'id_rule'}},@id_rule);
8503: }
8504:
1.43 raeburn 8505: my @authen_contexts = ('author','course','domain');
1.28 raeburn 8506: my @authtypes = ('int','krb4','krb5','loc');
8507: my %authhash;
1.43 raeburn 8508: foreach my $item (@authen_contexts) {
1.28 raeburn 8509: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
8510: foreach my $auth (@authtypes) {
8511: if (grep(/^\Q$auth\E$/,@authallowed)) {
8512: $authhash{$item}{$auth} = 1;
8513: } else {
8514: $authhash{$item}{$auth} = 0;
8515: }
8516: }
8517: }
8518: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 8519: foreach my $item (@authen_contexts) {
1.28 raeburn 8520: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
8521: foreach my $auth (@authtypes) {
8522: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
8523: push(@{$changes{'authtypes'}},$item);
8524: last;
8525: }
8526: }
8527: }
8528: }
8529: } else {
1.43 raeburn 8530: foreach my $item (@authen_contexts) {
1.28 raeburn 8531: push(@{$changes{'authtypes'}},$item);
8532: }
8533: }
8534:
1.224 raeburn 8535: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
8536: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
8537: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
8538: $save_usercreate{'id_rule'} = \@id_rule;
8539: $save_usercreate{'username_rule'} = \@username_rule,
8540: $save_usercreate{'authtypes'} = \%authhash;
8541:
1.27 raeburn 8542: my %usercreation_hash = (
1.224 raeburn 8543: usercreation => \%save_usercreate,
8544: );
1.27 raeburn 8545:
8546: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
8547: $dom);
1.50 raeburn 8548:
1.224 raeburn 8549: if ($putresult eq 'ok') {
8550: if (keys(%changes) > 0) {
8551: $resulttext = &mt('Changes made:').'<ul>';
8552: if (ref($changes{'cancreate'}) eq 'ARRAY') {
8553: my %lt = &usercreation_types();
8554: foreach my $type (@{$changes{'cancreate'}}) {
8555: my $chgtext = $lt{$type}.', ';
8556: if ($cancreate{$type} eq 'none') {
8557: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
8558: } elsif ($cancreate{$type} eq 'any') {
8559: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
8560: } elsif ($cancreate{$type} eq 'official') {
8561: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
8562: } elsif ($cancreate{$type} eq 'unofficial') {
8563: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
8564: }
8565: $resulttext .= '<li>'.$chgtext.'</li>';
8566: }
8567: }
8568: if (ref($changes{'username_rule'}) eq 'ARRAY') {
8569: my ($rules,$ruleorder) =
8570: &Apache::lonnet::inst_userrules($dom,'username');
8571: my $chgtext = '<ul>';
8572: foreach my $type (@username_rule) {
8573: if (ref($rules->{$type}) eq 'HASH') {
8574: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
8575: }
8576: }
8577: $chgtext .= '</ul>';
8578: if (@username_rule > 0) {
8579: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8580: } else {
8581: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
8582: }
8583: }
8584: if (ref($changes{'id_rule'}) eq 'ARRAY') {
8585: my ($idrules,$idruleorder) =
8586: &Apache::lonnet::inst_userrules($dom,'id');
8587: my $chgtext = '<ul>';
8588: foreach my $type (@id_rule) {
8589: if (ref($idrules->{$type}) eq 'HASH') {
8590: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
8591: }
8592: }
8593: $chgtext .= '</ul>';
8594: if (@id_rule > 0) {
8595: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
8596: } else {
8597: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
8598: }
8599: }
8600: my %authname = &authtype_names();
8601: my %context_title = &context_names();
8602: if (ref($changes{'authtypes'}) eq 'ARRAY') {
8603: my $chgtext = '<ul>';
8604: foreach my $type (@{$changes{'authtypes'}}) {
8605: my @allowed;
8606: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
8607: foreach my $auth (@authtypes) {
8608: if ($authhash{$type}{$auth}) {
8609: push(@allowed,$authname{$auth});
8610: }
8611: }
8612: if (@allowed > 0) {
8613: $chgtext .= join(', ',@allowed).'</li>';
8614: } else {
8615: $chgtext .= &mt('none').'</li>';
8616: }
8617: }
8618: $chgtext .= '</ul>';
8619: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
8620: $resulttext .= '</li>';
8621: }
8622: $resulttext .= '</ul>';
8623: } else {
8624: $resulttext = &mt('No changes made to user creation settings');
8625: }
8626: } else {
8627: $resulttext = '<span class="LC_error">'.
8628: &mt('An error occurred: [_1]',$putresult).'</span>';
8629: }
8630: if ($warningmsg ne '') {
8631: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
8632: }
8633: return $resulttext;
8634: }
8635:
8636: sub modify_selfcreation {
8637: my ($dom,%domconfig) = @_;
8638: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
8639: my (%save_usercreate,%save_usermodify);
1.228 raeburn 8640: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8641: if (ref($types) eq 'ARRAY') {
8642: $usertypes->{'default'} = $othertitle;
8643: push(@{$types},'default');
8644: }
1.224 raeburn 8645: #
8646: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
8647: #
8648: if (ref($domconfig{'usercreation'}) eq 'HASH') {
8649: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
8650: if ($key eq 'cancreate') {
8651: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
8652: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
8653: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
8654: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.236 raeburn 8655: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 8656: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 8657: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8658: } else {
8659: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
8660: }
8661: }
8662: }
8663: } elsif ($key eq 'email_rule') {
8664: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
8665: } else {
8666: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
8667: }
8668: }
8669: }
8670: #
8671: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
8672: #
8673: if (ref($domconfig{'usermodification'}) eq 'HASH') {
8674: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
8675: if ($key eq 'selfcreate') {
8676: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
8677: } else {
8678: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
8679: }
8680: }
8681: }
8682:
8683: my @contexts = ('selfcreate');
8684: @{$cancreate{'selfcreate'}} = ();
8685: %{$cancreate{'emailusername'}} = ();
8686: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 8687: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 8688: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 8689: my %selfcreatetypes = (
8690: sso => 'users authenticated by institutional single sign on',
8691: login => 'users authenticated by institutional log-in',
1.236 raeburn 8692: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 8693: );
1.224 raeburn 8694: #
8695: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
8696: # is permitted.
8697: #
1.236 raeburn 8698:
8699: my @statuses;
8700: if (ref($domconfig{'inststatus'}) eq 'HASH') {
8701: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
8702: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
8703: }
8704: }
8705: push(@statuses,'default');
8706:
1.228 raeburn 8707: foreach my $item ('login','sso','email') {
1.224 raeburn 8708: if ($item eq 'email') {
1.236 raeburn 8709: if ($env{'form.cancreate_email'}) {
1.224 raeburn 8710: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 8711: push(@contexts,'selfcreateprocessing');
8712: foreach my $type (@statuses) {
8713: if ($type eq 'default') {
8714: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
8715: } else {
8716: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
8717: }
8718: }
1.224 raeburn 8719: }
8720: } else {
8721: if ($env{'form.cancreate_'.$item}) {
8722: push(@{$cancreate{'selfcreate'}},$item);
8723: }
8724: }
8725: }
8726: my (@email_rule,%userinfo,%savecaptcha);
8727: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8728: #
1.228 raeburn 8729: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
8730: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 8731: #
1.236 raeburn 8732:
1.244 raeburn 8733: if ($env{'form.cancreate_email'}) {
1.228 raeburn 8734: push(@contexts,'emailusername');
8735: if (ref($types) eq 'ARRAY') {
8736: foreach my $type (@{$types}) {
8737: if (ref($infofields) eq 'ARRAY') {
8738: foreach my $field (@{$infofields}) {
8739: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
8740: $cancreate{'emailusername'}{$type}{$field} = $1;
8741: }
8742: }
1.224 raeburn 8743: }
8744: }
8745: }
8746: #
8747: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
8748: # queued requests for self-creation of account using e-mail address as username
8749: #
8750:
8751: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
8752: @approvalnotify = sort(@approvalnotify);
8753: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
8754: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8755: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
8756: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
8757: push(@{$changes{'cancreate'}},'notify');
8758: }
8759: } else {
8760: if ($cancreate{'notify'}{'approval'}) {
8761: push(@{$changes{'cancreate'}},'notify');
8762: }
8763: }
8764: } elsif ($cancreate{'notify'}{'approval'}) {
8765: push(@{$changes{'cancreate'}},'notify');
8766: }
8767:
8768: #
8769: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
8770: #
8771: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
8772: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
8773: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
8774: if (@{$curr_usercreation{'email_rule'}} > 0) {
8775: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
8776: if (!grep(/^\Q$type\E$/,@email_rule)) {
8777: push(@{$changes{'email_rule'}},$type);
8778: }
8779: }
8780: }
8781: if (@email_rule > 0) {
8782: foreach my $type (@email_rule) {
8783: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
8784: push(@{$changes{'email_rule'}},$type);
8785: }
8786: }
8787: }
8788: } elsif (@email_rule > 0) {
8789: push(@{$changes{'email_rule'}},@email_rule);
8790: }
8791: }
8792: #
1.236 raeburn 8793: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 8794: # institutional log-in.
8795: #
8796: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
8797: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8798: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
8799: ($domdefaults{'auth_def'} eq 'localauth'))) {
8800: $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.').' '.
8801: &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.');
8802: }
8803: }
8804: my @fields = ('lastname','firstname','middlename','generation',
8805: 'permanentemail','id');
1.240 raeburn 8806: my @shibfields = (@fields,'inststatus');
1.224 raeburn 8807: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8808: #
8809: # Where usernames may created for institutional log-in and/or institutional single sign on:
8810: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
8811: # may self-create accounts
8812: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
8813: # which the user may supply, if institutional data is unavailable.
8814: #
8815: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
8816: if (ref($types) eq 'ARRAY') {
1.228 raeburn 8817: if (@{$types} > 1) {
1.224 raeburn 8818: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
8819: push(@contexts,'statustocreate');
8820: } else {
8821: undef($cancreate{'statustocreate'});
8822: }
8823: foreach my $type (@{$types}) {
8824: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
8825: foreach my $field (@fields) {
8826: if (grep(/^\Q$field\E$/,@modifiable)) {
8827: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
8828: } else {
8829: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
8830: }
8831: }
8832: }
8833: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
8834: foreach my $type (@{$types}) {
8835: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
8836: foreach my $field (@fields) {
8837: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
8838: $curr_usermodify{'selfcreate'}{$type}{$field}) {
8839: push(@{$changes{'selfcreate'}},$type);
8840: last;
8841: }
8842: }
8843: }
8844: }
8845: } else {
8846: foreach my $type (@{$types}) {
8847: push(@{$changes{'selfcreate'}},$type);
8848: }
8849: }
8850: }
1.240 raeburn 8851: foreach my $field (@shibfields) {
8852: if ($env{'form.shibenv_'.$field} ne '') {
8853: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
8854: }
8855: }
8856: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
8857: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
8858: foreach my $field (@shibfields) {
8859: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
8860: push(@{$changes{'cancreate'}},'shibenv');
8861: }
8862: }
8863: } else {
8864: foreach my $field (@shibfields) {
8865: if ($env{'form.shibenv_'.$field}) {
8866: push(@{$changes{'cancreate'}},'shibenv');
8867: last;
8868: }
8869: }
8870: }
8871: }
1.224 raeburn 8872: }
8873: foreach my $item (@contexts) {
8874: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
8875: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
8876: if (ref($cancreate{$item}) eq 'ARRAY') {
8877: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
8878: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8879: push(@{$changes{'cancreate'}},$item);
8880: }
8881: }
8882: }
8883: }
8884: if (ref($cancreate{$item}) eq 'ARRAY') {
8885: foreach my $type (@{$cancreate{$item}}) {
8886: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
8887: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8888: push(@{$changes{'cancreate'}},$item);
8889: }
8890: }
8891: }
8892: }
8893: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
8894: if (ref($cancreate{$item}) eq 'HASH') {
8895: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 8896: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
8897: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
8898: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
8899: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8900: push(@{$changes{'cancreate'}},$item);
8901: }
8902: }
8903: }
1.236 raeburn 8904: } elsif ($item eq 'selfcreateprocessing') {
8905: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
8906: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8907: push(@{$changes{'cancreate'}},$item);
8908: }
8909: }
1.228 raeburn 8910: } else {
8911: if (!$cancreate{$item}{$curr}) {
8912: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8913: push(@{$changes{'cancreate'}},$item);
8914: }
1.224 raeburn 8915: }
8916: }
8917: }
8918: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 8919: if (ref($cancreate{$item}{$field}) eq 'HASH') {
8920: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
8921: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
8922: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
8923: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8924: push(@{$changes{'cancreate'}},$item);
8925: }
8926: }
8927: } else {
8928: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8929: push(@{$changes{'cancreate'}},$item);
8930: }
8931: }
8932: }
1.236 raeburn 8933: } elsif ($item eq 'selfcreateprocessing') {
8934: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
8935: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8936: push(@{$changes{'cancreate'}},$item);
8937: }
8938: }
1.228 raeburn 8939: } else {
8940: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
8941: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8942: push(@{$changes{'cancreate'}},$item);
8943: }
1.224 raeburn 8944: }
8945: }
8946: }
8947: }
8948: } elsif ($curr_usercreation{'cancreate'}{$item}) {
8949: if (ref($cancreate{$item}) eq 'ARRAY') {
8950: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
8951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8952: push(@{$changes{'cancreate'}},$item);
8953: }
8954: }
8955: } elsif (ref($cancreate{$item}) eq 'HASH') {
8956: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
8957: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8958: push(@{$changes{'cancreate'}},$item);
8959: }
8960: }
8961: }
8962: } elsif ($item eq 'emailusername') {
1.228 raeburn 8963: if (ref($cancreate{$item}) eq 'HASH') {
8964: foreach my $type (keys(%{$cancreate{$item}})) {
8965: if (ref($cancreate{$item}{$type}) eq 'HASH') {
8966: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
8967: if ($cancreate{$item}{$type}{$field}) {
8968: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
8969: push(@{$changes{'cancreate'}},$item);
8970: }
8971: last;
8972: }
8973: }
8974: }
8975: }
1.224 raeburn 8976: }
8977: }
8978: }
8979: #
8980: # Populate %save_usercreate hash with updates to self-creation configuration.
8981: #
8982: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
8983: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
8984: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
8985: if (ref($cancreate{'notify'}) eq 'HASH') {
8986: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
8987: }
1.236 raeburn 8988: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
8989: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
8990: }
1.224 raeburn 8991: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
8992: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
8993: }
1.240 raeburn 8994: if (ref($cancreate{'shibenv'}) eq 'HASH') {
8995: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
8996: }
1.224 raeburn 8997: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
8998: $save_usercreate{'emailrule'} = \@email_rule;
8999:
9000: my %userconfig_hash = (
9001: usercreation => \%save_usercreate,
9002: usermodification => \%save_usermodify,
9003: );
9004: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
9005: $dom);
9006: #
9007: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
9008: #
1.27 raeburn 9009: if ($putresult eq 'ok') {
9010: if (keys(%changes) > 0) {
9011: $resulttext = &mt('Changes made:').'<ul>';
9012: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 9013: my %lt = &selfcreation_types();
1.34 raeburn 9014: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 9015: my $chgtext;
1.45 raeburn 9016: if ($type eq 'selfcreate') {
1.50 raeburn 9017: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 9018: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 9019: } else {
1.224 raeburn 9020: $chgtext .= &mt('Self-creation of a new account is permitted for:').
9021: '<ul>';
1.50 raeburn 9022: foreach my $case (@{$cancreate{$type}}) {
9023: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
9024: }
9025: $chgtext .= '</ul>';
1.100 raeburn 9026: if (ref($cancreate{$type}) eq 'ARRAY') {
9027: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
9028: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
9029: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 9030: $chgtext .= '<br />'.
9031: '<span class="LC_warning">'.
9032: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9033: '</span>';
1.100 raeburn 9034: }
9035: }
9036: }
9037: }
1.43 raeburn 9038: }
1.240 raeburn 9039: } elsif ($type eq 'shibenv') {
9040: if (keys(%{$cancreate{$type}}) == 0) {
9041: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
9042: } else {
9043: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
9044: '<ul>';
9045: foreach my $field (@shibfields) {
9046: next if ($cancreate{$type}{$field} eq '');
9047: if ($field eq 'inststatus') {
9048: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
9049: } else {
9050: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
9051: }
9052: }
9053: $chgtext .= '</ul>';
9054: }
1.93 raeburn 9055: } elsif ($type eq 'statustocreate') {
1.96 raeburn 9056: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
9057: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
9058: if (@{$cancreate{'selfcreate'}} > 0) {
9059: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 9060: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 9061: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 9062: $chgtext .= '<br />'.
9063: '<span class="LC_warning">'.
9064: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
9065: '</span>';
9066: }
1.96 raeburn 9067: } elsif (ref($usertypes) eq 'HASH') {
9068: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 9069: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
9070: } else {
9071: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
9072: }
9073: $chgtext .= '<ul>';
9074: foreach my $case (@{$cancreate{$type}}) {
9075: if ($case eq 'default') {
9076: $chgtext .= '<li>'.$othertitle.'</li>';
9077: } else {
9078: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 9079: }
9080: }
1.100 raeburn 9081: $chgtext .= '</ul>';
9082: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 9083: $chgtext .= '<br /><span class="LC_warning">'.
9084: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
9085: '</span>';
1.100 raeburn 9086: }
9087: }
9088: } else {
9089: if (@{$cancreate{$type}} == 0) {
9090: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
9091: } else {
9092: $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 9093: }
9094: }
9095: }
1.236 raeburn 9096: } elsif ($type eq 'selfcreateprocessing') {
9097: my %choices = &Apache::lonlocal::texthash (
9098: automatic => 'Automatic approval',
9099: approval => 'Queued for approval',
9100: );
9101: if (@statuses > 1) {
9102: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
9103: '<ul>';
9104: foreach my $type (@statuses) {
9105: if ($type eq 'default') {
9106: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9107: } else {
9108: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
9109: }
9110: }
9111: $chgtext .= '</ul>';
9112: } else {
9113: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
9114: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
9115: }
1.165 raeburn 9116: } elsif ($type eq 'captcha') {
1.224 raeburn 9117: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 9118: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
9119: } else {
9120: my %captchas = &captcha_phrases();
1.224 raeburn 9121: if ($captchas{$savecaptcha{$type}}) {
9122: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 9123: } else {
1.210 raeburn 9124: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 9125: }
9126: }
9127: } elsif ($type eq 'recaptchakeys') {
9128: my ($privkey,$pubkey);
1.224 raeburn 9129: if (ref($savecaptcha{$type}) eq 'HASH') {
9130: $pubkey = $savecaptcha{$type}{'public'};
9131: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 9132: }
9133: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
9134: if (!$pubkey) {
9135: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
9136: } else {
9137: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
9138: }
9139: if (!$privkey) {
9140: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
9141: } else {
9142: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
9143: }
9144: $chgtext .= '</ul>';
1.224 raeburn 9145: } elsif ($type eq 'emailusername') {
9146: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 9147: if (ref($types) eq 'ARRAY') {
9148: foreach my $type (@{$types}) {
9149: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
9150: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 9151: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 9152: '<ul>';
9153: foreach my $field (@{$infofields}) {
9154: if ($cancreate{'emailusername'}{$type}{$field}) {
9155: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
9156: }
9157: }
1.245 raeburn 9158: $chgtext .= '</ul>';
9159: } else {
9160: $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 9161: }
9162: } else {
1.245 raeburn 9163: $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 9164: }
9165: }
9166: }
9167: }
9168: } elsif ($type eq 'notify') {
9169: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
9170: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9171: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
9172: if ($cancreate{'notify'}{'approval'}) {
9173: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
9174: }
9175: }
1.43 raeburn 9176: }
1.34 raeburn 9177: }
1.224 raeburn 9178: if ($chgtext) {
9179: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 9180: }
9181: }
9182: }
1.43 raeburn 9183: if (ref($changes{'email_rule'}) eq 'ARRAY') {
9184: my ($emailrules,$emailruleorder) =
9185: &Apache::lonnet::inst_userrules($dom,'email');
9186: my $chgtext = '<ul>';
9187: foreach my $type (@email_rule) {
9188: if (ref($emailrules->{$type}) eq 'HASH') {
9189: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
9190: }
9191: }
9192: $chgtext .= '</ul>';
9193: if (@email_rule > 0) {
1.224 raeburn 9194: $resulttext .= '<li>'.
9195: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
9196: $chgtext.
9197: '</li>';
1.43 raeburn 9198: } else {
1.224 raeburn 9199: $resulttext .= '<li>'.
9200: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
9201: '</li>';
1.43 raeburn 9202: }
9203: }
1.224 raeburn 9204: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
9205: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
9206: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9207: foreach my $type (@{$changes{'selfcreate'}}) {
9208: my $typename = $type;
9209: if (ref($usertypes) eq 'HASH') {
9210: if ($usertypes->{$type} ne '') {
9211: $typename = $usertypes->{$type};
9212: }
9213: }
9214: my @modifiable;
9215: $resulttext .= '<li>'.
9216: &mt('Self-creation of account by users with status: [_1]',
9217: '<span class="LC_cusr_emph">'.$typename.'</span>').
9218: ' - '.&mt('modifiable fields (if institutional data blank): ');
9219: foreach my $field (@fields) {
9220: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
9221: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 9222: }
9223: }
1.224 raeburn 9224: if (@modifiable > 0) {
9225: $resulttext .= join(', ',@modifiable);
1.43 raeburn 9226: } else {
1.224 raeburn 9227: $resulttext .= &mt('none');
1.43 raeburn 9228: }
1.224 raeburn 9229: $resulttext .= '</li>';
1.28 raeburn 9230: }
1.224 raeburn 9231: $resulttext .= '</ul></li>';
1.28 raeburn 9232: }
1.27 raeburn 9233: $resulttext .= '</ul>';
9234: } else {
1.224 raeburn 9235: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 9236: }
9237: } else {
9238: $resulttext = '<span class="LC_error">'.
1.23 raeburn 9239: &mt('An error occurred: [_1]',$putresult).'</span>';
9240: }
1.43 raeburn 9241: if ($warningmsg ne '') {
9242: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9243: }
1.23 raeburn 9244: return $resulttext;
9245: }
9246:
1.165 raeburn 9247: sub process_captcha {
9248: my ($container,$changes,$newsettings,$current) = @_;
9249: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
9250: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
9251: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
9252: $newsettings->{'captcha'} = 'original';
9253: }
9254: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 9255: if ($container eq 'cancreate') {
1.169 raeburn 9256: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9257: push(@{$changes->{'cancreate'}},'captcha');
9258: } elsif (!defined($changes->{'cancreate'})) {
9259: $changes->{'cancreate'} = ['captcha'];
9260: }
9261: } else {
9262: $changes->{'captcha'} = 1;
1.165 raeburn 9263: }
9264: }
9265: my ($newpub,$newpriv,$currpub,$currpriv);
9266: if ($newsettings->{'captcha'} eq 'recaptcha') {
9267: $newpub = $env{'form.'.$container.'_recaptchapub'};
9268: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 9269: $newpub =~ s/[^\w\-]//g;
9270: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 9271: $newsettings->{'recaptchakeys'} = {
9272: public => $newpub,
9273: private => $newpriv,
9274: };
1.165 raeburn 9275: }
9276: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
9277: $currpub = $current->{'recaptchakeys'}{'public'};
9278: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 9279: unless ($newsettings->{'captcha'} eq 'recaptcha') {
9280: $newsettings->{'recaptchakeys'} = {
9281: public => '',
9282: private => '',
9283: }
9284: }
1.165 raeburn 9285: }
9286: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 9287: if ($container eq 'cancreate') {
9288: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
9289: push(@{$changes->{'cancreate'}},'recaptchakeys');
9290: } elsif (!defined($changes->{'cancreate'})) {
9291: $changes->{'cancreate'} = ['recaptchakeys'];
9292: }
9293: } else {
1.210 raeburn 9294: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 9295: }
9296: }
9297: return;
9298: }
9299:
1.33 raeburn 9300: sub modify_usermodification {
9301: my ($dom,%domconfig) = @_;
1.224 raeburn 9302: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 9303: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9304: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 9305: if ($key eq 'selfcreate') {
9306: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
9307: } else {
9308: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
9309: }
1.33 raeburn 9310: }
9311: }
1.224 raeburn 9312: my @contexts = ('author','course');
1.33 raeburn 9313: my %context_title = (
9314: author => 'In author context',
9315: course => 'In course context',
9316: );
9317: my @fields = ('lastname','firstname','middlename','generation',
9318: 'permanentemail','id');
9319: my %roles = (
9320: author => ['ca','aa'],
9321: course => ['st','ep','ta','in','cr'],
9322: );
9323: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9324: foreach my $context (@contexts) {
9325: foreach my $role (@{$roles{$context}}) {
9326: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
9327: foreach my $item (@fields) {
9328: if (grep(/^\Q$item\E$/,@modifiable)) {
9329: $modifyhash{$context}{$role}{$item} = 1;
9330: } else {
9331: $modifyhash{$context}{$role}{$item} = 0;
9332: }
9333: }
9334: }
9335: if (ref($curr_usermodification{$context}) eq 'HASH') {
9336: foreach my $role (@{$roles{$context}}) {
9337: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
9338: foreach my $field (@fields) {
9339: if ($modifyhash{$context}{$role}{$field} ne
9340: $curr_usermodification{$context}{$role}{$field}) {
9341: push(@{$changes{$context}},$role);
9342: last;
9343: }
9344: }
9345: }
9346: }
9347: } else {
9348: foreach my $context (@contexts) {
9349: foreach my $role (@{$roles{$context}}) {
9350: push(@{$changes{$context}},$role);
9351: }
9352: }
9353: }
9354: }
9355: my %usermodification_hash = (
9356: usermodification => \%modifyhash,
9357: );
9358: my $putresult = &Apache::lonnet::put_dom('configuration',
9359: \%usermodification_hash,$dom);
9360: if ($putresult eq 'ok') {
9361: if (keys(%changes) > 0) {
9362: $resulttext = &mt('Changes made: ').'<ul>';
9363: foreach my $context (@contexts) {
9364: if (ref($changes{$context}) eq 'ARRAY') {
9365: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
9366: if (ref($changes{$context}) eq 'ARRAY') {
9367: foreach my $role (@{$changes{$context}}) {
9368: my $rolename;
1.224 raeburn 9369: if ($role eq 'cr') {
9370: $rolename = &mt('Custom');
1.33 raeburn 9371: } else {
1.224 raeburn 9372: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 9373: }
9374: my @modifiable;
1.224 raeburn 9375: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 9376: foreach my $field (@fields) {
9377: if ($modifyhash{$context}{$role}{$field}) {
9378: push(@modifiable,$fieldtitles{$field});
9379: }
9380: }
9381: if (@modifiable > 0) {
9382: $resulttext .= join(', ',@modifiable);
9383: } else {
9384: $resulttext .= &mt('none');
9385: }
9386: $resulttext .= '</li>';
9387: }
9388: $resulttext .= '</ul></li>';
9389: }
9390: }
9391: }
9392: $resulttext .= '</ul>';
9393: } else {
9394: $resulttext = &mt('No changes made to user modification settings');
9395: }
9396: } else {
9397: $resulttext = '<span class="LC_error">'.
9398: &mt('An error occurred: [_1]',$putresult).'</span>';
9399: }
9400: return $resulttext;
9401: }
9402:
1.43 raeburn 9403: sub modify_defaults {
1.212 raeburn 9404: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 9405: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 9406: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 9407: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 9408: my @authtypes = ('internal','krb4','krb5','localauth');
9409: foreach my $item (@items) {
9410: $newvalues{$item} = $env{'form.'.$item};
9411: if ($item eq 'auth_def') {
9412: if ($newvalues{$item} ne '') {
9413: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
9414: push(@errors,$item);
9415: }
9416: }
9417: } elsif ($item eq 'lang_def') {
9418: if ($newvalues{$item} ne '') {
9419: if ($newvalues{$item} =~ /^(\w+)/) {
9420: my $langcode = $1;
1.103 raeburn 9421: if ($langcode ne 'x_chef') {
9422: if (code2language($langcode) eq '') {
9423: push(@errors,$item);
9424: }
1.43 raeburn 9425: }
9426: } else {
9427: push(@errors,$item);
9428: }
9429: }
1.54 raeburn 9430: } elsif ($item eq 'timezone_def') {
9431: if ($newvalues{$item} ne '') {
1.62 raeburn 9432: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 9433: push(@errors,$item);
9434: }
9435: }
1.68 raeburn 9436: } elsif ($item eq 'datelocale_def') {
9437: if ($newvalues{$item} ne '') {
9438: my @datelocale_ids = DateTime::Locale->ids();
9439: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
9440: push(@errors,$item);
9441: }
9442: }
1.141 raeburn 9443: } elsif ($item eq 'portal_def') {
9444: if ($newvalues{$item} ne '') {
9445: 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])\/?$/) {
9446: push(@errors,$item);
9447: }
9448: }
1.43 raeburn 9449: }
9450: if (grep(/^\Q$item\E$/,@errors)) {
9451: $newvalues{$item} = $domdefaults{$item};
9452: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
9453: $changes{$item} = 1;
9454: }
1.72 raeburn 9455: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 9456: }
9457: my %defaults_hash = (
1.72 raeburn 9458: defaults => \%newvalues,
9459: );
1.43 raeburn 9460: my $title = &defaults_titles();
1.236 raeburn 9461:
9462: my $currinststatus;
9463: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9464: $currinststatus = $domconfig{'inststatus'};
9465: } else {
9466: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9467: $currinststatus = {
9468: inststatustypes => $usertypes,
9469: inststatusorder => $types,
9470: inststatusguest => [],
9471: };
9472: }
9473: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
9474: my @allpos;
9475: my %guests;
9476: my %alltypes;
9477: my ($currtitles,$currguests,$currorder);
9478: if (ref($currinststatus) eq 'HASH') {
9479: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
9480: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
9481: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
9482: if ($currinststatus->{inststatustypes}->{$type} ne '') {
9483: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
9484: }
9485: }
9486: unless (grep(/^\Q$type\E$/,@todelete)) {
9487: my $position = $env{'form.inststatus_pos_'.$type};
9488: $position =~ s/\D+//g;
9489: $allpos[$position] = $type;
9490: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
9491: $alltypes{$type} =~ s/`//g;
9492: if ($env{'form.inststatus_guest_'.$type}) {
9493: $guests{$type} = 1;
9494: }
9495: }
9496: }
9497: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
9498: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
9499: }
9500: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
9501: $currtitles =~ s/,$//;
9502: }
9503: }
9504: if ($env{'form.addinststatus'}) {
9505: my $newtype = $env{'form.addinststatus'};
9506: $newtype =~ s/\W//g;
9507: unless (exists($alltypes{$newtype})) {
9508: if ($env{'form.addinststatus_guest'}) {
9509: $guests{$newtype} = 1;
9510: }
9511: $alltypes{$newtype} = $env{'form.addinststatus_title'};
9512: $alltypes{$newtype} =~ s/`//g;
9513: my $position = $env{'form.addinststatus_pos'};
9514: $position =~ s/\D+//g;
9515: if ($position ne '') {
9516: $allpos[$position] = $newtype;
9517: }
9518: }
9519: }
9520: my (@orderedstatus,@orderedguests);
9521: foreach my $type (@allpos) {
9522: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
9523: push(@orderedstatus,$type);
9524: if ($guests{$type}) {
9525: push(@orderedguests,$type);
9526: }
9527: }
9528: }
9529: foreach my $type (keys(%alltypes)) {
9530: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
9531: delete($alltypes{$type});
9532: }
9533: }
9534: $defaults_hash{'inststatus'} = {
9535: inststatustypes => \%alltypes,
9536: inststatusorder => \@orderedstatus,
9537: inststatusguest => \@orderedguests,
9538: };
9539: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
9540: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
9541: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
9542: }
9543: }
9544: if ($currorder ne join(',',@orderedstatus)) {
9545: $changes{'inststatus'}{'inststatusorder'} = 1;
9546: }
9547: if ($currguests ne join(',',@orderedguests)) {
9548: $changes{'inststatus'}{'inststatusguest'} = 1;
9549: }
9550: my $newtitles;
9551: foreach my $item (@orderedstatus) {
9552: $newtitles .= $alltypes{$item}.',';
9553: }
9554: $newtitles =~ s/,$//;
9555: if ($currtitles ne $newtitles) {
9556: $changes{'inststatus'}{'inststatustypes'} = 1;
9557: }
1.43 raeburn 9558: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
9559: $dom);
9560: if ($putresult eq 'ok') {
9561: if (keys(%changes) > 0) {
9562: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 9563: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 9564: 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";
9565: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 9566: if ($item eq 'inststatus') {
9567: if (ref($changes{'inststatus'}) eq 'HASH') {
9568: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
9569: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
9570: foreach my $type (@orderedstatus) {
9571: $resulttext .= $alltypes{$type}.', ';
9572: }
9573: $resulttext =~ s/, $//;
9574: $resulttext .= '</li>';
9575: }
9576: if ($changes{'inststatus'}{'inststatusguest'}) {
9577: $resulttext .= '<li>';
9578: if (@orderedguests) {
9579: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
9580: foreach my $type (@orderedguests) {
9581: $resulttext .= $alltypes{$type}.', ';
9582: }
9583: $resulttext =~ s/, $//;
9584: } else {
9585: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
9586: }
9587: $resulttext .= '</li>';
9588: }
9589: }
9590: } else {
9591: my $value = $env{'form.'.$item};
9592: if ($value eq '') {
9593: $value = &mt('none');
9594: } elsif ($item eq 'auth_def') {
9595: my %authnames = &authtype_names();
9596: my %shortauth = (
9597: internal => 'int',
9598: krb4 => 'krb4',
9599: krb5 => 'krb5',
9600: localauth => 'loc',
9601: );
9602: $value = $authnames{$shortauth{$value}};
9603: }
9604: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
9605: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 9606: }
9607: }
9608: $resulttext .= '</ul>';
9609: $mailmsgtext .= "\n";
9610: my $cachetime = 24*60*60;
1.72 raeburn 9611: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9612: if (ref($lastactref) eq 'HASH') {
9613: $lastactref->{'domdefaults'} = 1;
9614: }
1.68 raeburn 9615: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 9616: my $notify = 1;
9617: if (ref($domconfig{'contacts'}) eq 'HASH') {
9618: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
9619: $notify = 0;
9620: }
9621: }
9622: if ($notify) {
9623: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
9624: "LON-CAPA Domain Settings Change - $dom",
9625: $mailmsgtext);
9626: }
1.54 raeburn 9627: }
1.43 raeburn 9628: } else {
1.54 raeburn 9629: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 9630: }
9631: } else {
9632: $resulttext = '<span class="LC_error">'.
9633: &mt('An error occurred: [_1]',$putresult).'</span>';
9634: }
9635: if (@errors > 0) {
9636: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
9637: foreach my $item (@errors) {
9638: $resulttext .= ' "'.$title->{$item}.'",';
9639: }
9640: $resulttext =~ s/,$//;
9641: }
9642: return $resulttext;
9643: }
9644:
1.46 raeburn 9645: sub modify_scantron {
1.205 raeburn 9646: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 9647: my ($resulttext,%confhash,%changes,$errors);
9648: my $custom = 'custom.tab';
9649: my $default = 'default.tab';
9650: my $servadm = $r->dir_config('lonAdmEMail');
9651: my ($configuserok,$author_ok,$switchserver) =
9652: &config_check($dom,$confname,$servadm);
9653: if ($env{'form.scantronformat.filename'} ne '') {
9654: my $error;
9655: if ($configuserok eq 'ok') {
9656: if ($switchserver) {
1.130 raeburn 9657: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 9658: } else {
9659: if ($author_ok eq 'ok') {
9660: my ($result,$scantronurl) =
9661: &publishlogo($r,'upload','scantronformat',$dom,
9662: $confname,'scantron','','',$custom);
9663: if ($result eq 'ok') {
9664: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 9665: $changes{'scantronformat'} = 1;
1.46 raeburn 9666: } else {
9667: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
9668: }
9669: } else {
9670: $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);
9671: }
9672: }
9673: } else {
9674: $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);
9675: }
9676: if ($error) {
9677: &Apache::lonnet::logthis($error);
9678: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9679: }
9680: }
1.48 raeburn 9681: if (ref($domconfig{'scantron'}) eq 'HASH') {
9682: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
9683: if ($env{'form.scantronformat_del'}) {
9684: $confhash{'scantron'}{'scantronformat'} = '';
9685: $changes{'scantronformat'} = 1;
1.46 raeburn 9686: }
9687: }
9688: }
9689: if (keys(%confhash) > 0) {
9690: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
9691: $dom);
9692: if ($putresult eq 'ok') {
9693: if (keys(%changes) > 0) {
1.48 raeburn 9694: if (ref($confhash{'scantron'}) eq 'HASH') {
9695: $resulttext = &mt('Changes made:').'<ul>';
9696: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 9697: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 9698: } else {
1.130 raeburn 9699: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 9700: }
1.48 raeburn 9701: $resulttext .= '</ul>';
9702: } else {
1.130 raeburn 9703: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 9704: }
9705: $resulttext .= '</ul>';
9706: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9707: if (ref($lastactref) eq 'HASH') {
9708: $lastactref->{'domainconfig'} = 1;
9709: }
1.46 raeburn 9710: } else {
1.130 raeburn 9711: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9712: }
9713: } else {
9714: $resulttext = '<span class="LC_error">'.
9715: &mt('An error occurred: [_1]',$putresult).'</span>';
9716: }
9717: } else {
1.130 raeburn 9718: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 9719: }
9720: if ($errors) {
9721: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9722: $errors.'</ul>';
9723: }
9724: return $resulttext;
9725: }
9726:
1.48 raeburn 9727: sub modify_coursecategories {
1.239 raeburn 9728: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 9729: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
9730: $cathash);
1.48 raeburn 9731: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 9732: my @catitems = ('unauth','auth');
9733: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 9734: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 9735: $cathash = $domconfig{'coursecategories'}{'cats'};
9736: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
9737: $changes{'togglecats'} = 1;
9738: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
9739: }
9740: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
9741: $changes{'categorize'} = 1;
9742: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
9743: }
1.120 raeburn 9744: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
9745: $changes{'togglecatscomm'} = 1;
9746: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
9747: }
9748: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
9749: $changes{'categorizecomm'} = 1;
9750: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
9751: }
1.238 raeburn 9752: foreach my $item (@catitems) {
9753: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9754: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
9755: $changes{$item} = 1;
9756: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9757: }
9758: }
9759: }
1.57 raeburn 9760: } else {
9761: $changes{'togglecats'} = 1;
9762: $changes{'categorize'} = 1;
1.124 raeburn 9763: $changes{'togglecatscomm'} = 1;
9764: $changes{'categorizecomm'} = 1;
1.87 raeburn 9765: $domconfig{'coursecategories'} = {
9766: togglecats => $env{'form.togglecats'},
9767: categorize => $env{'form.categorize'},
1.124 raeburn 9768: togglecatscomm => $env{'form.togglecatscomm'},
9769: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 9770: };
1.238 raeburn 9771: foreach my $item (@catitems) {
9772: if ($env{'form.coursecat_'.$item} ne 'std') {
9773: $changes{$item} = 1;
9774: }
9775: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
9776: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
9777: }
9778: }
1.57 raeburn 9779: }
9780: if (ref($cathash) eq 'HASH') {
9781: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 9782: push (@deletecategory,'instcode::0');
9783: }
1.120 raeburn 9784: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
9785: push(@deletecategory,'communities::0');
9786: }
1.48 raeburn 9787: }
1.57 raeburn 9788: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
9789: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9790: if (@deletecategory > 0) {
9791: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 9792: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 9793: foreach my $item (@deletecategory) {
1.57 raeburn 9794: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
9795: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 9796: $deletions{$item} = 1;
1.57 raeburn 9797: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 9798: }
9799: }
9800: }
1.57 raeburn 9801: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 9802: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 9803: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 9804: $reorderings{$item} = 1;
1.57 raeburn 9805: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 9806: }
9807: if ($env{'form.addcategory_name_'.$item} ne '') {
9808: my $newcat = $env{'form.addcategory_name_'.$item};
9809: my $newdepth = $depth+1;
9810: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9811: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 9812: $adds{$newitem} = 1;
9813: }
9814: if ($env{'form.subcat_'.$item} ne '') {
9815: my $newcat = $env{'form.subcat_'.$item};
9816: my $newdepth = $depth+1;
9817: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 9818: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 9819: $adds{$newitem} = 1;
9820: }
9821: }
9822: }
9823: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 9824: if (ref($cathash) eq 'HASH') {
1.48 raeburn 9825: my $newitem = 'instcode::0';
1.57 raeburn 9826: if ($cathash->{$newitem} eq '') {
9827: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9828: $adds{$newitem} = 1;
9829: }
9830: } else {
9831: my $newitem = 'instcode::0';
1.57 raeburn 9832: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 9833: $adds{$newitem} = 1;
9834: }
9835: }
1.120 raeburn 9836: if ($env{'form.communities'} eq '1') {
9837: if (ref($cathash) eq 'HASH') {
9838: my $newitem = 'communities::0';
9839: if ($cathash->{$newitem} eq '') {
9840: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9841: $adds{$newitem} = 1;
9842: }
9843: } else {
9844: my $newitem = 'communities::0';
9845: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
9846: $adds{$newitem} = 1;
9847: }
9848: }
1.48 raeburn 9849: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 9850: if (($env{'form.addcategory_name'} ne 'instcode') &&
9851: ($env{'form.addcategory_name'} ne 'communities')) {
9852: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
9853: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
9854: $adds{$newitem} = 1;
9855: }
1.48 raeburn 9856: }
1.57 raeburn 9857: my $putresult;
1.48 raeburn 9858: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9859: if (keys(%deletions) > 0) {
9860: foreach my $key (keys(%deletions)) {
9861: if ($predelallitems{$key} ne '') {
9862: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
9863: }
9864: }
9865: }
9866: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 9867: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 9868: if (ref($chkcats[0]) eq 'ARRAY') {
9869: my $depth = 0;
9870: my $chg = 0;
9871: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
9872: my $name = $chkcats[0][$i];
9873: my $item;
9874: if ($name eq '') {
9875: $chg ++;
9876: } else {
9877: $item = &escape($name).'::0';
9878: if ($chg) {
1.57 raeburn 9879: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 9880: }
9881: $depth ++;
1.57 raeburn 9882: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 9883: $depth --;
9884: }
9885: }
9886: }
1.57 raeburn 9887: }
9888: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9889: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 9890: if ($putresult eq 'ok') {
1.57 raeburn 9891: my %title = (
1.120 raeburn 9892: togglecats => 'Show/Hide a course in catalog',
9893: categorize => 'Assign a category to a course',
9894: togglecatscomm => 'Show/Hide a community in catalog',
9895: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9896: );
9897: my %level = (
1.120 raeburn 9898: dom => 'set in Domain ("Modify Course/Community")',
9899: crs => 'set in Course ("Course Configuration")',
9900: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 9901: none => 'No catalog',
9902: std => 'Standard catalog',
9903: domonly => 'Domain-only catalog',
9904: codesrch => 'Code search form',
1.57 raeburn 9905: );
1.48 raeburn 9906: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 9907: if ($changes{'togglecats'}) {
9908: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
9909: }
9910: if ($changes{'categorize'}) {
9911: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 9912: }
1.120 raeburn 9913: if ($changes{'togglecatscomm'}) {
9914: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
9915: }
9916: if ($changes{'categorizecomm'}) {
9917: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
9918: }
1.238 raeburn 9919: if ($changes{'unauth'}) {
9920: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
9921: }
9922: if ($changes{'auth'}) {
9923: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
9924: }
1.57 raeburn 9925: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
9926: my $cathash;
9927: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
9928: $cathash = $domconfig{'coursecategories'}{'cats'};
9929: } else {
9930: $cathash = {};
9931: }
9932: my (@cats,@trails,%allitems);
9933: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
9934: if (keys(%deletions) > 0) {
9935: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
9936: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
9937: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
9938: }
9939: $resulttext .= '</ul></li>';
9940: }
9941: if (keys(%reorderings) > 0) {
9942: my %sort_by_trail;
9943: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
9944: foreach my $key (keys(%reorderings)) {
9945: if ($allitems{$key} ne '') {
9946: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9947: }
1.48 raeburn 9948: }
1.57 raeburn 9949: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9950: $resulttext .= '<li>'.$trails[$trail].'</li>';
9951: }
9952: $resulttext .= '</ul></li>';
1.48 raeburn 9953: }
1.57 raeburn 9954: if (keys(%adds) > 0) {
9955: my %sort_by_trail;
9956: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
9957: foreach my $key (keys(%adds)) {
9958: if ($allitems{$key} ne '') {
9959: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
9960: }
9961: }
9962: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
9963: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 9964: }
1.57 raeburn 9965: $resulttext .= '</ul></li>';
1.48 raeburn 9966: }
9967: }
9968: $resulttext .= '</ul>';
1.239 raeburn 9969: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 9970: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9971: if ($changes{'auth'}) {
9972: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
9973: }
9974: if ($changes{'unauth'}) {
9975: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
9976: }
9977: my $cachetime = 24*60*60;
9978: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 9979: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 9980: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 9981: }
9982: }
1.48 raeburn 9983: } else {
9984: $resulttext = '<span class="LC_error">'.
1.57 raeburn 9985: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 9986: }
9987: } else {
1.120 raeburn 9988: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 9989: }
9990: return $resulttext;
9991: }
9992:
1.69 raeburn 9993: sub modify_serverstatuses {
9994: my ($dom,%domconfig) = @_;
9995: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
9996: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
9997: %currserverstatus = %{$domconfig{'serverstatuses'}};
9998: }
9999: my @pages = &serverstatus_pages();
10000: foreach my $type (@pages) {
10001: $newserverstatus{$type}{'namedusers'} = '';
10002: $newserverstatus{$type}{'machines'} = '';
10003: if (defined($env{'form.'.$type.'_namedusers'})) {
10004: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
10005: my @okusers;
10006: foreach my $user (@users) {
10007: my ($uname,$udom) = split(/:/,$user);
10008: if (($udom =~ /^$match_domain$/) &&
10009: (&Apache::lonnet::domain($udom)) &&
10010: ($uname =~ /^$match_username$/)) {
10011: if (!grep(/^\Q$user\E/,@okusers)) {
10012: push(@okusers,$user);
10013: }
10014: }
10015: }
10016: if (@okusers > 0) {
10017: @okusers = sort(@okusers);
10018: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
10019: }
10020: }
10021: if (defined($env{'form.'.$type.'_machines'})) {
10022: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
10023: my @okmachines;
10024: foreach my $ip (@machines) {
10025: my @parts = split(/\./,$ip);
10026: next if (@parts < 4);
10027: my $badip = 0;
10028: for (my $i=0; $i<4; $i++) {
10029: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
10030: $badip = 1;
10031: last;
10032: }
10033: }
10034: if (!$badip) {
10035: push(@okmachines,$ip);
10036: }
10037: }
10038: @okmachines = sort(@okmachines);
10039: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
10040: }
10041: }
10042: my %serverstatushash = (
10043: serverstatuses => \%newserverstatus,
10044: );
10045: foreach my $type (@pages) {
1.83 raeburn 10046: foreach my $setting ('namedusers','machines') {
1.84 raeburn 10047: my (@current,@new);
1.83 raeburn 10048: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 10049: if ($currserverstatus{$type}{$setting} ne '') {
10050: @current = split(/,/,$currserverstatus{$type}{$setting});
10051: }
10052: }
10053: if ($newserverstatus{$type}{$setting} ne '') {
10054: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 10055: }
10056: if (@current > 0) {
10057: if (@new > 0) {
10058: foreach my $item (@current) {
10059: if (!grep(/^\Q$item\E$/,@new)) {
10060: $changes{$type}{$setting} = 1;
1.82 raeburn 10061: last;
10062: }
10063: }
1.84 raeburn 10064: foreach my $item (@new) {
10065: if (!grep(/^\Q$item\E$/,@current)) {
10066: $changes{$type}{$setting} = 1;
10067: last;
1.82 raeburn 10068: }
10069: }
10070: } else {
1.83 raeburn 10071: $changes{$type}{$setting} = 1;
1.69 raeburn 10072: }
1.83 raeburn 10073: } elsif (@new > 0) {
10074: $changes{$type}{$setting} = 1;
1.69 raeburn 10075: }
10076: }
10077: }
10078: if (keys(%changes) > 0) {
1.81 raeburn 10079: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10080: my $putresult = &Apache::lonnet::put_dom('configuration',
10081: \%serverstatushash,$dom);
10082: if ($putresult eq 'ok') {
10083: $resulttext .= &mt('Changes made:').'<ul>';
10084: foreach my $type (@pages) {
1.84 raeburn 10085: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 10086: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 10087: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 10088: if ($newserverstatus{$type}{'namedusers'} eq '') {
10089: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
10090: } else {
10091: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
10092: }
1.84 raeburn 10093: }
10094: if ($changes{$type}{'machines'}) {
1.69 raeburn 10095: if ($newserverstatus{$type}{'machines'} eq '') {
10096: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
10097: } else {
10098: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
10099: }
10100:
10101: }
10102: $resulttext .= '</ul></li>';
10103: }
10104: }
10105: $resulttext .= '</ul>';
10106: } else {
10107: $resulttext = '<span class="LC_error">'.
10108: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
10109:
10110: }
10111: } else {
10112: $resulttext = &mt('No changes made to access to server status pages');
10113: }
10114: return $resulttext;
10115: }
10116:
1.118 jms 10117: sub modify_helpsettings {
1.122 jms 10118: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 10119: my ($resulttext,$errors,%changes,%helphash);
10120: my %defaultchecked = ('submitbugs' => 'on');
10121: my @offon = ('off','on');
1.118 jms 10122: my @toggles = ('submitbugs');
10123: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
10124: foreach my $item (@toggles) {
1.166 raeburn 10125: if ($defaultchecked{$item} eq 'on') {
10126: if ($domconfig{'helpsettings'}{$item} eq '') {
10127: if ($env{'form.'.$item} eq '0') {
10128: $changes{$item} = 1;
10129: }
10130: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10131: $changes{$item} = 1;
10132: }
10133: } elsif ($defaultchecked{$item} eq 'off') {
10134: if ($domconfig{'helpsettings'}{$item} eq '') {
10135: if ($env{'form.'.$item} eq '1') {
10136: $changes{$item} = 1;
10137: }
10138: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
10139: $changes{$item} = 1;
10140: }
10141: }
1.210 raeburn 10142: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 10143: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
10144: }
10145: }
1.118 jms 10146: }
1.123 jms 10147: my $putresult;
10148: if (keys(%changes) > 0) {
1.166 raeburn 10149: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 10150: if ($putresult eq 'ok') {
1.166 raeburn 10151: $resulttext = &mt('Changes made:').'<ul>';
10152: foreach my $item (sort(keys(%changes))) {
10153: if ($item eq 'submitbugs') {
10154: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
10155: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
10156: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
10157: }
10158: }
10159: $resulttext .= '</ul>';
10160: } else {
10161: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 10162: $errors .= '<li><span class="LC_error">'.
10163: &mt('An error occurred storing the settings: [_1]',
10164: $putresult).'</span></li>';
1.166 raeburn 10165: }
1.118 jms 10166: }
10167: if ($errors) {
1.168 raeburn 10168: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 10169: $errors.'</ul>';
10170: }
10171: return $resulttext;
10172: }
10173:
1.121 raeburn 10174: sub modify_coursedefaults {
1.212 raeburn 10175: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 10176: my ($resulttext,$errors,%changes,%defaultshash);
10177: my %defaultchecked = ('canuse_pdfforms' => 'off');
10178: my @toggles = ('canuse_pdfforms');
1.198 raeburn 10179: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.216 raeburn 10180: 'uploadquota_community','uploadquota_textbook');
10181: my @types = ('official','unofficial','community','textbook');
1.198 raeburn 10182: my %staticdefaults = (
10183: anonsurvey_threshold => 10,
10184: uploadquota => 500,
10185: );
1.121 raeburn 10186:
10187: $defaultshash{'coursedefaults'} = {};
10188:
10189: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
10190: if ($domconfig{'coursedefaults'} eq '') {
10191: $domconfig{'coursedefaults'} = {};
10192: }
10193: }
10194:
10195: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
10196: foreach my $item (@toggles) {
10197: if ($defaultchecked{$item} eq 'on') {
10198: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10199: ($env{'form.'.$item} eq '0')) {
10200: $changes{$item} = 1;
1.192 raeburn 10201: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 10202: $changes{$item} = 1;
10203: }
10204: } elsif ($defaultchecked{$item} eq 'off') {
10205: if (($domconfig{'coursedefaults'}{$item} eq '') &&
10206: ($env{'form.'.$item} eq '1')) {
10207: $changes{$item} = 1;
10208: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
10209: $changes{$item} = 1;
10210: }
10211: }
10212: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
10213: }
1.198 raeburn 10214: foreach my $item (@numbers) {
10215: my ($currdef,$newdef);
1.208 raeburn 10216: $newdef = $env{'form.'.$item};
1.198 raeburn 10217: if ($item eq 'anonsurvey_threshold') {
10218: $currdef = $domconfig{'coursedefaults'}{$item};
10219: $newdef =~ s/\D//g;
10220: if ($newdef eq '' || $newdef < 1) {
10221: $newdef = 1;
10222: }
10223: $defaultshash{'coursedefaults'}{$item} = $newdef;
10224: } else {
10225: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
10226: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10227: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
10228: }
10229: $newdef =~ s/[^\w.\-]//g;
10230: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
10231: }
10232: if ($currdef ne $newdef) {
10233: my $staticdef;
10234: if ($item eq 'anonsurvey_threshold') {
10235: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
10236: $changes{$item} = 1;
10237: }
10238: } else {
10239: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
10240: $changes{'uploadquota'} = 1;
10241: }
10242: }
1.139 raeburn 10243: }
10244: }
1.231 raeburn 10245:
1.192 raeburn 10246: my $officialcreds = $env{'form.official_credits'};
1.216 raeburn 10247: $officialcreds =~ s/[^\d.]+//g;
1.192 raeburn 10248: my $unofficialcreds = $env{'form.unofficial_credits'};
1.216 raeburn 10249: $unofficialcreds =~ s/[^\d.]+//g;
10250: my $textbookcreds = $env{'form.textbook_credits'};
10251: $textbookcreds =~ s/[^\d.]+//g;
1.192 raeburn 10252: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
10253: ($env{'form.coursecredits'} eq '1')) {
10254: $changes{'coursecredits'} = 1;
10255: } else {
10256: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
1.216 raeburn 10257: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds) ||
10258: ($domconfig{'coursedefaults'}{'coursecredits'}{'textbook'} ne $textbookcreds)) {
1.192 raeburn 10259: $changes{'coursecredits'} = 1;
10260: }
10261: }
10262: $defaultshash{'coursedefaults'}{'coursecredits'} = {
10263: official => $officialcreds,
10264: unofficial => $unofficialcreds,
1.216 raeburn 10265: textbook => $textbookcreds,
1.192 raeburn 10266: }
1.121 raeburn 10267: }
10268: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10269: $dom);
10270: if ($putresult eq 'ok') {
10271: if (keys(%changes) > 0) {
1.213 raeburn 10272: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.230 raeburn 10273: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) ||
1.231 raeburn 10274: ($changes{'uploadquota'})) {
1.192 raeburn 10275: if ($changes{'canuse_pdfforms'}) {
10276: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
10277: }
10278: if ($changes{'coursecredits'}) {
10279: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10280: $domdefaults{'officialcredits'} =
10281: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
10282: $domdefaults{'unofficialcredits'} =
10283: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
1.216 raeburn 10284: $domdefaults{'textbookcredits'} =
10285: $domdefaults{'coursedefaults'}{'coursecredits'}{'textbook'};
1.192 raeburn 10286: }
10287: }
1.198 raeburn 10288: if ($changes{'uploadquota'}) {
10289: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10290: foreach my $type (@types) {
10291: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
10292: }
10293: }
10294: }
1.121 raeburn 10295: my $cachetime = 24*60*60;
10296: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10297: if (ref($lastactref) eq 'HASH') {
10298: $lastactref->{'domdefaults'} = 1;
10299: }
1.121 raeburn 10300: }
10301: $resulttext = &mt('Changes made:').'<ul>';
10302: foreach my $item (sort(keys(%changes))) {
10303: if ($item eq 'canuse_pdfforms') {
10304: if ($env{'form.'.$item} eq '1') {
10305: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
10306: } else {
10307: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
10308: }
1.139 raeburn 10309: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 10310: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 10311: } elsif ($item eq 'uploadquota') {
10312: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
10313: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
10314: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
10315: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 10316: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
10317:
1.198 raeburn 10318: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
10319: '</ul>'.
10320: '</li>';
10321: } else {
10322: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
10323: }
1.192 raeburn 10324: } elsif ($item eq 'coursecredits') {
10325: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
10326: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 10327: ($domdefaults{'unofficialcredits'} eq '') &&
10328: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 10329: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10330: } else {
10331: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
10332: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
10333: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 10334: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 10335: '</ul>'.
10336: '</li>';
10337: }
10338: } else {
10339: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
10340: }
1.140 raeburn 10341: }
1.121 raeburn 10342: }
10343: $resulttext .= '</ul>';
10344: } else {
10345: $resulttext = &mt('No changes made to course defaults');
10346: }
10347: } else {
10348: $resulttext = '<span class="LC_error">'.
10349: &mt('An error occurred: [_1]',$putresult).'</span>';
10350: }
10351: return $resulttext;
10352: }
10353:
1.231 raeburn 10354: sub modify_selfenrollment {
10355: my ($dom,$lastactref,%domconfig) = @_;
10356: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
10357: my @types = ('official','unofficial','community','textbook');
10358: my %titles = &tool_titles();
1.232 raeburn 10359: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
10360: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 10361: $ordered{'default'} = ['types','registered','approval','limit'];
10362:
10363: my (%roles,%shown,%toplevel);
10364: $roles{'0'} = &Apache::lonnet::plaintext('dc');
10365:
10366: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
10367: if ($domconfig{'selfenrollment'} eq '') {
10368: $domconfig{'selfenrollment'} = {};
10369: }
10370: }
10371: %toplevel = (
10372: admin => 'Configuration Rights',
10373: default => 'Default settings',
10374: validation => 'Validation of self-enrollment requests',
10375: );
1.233 raeburn 10376: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 10377:
10378: if (ref($ordered{'admin'}) eq 'ARRAY') {
10379: foreach my $item (@{$ordered{'admin'}}) {
10380: foreach my $type (@types) {
10381: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
10382: $selfenrollhash{'admin'}{$type}{$item} = 1;
10383: } else {
10384: $selfenrollhash{'admin'}{$type}{$item} = 0;
10385: }
10386: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
10387: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
10388: if ($selfenrollhash{'admin'}{$type}{$item} ne
10389: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
10390: push(@{$changes{'admin'}{$type}},$item);
10391: }
10392: } else {
10393: if (!$selfenrollhash{'admin'}{$type}{$item}) {
10394: push(@{$changes{'admin'}{$type}},$item);
10395: }
10396: }
10397: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
10398: push(@{$changes{'admin'}{$type}},$item);
10399: }
10400: }
10401: }
10402: }
10403:
10404: foreach my $item (@{$ordered{'default'}}) {
10405: foreach my $type (@types) {
10406: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
10407: if ($item eq 'types') {
10408: unless (($value eq 'all') || ($value eq 'dom')) {
10409: $value = '';
10410: }
10411: } elsif ($item eq 'registered') {
10412: unless ($value eq '1') {
10413: $value = 0;
10414: }
10415: } elsif ($item eq 'approval') {
10416: unless ($value =~ /^[012]$/) {
10417: $value = 0;
10418: }
10419: } else {
10420: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10421: $value = 'none';
10422: }
10423: }
10424: $selfenrollhash{'default'}{$type}{$item} = $value;
10425: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
10426: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10427: if ($selfenrollhash{'default'}{$type}{$item} ne
10428: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
10429: push(@{$changes{'default'}{$type}},$item);
10430: }
10431: } else {
10432: push(@{$changes{'default'}{$type}},$item);
10433: }
10434: } else {
10435: push(@{$changes{'default'}{$type}},$item);
10436: }
10437: if ($item eq 'limit') {
10438: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
10439: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
10440: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
10441: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
10442: }
10443: } else {
10444: $selfenrollhash{'default'}{$type}{'cap'} = '';
10445: }
10446: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
10447: if ($selfenrollhash{'default'}{$type}{'cap'} ne
10448: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
10449: push(@{$changes{'default'}{$type}},'cap');
10450: }
10451: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
10452: push(@{$changes{'default'}{$type}},'cap');
10453: }
10454: }
10455: }
10456: }
10457:
10458: foreach my $item (@{$itemsref}) {
10459: if ($item eq 'fields') {
10460: my @changed;
10461: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
10462: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
10463: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
10464: }
10465: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10466: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
10467: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
10468: $domconfig{'selfenrollment'}{'validation'}{$item});
10469: } else {
10470: @changed = @{$selfenrollhash{'validation'}{$item}};
10471: }
10472: } else {
10473: @changed = @{$selfenrollhash{'validation'}{$item}};
10474: }
10475: if (@changed) {
10476: if ($selfenrollhash{'validation'}{$item}) {
10477: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
10478: } else {
10479: $changes{'validation'}{$item} = &mt('None');
10480: }
10481: }
10482: } else {
10483: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
10484: if ($item eq 'markup') {
10485: if ($env{'form.selfenroll_validation_'.$item}) {
10486: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
10487: }
10488: }
10489: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
10490: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
10491: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
10492: }
10493: }
10494: }
10495: }
10496:
10497: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
10498: $dom);
10499: if ($putresult eq 'ok') {
10500: if (keys(%changes) > 0) {
10501: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10502: $resulttext = &mt('Changes made:').'<ul>';
10503: foreach my $key ('admin','default','validation') {
10504: if (ref($changes{$key}) eq 'HASH') {
10505: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
10506: if ($key eq 'validation') {
10507: foreach my $item (@{$itemsref}) {
10508: if (exists($changes{$key}{$item})) {
10509: if ($item eq 'markup') {
10510: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10511: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
10512: } else {
10513: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
10514: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
10515: }
10516: }
10517: }
10518: } else {
10519: foreach my $type (@types) {
10520: if ($type eq 'community') {
10521: $roles{'1'} = &mt('Community personnel');
10522: } else {
10523: $roles{'1'} = &mt('Course personnel');
10524: }
10525: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 10526: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10527: if ($key eq 'admin') {
10528: my @mgrdc = ();
10529: if (ref($ordered{$key}) eq 'ARRAY') {
10530: foreach my $item (@{$ordered{'admin'}}) {
10531: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
10532: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
10533: push(@mgrdc,$item);
10534: }
10535: }
10536: }
10537: if (@mgrdc) {
10538: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
10539: } else {
10540: delete($domdefaults{$type.'selfenrolladmdc'});
10541: }
10542: }
10543: } else {
10544: if (ref($ordered{$key}) eq 'ARRAY') {
10545: foreach my $item (@{$ordered{$key}}) {
10546: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10547: $domdefaults{$type.'selfenroll'.$item} =
10548: $selfenrollhash{$key}{$type}{$item};
10549: }
10550: }
10551: }
10552: }
10553: }
1.231 raeburn 10554: $resulttext .= '<li>'.$titles{$type}.'<ul>';
10555: foreach my $item (@{$ordered{$key}}) {
10556: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
10557: $resulttext .= '<li>';
10558: if ($key eq 'admin') {
10559: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
10560: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
10561: } else {
10562: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
10563: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
10564: }
10565: $resulttext .= '</li>';
10566: }
10567: }
10568: $resulttext .= '</ul></li>';
10569: }
10570: }
10571: $resulttext .= '</ul></li>';
10572: }
10573: }
1.232 raeburn 10574: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
10575: my $cachetime = 24*60*60;
10576: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10577: if (ref($lastactref) eq 'HASH') {
10578: $lastactref->{'domdefaults'} = 1;
10579: }
10580: }
1.231 raeburn 10581: }
10582: $resulttext .= '</ul>';
10583: } else {
10584: $resulttext = &mt('No changes made to self-enrollment settings');
10585: }
10586: } else {
10587: $resulttext = '<span class="LC_error">'.
10588: &mt('An error occurred: [_1]',$putresult).'</span>';
10589: }
10590: return $resulttext;
10591: }
10592:
1.137 raeburn 10593: sub modify_usersessions {
1.212 raeburn 10594: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 10595: my @hostingtypes = ('version','excludedomain','includedomain');
10596: my @offloadtypes = ('primary','default');
10597: my %types = (
10598: remote => \@hostingtypes,
10599: hosted => \@hostingtypes,
10600: spares => \@offloadtypes,
10601: );
10602: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 10603: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 10604: my (%by_ip,%by_location,@intdoms);
10605: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
10606: my @locations = sort(keys(%by_location));
1.137 raeburn 10607: my (%defaultshash,%changes);
10608: foreach my $prefix (@prefixes) {
10609: $defaultshash{'usersessions'}{$prefix} = {};
10610: }
1.212 raeburn 10611: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 10612: my $resulttext;
1.138 raeburn 10613: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 10614: foreach my $prefix (@prefixes) {
1.145 raeburn 10615: next if ($prefix eq 'spares');
10616: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 10617: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
10618: if ($type eq 'version') {
10619: my $value = $env{'form.'.$prefix.'_'.$type};
10620: my $okvalue;
10621: if ($value ne '') {
10622: if (grep(/^\Q$value\E$/,@lcversions)) {
10623: $okvalue = $value;
10624: }
10625: }
10626: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10627: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10628: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
10629: if ($inuse == 0) {
10630: $changes{$prefix}{$type} = 1;
10631: } else {
10632: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
10633: $changes{$prefix}{$type} = 1;
10634: }
10635: if ($okvalue ne '') {
10636: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10637: }
10638: }
10639: } else {
10640: if (($inuse == 1) && ($okvalue ne '')) {
10641: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10642: $changes{$prefix}{$type} = 1;
10643: }
10644: }
10645: } else {
10646: if (($inuse == 1) && ($okvalue ne '')) {
10647: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10648: $changes{$prefix}{$type} = 1;
10649: }
10650: }
10651: } else {
10652: if (($inuse == 1) && ($okvalue ne '')) {
10653: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
10654: $changes{$prefix}{$type} = 1;
10655: }
10656: }
10657: } else {
10658: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
10659: my @okvals;
10660: foreach my $val (@vals) {
1.138 raeburn 10661: if ($val =~ /:/) {
10662: my @items = split(/:/,$val);
10663: foreach my $item (@items) {
10664: if (ref($by_location{$item}) eq 'ARRAY') {
10665: push(@okvals,$item);
10666: }
10667: }
10668: } else {
10669: if (ref($by_location{$val}) eq 'ARRAY') {
10670: push(@okvals,$val);
10671: }
1.137 raeburn 10672: }
10673: }
10674: @okvals = sort(@okvals);
10675: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10676: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
10677: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10678: if ($inuse == 0) {
10679: $changes{$prefix}{$type} = 1;
10680: } else {
10681: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10682: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
10683: if (@changed > 0) {
10684: $changes{$prefix}{$type} = 1;
10685: }
10686: }
10687: } else {
10688: if ($inuse == 1) {
10689: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10690: $changes{$prefix}{$type} = 1;
10691: }
10692: }
10693: } else {
10694: if ($inuse == 1) {
10695: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10696: $changes{$prefix}{$type} = 1;
10697: }
10698: }
10699: } else {
10700: if ($inuse == 1) {
10701: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
10702: $changes{$prefix}{$type} = 1;
10703: }
10704: }
10705: }
10706: }
10707: }
1.145 raeburn 10708:
10709: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 10710: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 10711: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
10712: my $savespares;
10713:
10714: foreach my $lonhost (sort(keys(%servers))) {
10715: my $serverhomeID =
10716: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 10717: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 10718: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
10719: my %spareschg;
10720: foreach my $type (@{$types{'spares'}}) {
10721: my @okspares;
10722: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
10723: foreach my $server (@checked) {
1.152 raeburn 10724: if (&Apache::lonnet::hostname($server) ne '') {
10725: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
10726: unless (grep(/^\Q$server\E$/,@okspares)) {
10727: push(@okspares,$server);
10728: }
1.145 raeburn 10729: }
10730: }
10731: }
10732: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
10733: my $newspare;
1.152 raeburn 10734: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
10735: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 10736: $newspare = $new;
10737: }
10738: }
1.152 raeburn 10739: my @spares;
10740: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
10741: @spares = sort(@okspares,$newspare);
10742: } else {
10743: @spares = sort(@okspares);
10744: }
10745: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 10746: if (ref($spareid{$lonhost}) eq 'HASH') {
10747: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 10748: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 10749: if (@diffs > 0) {
10750: $spareschg{$type} = 1;
10751: }
10752: }
10753: }
10754: }
10755: if (keys(%spareschg) > 0) {
10756: $changes{'spares'}{$lonhost} = \%spareschg;
10757: }
10758: }
10759:
10760: if (ref($domconfig{'usersessions'}) eq 'HASH') {
10761: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
10762: if (ref($changes{'spares'}) eq 'HASH') {
10763: if (keys(%{$changes{'spares'}}) > 0) {
10764: $savespares = 1;
10765: }
10766: }
10767: } else {
10768: $savespares = 1;
10769: }
10770: }
10771:
1.147 raeburn 10772: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
10773: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 10774: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10775: $dom);
10776: if ($putresult eq 'ok') {
10777: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10778: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
10779: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
10780: }
10781: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
10782: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
10783: }
10784: }
10785: my $cachetime = 24*60*60;
10786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10787: if (ref($lastactref) eq 'HASH') {
10788: $lastactref->{'domdefaults'} = 1;
10789: }
1.147 raeburn 10790: if (keys(%changes) > 0) {
10791: my %lt = &usersession_titles();
10792: $resulttext = &mt('Changes made:').'<ul>';
10793: foreach my $prefix (@prefixes) {
10794: if (ref($changes{$prefix}) eq 'HASH') {
10795: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
10796: if ($prefix eq 'spares') {
10797: if (ref($changes{$prefix}) eq 'HASH') {
10798: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
10799: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 10800: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 10801: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
10802: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 10803: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
10804: foreach my $type (@{$types{$prefix}}) {
10805: if ($changes{$prefix}{$lonhost}{$type}) {
10806: my $offloadto = &mt('None');
10807: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
10808: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
10809: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
10810: }
1.145 raeburn 10811: }
1.147 raeburn 10812: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 10813: }
1.137 raeburn 10814: }
10815: }
1.147 raeburn 10816: $resulttext .= '</li>';
1.137 raeburn 10817: }
10818: }
1.147 raeburn 10819: } else {
10820: foreach my $type (@{$types{$prefix}}) {
10821: if (defined($changes{$prefix}{$type})) {
10822: my $newvalue;
10823: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
10824: if (ref($defaultshash{'usersessions'}{$prefix})) {
10825: if ($type eq 'version') {
10826: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
10827: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
10828: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
10829: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
10830: }
1.145 raeburn 10831: }
10832: }
10833: }
1.147 raeburn 10834: if ($newvalue eq '') {
10835: if ($type eq 'version') {
10836: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
10837: } else {
10838: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
10839: }
1.145 raeburn 10840: } else {
1.147 raeburn 10841: if ($type eq 'version') {
10842: $newvalue .= ' '.&mt('(or later)');
10843: }
10844: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 10845: }
1.137 raeburn 10846: }
10847: }
10848: }
1.147 raeburn 10849: $resulttext .= '</ul>';
1.137 raeburn 10850: }
10851: }
1.147 raeburn 10852: $resulttext .= '</ul>';
10853: } else {
10854: $resulttext = $nochgmsg;
1.137 raeburn 10855: }
10856: } else {
10857: $resulttext = '<span class="LC_error">'.
10858: &mt('An error occurred: [_1]',$putresult).'</span>';
10859: }
10860: } else {
1.147 raeburn 10861: $resulttext = $nochgmsg;
1.137 raeburn 10862: }
10863: return $resulttext;
10864: }
10865:
1.150 raeburn 10866: sub modify_loadbalancing {
10867: my ($dom,%domconfig) = @_;
10868: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10869: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10870: my ($othertitle,$usertypes,$types) =
10871: &Apache::loncommon::sorted_inst_types($dom);
10872: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 10873: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 10874: my @sparestypes = ('primary','default');
10875: my %typetitles = &sparestype_titles();
10876: my $resulttext;
1.171 raeburn 10877: my (%currbalancer,%currtargets,%currrules,%existing);
10878: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10879: %existing = %{$domconfig{'loadbalancing'}};
10880: }
10881: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
10882: \%currtargets,\%currrules);
10883: my ($saveloadbalancing,%defaultshash,%changes);
10884: my ($alltypes,$othertypes,$titles) =
10885: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
10886: my %ruletitles = &offloadtype_text();
10887: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
10888: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
10889: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
10890: if ($balancer eq '') {
10891: next;
10892: }
1.210 raeburn 10893: if (!exists($servers{$balancer})) {
1.171 raeburn 10894: if (exists($currbalancer{$balancer})) {
10895: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 10896: }
1.171 raeburn 10897: next;
10898: }
10899: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
10900: push(@{$changes{'delete'}},$balancer);
10901: next;
10902: }
10903: if (!exists($currbalancer{$balancer})) {
10904: push(@{$changes{'add'}},$balancer);
10905: }
10906: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
10907: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
10908: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
10909: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
10910: $saveloadbalancing = 1;
10911: }
10912: foreach my $sparetype (@sparestypes) {
10913: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
10914: my @offloadto;
10915: foreach my $target (@targets) {
10916: if (($servers{$target}) && ($target ne $balancer)) {
10917: if ($sparetype eq 'default') {
10918: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
10919: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 10920: }
10921: }
1.171 raeburn 10922: unless(grep(/^\Q$target\E$/,@offloadto)) {
10923: push(@offloadto,$target);
10924: }
1.150 raeburn 10925: }
1.171 raeburn 10926: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 10927: }
10928: }
1.171 raeburn 10929: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 10930: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10931: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
10932: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 10933: if (@targetdiffs > 0) {
1.171 raeburn 10934: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10935: }
1.171 raeburn 10936: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10937: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10938: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 10939: }
10940: }
10941: }
10942: } else {
1.171 raeburn 10943: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 10944: foreach my $sparetype (@sparestypes) {
1.171 raeburn 10945: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
10946: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
10947: $changes{'curr'}{$balancer}{'targets'} = 1;
10948: }
1.150 raeburn 10949: }
10950: }
1.210 raeburn 10951: }
1.150 raeburn 10952: }
10953: my $ishomedom;
1.171 raeburn 10954: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
10955: $ishomedom = 1;
1.150 raeburn 10956: }
10957: if (ref($alltypes) eq 'ARRAY') {
10958: foreach my $type (@{$alltypes}) {
10959: my $rule;
1.210 raeburn 10960: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 10961: (!$ishomedom)) {
1.171 raeburn 10962: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
10963: }
10964: if ($rule eq 'specific') {
1.255 raeburn 10965: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
10966: if (exists($servers{$specifiedhost})) {
10967: $rule = $specifiedhost;
10968: }
1.150 raeburn 10969: }
1.171 raeburn 10970: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
10971: if (ref($currrules{$balancer}) eq 'HASH') {
10972: if ($rule ne $currrules{$balancer}{$type}) {
10973: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10974: }
10975: } elsif ($rule ne '') {
1.171 raeburn 10976: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 10977: }
10978: }
10979: }
1.171 raeburn 10980: }
10981: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
10982: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
10983: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
10984: $defaultshash{'loadbalancing'} = {};
10985: }
10986: my $putresult = &Apache::lonnet::put_dom('configuration',
10987: \%defaultshash,$dom);
10988: if ($putresult eq 'ok') {
10989: if (keys(%changes) > 0) {
1.252 raeburn 10990: my %toupdate;
1.171 raeburn 10991: if (ref($changes{'delete'}) eq 'ARRAY') {
10992: foreach my $balancer (sort(@{$changes{'delete'}})) {
10993: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 10994: $toupdate{$balancer} = 1;
1.150 raeburn 10995: }
1.171 raeburn 10996: }
10997: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 10998: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 10999: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 11000: $toupdate{$balancer} = 1;
1.171 raeburn 11001: }
11002: }
11003: if (ref($changes{'curr'}) eq 'HASH') {
11004: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 11005: $toupdate{$balancer} = 1;
1.171 raeburn 11006: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
11007: if ($changes{'curr'}{$balancer}{'targets'}) {
11008: my %offloadstr;
11009: foreach my $sparetype (@sparestypes) {
11010: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11011: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
11012: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11013: }
11014: }
1.150 raeburn 11015: }
1.171 raeburn 11016: if (keys(%offloadstr) == 0) {
11017: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 11018: } else {
1.171 raeburn 11019: my $showoffload;
11020: foreach my $sparetype (@sparestypes) {
11021: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
11022: if (defined($offloadstr{$sparetype})) {
11023: $showoffload .= $offloadstr{$sparetype};
11024: } else {
11025: $showoffload .= &mt('None');
11026: }
11027: $showoffload .= (' 'x3);
11028: }
11029: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 11030: }
11031: }
11032: }
1.171 raeburn 11033: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
11034: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
11035: foreach my $type (@{$alltypes}) {
11036: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
11037: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11038: my $balancetext;
11039: if ($rule eq '') {
11040: $balancetext = $ruletitles{'default'};
1.209 raeburn 11041: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 11042: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
11043: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 11044: foreach my $sparetype (@sparestypes) {
11045: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
11046: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
11047: }
11048: }
1.253 raeburn 11049: foreach my $item (@{$alltypes}) {
11050: next if ($item =~ /^_LC_ipchange/);
11051: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
11052: if ($hasrule eq 'homeserver') {
11053: map { $toupdate{$_} = 1; } (keys(%libraryservers));
11054: } else {
11055: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
11056: if ($servers{$hasrule}) {
11057: $toupdate{$hasrule} = 1;
11058: }
11059: }
11060: }
11061: }
1.254 raeburn 11062: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
11063: $balancetext = $ruletitles{$rule};
11064: } else {
11065: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
11066: $balancetext = $ruletitles{'particular'}.' '.$receiver;
11067: if ($receiver) {
11068: $toupdate{$receiver};
11069: }
11070: }
11071: } else {
11072: $balancetext = $ruletitles{$rule};
1.252 raeburn 11073: }
1.171 raeburn 11074: } else {
11075: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
11076: }
1.210 raeburn 11077: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 11078: }
11079: }
11080: }
11081: }
1.252 raeburn 11082: if (keys(%toupdate)) {
11083: my %thismachine;
11084: my $updatedhere;
11085: my $cachetime = 60*60*24;
11086: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
11087: foreach my $lonhost (keys(%toupdate)) {
11088: if ($thismachine{$lonhost}) {
11089: unless ($updatedhere) {
11090: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
11091: $defaultshash{'loadbalancing'},
11092: $cachetime);
11093: $updatedhere = 1;
11094: }
11095: } else {
11096: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
11097: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
11098: }
11099: }
11100: }
1.150 raeburn 11101: }
1.171 raeburn 11102: }
11103: if ($resulttext ne '') {
11104: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 11105: } else {
11106: $resulttext = $nochgmsg;
11107: }
11108: } else {
1.171 raeburn 11109: $resulttext = $nochgmsg;
1.150 raeburn 11110: }
11111: } else {
1.171 raeburn 11112: $resulttext = '<span class="LC_error">'.
11113: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 11114: }
11115: } else {
1.171 raeburn 11116: $resulttext = $nochgmsg;
1.150 raeburn 11117: }
11118: return $resulttext;
11119: }
11120:
1.48 raeburn 11121: sub recurse_check {
11122: my ($chkcats,$categories,$depth,$name) = @_;
11123: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
11124: my $chg = 0;
11125: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
11126: my $category = $chkcats->[$depth]{$name}[$j];
11127: my $item;
11128: if ($category eq '') {
11129: $chg ++;
11130: } else {
11131: my $deeper = $depth + 1;
11132: $item = &escape($category).':'.&escape($name).':'.$depth;
11133: if ($chg) {
11134: $categories->{$item} -= $chg;
11135: }
11136: &recurse_check($chkcats,$categories,$deeper,$category);
11137: $deeper --;
11138: }
11139: }
11140: }
11141: return;
11142: }
11143:
11144: sub recurse_cat_deletes {
11145: my ($item,$coursecategories,$deletions) = @_;
11146: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
11147: my $subdepth = $depth + 1;
11148: if (ref($coursecategories) eq 'HASH') {
11149: foreach my $subitem (keys(%{$coursecategories})) {
11150: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
11151: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
11152: delete($coursecategories->{$subitem});
11153: $deletions->{$subitem} = 1;
11154: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 11155: }
1.48 raeburn 11156: }
11157: }
11158: return;
11159: }
11160:
1.125 raeburn 11161: sub get_active_dcs {
11162: my ($dom) = @_;
1.191 raeburn 11163: my $now = time;
11164: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 11165: my %domcoords;
11166: my $numdcs = 0;
11167: foreach my $server (keys(%dompersonnel)) {
11168: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
11169: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 11170: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 11171: }
11172: }
11173: return %domcoords;
11174: }
11175:
11176: sub active_dc_picker {
1.191 raeburn 11177: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 11178: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 11179: my @domcoord = keys(%domcoords);
11180: if (keys(%currhash)) {
11181: foreach my $dc (keys(%currhash)) {
11182: unless (exists($domcoords{$dc})) {
11183: push(@domcoord,$dc);
11184: }
11185: }
11186: }
11187: @domcoord = sort(@domcoord);
1.210 raeburn 11188: my $numdcs = scalar(@domcoord);
1.191 raeburn 11189: my $rows = 0;
11190: my $table;
1.125 raeburn 11191: if ($numdcs > 1) {
1.191 raeburn 11192: $table = '<table>';
11193: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 11194: my $rem = $i%($numinrow);
11195: if ($rem == 0) {
11196: if ($i > 0) {
1.191 raeburn 11197: $table .= '</tr>';
1.125 raeburn 11198: }
1.191 raeburn 11199: $table .= '<tr>';
11200: $rows ++;
1.125 raeburn 11201: }
1.191 raeburn 11202: my $check = '';
11203: if ($inputtype eq 'radio') {
11204: if (keys(%currhash) == 0) {
11205: if (!$i) {
11206: $check = ' checked="checked"';
11207: }
11208: } elsif (exists($currhash{$domcoord[$i]})) {
11209: $check = ' checked="checked"';
11210: }
11211: } else {
11212: if (exists($currhash{$domcoord[$i]})) {
11213: $check = ' checked="checked"';
1.125 raeburn 11214: }
11215: }
1.191 raeburn 11216: if ($i == @domcoord - 1) {
1.125 raeburn 11217: my $colsleft = $numinrow - $rem;
11218: if ($colsleft > 1) {
1.191 raeburn 11219: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 11220: } else {
1.191 raeburn 11221: $table .= '<td class="LC_left_item">';
1.125 raeburn 11222: }
11223: } else {
1.191 raeburn 11224: $table .= '<td class="LC_left_item">';
11225: }
11226: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
11227: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
11228: $table .= '<span class="LC_nobreak"><label>'.
11229: '<input type="'.$inputtype.'" name="'.$name.'"'.
11230: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
11231: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 11232: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 11233: }
1.219 raeburn 11234: $table .= '</label></span></td>';
1.191 raeburn 11235: }
11236: $table .= '</tr></table>';
11237: } elsif ($numdcs == 1) {
1.219 raeburn 11238: my ($dcname,$dcdom) = split(':',$domcoord[0]);
11239: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 11240: if ($inputtype eq 'radio') {
1.247 raeburn 11241: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 11242: if ($user ne $dcname.':'.$dcdom) {
11243: $table .= ' ('.$dcname.':'.$dcdom.')';
11244: }
1.191 raeburn 11245: } else {
11246: my $check;
11247: if (exists($currhash{$domcoord[0]})) {
11248: $check = ' checked="checked"';
1.125 raeburn 11249: }
1.247 raeburn 11250: $table = '<span class="LC_nobreak"><label>'.
11251: '<input type="checkbox" name="'.$name.'" '.
11252: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 11253: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 11254: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 11255: }
1.220 raeburn 11256: $table .= '</label></span>';
1.191 raeburn 11257: $rows ++;
1.125 raeburn 11258: }
11259: }
1.191 raeburn 11260: return ($numdcs,$table,$rows);
1.125 raeburn 11261: }
11262:
1.137 raeburn 11263: sub usersession_titles {
11264: return &Apache::lonlocal::texthash(
11265: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
11266: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 11267: spares => 'Servers offloaded to, when busy',
1.137 raeburn 11268: version => 'LON-CAPA version requirement',
1.138 raeburn 11269: excludedomain => 'Allow all, but exclude specific domains',
11270: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 11271: primary => 'Primary (checked first)',
1.154 raeburn 11272: default => 'Default',
1.137 raeburn 11273: );
11274: }
11275:
1.152 raeburn 11276: sub id_for_thisdom {
11277: my (%servers) = @_;
11278: my %altids;
11279: foreach my $server (keys(%servers)) {
11280: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
11281: if ($serverhome ne $server) {
11282: $altids{$serverhome} = $server;
11283: }
11284: }
11285: return %altids;
11286: }
11287:
1.150 raeburn 11288: sub count_servers {
11289: my ($currbalancer,%servers) = @_;
11290: my (@spares,$numspares);
11291: foreach my $lonhost (sort(keys(%servers))) {
11292: next if ($currbalancer eq $lonhost);
11293: push(@spares,$lonhost);
11294: }
11295: if ($currbalancer) {
11296: $numspares = scalar(@spares);
11297: } else {
11298: $numspares = scalar(@spares) - 1;
11299: }
11300: return ($numspares,@spares);
11301: }
11302:
11303: sub lonbalance_targets_js {
1.171 raeburn 11304: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 11305: my $select = &mt('Select');
11306: my ($alltargets,$allishome,$allinsttypes,@alltypes);
11307: if (ref($servers) eq 'HASH') {
11308: $alltargets = join("','",sort(keys(%{$servers})));
11309: my @homedoms;
11310: foreach my $server (sort(keys(%{$servers}))) {
11311: if (&Apache::lonnet::host_domain($server) eq $dom) {
11312: push(@homedoms,'1');
11313: } else {
11314: push(@homedoms,'0');
11315: }
11316: }
11317: $allishome = join("','",@homedoms);
11318: }
11319: if (ref($types) eq 'ARRAY') {
11320: if (@{$types} > 0) {
11321: @alltypes = @{$types};
11322: }
11323: }
11324: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
11325: $allinsttypes = join("','",@alltypes);
1.171 raeburn 11326: my (%currbalancer,%currtargets,%currrules,%existing);
11327: if (ref($settings) eq 'HASH') {
11328: %existing = %{$settings};
11329: }
11330: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
11331: \%currtargets,\%currrules);
1.210 raeburn 11332: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 11333: return <<"END";
11334:
11335: <script type="text/javascript">
11336: // <![CDATA[
11337:
1.171 raeburn 11338: currBalancers = new Array('$balancers');
11339:
11340: function toggleTargets(balnum) {
11341: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11342: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
11343: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
11344: var prevbalancer = prevhostitem.value;
11345: var baltotal = document.getElementById('loadbalancing_total').value;
11346: prevhostitem.value = balancer;
11347: if (prevbalancer != '') {
11348: var prevIdx = currBalancers.indexOf(prevbalancer);
11349: if (prevIdx != -1) {
11350: currBalancers.splice(prevIdx,1);
11351: }
11352: }
1.150 raeburn 11353: if (balancer == '') {
1.171 raeburn 11354: hideSpares(balnum);
1.150 raeburn 11355: } else {
1.171 raeburn 11356: var currIdx = currBalancers.indexOf(balancer);
11357: if (currIdx == -1) {
11358: currBalancers.push(balancer);
11359: }
1.150 raeburn 11360: var homedoms = new Array('$allishome');
1.171 raeburn 11361: var ishomedom = homedoms[lonhostitem.selectedIndex];
11362: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 11363: }
1.171 raeburn 11364: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 11365: return;
11366: }
11367:
1.171 raeburn 11368: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 11369: var alltargets = new Array('$alltargets');
11370: var insttypes = new Array('$allinsttypes');
1.151 raeburn 11371: var offloadtypes = new Array('primary','default');
11372:
1.171 raeburn 11373: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
11374: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 11375:
1.151 raeburn 11376: for (var i=0; i<offloadtypes.length; i++) {
11377: var count = 0;
11378: for (var j=0; j<alltargets.length; j++) {
11379: if (alltargets[j] != balancer) {
1.171 raeburn 11380: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
11381: item.value = alltargets[j];
11382: item.style.textAlign='left';
11383: item.style.textFace='normal';
11384: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
11385: if (currBalancers.indexOf(alltargets[j]) == -1) {
11386: item.disabled = '';
11387: } else {
11388: item.disabled = 'disabled';
11389: item.checked = false;
11390: }
1.151 raeburn 11391: count ++;
11392: }
1.150 raeburn 11393: }
11394: }
1.151 raeburn 11395: for (var k=0; k<insttypes.length; k++) {
11396: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 11397: if (ishomedom == 1) {
1.171 raeburn 11398: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11399: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11400: } else {
1.171 raeburn 11401: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11402: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 11403: }
11404: } else {
1.171 raeburn 11405: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
11406: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 11407: }
1.151 raeburn 11408: if ((insttypes[k] != '_LC_external') &&
11409: ((insttypes[k] != '_LC_internetdom') ||
11410: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 11411: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
11412: item.options.length = 0;
11413: item.options[0] = new Option("","",true,true);
1.210 raeburn 11414: var idx = 0;
1.151 raeburn 11415: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 11416: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
11417: idx ++;
11418: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 11419: }
11420: }
11421: }
11422: }
11423: return;
11424: }
11425:
1.171 raeburn 11426: function hideSpares(balnum) {
1.150 raeburn 11427: var alltargets = new Array('$alltargets');
11428: var insttypes = new Array('$allinsttypes');
11429: var offloadtypes = new Array('primary','default');
11430:
1.171 raeburn 11431: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
11432: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 11433:
11434: var total = alltargets.length - 1;
11435: for (var i=0; i<offloadtypes; i++) {
11436: for (var j=0; j<total; j++) {
1.171 raeburn 11437: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
11438: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
11439: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 11440: }
1.150 raeburn 11441: }
11442: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 11443: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
11444: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 11445: if (insttypes[k] != '_LC_external') {
1.171 raeburn 11446: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
11447: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 11448: }
11449: }
11450: return;
11451: }
11452:
1.171 raeburn 11453: function checkOffloads(item,balnum,type) {
1.150 raeburn 11454: var alltargets = new Array('$alltargets');
11455: var offloadtypes = new Array('primary','default');
11456: if (item.checked) {
11457: var total = alltargets.length - 1;
11458: var other;
11459: if (type == offloadtypes[0]) {
1.151 raeburn 11460: other = offloadtypes[1];
1.150 raeburn 11461: } else {
1.151 raeburn 11462: other = offloadtypes[0];
1.150 raeburn 11463: }
11464: for (var i=0; i<total; i++) {
1.171 raeburn 11465: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 11466: if (server == item.value) {
1.171 raeburn 11467: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
11468: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 11469: }
11470: }
11471: }
11472: }
11473: return;
11474: }
11475:
1.171 raeburn 11476: function singleServerToggle(balnum,type) {
11477: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 11478: if (offloadtoSelIdx == 0) {
1.171 raeburn 11479: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
11480: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11481:
11482: } else {
1.171 raeburn 11483: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
11484: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 11485: }
11486: return;
11487: }
11488:
1.171 raeburn 11489: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 11490: if (type == '_LC_external') {
1.171 raeburn 11491: return;
1.150 raeburn 11492: }
1.171 raeburn 11493: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 11494: for (var i=0; i<typesRules.length; i++) {
11495: if (formname.elements[typesRules[i]].checked) {
11496: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 11497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
11498: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 11499: } else {
1.171 raeburn 11500: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
11501: }
11502: }
11503: }
11504: return;
11505: }
11506:
11507: function balancerDeleteChange(balnum) {
11508: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
11509: var baltotal = document.getElementById('loadbalancing_total').value;
11510: var addtarget;
11511: var removetarget;
11512: var action = 'delete';
11513: if (document.getElementById('loadbalancing_delete_'+balnum)) {
11514: var lonhost = hostitem.value;
11515: var currIdx = currBalancers.indexOf(lonhost);
11516: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
11517: if (currIdx != -1) {
11518: currBalancers.splice(currIdx,1);
11519: }
11520: addtarget = lonhost;
11521: } else {
11522: if (currIdx == -1) {
11523: currBalancers.push(lonhost);
11524: }
11525: removetarget = lonhost;
11526: action = 'undelete';
11527: }
11528: balancerChange(balnum,baltotal,action,addtarget,removetarget);
11529: }
11530: return;
11531: }
11532:
11533: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
11534: if (baltotal > 1) {
11535: var offloadtypes = new Array('primary','default');
11536: var alltargets = new Array('$alltargets');
11537: var insttypes = new Array('$allinsttypes');
11538: for (var i=0; i<baltotal; i++) {
11539: if (i != balnum) {
11540: for (var j=0; j<offloadtypes.length; j++) {
11541: var total = alltargets.length - 1;
11542: for (var k=0; k<total; k++) {
11543: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
11544: var server = serveritem.value;
11545: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11546: if (server == addtarget) {
11547: serveritem.disabled = '';
11548: }
11549: }
11550: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11551: if (server == removetarget) {
11552: serveritem.disabled = 'disabled';
11553: serveritem.checked = false;
11554: }
11555: }
11556: }
11557: }
11558: for (var j=0; j<insttypes.length; j++) {
11559: if (insttypes[j] != '_LC_external') {
11560: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
11561: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
11562: var currSel = singleserver.selectedIndex;
11563: var currVal = singleserver.options[currSel].value;
11564: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
11565: var numoptions = singleserver.options.length;
11566: var needsnew = 1;
11567: for (var k=0; k<numoptions; k++) {
11568: if (singleserver.options[k] == addtarget) {
11569: needsnew = 0;
11570: break;
11571: }
11572: }
11573: if (needsnew == 1) {
11574: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
11575: }
11576: }
11577: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
11578: singleserver.options.length = 0;
11579: if ((currVal) && (currVal != removetarget)) {
11580: singleserver.options[0] = new Option("","",false,false);
11581: } else {
11582: singleserver.options[0] = new Option("","",true,true);
11583: }
11584: var idx = 0;
11585: for (var m=0; m<alltargets.length; m++) {
11586: if (currBalancers.indexOf(alltargets[m]) == -1) {
11587: idx ++;
11588: if (currVal == alltargets[m]) {
11589: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
11590: } else {
11591: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
11592: }
11593: }
11594: }
11595: }
11596: }
11597: }
11598: }
1.150 raeburn 11599: }
11600: }
11601: }
11602: return;
11603: }
11604:
1.152 raeburn 11605: // ]]>
11606: </script>
11607:
11608: END
11609: }
11610:
11611: sub new_spares_js {
11612: my @sparestypes = ('primary','default');
11613: my $types = join("','",@sparestypes);
11614: my $select = &mt('Select');
11615: return <<"END";
11616:
11617: <script type="text/javascript">
11618: // <![CDATA[
11619:
11620: function updateNewSpares(formname,lonhost) {
11621: var types = new Array('$types');
11622: var include = new Array();
11623: var exclude = new Array();
11624: for (var i=0; i<types.length; i++) {
11625: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
11626: for (var j=0; j<spareboxes.length; j++) {
11627: if (formname.elements[spareboxes[j]].checked) {
11628: exclude.push(formname.elements[spareboxes[j]].value);
11629: } else {
11630: include.push(formname.elements[spareboxes[j]].value);
11631: }
11632: }
11633: }
11634: for (var i=0; i<types.length; i++) {
11635: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
11636: var selIdx = newSpare.selectedIndex;
11637: var currnew = newSpare.options[selIdx].value;
11638: var okSpares = new Array();
11639: for (var j=0; j<newSpare.options.length; j++) {
11640: var possible = newSpare.options[j].value;
11641: if (possible != '') {
11642: if (exclude.indexOf(possible) == -1) {
11643: okSpares.push(possible);
11644: } else {
11645: if (currnew == possible) {
11646: selIdx = 0;
11647: }
11648: }
11649: }
11650: }
11651: for (var k=0; k<include.length; k++) {
11652: if (okSpares.indexOf(include[k]) == -1) {
11653: okSpares.push(include[k]);
11654: }
11655: }
11656: okSpares.sort();
11657: newSpare.options.length = 0;
11658: if (selIdx == 0) {
11659: newSpare.options[0] = new Option("$select","",true,true);
11660: } else {
11661: newSpare.options[0] = new Option("$select","",false,false);
11662: }
11663: for (var m=0; m<okSpares.length; m++) {
11664: var idx = m+1;
11665: var selThis = 0;
11666: if (selIdx != 0) {
11667: if (okSpares[m] == currnew) {
11668: selThis = 1;
11669: }
11670: }
11671: if (selThis == 1) {
11672: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
11673: } else {
11674: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
11675: }
11676: }
11677: }
11678: return;
11679: }
11680:
11681: function checkNewSpares(lonhost,type) {
11682: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
11683: var chosen = newSpare.options[newSpare.selectedIndex].value;
11684: if (chosen != '') {
11685: var othertype;
11686: var othernewSpare;
11687: if (type == 'primary') {
11688: othernewSpare = document.getElementById('newspare_default_'+lonhost);
11689: }
11690: if (type == 'default') {
11691: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
11692: }
11693: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
11694: othernewSpare.selectedIndex = 0;
11695: }
11696: }
11697: return;
11698: }
11699:
11700: // ]]>
11701: </script>
11702:
11703: END
11704:
11705: }
11706:
11707: sub common_domprefs_js {
11708: return <<"END";
11709:
11710: <script type="text/javascript">
11711: // <![CDATA[
11712:
1.150 raeburn 11713: function getIndicesByName(formname,item) {
1.152 raeburn 11714: var group = new Array();
1.150 raeburn 11715: for (var i=0;i<formname.elements.length;i++) {
11716: if (formname.elements[i].name == item) {
1.152 raeburn 11717: group.push(formname.elements[i].id);
1.150 raeburn 11718: }
11719: }
1.152 raeburn 11720: return group;
1.150 raeburn 11721: }
11722:
11723: // ]]>
11724: </script>
11725:
11726: END
1.152 raeburn 11727:
1.150 raeburn 11728: }
11729:
1.165 raeburn 11730: sub recaptcha_js {
11731: my %lt = &captcha_phrases();
11732: return <<"END";
11733:
11734: <script type="text/javascript">
11735: // <![CDATA[
11736:
11737: function updateCaptcha(caller,context) {
11738: var privitem;
11739: var pubitem;
11740: var privtext;
11741: var pubtext;
11742: if (document.getElementById(context+'_recaptchapub')) {
11743: pubitem = document.getElementById(context+'_recaptchapub');
11744: } else {
11745: return;
11746: }
11747: if (document.getElementById(context+'_recaptchapriv')) {
11748: privitem = document.getElementById(context+'_recaptchapriv');
11749: } else {
11750: return;
11751: }
11752: if (document.getElementById(context+'_recaptchapubtxt')) {
11753: pubtext = document.getElementById(context+'_recaptchapubtxt');
11754: } else {
11755: return;
11756: }
11757: if (document.getElementById(context+'_recaptchaprivtxt')) {
11758: privtext = document.getElementById(context+'_recaptchaprivtxt');
11759: } else {
11760: return;
11761: }
11762: if (caller.checked) {
11763: if (caller.value == 'recaptcha') {
11764: pubitem.type = 'text';
11765: privitem.type = 'text';
11766: pubitem.size = '40';
11767: privitem.size = '40';
11768: pubtext.innerHTML = "$lt{'pub'}";
11769: privtext.innerHTML = "$lt{'priv'}";
11770: } else {
11771: pubitem.type = 'hidden';
11772: privitem.type = 'hidden';
11773: pubtext.innerHTML = '';
11774: privtext.innerHTML = '';
11775: }
11776: }
11777: return;
11778: }
11779:
11780: // ]]>
11781: </script>
11782:
11783: END
11784:
11785: }
11786:
1.236 raeburn 11787: sub toggle_display_js {
1.192 raeburn 11788: return <<"END";
11789:
11790: <script type="text/javascript">
11791: // <![CDATA[
11792:
1.236 raeburn 11793: function toggleDisplay(domForm,caller) {
11794: if (document.getElementById(caller)) {
11795: var divitem = document.getElementById(caller);
11796: var optionsElement = domForm.coursecredits;
11797: if (caller == 'emailoptions') {
11798: optionsElement = domForm.cancreate_email;
11799: }
11800: if (optionsElement.length) {
1.192 raeburn 11801: var currval;
1.236 raeburn 11802: for (var i=0; i<optionsElement.length; i++) {
11803: if (optionsElement[i].checked) {
11804: currval = optionsElement[i].value;
1.192 raeburn 11805: }
11806: }
11807: if (currval == 1) {
1.236 raeburn 11808: divitem.style.display = 'block';
1.192 raeburn 11809: } else {
1.236 raeburn 11810: divitem.style.display = 'none';
1.192 raeburn 11811: }
11812: }
11813: }
11814: return;
11815: }
11816:
11817: // ]]>
11818: </script>
11819:
11820: END
11821:
11822: }
11823:
1.165 raeburn 11824: sub captcha_phrases {
11825: return &Apache::lonlocal::texthash (
11826: priv => 'Private key',
11827: pub => 'Public key',
11828: original => 'original (CAPTCHA)',
11829: recaptcha => 'successor (ReCAPTCHA)',
11830: notused => 'unused',
11831: );
11832: }
11833:
1.205 raeburn 11834: sub devalidate_remote_domconfs {
1.212 raeburn 11835: my ($dom,$cachekeys) = @_;
11836: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 11837: my %servers = &Apache::lonnet::internet_dom_servers($dom);
11838: my %thismachine;
11839: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 raeburn 11840: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 11841: if (keys(%servers) > 1) {
11842: foreach my $server (keys(%servers)) {
11843: next if ($thismachine{$server});
1.212 raeburn 11844: my @cached;
11845: foreach my $name (@posscached) {
11846: if ($cachekeys->{$name}) {
11847: push(@cached,&escape($name).':'.&escape($dom));
11848: }
11849: }
11850: if (@cached) {
11851: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
11852: }
1.205 raeburn 11853: }
11854: }
11855: return;
11856: }
11857:
1.3 raeburn 11858: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>