Annotation of loncom/interface/domainprefs.pm, revision 1.271
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.271 ! raeburn 4: # $Id: domainprefs.pm,v 1.270 2016/02/19 20:28:46 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.271 ! raeburn 106: (official, unofficial, community, textbook, and placement).
! 107: In each case the radio buttons 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.267 raeburn 176: use Time::HiRes qw( sleep );
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
217: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 218: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 219: 'requestauthor','selfenrollment','inststatus',
220: 'ltitools'],$dom);
1.43 raeburn 221: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 222: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 223: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 224: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 225: 'serverstatuses','helpsettings','coursedefaults',
226: 'ltitools','selfenrollment','usersessions');
1.171 raeburn 227: my %existing;
228: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
229: %existing = %{$domconfig{'loadbalancing'}};
230: }
231: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 232: push(@prefs_order,'loadbalancing');
233: }
1.30 raeburn 234: my %prefs = (
235: 'rolecolors' =>
236: { text => 'Default color schemes',
1.67 raeburn 237: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 238: header => [{col1 => 'Student Settings',
239: col2 => '',},
240: {col1 => 'Coordinator Settings',
241: col2 => '',},
242: {col1 => 'Author Settings',
243: col2 => '',},
244: {col1 => 'Administrator Settings',
245: col2 => '',}],
1.230 raeburn 246: print => \&print_rolecolors,
247: modify => \&modify_rolecolors,
1.30 raeburn 248: },
1.110 raeburn 249: 'login' =>
1.30 raeburn 250: { text => 'Log-in page options',
1.67 raeburn 251: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 252: header => [{col1 => 'Log-in Page Items',
253: col2 => '',},
254: {col1 => 'Log-in Help',
1.256 raeburn 255: col2 => 'Value'},
256: {col1 => 'Custom HTML in document head',
1.168 raeburn 257: col2 => 'Value'}],
1.230 raeburn 258: print => \&print_login,
259: modify => \&modify_login,
1.30 raeburn 260: },
1.43 raeburn 261: 'defaults' =>
1.236 raeburn 262: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 263: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 264: header => [{col1 => 'Setting',
1.236 raeburn 265: col2 => 'Value'},
266: {col1 => 'Institutional user types',
267: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 268: print => \&print_defaults,
269: modify => \&modify_defaults,
1.43 raeburn 270: },
1.30 raeburn 271: 'quotas' =>
1.197 raeburn 272: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 273: help => 'Domain_Configuration_Quotas',
1.77 raeburn 274: header => [{col1 => 'User affiliation',
1.72 raeburn 275: col2 => 'Available tools',
1.213 raeburn 276: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 277: print => \&print_quotas,
278: modify => \&modify_quotas,
1.30 raeburn 279: },
280: 'autoenroll' =>
281: { text => 'Auto-enrollment settings',
1.67 raeburn 282: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 283: header => [{col1 => 'Configuration setting',
284: col2 => 'Value(s)'}],
1.230 raeburn 285: print => \&print_autoenroll,
286: modify => \&modify_autoenroll,
1.30 raeburn 287: },
288: 'autoupdate' =>
289: { text => 'Auto-update settings',
1.67 raeburn 290: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 291: header => [{col1 => 'Setting',
292: col2 => 'Value',},
1.131 raeburn 293: {col1 => 'Setting',
294: col2 => 'Affiliation'},
1.43 raeburn 295: {col1 => 'User population',
1.227 bisitz 296: col2 => 'Updatable user data'}],
1.230 raeburn 297: print => \&print_autoupdate,
298: modify => \&modify_autoupdate,
1.30 raeburn 299: },
1.125 raeburn 300: 'autocreate' =>
301: { text => 'Auto-course creation settings',
302: help => 'Domain_Configuration_Auto_Creation',
303: header => [{col1 => 'Configuration Setting',
304: col2 => 'Value',}],
1.230 raeburn 305: print => \&print_autocreate,
306: modify => \&modify_autocreate,
1.125 raeburn 307: },
1.30 raeburn 308: 'directorysrch' =>
309: { text => 'Institutional directory searches',
1.67 raeburn 310: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 311: header => [{col1 => 'Setting',
312: col2 => 'Value',}],
1.230 raeburn 313: print => \&print_directorysrch,
314: modify => \&modify_directorysrch,
1.30 raeburn 315: },
316: 'contacts' =>
317: { text => 'Contact Information',
1.67 raeburn 318: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 319: header => [{col1 => 'Setting',
320: col2 => 'Value',}],
1.230 raeburn 321: print => \&print_contacts,
322: modify => \&modify_contacts,
1.30 raeburn 323: },
324: 'usercreation' =>
325: { text => 'User creation',
1.67 raeburn 326: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 327: header => [{col1 => 'Format rule type',
328: col2 => 'Format rules in force'},
1.34 raeburn 329: {col1 => 'User account creation',
330: col2 => 'Usernames which may be created',},
1.30 raeburn 331: {col1 => 'Context',
1.43 raeburn 332: col2 => 'Assignable authentication types'}],
1.230 raeburn 333: print => \&print_usercreation,
334: modify => \&modify_usercreation,
1.30 raeburn 335: },
1.224 raeburn 336: 'selfcreation' =>
337: { text => 'Users self-creating accounts',
338: help => 'Domain_Configuration_Self_Creation',
339: header => [{col1 => 'Self-creation with institutional username',
340: col2 => 'Enabled?'},
341: {col1 => 'Institutional user type (login/SSO self-creation)',
342: col2 => 'Information user can enter'},
343: {col1 => 'Self-creation with e-mail as username',
344: col2 => 'Settings'}],
1.230 raeburn 345: print => \&print_selfcreation,
346: modify => \&modify_selfcreation,
1.224 raeburn 347: },
1.69 raeburn 348: 'usermodification' =>
1.33 raeburn 349: { text => 'User modification',
1.67 raeburn 350: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 351: header => [{col1 => 'Target user has role',
1.227 bisitz 352: col2 => 'User information updatable in author context'},
1.33 raeburn 353: {col1 => 'Target user has role',
1.227 bisitz 354: col2 => 'User information updatable in course context'}],
1.230 raeburn 355: print => \&print_usermodification,
356: modify => \&modify_usermodification,
1.33 raeburn 357: },
1.69 raeburn 358: 'scantron' =>
1.95 www 359: { text => 'Bubblesheet format file',
1.67 raeburn 360: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 361: header => [ {col1 => 'Item',
362: col2 => '',
363: }],
1.230 raeburn 364: print => \&print_scantron,
365: modify => \&modify_scantron,
1.46 raeburn 366: },
1.86 raeburn 367: 'requestcourses' =>
368: {text => 'Request creation of courses',
369: help => 'Domain_Configuration_Request_Courses',
370: header => [{col1 => 'User affiliation',
1.102 raeburn 371: col2 => 'Availability/Processing of requests',},
372: {col1 => 'Setting',
1.216 raeburn 373: col2 => 'Value'},
374: {col1 => 'Available textbooks',
1.235 raeburn 375: col2 => ''},
1.242 raeburn 376: {col1 => 'Available templates',
377: col2 => ''},
1.235 raeburn 378: {col1 => 'Validation (not official courses)',
379: col2 => 'Value'},],
1.230 raeburn 380: print => \&print_quotas,
381: modify => \&modify_quotas,
1.86 raeburn 382: },
1.163 raeburn 383: 'requestauthor' =>
1.223 bisitz 384: {text => 'Request Authoring Space',
1.163 raeburn 385: help => 'Domain_Configuration_Request_Author',
386: header => [{col1 => 'User affiliation',
387: col2 => 'Availability/Processing of requests',},
388: {col1 => 'Setting',
389: col2 => 'Value'}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.163 raeburn 392: },
1.69 raeburn 393: 'coursecategories' =>
1.120 raeburn 394: { text => 'Cataloging of courses/communities',
1.67 raeburn 395: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 396: header => [{col1 => 'Catalog type/availability',
397: col2 => '',},
398: {col1 => 'Category settings for standard catalog',
1.57 raeburn 399: col2 => '',},
400: {col1 => 'Categories',
401: col2 => '',
402: }],
1.230 raeburn 403: print => \&print_coursecategories,
404: modify => \&modify_coursecategories,
1.69 raeburn 405: },
406: 'serverstatuses' =>
1.77 raeburn 407: {text => 'Access to server status pages',
1.69 raeburn 408: help => 'Domain_Configuration_Server_Status',
409: header => [{col1 => 'Status Page',
410: col2 => 'Other named users',
411: col3 => 'Specific IPs',
412: }],
1.230 raeburn 413: print => \&print_serverstatuses,
414: modify => \&modify_serverstatuses,
1.69 raeburn 415: },
1.118 jms 416: 'helpsettings' =>
417: {text => 'Help page settings',
418: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 419: header => [{col1 => 'Help Settings (logged-in users)',
420: col2 => 'Value'}],
1.230 raeburn 421: print => \&print_helpsettings,
422: modify => \&modify_helpsettings,
1.118 jms 423: },
1.121 raeburn 424: 'coursedefaults' =>
425: {text => 'Course/Community defaults',
426: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 427: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
428: col2 => 'Value',},
429: {col1 => 'Defaults which can be overridden for each course by a DC',
430: col2 => 'Value',},],
1.230 raeburn 431: print => \&print_coursedefaults,
432: modify => \&modify_coursedefaults,
1.121 raeburn 433: },
1.231 raeburn 434: 'selfenrollment' =>
435: {text => 'Self-enrollment in Course/Community',
436: help => 'Domain_Configuration_Selfenrollment',
437: header => [{col1 => 'Configuration Rights',
438: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
439: {col1 => 'Defaults',
440: col2 => 'Value'},
441: {col1 => 'Self-enrollment validation (optional)',
442: col2 => 'Value'},],
443: print => \&print_selfenrollment,
444: modify => \&modify_selfenrollment,
445: },
1.120 raeburn 446: 'privacy' =>
447: {text => 'User Privacy',
448: help => 'Domain_Configuration_User_Privacy',
449: header => [{col1 => 'Setting',
450: col2 => 'Value',}],
1.230 raeburn 451: print => \&print_privacy,
452: modify => \&modify_privacy,
1.120 raeburn 453: },
1.141 raeburn 454: 'usersessions' =>
1.145 raeburn 455: {text => 'User session hosting/offloading',
1.137 raeburn 456: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 457: header => [{col1 => 'Domain server',
458: col2 => 'Servers to offload sessions to when busy'},
459: {col1 => 'Hosting of users from other domains',
1.137 raeburn 460: col2 => 'Rules'},
461: {col1 => "Hosting domain's own users elsewhere",
462: col2 => 'Rules'}],
1.230 raeburn 463: print => \&print_usersessions,
464: modify => \&modify_usersessions,
1.137 raeburn 465: },
1.150 raeburn 466: 'loadbalancing' =>
1.185 raeburn 467: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 468: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 469: header => [{col1 => 'Balancers',
1.150 raeburn 470: col2 => 'Default destinations',
1.183 bisitz 471: col3 => 'User affiliation',
1.150 raeburn 472: col4 => 'Overrides'},
473: ],
1.230 raeburn 474: print => \&print_loadbalancing,
475: modify => \&modify_loadbalancing,
1.150 raeburn 476: },
1.267 raeburn 477: 'ltitools' =>
478: {text => 'External Tools (LTI)',
479: help => 'Domain_configuration_LTI_Tools',
480: header => [{col1 => 'Setting',
481: col2 => 'Value',}],
482: print => \&print_ltitools,
483: modify => \&modify_ltitools,
484: },
485:
1.3 raeburn 486: );
1.110 raeburn 487: if (keys(%servers) > 1) {
488: $prefs{'login'} = { text => 'Log-in page options',
489: help => 'Domain_Configuration_Login_Page',
490: header => [{col1 => 'Log-in Service',
491: col2 => 'Server Setting',},
492: {col1 => 'Log-in Page Items',
1.168 raeburn 493: col2 => ''},
494: {col1 => 'Log-in Help',
1.256 raeburn 495: col2 => 'Value'},
496: {col1 => 'Custom HTML in document head',
1.168 raeburn 497: col2 => 'Value'}],
1.230 raeburn 498: print => \&print_login,
499: modify => \&modify_login,
1.110 raeburn 500: };
501: }
1.174 foxr 502:
1.6 raeburn 503: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 504: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 505: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 506: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 507: text=>"Settings to display/modify"});
1.9 raeburn 508: my $confname = $dom.'-domainconfig';
1.174 foxr 509:
1.3 raeburn 510: if ($phase eq 'process') {
1.212 raeburn 511: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
512: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 513: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 514: $r->rflush();
1.212 raeburn 515: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 516: }
1.30 raeburn 517: } elsif ($phase eq 'display') {
1.192 raeburn 518: my $js = &recaptcha_js().
1.236 raeburn 519: &toggle_display_js();
1.171 raeburn 520: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 521: my ($othertitle,$usertypes,$types) =
522: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 523: $js .= &lonbalance_targets_js($dom,$types,\%servers,
524: $domconfig{'loadbalancing'}).
1.170 raeburn 525: &new_spares_js().
526: &common_domprefs_js().
527: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 528: }
1.216 raeburn 529: if (grep(/^requestcourses$/,@actions)) {
530: my $javascript_validations;
531: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
532: $js .= <<END;
533: <script type="text/javascript">
534: $javascript_validations
535: </script>
536: $coursebrowserjs
537: END
538: }
1.150 raeburn 539: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 540: } else {
1.180 raeburn 541: # check if domconfig user exists for the domain.
542: my $servadm = $r->dir_config('lonAdmEMail');
543: my ($configuserok,$author_ok,$switchserver) =
544: &config_check($dom,$confname,$servadm);
545: unless ($configuserok eq 'ok') {
1.181 raeburn 546: &Apache::lonconfigsettings::print_header($r,$phase,$context);
547: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 548: $confname).
1.181 raeburn 549: '<br />'
550: );
1.180 raeburn 551: if ($switchserver) {
1.181 raeburn 552: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
553: '<br />'.
554: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
555: '<br />'.
556: &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).
557: '<br />'.
558: &mt('To do that now, use the following link: [_1]',$switchserver)
559: );
560: } else {
561: $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.').
562: '<br />'.
563: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
564: );
1.180 raeburn 565: }
566: $r->print(&Apache::loncommon::end_page());
567: return OK;
568: }
1.21 raeburn 569: if (keys(%domconfig) == 0) {
570: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 571: my @ids=&Apache::lonnet::current_machine_ids();
572: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 573: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 574: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 575: my $custom_img_count = 0;
576: foreach my $img (@loginimages) {
577: if ($designhash{$dom.'.login.'.$img} ne '') {
578: $custom_img_count ++;
579: }
580: }
581: foreach my $role (@roles) {
582: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
583: $custom_img_count ++;
584: }
585: }
586: if ($custom_img_count > 0) {
1.94 raeburn 587: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 588: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 589: $r->print(
590: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
591: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
592: &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 />'.
593: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
594: if ($switch_server) {
1.30 raeburn 595: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 596: }
1.91 raeburn 597: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 598: return OK;
599: }
600: }
601: }
1.91 raeburn 602: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 603: }
604: return OK;
605: }
606:
607: sub process_changes {
1.205 raeburn 608: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 609: my %domconfig;
610: if (ref($values) eq 'HASH') {
611: %domconfig = %{$values};
612: }
1.3 raeburn 613: my $output;
614: if ($action eq 'login') {
1.205 raeburn 615: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 616: } elsif ($action eq 'rolecolors') {
1.9 raeburn 617: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 618: $lastactref,%domconfig);
1.3 raeburn 619: } elsif ($action eq 'quotas') {
1.216 raeburn 620: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 621: } elsif ($action eq 'autoenroll') {
1.205 raeburn 622: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 623: } elsif ($action eq 'autoupdate') {
624: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 625: } elsif ($action eq 'autocreate') {
626: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 627: } elsif ($action eq 'directorysrch') {
628: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 629: } elsif ($action eq 'usercreation') {
1.28 raeburn 630: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 631: } elsif ($action eq 'selfcreation') {
632: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 633: } elsif ($action eq 'usermodification') {
634: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 635: } elsif ($action eq 'contacts') {
1.205 raeburn 636: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 637: } elsif ($action eq 'defaults') {
1.212 raeburn 638: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 639: } elsif ($action eq 'scantron') {
1.205 raeburn 640: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 641: } elsif ($action eq 'coursecategories') {
1.239 raeburn 642: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 643: } elsif ($action eq 'serverstatuses') {
644: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 645: } elsif ($action eq 'requestcourses') {
1.216 raeburn 646: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 647: } elsif ($action eq 'requestauthor') {
1.216 raeburn 648: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 649: } elsif ($action eq 'helpsettings') {
1.122 jms 650: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 651: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 652: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 653: } elsif ($action eq 'selfenrollment') {
654: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 655: } elsif ($action eq 'usersessions') {
1.212 raeburn 656: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 657: } elsif ($action eq 'loadbalancing') {
658: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 659: } elsif ($action eq 'ltitools') {
660: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 661: }
662: return $output;
663: }
664:
665: sub print_config_box {
1.9 raeburn 666: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 667: my $rowtotal = 0;
1.49 raeburn 668: my $output;
669: if ($action eq 'coursecategories') {
670: $output = &coursecategories_javascript($settings);
1.236 raeburn 671: } elsif ($action eq 'defaults') {
672: $output = &defaults_javascript($settings);
1.91 raeburn 673: }
1.236 raeburn 674: $output .=
1.30 raeburn 675: '<table class="LC_nested_outer">
1.3 raeburn 676: <tr>
1.66 raeburn 677: <th align="left" valign="middle"><span class="LC_nobreak">'.
678: &mt($item->{text}).' '.
679: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
680: '</tr>';
1.30 raeburn 681: $rowtotal ++;
1.110 raeburn 682: my $numheaders = 1;
683: if (ref($item->{'header'}) eq 'ARRAY') {
684: $numheaders = scalar(@{$item->{'header'}});
685: }
686: if ($numheaders > 1) {
1.64 raeburn 687: my $colspan = '';
1.145 raeburn 688: my $rightcolspan = '';
1.238 raeburn 689: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.256 raeburn 690: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 691: $colspan = ' colspan="2"';
692: }
1.145 raeburn 693: if ($action eq 'usersessions') {
694: $rightcolspan = ' colspan="3"';
695: }
1.30 raeburn 696: $output .= '
1.3 raeburn 697: <tr>
698: <td>
699: <table class="LC_nested">
700: <tr class="LC_info_row">
1.59 bisitz 701: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 702: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 703: </tr>';
1.69 raeburn 704: $rowtotal ++;
1.230 raeburn 705: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 706: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230 raeburn 707: ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
708: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 709: } elsif ($action eq 'coursecategories') {
1.230 raeburn 710: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 711: } elsif ($action eq 'login') {
1.256 raeburn 712: if ($numheaders == 4) {
1.168 raeburn 713: $colspan = ' colspan="2"';
714: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
715: } else {
716: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
717: }
1.230 raeburn 718: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 719: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 720: } elsif ($action eq 'rolecolors') {
1.30 raeburn 721: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 722: }
1.30 raeburn 723: $output .= '
1.6 raeburn 724: </table>
725: </td>
726: </tr>
727: <tr>
728: <td>
729: <table class="LC_nested">
730: <tr class="LC_info_row">
1.230 raeburn 731: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 732: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 733: </tr>';
734: $rowtotal ++;
1.230 raeburn 735: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
736: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238 raeburn 737: ($action eq 'usersessions') || ($action eq 'coursecategories')) {
738: if ($action eq 'coursecategories') {
739: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
740: $colspan = ' colspan="2"';
741: } else {
742: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
743: }
744: $output .= '
1.63 raeburn 745: </table>
746: </td>
747: </tr>
748: <tr>
749: <td>
750: <table class="LC_nested">
751: <tr class="LC_info_row">
752: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 753: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 754: </tr>'."\n";
755: if ($action eq 'coursecategories') {
756: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
757: } else {
758: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
759: }
1.63 raeburn 760: $rowtotal ++;
1.236 raeburn 761: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
762: ($action eq 'defaults')) {
1.230 raeburn 763: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 764: } elsif ($action eq 'login') {
1.256 raeburn 765: if ($numheaders == 4) {
1.168 raeburn 766: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
767: </table>
768: </td>
769: </tr>
770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
774: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 775: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 776: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
777: $rowtotal ++;
778: } else {
779: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
780: }
1.256 raeburn 781: $output .= '
782: </table>
783: </td>
784: </tr>
785: <tr>
786: <td>
787: <table class="LC_nested">
788: <tr class="LC_info_row">';
789: if ($numheaders == 4) {
790: $output .= '
791: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
792: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
793: </tr>';
794: } else {
795: $output .= '
796: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
797: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
798: </tr>';
799: }
800: $rowtotal ++;
801: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 802: } elsif ($action eq 'requestcourses') {
1.247 raeburn 803: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
804: $rowtotal ++;
805: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 806: </table>
807: </td>
808: </tr>
809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">
813: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
814: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 815: &textbookcourses_javascript($settings).
816: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
817: </table>
818: </td>
819: </tr>
820: <tr>
821: <td>
822: <table class="LC_nested">
823: <tr class="LC_info_row">
824: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
825: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
826: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 827: </table>
828: </td>
829: </tr>
830: <tr>
831: <td>
832: <table class="LC_nested">
833: <tr class="LC_info_row">
1.242 raeburn 834: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
835: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 836: </tr>'.
837: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 838: } elsif ($action eq 'requestauthor') {
839: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 840: $rowtotal ++;
1.122 jms 841: } elsif ($action eq 'rolecolors') {
1.30 raeburn 842: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
1.69 raeburn 850: <td class="LC_left_item"'.$colspan.' valign="top">'.
851: &mt($item->{'header'}->[2]->{'col1'}).'</td>
852: <td class="LC_right_item" valign="top">'.
853: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 854: </tr>'.
1.30 raeburn 855: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 856: </table>
857: </td>
858: </tr>
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
1.59 bisitz 863: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
864: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 865: </tr>'.
1.30 raeburn 866: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
867: $rowtotal += 2;
1.6 raeburn 868: }
1.3 raeburn 869: } else {
1.30 raeburn 870: $output .= '
1.3 raeburn 871: <tr>
872: <td>
873: <table class="LC_nested">
1.30 raeburn 874: <tr class="LC_info_row">';
1.24 raeburn 875: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 876: $output .= '
1.59 bisitz 877: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 878: } elsif ($action eq 'serverstatuses') {
879: $output .= '
880: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
881: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
882:
1.6 raeburn 883: } else {
1.30 raeburn 884: $output .= '
1.69 raeburn 885: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
886: }
1.72 raeburn 887: if (defined($item->{'header'}->[0]->{'col3'})) {
888: $output .= '<td class="LC_left_item" valign="top">'.
889: &mt($item->{'header'}->[0]->{'col2'});
890: if ($action eq 'serverstatuses') {
891: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
892: }
1.69 raeburn 893: } else {
894: $output .= '<td class="LC_right_item" valign="top">'.
895: &mt($item->{'header'}->[0]->{'col2'});
896: }
897: $output .= '</td>';
898: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 899: if (defined($item->{'header'}->[0]->{'col4'})) {
900: $output .= '<td class="LC_left_item" valign="top">'.
901: &mt($item->{'header'}->[0]->{'col3'});
902: } else {
903: $output .= '<td class="LC_right_item" valign="top">'.
904: &mt($item->{'header'}->[0]->{'col3'});
905: }
1.69 raeburn 906: if ($action eq 'serverstatuses') {
907: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
908: }
909: $output .= '</td>';
1.6 raeburn 910: }
1.150 raeburn 911: if ($item->{'header'}->[0]->{'col4'}) {
912: $output .= '<td class="LC_right_item" valign="top">'.
913: &mt($item->{'header'}->[0]->{'col4'});
914: }
1.69 raeburn 915: $output .= '</tr>';
1.48 raeburn 916: $rowtotal ++;
1.168 raeburn 917: if ($action eq 'quotas') {
1.86 raeburn 918: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230 raeburn 919: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.267 raeburn 920: ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
921: ($action eq 'ltitools')) {
1.230 raeburn 922: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 923: } elsif ($action eq 'scantron') {
924: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118 jms 925: } elsif ($action eq 'helpsettings') {
1.168 raeburn 926: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121 raeburn 927: }
1.3 raeburn 928: }
1.30 raeburn 929: $output .= '
1.3 raeburn 930: </table>
931: </td>
932: </tr>
1.30 raeburn 933: </table><br />';
934: return ($output,$rowtotal);
1.1 raeburn 935: }
936:
1.3 raeburn 937: sub print_login {
1.168 raeburn 938: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 939: my ($css_class,$datatable);
1.6 raeburn 940: my %choices = &login_choices();
1.110 raeburn 941:
1.168 raeburn 942: if ($caller eq 'service') {
1.149 raeburn 943: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 944: my $choice = $choices{'disallowlogin'};
945: $css_class = ' class="LC_odd_row"';
1.128 raeburn 946: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 947: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 948: '<th>'.$choices{'server'}.'</th>'.
949: '<th>'.$choices{'serverpath'}.'</th>'.
950: '<th>'.$choices{'custompath'}.'</th>'.
951: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 952: my %disallowed;
953: if (ref($settings) eq 'HASH') {
954: if (ref($settings->{'loginvia'}) eq 'HASH') {
955: %disallowed = %{$settings->{'loginvia'}};
956: }
957: }
958: foreach my $lonhost (sort(keys(%servers))) {
959: my $direct = 'selected="selected"';
1.128 raeburn 960: if (ref($disallowed{$lonhost}) eq 'HASH') {
961: if ($disallowed{$lonhost}{'server'} ne '') {
962: $direct = '';
963: }
1.110 raeburn 964: }
1.115 raeburn 965: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 966: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 967: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
968: '</option>';
1.184 raeburn 969: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 970: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 971: my $selected = '';
1.128 raeburn 972: if (ref($disallowed{$lonhost}) eq 'HASH') {
973: if ($hostid eq $disallowed{$lonhost}{'server'}) {
974: $selected = 'selected="selected"';
975: }
1.110 raeburn 976: }
977: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
978: $servers{$hostid}.'</option>';
979: }
1.128 raeburn 980: $datatable .= '</select></td>'.
981: '<td><select name="'.$lonhost.'_serverpath">';
982: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
983: my $pathname = $path;
984: if ($path eq 'custom') {
985: $pathname = &mt('Custom Path').' ->';
986: }
987: my $selected = '';
988: if (ref($disallowed{$lonhost}) eq 'HASH') {
989: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
990: $selected = 'selected="selected"';
991: }
992: } elsif ($path eq '') {
993: $selected = 'selected="selected"';
994: }
995: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
996: }
997: $datatable .= '</select></td>';
998: my ($custom,$exempt);
999: if (ref($disallowed{$lonhost}) eq 'HASH') {
1000: $custom = $disallowed{$lonhost}{'custompath'};
1001: $exempt = $disallowed{$lonhost}{'exempt'};
1002: }
1003: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1004: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1005: '</tr>';
1.110 raeburn 1006: }
1007: $datatable .= '</table></td></tr>';
1008: return $datatable;
1.168 raeburn 1009: } elsif ($caller eq 'page') {
1010: my %defaultchecked = (
1011: 'coursecatalog' => 'on',
1.188 raeburn 1012: 'helpdesk' => 'on',
1.168 raeburn 1013: 'adminmail' => 'off',
1014: 'newuser' => 'off',
1015: );
1.188 raeburn 1016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1017: my (%checkedon,%checkedoff);
1.42 raeburn 1018: foreach my $item (@toggles) {
1.168 raeburn 1019: if ($defaultchecked{$item} eq 'on') {
1020: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1021: $checkedoff{$item} = ' ';
1.168 raeburn 1022: } elsif ($defaultchecked{$item} eq 'off') {
1023: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1024: $checkedon{$item} = ' ';
1025: }
1.1 raeburn 1026: }
1.168 raeburn 1027: my @images = ('img','logo','domlogo','login');
1028: my @logintext = ('textcol','bgcol');
1029: my @bgs = ('pgbg','mainbg','sidebg');
1030: my @links = ('link','alink','vlink');
1031: my %designhash = &Apache::loncommon::get_domainconf($dom);
1032: my %defaultdesign = %Apache::loncommon::defaultdesign;
1033: my (%is_custom,%designs);
1034: my %defaults = (
1035: font => $defaultdesign{'login.font'},
1036: );
1.6 raeburn 1037: foreach my $item (@images) {
1.168 raeburn 1038: $defaults{$item} = $defaultdesign{'login.'.$item};
1039: $defaults{'showlogo'}{$item} = 1;
1040: }
1041: foreach my $item (@bgs) {
1042: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1043: }
1.41 raeburn 1044: foreach my $item (@logintext) {
1.168 raeburn 1045: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1046: }
1.168 raeburn 1047: foreach my $item (@links) {
1048: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1049: }
1.168 raeburn 1050: if (ref($settings) eq 'HASH') {
1051: foreach my $item (@toggles) {
1052: if ($settings->{$item} eq '1') {
1053: $checkedon{$item} = ' checked="checked" ';
1054: $checkedoff{$item} = ' ';
1055: } elsif ($settings->{$item} eq '0') {
1056: $checkedoff{$item} = ' checked="checked" ';
1057: $checkedon{$item} = ' ';
1058: }
1059: }
1060: foreach my $item (@images) {
1061: if (defined($settings->{$item})) {
1062: $designs{$item} = $settings->{$item};
1063: $is_custom{$item} = 1;
1064: }
1065: if (defined($settings->{'showlogo'}{$item})) {
1066: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1067: }
1068: }
1069: foreach my $item (@logintext) {
1070: if ($settings->{$item} ne '') {
1071: $designs{'logintext'}{$item} = $settings->{$item};
1072: $is_custom{$item} = 1;
1073: }
1074: }
1075: if ($settings->{'font'} ne '') {
1076: $designs{'font'} = $settings->{'font'};
1077: $is_custom{'font'} = 1;
1078: }
1079: foreach my $item (@bgs) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'bgs'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: foreach my $item (@links) {
1086: if ($settings->{$item} ne '') {
1087: $designs{'links'}{$item} = $settings->{$item};
1088: $is_custom{$item} = 1;
1089: }
1090: }
1091: } else {
1092: if ($designhash{$dom.'.login.font'} ne '') {
1093: $designs{'font'} = $designhash{$dom.'.login.font'};
1094: $is_custom{'font'} = 1;
1095: }
1096: foreach my $item (@images) {
1097: if ($designhash{$dom.'.login.'.$item} ne '') {
1098: $designs{$item} = $designhash{$dom.'.login.'.$item};
1099: $is_custom{$item} = 1;
1100: }
1101: }
1102: foreach my $item (@bgs) {
1103: if ($designhash{$dom.'.login.'.$item} ne '') {
1104: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1105: $is_custom{$item} = 1;
1106: }
1.6 raeburn 1107: }
1.168 raeburn 1108: foreach my $item (@links) {
1109: if ($designhash{$dom.'.login.'.$item} ne '') {
1110: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1111: $is_custom{$item} = 1;
1112: }
1.6 raeburn 1113: }
1114: }
1.168 raeburn 1115: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1116: logo => 'Institution Logo',
1117: domlogo => 'Domain Logo',
1118: login => 'Login box');
1119: my $itemcount = 1;
1120: foreach my $item (@toggles) {
1121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1122: $datatable .=
1123: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1124: '</td><td>'.
1125: '<span class="LC_nobreak"><label><input type="radio" name="'.
1126: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1127: '</label> <label><input type="radio" name="'.$item.'"'.
1128: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1129: '</tr>';
1130: $itemcount ++;
1.6 raeburn 1131: }
1.168 raeburn 1132: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1133: $datatable .= '</tr></table></td></tr>';
1134: } elsif ($caller eq 'help') {
1135: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1136: my $switchserver = &check_switchserver($dom,$confname);
1137: my $itemcount = 1;
1138: $defaulturl = '/adm/loginproblems.html';
1139: $defaulttype = 'default';
1140: %lt = &Apache::lonlocal::texthash (
1141: del => 'Delete?',
1142: rep => 'Replace:',
1143: upl => 'Upload:',
1144: default => 'Default',
1145: custom => 'Custom',
1146: );
1147: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1148: my @currlangs;
1149: if (ref($settings) eq 'HASH') {
1150: if (ref($settings->{'helpurl'}) eq 'HASH') {
1151: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1152: next if ($settings->{'helpurl'}{$key} eq '');
1153: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1154: $type{$key} = 'custom';
1155: unless ($key eq 'nolang') {
1156: push(@currlangs,$key);
1157: }
1158: }
1159: } elsif ($settings->{'helpurl'} ne '') {
1160: $type{'nolang'} = 'custom';
1161: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1162: }
1163: }
1.168 raeburn 1164: foreach my $lang ('nolang',sort(@currlangs)) {
1165: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1166: $datatable .= '<tr'.$css_class.'>';
1167: if ($url{$lang} eq '') {
1168: $url{$lang} = $defaulturl;
1169: }
1170: if ($type{$lang} eq '') {
1171: $type{$lang} = $defaulttype;
1172: }
1173: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1174: if ($lang eq 'nolang') {
1175: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1176: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1177: } else {
1178: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1179: $langchoices{$lang},
1180: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1181: }
1182: $datatable .= '</span></td>'."\n".
1183: '<td class="LC_left_item">';
1184: if ($type{$lang} eq 'custom') {
1185: $datatable .= '<span class="LC_nobreak"><label>'.
1186: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1187: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1188: } else {
1189: $datatable .= $lt{'upl'};
1190: }
1191: $datatable .='<br />';
1192: if ($switchserver) {
1193: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1194: } else {
1195: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1196: }
1.168 raeburn 1197: $datatable .= '</td></tr>';
1198: $itemcount ++;
1.6 raeburn 1199: }
1.168 raeburn 1200: my @addlangs;
1201: foreach my $lang (sort(keys(%langchoices))) {
1202: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1203: push(@addlangs,$lang);
1204: }
1205: if (@addlangs > 0) {
1206: my %toadd;
1207: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1208: $toadd{''} = &mt('Select');
1209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1210: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1211: &mt('Add log-in help page for a specific language:').' '.
1212: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1213: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1214: if ($switchserver) {
1215: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1216: } else {
1217: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1218: }
1.168 raeburn 1219: $datatable .= '</td></tr>';
1.169 raeburn 1220: $itemcount ++;
1.6 raeburn 1221: }
1.169 raeburn 1222: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1223: } elsif ($caller eq 'headtag') {
1224: my %domservers = &Apache::lonnet::get_servers($dom);
1225: my $choice = $choices{'headtag'};
1226: $css_class = ' class="LC_odd_row"';
1227: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1228: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1229: '<th>'.$choices{'current'}.'</th>'.
1230: '<th>'.$choices{'action'}.'</th>'.
1231: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1232: my (%currurls,%currexempt);
1233: if (ref($settings) eq 'HASH') {
1234: if (ref($settings->{'headtag'}) eq 'HASH') {
1235: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1236: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1237: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1238: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1239: }
1240: }
1241: }
1242: }
1243: my %lt = &Apache::lonlocal::texthash(
1244: del => 'Delete?',
1245: rep => 'Replace:',
1246: upl => 'Upload:',
1247: curr => 'View contents',
1248: none => 'None',
1249: );
1250: my $switchserver = &check_switchserver($dom,$confname);
1251: foreach my $lonhost (sort(keys(%domservers))) {
1252: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1253: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1254: if ($currurls{$lonhost}) {
1255: $datatable .= '<td class="LC_right_item"><a href="'.
1256: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1257: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1258: '">'.$lt{'curr'}.'</a></td>'.
1259: '<td><span class="LC_nobreak"><label>'.
1260: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1261: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1262: } else {
1263: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1264: }
1265: $datatable .='<br />';
1266: if ($switchserver) {
1267: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1268: } else {
1269: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1270: }
1271: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1272: }
1273: $datatable .= '</table></td></tr>';
1.1 raeburn 1274: }
1.6 raeburn 1275: return $datatable;
1276: }
1277:
1278: sub login_choices {
1279: my %choices =
1280: &Apache::lonlocal::texthash (
1.116 bisitz 1281: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1282: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1283: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1284: disallowlogin => "Login page requests redirected",
1285: hostid => "Server",
1.128 raeburn 1286: server => "Redirect to:",
1287: serverpath => "Path",
1288: custompath => "Custom",
1289: exempt => "Exempt IP(s)",
1.110 raeburn 1290: directlogin => "No redirect",
1291: newuser => "Link to create a user account",
1292: img => "Header",
1293: logo => "Main Logo",
1294: domlogo => "Domain Logo",
1295: login => "Log-in Header",
1296: textcol => "Text color",
1297: bgcol => "Box color",
1298: bgs => "Background colors",
1299: links => "Link colors",
1300: font => "Font color",
1301: pgbg => "Header",
1302: mainbg => "Page",
1303: sidebg => "Login box",
1304: link => "Link",
1305: alink => "Active link",
1306: vlink => "Visited link",
1.256 raeburn 1307: headtag => "Custom markup",
1308: action => "Action",
1309: current => "Current",
1.6 raeburn 1310: );
1311: return %choices;
1312: }
1313:
1314: sub print_rolecolors {
1.30 raeburn 1315: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1316: my %choices = &color_font_choices();
1317: my @bgs = ('pgbg','tabbg','sidebg');
1318: my @links = ('link','alink','vlink');
1319: my @images = ('img');
1320: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1321: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1322: my %defaultdesign = %Apache::loncommon::defaultdesign;
1323: my (%is_custom,%designs);
1.200 raeburn 1324: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1325: if (ref($settings) eq 'HASH') {
1326: if (ref($settings->{$role}) eq 'HASH') {
1327: if ($settings->{$role}->{'img'} ne '') {
1328: $designs{'img'} = $settings->{$role}->{'img'};
1329: $is_custom{'img'} = 1;
1330: }
1331: if ($settings->{$role}->{'font'} ne '') {
1332: $designs{'font'} = $settings->{$role}->{'font'};
1333: $is_custom{'font'} = 1;
1334: }
1.97 tempelho 1335: if ($settings->{$role}->{'fontmenu'} ne '') {
1336: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1337: $is_custom{'fontmenu'} = 1;
1338: }
1.6 raeburn 1339: foreach my $item (@bgs) {
1340: if ($settings->{$role}->{$item} ne '') {
1341: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1342: $is_custom{$item} = 1;
1343: }
1344: }
1345: foreach my $item (@links) {
1346: if ($settings->{$role}->{$item} ne '') {
1347: $designs{'links'}{$item} = $settings->{$role}->{$item};
1348: $is_custom{$item} = 1;
1349: }
1350: }
1351: }
1352: } else {
1353: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1354: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1355: $is_custom{'img'} = 1;
1356: }
1.97 tempelho 1357: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1358: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1359: $is_custom{'fontmenu'} = 1;
1360: }
1.6 raeburn 1361: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1362: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1363: $is_custom{'font'} = 1;
1364: }
1365: foreach my $item (@bgs) {
1366: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1367: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1368: $is_custom{$item} = 1;
1369:
1370: }
1371: }
1372: foreach my $item (@links) {
1373: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1374: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1375: $is_custom{$item} = 1;
1376: }
1377: }
1378: }
1379: my $itemcount = 1;
1.30 raeburn 1380: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1381: $datatable .= '</tr></table></td></tr>';
1382: return $datatable;
1383: }
1384:
1.200 raeburn 1385: sub role_defaults {
1386: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1387: my %defaults;
1388: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1389: return %defaults;
1390: }
1391: my %defaultdesign = %Apache::loncommon::defaultdesign;
1392: if ($role eq 'login') {
1393: %defaults = (
1394: font => $defaultdesign{$role.'.font'},
1395: );
1396: if (ref($logintext) eq 'ARRAY') {
1397: foreach my $item (@{$logintext}) {
1398: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1399: }
1400: }
1401: foreach my $item (@{$images}) {
1402: $defaults{'showlogo'}{$item} = 1;
1403: }
1404: } else {
1405: %defaults = (
1406: img => $defaultdesign{$role.'.img'},
1407: font => $defaultdesign{$role.'.font'},
1408: fontmenu => $defaultdesign{$role.'.fontmenu'},
1409: );
1410: }
1411: foreach my $item (@{$bgs}) {
1412: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1413: }
1414: foreach my $item (@{$links}) {
1415: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1416: }
1417: foreach my $item (@{$images}) {
1418: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1419: }
1420: return %defaults;
1421: }
1422:
1.6 raeburn 1423: sub display_color_options {
1.9 raeburn 1424: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1425: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1426: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1427: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1428: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1429: '<td>'.$choices->{'font'}.'</td>';
1430: if (!$is_custom->{'font'}) {
1.30 raeburn 1431: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1432: } else {
1433: $datatable .= '<td> </td>';
1434: }
1.174 foxr 1435: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1436:
1.8 raeburn 1437: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1438: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1439: ' value="'.$current_color.'" /> '.
1.174 foxr 1440: ' </td></tr>';
1.107 raeburn 1441: unless ($role eq 'login') {
1442: $datatable .= '<tr'.$css_class.'>'.
1443: '<td>'.$choices->{'fontmenu'}.'</td>';
1444: if (!$is_custom->{'fontmenu'}) {
1445: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1446: } else {
1447: $datatable .= '<td> </td>';
1448: }
1.202 raeburn 1449: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1450: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1451: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1452: '<input class="colorchooser" type="text" size="10" name="'
1453: .$role.'_fontmenu"'.
1454: ' value="'.$current_color.'" /> '.
1455: ' </td></tr>';
1.97 tempelho 1456: }
1.9 raeburn 1457: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1458: foreach my $img (@{$images}) {
1.18 albertel 1459: $itemcount ++;
1.6 raeburn 1460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1461: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1462: '<td>'.$choices->{$img};
1.41 raeburn 1463: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1464: if ($role eq 'login') {
1465: if ($img eq 'login') {
1466: $login_hdr_pick =
1.135 bisitz 1467: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1468: $logincolors =
1469: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1470: $designs,$defaults);
1.70 raeburn 1471: } elsif ($img ne 'domlogo') {
1472: $datatable.= &logo_display_options($img,$defaults,$designs);
1473: }
1474: }
1475: $datatable .= '</td>';
1.6 raeburn 1476: if ($designs->{$img} ne '') {
1477: $imgfile = $designs->{$img};
1.18 albertel 1478: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1479: } else {
1480: $imgfile = $defaults->{$img};
1481: }
1482: if ($imgfile) {
1.9 raeburn 1483: my ($showfile,$fullsize);
1484: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1485: my $urldir = $1;
1486: my $filename = $2;
1487: my @info = &Apache::lonnet::stat_file($designs->{$img});
1488: if (@info) {
1489: my $thumbfile = 'tn-'.$filename;
1490: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1491: if (@thumb) {
1492: $showfile = $urldir.'/'.$thumbfile;
1493: } else {
1494: $showfile = $imgfile;
1495: }
1496: } else {
1497: $showfile = '';
1498: }
1499: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1500: $showfile = $imgfile;
1.6 raeburn 1501: my $imgdir = $1;
1502: my $filename = $2;
1.159 raeburn 1503: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1504: $showfile = "/$imgdir/tn-".$filename;
1505: } else {
1.159 raeburn 1506: my $input = $londocroot.$imgfile;
1507: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1508: if (!-e $output) {
1.9 raeburn 1509: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1510: my ($fullwidth,$fullheight) = &check_dimensions($input);
1511: if ($fullwidth ne '' && $fullheight ne '') {
1512: if ($fullwidth > $width && $fullheight > $height) {
1513: my $size = $width.'x'.$height;
1514: system("convert -sample $size $input $output");
1.159 raeburn 1515: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1516: }
1517: }
1.6 raeburn 1518: }
1519: }
1.16 raeburn 1520: }
1.6 raeburn 1521: if ($showfile) {
1.40 raeburn 1522: if ($showfile =~ m{^/(adm|res)/}) {
1523: if ($showfile =~ m{^/res/}) {
1524: my $local_showfile =
1525: &Apache::lonnet::filelocation('',$showfile);
1526: &Apache::lonnet::repcopy($local_showfile);
1527: }
1528: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1529: }
1530: if ($imgfile) {
1531: if ($imgfile =~ m{^/(adm|res)/}) {
1532: if ($imgfile =~ m{^/res/}) {
1533: my $local_imgfile =
1534: &Apache::lonnet::filelocation('',$imgfile);
1535: &Apache::lonnet::repcopy($local_imgfile);
1536: }
1537: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1538: } else {
1539: $fullsize = $imgfile;
1540: }
1541: }
1.41 raeburn 1542: $datatable .= '<td>';
1543: if ($img eq 'login') {
1.135 bisitz 1544: $datatable .= $login_hdr_pick;
1545: }
1.41 raeburn 1546: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1547: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1548: } else {
1.201 raeburn 1549: $datatable .= '<td> </td><td class="LC_left_item">'.
1550: &mt('Upload:').'<br />';
1.6 raeburn 1551: }
1552: } else {
1.201 raeburn 1553: $datatable .= '<td> </td><td class="LC_left_item">'.
1554: &mt('Upload:').'<br />';
1.6 raeburn 1555: }
1.9 raeburn 1556: if ($switchserver) {
1557: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1558: } else {
1.135 bisitz 1559: if ($img ne 'login') { # suppress file selection for Log-in header
1560: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1561: }
1.9 raeburn 1562: }
1563: $datatable .= '</td></tr>';
1.6 raeburn 1564: }
1565: $itemcount ++;
1566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1567: $datatable .= '<tr'.$css_class.'>'.
1568: '<td>'.$choices->{'bgs'}.'</td>';
1569: my $bgs_def;
1570: foreach my $item (@{$bgs}) {
1571: if (!$is_custom->{$item}) {
1.70 raeburn 1572: $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 1573: }
1574: }
1575: if ($bgs_def) {
1.8 raeburn 1576: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1580: $datatable .= '<td class="LC_right_item">'.
1581: '<table border="0"><tr>';
1.174 foxr 1582:
1.6 raeburn 1583: foreach my $item (@{$bgs}) {
1.201 raeburn 1584: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1585: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1586: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1587: $datatable .= ' ';
1.6 raeburn 1588: }
1.174 foxr 1589: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1590: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1591: }
1592: $datatable .= '</tr></table></td></tr>';
1593: $itemcount ++;
1594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1595: $datatable .= '<tr'.$css_class.'>'.
1596: '<td>'.$choices->{'links'}.'</td>';
1597: my $links_def;
1598: foreach my $item (@{$links}) {
1599: if (!$is_custom->{$item}) {
1.30 raeburn 1600: $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 1601: }
1602: }
1603: if ($links_def) {
1.8 raeburn 1604: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1605: } else {
1606: $datatable .= '<td> </td>';
1607: }
1608: $datatable .= '<td class="LC_right_item">'.
1609: '<table border="0"><tr>';
1610: foreach my $item (@{$links}) {
1.234 raeburn 1611: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1612: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1613: if ($designs->{'links'}{$item}) {
1.174 foxr 1614: $datatable.=' ';
1.6 raeburn 1615: }
1.174 foxr 1616: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1617: '" /></td>';
1618: }
1.30 raeburn 1619: $$rowtotal += $itemcount;
1.3 raeburn 1620: return $datatable;
1621: }
1622:
1.70 raeburn 1623: sub logo_display_options {
1624: my ($img,$defaults,$designs) = @_;
1625: my $checkedon;
1626: if (ref($defaults) eq 'HASH') {
1627: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1628: if ($defaults->{'showlogo'}{$img}) {
1629: $checkedon = 'checked="checked" ';
1630: }
1631: }
1632: }
1633: if (ref($designs) eq 'HASH') {
1634: if (ref($designs->{'showlogo'}) eq 'HASH') {
1635: if (defined($designs->{'showlogo'}{$img})) {
1636: if ($designs->{'showlogo'}{$img} == 0) {
1637: $checkedon = '';
1638: } elsif ($designs->{'showlogo'}{$img} == 1) {
1639: $checkedon = 'checked="checked" ';
1640: }
1641: }
1642: }
1643: }
1644: return '<br /><label> <input type="checkbox" name="'.
1645: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1646: &mt('show').'</label>'."\n";
1647: }
1648:
1.41 raeburn 1649: sub login_header_options {
1.135 bisitz 1650: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1651: my $output = '';
1.41 raeburn 1652: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1653: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1654: if (!$is_custom->{'textcol'}) {
1655: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1656: ' ';
1657: }
1658: if (!$is_custom->{'bgcol'}) {
1659: $output .= $choices->{'bgcol'}.': '.
1660: '<span id="css_'.$role.'_font" style="background-color: '.
1661: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1662: }
1663: $output .= '<br />';
1664: }
1665: $output .='<br />';
1666: return $output;
1667: }
1668:
1669: sub login_text_colors {
1.201 raeburn 1670: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1671: my $color_menu = '<table border="0"><tr>';
1672: foreach my $item (@{$logintext}) {
1.201 raeburn 1673: $color_menu .= '<td align="center">'.$choices->{$item};
1674: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1675: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1676: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1677: }
1678: $color_menu .= '</tr></table><br />';
1679: return $color_menu;
1680: }
1681:
1682: sub image_changes {
1683: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1684: my $output;
1.135 bisitz 1685: if ($img eq 'login') {
1686: # suppress image for Log-in header
1687: } elsif (!$is_custom) {
1.70 raeburn 1688: if ($img ne 'domlogo') {
1.41 raeburn 1689: $output .= &mt('Default image:').'<br />';
1690: } else {
1691: $output .= &mt('Default in use:').'<br />';
1692: }
1693: }
1.135 bisitz 1694: if ($img eq 'login') { # suppress image for Log-in header
1695: $output .= '<td>'.$logincolors;
1.41 raeburn 1696: } else {
1.135 bisitz 1697: if ($img_import) {
1698: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1699: }
1700: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1701: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1702: if ($is_custom) {
1703: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1704: '<input type="checkbox" name="'.
1705: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1706: '</label> '.&mt('Replace:').'</span><br />';
1707: } else {
1.201 raeburn 1708: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1709: }
1.41 raeburn 1710: }
1711: return $output;
1712: }
1713:
1.3 raeburn 1714: sub print_quotas {
1.86 raeburn 1715: my ($dom,$settings,$rowtotal,$action) = @_;
1716: my $context;
1717: if ($action eq 'quotas') {
1718: $context = 'tools';
1719: } else {
1720: $context = $action;
1721: }
1.197 raeburn 1722: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1724: my $typecount = 0;
1.101 raeburn 1725: my ($css_class,%titles);
1.86 raeburn 1726: if ($context eq 'requestcourses') {
1.271 ! raeburn 1727: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1728: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1729: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1730: %titles = &courserequest_titles();
1.163 raeburn 1731: } elsif ($context eq 'requestauthor') {
1732: @usertools = ('author');
1733: @options = ('norequest','approval','automatic');
1.210 raeburn 1734: %titles = &authorrequest_titles();
1.86 raeburn 1735: } else {
1.162 raeburn 1736: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1737: %titles = &tool_titles();
1.86 raeburn 1738: }
1.26 raeburn 1739: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1740: foreach my $type (@{$types}) {
1.197 raeburn 1741: my ($currdefquota,$currauthorquota);
1.163 raeburn 1742: unless (($context eq 'requestcourses') ||
1743: ($context eq 'requestauthor')) {
1.86 raeburn 1744: if (ref($settings) eq 'HASH') {
1745: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1746: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1747: } else {
1748: $currdefquota = $settings->{$type};
1749: }
1.197 raeburn 1750: if (ref($settings->{authorquota}) eq 'HASH') {
1751: $currauthorquota = $settings->{authorquota}->{$type};
1752: }
1.78 raeburn 1753: }
1.72 raeburn 1754: }
1.3 raeburn 1755: if (defined($usertypes->{$type})) {
1756: $typecount ++;
1757: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1758: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1759: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1760: '<td class="LC_left_item">';
1.101 raeburn 1761: if ($context eq 'requestcourses') {
1762: $datatable .= '<table><tr>';
1763: }
1764: my %cell;
1.72 raeburn 1765: foreach my $item (@usertools) {
1.101 raeburn 1766: if ($context eq 'requestcourses') {
1767: my ($curroption,$currlimit);
1768: if (ref($settings) eq 'HASH') {
1769: if (ref($settings->{$item}) eq 'HASH') {
1770: $curroption = $settings->{$item}->{$type};
1771: if ($curroption =~ /^autolimit=(\d*)$/) {
1772: $currlimit = $1;
1773: }
1774: }
1775: }
1776: if (!$curroption) {
1777: $curroption = 'norequest';
1778: }
1779: $datatable .= '<th>'.$titles{$item}.'</th>';
1780: foreach my $option (@options) {
1781: my $val = $option;
1782: if ($option eq 'norequest') {
1783: $val = 0;
1784: }
1785: if ($option eq 'validate') {
1786: my $canvalidate = 0;
1787: if (ref($validations{$item}) eq 'HASH') {
1788: if ($validations{$item}{$type}) {
1789: $canvalidate = 1;
1790: }
1791: }
1792: next if (!$canvalidate);
1793: }
1794: my $checked = '';
1795: if ($option eq $curroption) {
1796: $checked = ' checked="checked"';
1797: } elsif ($option eq 'autolimit') {
1798: if ($curroption =~ /^autolimit/) {
1799: $checked = ' checked="checked"';
1800: }
1801: }
1802: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1803: '<input type="radio" name="crsreq_'.$item.
1804: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1805: $titles{$option}.'</label>';
1.101 raeburn 1806: if ($option eq 'autolimit') {
1.127 raeburn 1807: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1808: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1809: 'value="'.$currlimit.'" />';
1.101 raeburn 1810: }
1.127 raeburn 1811: $cell{$item} .= '</span> ';
1.103 raeburn 1812: if ($option eq 'autolimit') {
1.127 raeburn 1813: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1814: }
1.101 raeburn 1815: }
1.163 raeburn 1816: } elsif ($context eq 'requestauthor') {
1817: my $curroption;
1818: if (ref($settings) eq 'HASH') {
1819: $curroption = $settings->{$type};
1820: }
1821: if (!$curroption) {
1822: $curroption = 'norequest';
1823: }
1824: foreach my $option (@options) {
1825: my $val = $option;
1826: if ($option eq 'norequest') {
1827: $val = 0;
1828: }
1829: my $checked = '';
1830: if ($option eq $curroption) {
1831: $checked = ' checked="checked"';
1832: }
1833: $datatable .= '<span class="LC_nobreak"><label>'.
1834: '<input type="radio" name="authorreq_'.$type.
1835: '" value="'.$val.'"'.$checked.' />'.
1836: $titles{$option}.'</label></span> ';
1837: }
1.101 raeburn 1838: } else {
1839: my $checked = 'checked="checked" ';
1840: if (ref($settings) eq 'HASH') {
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: if ($settings->{$item}->{$type} == 0) {
1843: $checked = '';
1844: } elsif ($settings->{$item}->{$type} == 1) {
1845: $checked = 'checked="checked" ';
1846: }
1.78 raeburn 1847: }
1.72 raeburn 1848: }
1.101 raeburn 1849: $datatable .= '<span class="LC_nobreak"><label>'.
1850: '<input type="checkbox" name="'.$context.'_'.$item.
1851: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1852: '</label></span> ';
1.72 raeburn 1853: }
1.101 raeburn 1854: }
1855: if ($context eq 'requestcourses') {
1856: $datatable .= '</tr><tr>';
1857: foreach my $item (@usertools) {
1.106 raeburn 1858: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1859: }
1860: $datatable .= '</tr></table>';
1.72 raeburn 1861: }
1.86 raeburn 1862: $datatable .= '</td>';
1.163 raeburn 1863: unless (($context eq 'requestcourses') ||
1864: ($context eq 'requestauthor')) {
1.86 raeburn 1865: $datatable .=
1.197 raeburn 1866: '<td class="LC_right_item">'.
1867: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1868: '<input type="text" name="quota_'.$type.
1.72 raeburn 1869: '" value="'.$currdefquota.
1.197 raeburn 1870: '" size="5" /></span>'.(' ' x 2).
1871: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1872: '<input type="text" name="authorquota_'.$type.
1873: '" value="'.$currauthorquota.
1874: '" size="5" /></span></td>';
1.86 raeburn 1875: }
1876: $datatable .= '</tr>';
1.3 raeburn 1877: }
1878: }
1879: }
1.163 raeburn 1880: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1881: $defaultquota = '20';
1.197 raeburn 1882: $authorquota = '500';
1.86 raeburn 1883: if (ref($settings) eq 'HASH') {
1884: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1885: $defaultquota = $settings->{'defaultquota'}->{'default'};
1886: } elsif (defined($settings->{'default'})) {
1887: $defaultquota = $settings->{'default'};
1888: }
1.197 raeburn 1889: if (ref($settings->{'authorquota'}) eq 'HASH') {
1890: $authorquota = $settings->{'authorquota'}->{'default'};
1891: }
1.3 raeburn 1892: }
1893: }
1894: $typecount ++;
1895: $css_class = $typecount%2?' class="LC_odd_row"':'';
1896: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1897: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1898: '<td class="LC_left_item">';
1.101 raeburn 1899: if ($context eq 'requestcourses') {
1900: $datatable .= '<table><tr>';
1901: }
1902: my %defcell;
1.72 raeburn 1903: foreach my $item (@usertools) {
1.101 raeburn 1904: if ($context eq 'requestcourses') {
1905: my ($curroption,$currlimit);
1906: if (ref($settings) eq 'HASH') {
1907: if (ref($settings->{$item}) eq 'HASH') {
1908: $curroption = $settings->{$item}->{'default'};
1909: if ($curroption =~ /^autolimit=(\d*)$/) {
1910: $currlimit = $1;
1911: }
1912: }
1913: }
1914: if (!$curroption) {
1915: $curroption = 'norequest';
1916: }
1917: $datatable .= '<th>'.$titles{$item}.'</th>';
1918: foreach my $option (@options) {
1919: my $val = $option;
1920: if ($option eq 'norequest') {
1921: $val = 0;
1922: }
1923: if ($option eq 'validate') {
1924: my $canvalidate = 0;
1925: if (ref($validations{$item}) eq 'HASH') {
1926: if ($validations{$item}{'default'}) {
1927: $canvalidate = 1;
1928: }
1929: }
1930: next if (!$canvalidate);
1931: }
1932: my $checked = '';
1933: if ($option eq $curroption) {
1934: $checked = ' checked="checked"';
1935: } elsif ($option eq 'autolimit') {
1936: if ($curroption =~ /^autolimit/) {
1937: $checked = ' checked="checked"';
1938: }
1939: }
1940: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1941: '<input type="radio" name="crsreq_'.$item.
1942: '_default" value="'.$val.'"'.$checked.' />'.
1943: $titles{$option}.'</label>';
1944: if ($option eq 'autolimit') {
1.127 raeburn 1945: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1946: $item.'_limit_default" size="1" '.
1947: 'value="'.$currlimit.'" />';
1948: }
1.127 raeburn 1949: $defcell{$item} .= '</span> ';
1.104 raeburn 1950: if ($option eq 'autolimit') {
1.127 raeburn 1951: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1952: }
1.101 raeburn 1953: }
1.163 raeburn 1954: } elsif ($context eq 'requestauthor') {
1955: my $curroption;
1956: if (ref($settings) eq 'HASH') {
1.172 raeburn 1957: $curroption = $settings->{'default'};
1.163 raeburn 1958: }
1959: if (!$curroption) {
1960: $curroption = 'norequest';
1961: }
1962: foreach my $option (@options) {
1963: my $val = $option;
1964: if ($option eq 'norequest') {
1965: $val = 0;
1966: }
1967: my $checked = '';
1968: if ($option eq $curroption) {
1969: $checked = ' checked="checked"';
1970: }
1971: $datatable .= '<span class="LC_nobreak"><label>'.
1972: '<input type="radio" name="authorreq_default"'.
1973: ' value="'.$val.'"'.$checked.' />'.
1974: $titles{$option}.'</label></span> ';
1975: }
1.101 raeburn 1976: } else {
1977: my $checked = 'checked="checked" ';
1978: if (ref($settings) eq 'HASH') {
1979: if (ref($settings->{$item}) eq 'HASH') {
1980: if ($settings->{$item}->{'default'} == 0) {
1981: $checked = '';
1982: } elsif ($settings->{$item}->{'default'} == 1) {
1983: $checked = 'checked="checked" ';
1984: }
1.78 raeburn 1985: }
1.72 raeburn 1986: }
1.101 raeburn 1987: $datatable .= '<span class="LC_nobreak"><label>'.
1988: '<input type="checkbox" name="'.$context.'_'.$item.
1989: '" value="default" '.$checked.'/>'.$titles{$item}.
1990: '</label></span> ';
1991: }
1992: }
1993: if ($context eq 'requestcourses') {
1994: $datatable .= '</tr><tr>';
1995: foreach my $item (@usertools) {
1.106 raeburn 1996: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1997: }
1.101 raeburn 1998: $datatable .= '</tr></table>';
1.72 raeburn 1999: }
1.86 raeburn 2000: $datatable .= '</td>';
1.163 raeburn 2001: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2002: $datatable .= '<td class="LC_right_item">'.
2003: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2004: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2005: $defaultquota.'" size="5" /></span>'.(' ' x2).
2006: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2007: '<input type="text" name="authorquota" value="'.
2008: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2009: }
2010: $datatable .= '</tr>';
1.72 raeburn 2011: $typecount ++;
2012: $css_class = $typecount%2?' class="LC_odd_row"':'';
2013: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2014: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2015: if ($context eq 'requestcourses') {
1.109 raeburn 2016: $datatable .= &mt('(overrides affiliation, if set)').
2017: '</td>'.
2018: '<td class="LC_left_item">'.
2019: '<table><tr>';
1.101 raeburn 2020: } else {
1.109 raeburn 2021: $datatable .= &mt('(overrides affiliation, if checked)').
2022: '</td>'.
2023: '<td class="LC_left_item" colspan="2">'.
2024: '<br />';
1.101 raeburn 2025: }
2026: my %advcell;
1.72 raeburn 2027: foreach my $item (@usertools) {
1.101 raeburn 2028: if ($context eq 'requestcourses') {
2029: my ($curroption,$currlimit);
2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$item}) eq 'HASH') {
2032: $curroption = $settings->{$item}->{'_LC_adv'};
2033: if ($curroption =~ /^autolimit=(\d*)$/) {
2034: $currlimit = $1;
2035: }
2036: }
2037: }
2038: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2039: my $checked = '';
2040: if ($curroption eq '') {
2041: $checked = ' checked="checked"';
2042: }
2043: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2044: '<input type="radio" name="crsreq_'.$item.
2045: '__LC_adv" value=""'.$checked.' />'.
2046: &mt('No override set').'</label></span> ';
1.101 raeburn 2047: foreach my $option (@options) {
2048: my $val = $option;
2049: if ($option eq 'norequest') {
2050: $val = 0;
2051: }
2052: if ($option eq 'validate') {
2053: my $canvalidate = 0;
2054: if (ref($validations{$item}) eq 'HASH') {
2055: if ($validations{$item}{'_LC_adv'}) {
2056: $canvalidate = 1;
2057: }
2058: }
2059: next if (!$canvalidate);
2060: }
2061: my $checked = '';
1.104 raeburn 2062: if ($val eq $curroption) {
1.101 raeburn 2063: $checked = ' checked="checked"';
2064: } elsif ($option eq 'autolimit') {
2065: if ($curroption =~ /^autolimit/) {
2066: $checked = ' checked="checked"';
2067: }
2068: }
2069: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="crsreq_'.$item.
2071: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label>';
2073: if ($option eq 'autolimit') {
1.127 raeburn 2074: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2075: $item.'_limit__LC_adv" size="1" '.
2076: 'value="'.$currlimit.'" />';
2077: }
1.127 raeburn 2078: $advcell{$item} .= '</span> ';
1.104 raeburn 2079: if ($option eq 'autolimit') {
1.127 raeburn 2080: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2081: }
1.101 raeburn 2082: }
1.163 raeburn 2083: } elsif ($context eq 'requestauthor') {
2084: my $curroption;
2085: if (ref($settings) eq 'HASH') {
2086: $curroption = $settings->{'_LC_adv'};
2087: }
2088: my $checked = '';
2089: if ($curroption eq '') {
2090: $checked = ' checked="checked"';
2091: }
2092: $datatable .= '<span class="LC_nobreak"><label>'.
2093: '<input type="radio" name="authorreq__LC_adv"'.
2094: ' value=""'.$checked.' />'.
2095: &mt('No override set').'</label></span> ';
2096: foreach my $option (@options) {
2097: my $val = $option;
2098: if ($option eq 'norequest') {
2099: $val = 0;
2100: }
2101: my $checked = '';
2102: if ($val eq $curroption) {
2103: $checked = ' checked="checked"';
2104: }
2105: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2106: '<input type="radio" name="authorreq__LC_adv"'.
2107: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2108: $titles{$option}.'</label></span> ';
2109: }
1.101 raeburn 2110: } else {
2111: my $checked = 'checked="checked" ';
2112: if (ref($settings) eq 'HASH') {
2113: if (ref($settings->{$item}) eq 'HASH') {
2114: if ($settings->{$item}->{'_LC_adv'} == 0) {
2115: $checked = '';
2116: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2117: $checked = 'checked="checked" ';
2118: }
1.79 raeburn 2119: }
1.72 raeburn 2120: }
1.101 raeburn 2121: $datatable .= '<span class="LC_nobreak"><label>'.
2122: '<input type="checkbox" name="'.$context.'_'.$item.
2123: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2124: '</label></span> ';
2125: }
2126: }
2127: if ($context eq 'requestcourses') {
2128: $datatable .= '</tr><tr>';
2129: foreach my $item (@usertools) {
1.106 raeburn 2130: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2131: }
1.101 raeburn 2132: $datatable .= '</tr></table>';
1.72 raeburn 2133: }
1.98 raeburn 2134: $datatable .= '</td></tr>';
1.30 raeburn 2135: $$rowtotal += $typecount;
1.3 raeburn 2136: return $datatable;
2137: }
2138:
1.163 raeburn 2139: sub print_requestmail {
2140: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2141: my ($now,$datatable,%currapp);
1.102 raeburn 2142: $now = time;
2143: if (ref($settings) eq 'HASH') {
2144: if (ref($settings->{'notify'}) eq 'HASH') {
2145: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2146: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2147: }
2148: }
2149: }
1.191 raeburn 2150: my $numinrow = 2;
1.224 raeburn 2151: my $css_class;
2152: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2153: my $text;
2154: if ($action eq 'requestcourses') {
2155: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2156: } elsif ($action eq 'requestauthor') {
2157: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2158: } else {
1.224 raeburn 2159: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2160: }
1.224 raeburn 2161: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2162: ' <td>'.$text.'</td>'.
1.102 raeburn 2163: ' <td class="LC_left_item">';
1.191 raeburn 2164: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2165: $action.'notifyapproval',%currapp);
1.191 raeburn 2166: if ($numdc > 0) {
2167: $datatable .= $table;
1.102 raeburn 2168: } else {
2169: $datatable .= &mt('There are no active Domain Coordinators');
2170: }
2171: $datatable .='</td></tr>';
2172: return $datatable;
2173: }
2174:
1.216 raeburn 2175: sub print_studentcode {
2176: my ($settings,$rowtotal) = @_;
2177: my $rownum = 0;
1.218 raeburn 2178: my ($output,%current);
1.271 ! raeburn 2179: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2180: if (ref($settings) eq 'HASH') {
2181: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2182: foreach my $type (@crstypes) {
2183: $current{$type} = $settings->{'uniquecode'}{$type};
2184: }
1.218 raeburn 2185: }
2186: }
2187: $output .= '<tr>'.
2188: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2189: '<td class="LC_left_item">';
2190: foreach my $type (@crstypes) {
2191: my $check = ' ';
2192: if ($current{$type}) {
2193: $check = ' checked="checked" ';
2194: }
2195: $output .= '<span class="LC_nobreak"><label>'.
2196: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2197: &mt($type).'</label></span>'.(' 'x2).' ';
2198: }
2199: $output .= '</td></tr>';
2200: $$rowtotal ++;
2201: return $output;
1.216 raeburn 2202: }
2203:
2204: sub print_textbookcourses {
1.242 raeburn 2205: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2206: my $rownum = 0;
2207: my $css_class;
2208: my $itemcount = 1;
2209: my $maxnum = 0;
2210: my $bookshash;
2211: if (ref($settings) eq 'HASH') {
1.242 raeburn 2212: $bookshash = $settings->{$type};
1.216 raeburn 2213: }
2214: my %ordered;
2215: if (ref($bookshash) eq 'HASH') {
2216: foreach my $item (keys(%{$bookshash})) {
2217: if (ref($bookshash->{$item}) eq 'HASH') {
2218: my $num = $bookshash->{$item}{'order'};
2219: $ordered{$num} = $item;
2220: }
2221: }
2222: }
2223: my $confname = $dom.'-domainconfig';
2224: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2225: my $maxnum = scalar(keys(%ordered));
2226: my $datatable;
1.216 raeburn 2227: if (keys(%ordered)) {
2228: my @items = sort { $a <=> $b } keys(%ordered);
2229: for (my $i=0; $i<@items; $i++) {
2230: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2231: my $key = $ordered{$items[$i]};
2232: my %coursehash=&Apache::lonnet::coursedescription($key);
2233: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2234: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2235: if (ref($bookshash->{$key}) eq 'HASH') {
2236: $subject = $bookshash->{$key}->{'subject'};
2237: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2238: if ($type eq 'textbooks') {
1.243 raeburn 2239: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2240: $author = $bookshash->{$key}->{'author'};
2241: $image = $bookshash->{$key}->{'image'};
2242: if ($image ne '') {
2243: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2244: my $imagethumb = "$path/tn-".$imagefile;
2245: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2246: }
1.216 raeburn 2247: }
2248: }
1.242 raeburn 2249: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2250: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2251: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2252: for (my $k=0; $k<=$maxnum; $k++) {
2253: my $vpos = $k+1;
2254: my $selstr;
2255: if ($k == $i) {
2256: $selstr = ' selected="selected" ';
2257: }
2258: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2259: }
2260: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2261: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2262: &mt('Delete?').'</label></span></td>'.
2263: '<td colspan="2">'.
1.242 raeburn 2264: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2265: (' 'x2).
1.242 raeburn 2266: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2267: if ($type eq 'textbooks') {
2268: $datatable .= (' 'x2).
1.243 raeburn 2269: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2270: (' 'x2).
1.242 raeburn 2271: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2272: (' 'x2).
2273: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2274: if ($image) {
1.267 raeburn 2275: $datatable .= $imgsrc.
1.242 raeburn 2276: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2277: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2278: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2279: }
2280: if ($switchserver) {
2281: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2282: } else {
2283: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2284: }
1.216 raeburn 2285: }
1.242 raeburn 2286: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2287: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2288: $coursetitle.'</span></td></tr>'."\n";
2289: $itemcount ++;
2290: }
2291: }
2292: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2293: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2294: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2295: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2296: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2297: for (my $k=0; $k<$maxnum+1; $k++) {
2298: my $vpos = $k+1;
2299: my $selstr;
2300: if ($k == $maxnum) {
2301: $selstr = ' selected="selected" ';
2302: }
2303: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2304: }
2305: $datatable .= '</select> '."\n".
1.242 raeburn 2306: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2307: '<td colspan="2">'.
1.242 raeburn 2308: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2309: (' 'x2).
1.242 raeburn 2310: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2311: (' 'x2);
2312: if ($type eq 'textbooks') {
1.243 raeburn 2313: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2314: (' 'x2).
2315: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2316: (' 'x2).
2317: '<span class="LC_nobreak">'.&mt('Image:').' ';
2318: if ($switchserver) {
2319: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2320: } else {
2321: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2322: }
1.216 raeburn 2323: }
2324: $datatable .= '</span>'."\n".
2325: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2326: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2327: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2328: &Apache::loncommon::selectcourse_link
1.242 raeburn 2329: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2330: '</span></td>'."\n".
2331: '</tr>'."\n";
2332: $itemcount ++;
2333: return $datatable;
2334: }
2335:
1.217 raeburn 2336: sub textbookcourses_javascript {
1.242 raeburn 2337: my ($settings) = @_;
2338: return unless(ref($settings) eq 'HASH');
2339: my (%ordered,%total,%jstext);
2340: foreach my $type ('textbooks','templates') {
2341: $total{$type} = 0;
2342: if (ref($settings->{$type}) eq 'HASH') {
2343: foreach my $item (keys(%{$settings->{$type}})) {
2344: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2345: my $num = $settings->{$type}->{$item}{'order'};
2346: $ordered{$type}{$num} = $item;
2347: }
2348: }
2349: $total{$type} = scalar(keys(%{$settings->{$type}}));
2350: }
2351: my @jsarray = ();
2352: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2353: push(@jsarray,$ordered{$type}{$item});
2354: }
2355: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2356: }
2357: return <<"ENDSCRIPT";
2358: <script type="text/javascript">
2359: // <![CDATA[
1.242 raeburn 2360: function reorderBooks(form,item,caller) {
1.217 raeburn 2361: var changedVal;
1.242 raeburn 2362: $jstext{'textbooks'};
2363: $jstext{'templates'};
2364: var newpos;
2365: var maxh;
2366: if (caller == 'textbooks') {
2367: newpos = 'textbooks_addbook_pos';
2368: maxh = 1 + $total{'textbooks'};
2369: } else {
2370: newpos = 'templates_addbook_pos';
2371: maxh = 1 + $total{'templates'};
2372: }
1.217 raeburn 2373: var current = new Array;
2374: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2375: if (item == newpos) {
2376: changedVal = newitemVal;
2377: } else {
2378: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2379: current[newitemVal] = newpos;
2380: }
1.242 raeburn 2381: if (caller == 'textbooks') {
2382: for (var i=0; i<textbooks.length; i++) {
2383: var elementName = 'textbooks_'+textbooks[i];
2384: if (elementName != item) {
2385: if (form.elements[elementName]) {
2386: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2387: current[currVal] = elementName;
2388: }
2389: }
2390: }
2391: }
2392: if (caller == 'templates') {
2393: for (var i=0; i<templates.length; i++) {
2394: var elementName = 'templates_'+templates[i];
2395: if (elementName != item) {
2396: if (form.elements[elementName]) {
2397: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2398: current[currVal] = elementName;
2399: }
1.217 raeburn 2400: }
2401: }
2402: }
2403: var oldVal;
2404: for (var j=0; j<maxh; j++) {
2405: if (current[j] == undefined) {
2406: oldVal = j;
2407: }
2408: }
2409: if (oldVal < changedVal) {
2410: for (var k=oldVal+1; k<=changedVal ; k++) {
2411: var elementName = current[k];
2412: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2413: }
2414: } else {
2415: for (var k=changedVal; k<oldVal; k++) {
2416: var elementName = current[k];
2417: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2418: }
2419: }
2420: return;
2421: }
2422:
2423: // ]]>
2424: </script>
2425:
2426: ENDSCRIPT
2427: }
2428:
1.267 raeburn 2429: sub ltitools_javascript {
2430: my ($settings) = @_;
2431: return unless(ref($settings) eq 'HASH');
2432: my (%ordered,$total,%jstext);
2433: $total = 0;
2434: foreach my $item (keys(%{$settings})) {
2435: if (ref($settings->{$item}) eq 'HASH') {
2436: my $num = $settings->{$item}{'order'};
2437: $ordered{$num} = $item;
2438: }
2439: }
2440: $total = scalar(keys(%{$settings}));
2441: my @jsarray = ();
2442: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2443: push(@jsarray,$ordered{$item});
2444: }
2445: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2446: return <<"ENDSCRIPT";
2447: <script type="text/javascript">
2448: // <![CDATA[
2449: function reorderLTI(form,item) {
2450: var changedVal;
2451: $jstext
2452: var newpos = 'ltitools_add_pos';
2453: var maxh = 1 + $total;
2454: var current = new Array;
2455: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2456: if (item == newpos) {
2457: changedVal = newitemVal;
2458: } else {
2459: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2460: current[newitemVal] = newpos;
2461: }
2462: for (var i=0; i<ltitools.length; i++) {
2463: var elementName = 'ltitools_'+ltitools[i];
2464: if (elementName != item) {
2465: if (form.elements[elementName]) {
2466: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2467: current[currVal] = elementName;
2468: }
2469: }
2470: }
2471: var oldVal;
2472: for (var j=0; j<maxh; j++) {
2473: if (current[j] == undefined) {
2474: oldVal = j;
2475: }
2476: }
2477: if (oldVal < changedVal) {
2478: for (var k=oldVal+1; k<=changedVal ; k++) {
2479: var elementName = current[k];
2480: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2481: }
2482: } else {
2483: for (var k=changedVal; k<oldVal; k++) {
2484: var elementName = current[k];
2485: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2486: }
2487: }
2488: return;
2489: }
2490:
2491: // ]]>
2492: </script>
2493:
2494: ENDSCRIPT
2495: }
2496:
1.3 raeburn 2497: sub print_autoenroll {
1.30 raeburn 2498: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2499: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2500: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2501: if (ref($settings) eq 'HASH') {
2502: if (exists($settings->{'run'})) {
2503: if ($settings->{'run'} eq '0') {
2504: $runoff = ' checked="checked" ';
2505: $runon = ' ';
2506: } else {
2507: $runon = ' checked="checked" ';
2508: $runoff = ' ';
2509: }
2510: } else {
2511: if ($autorun) {
2512: $runon = ' checked="checked" ';
2513: $runoff = ' ';
2514: } else {
2515: $runoff = ' checked="checked" ';
2516: $runon = ' ';
2517: }
2518: }
1.129 raeburn 2519: if (exists($settings->{'co-owners'})) {
2520: if ($settings->{'co-owners'} eq '0') {
2521: $coownersoff = ' checked="checked" ';
2522: $coownerson = ' ';
2523: } else {
2524: $coownerson = ' checked="checked" ';
2525: $coownersoff = ' ';
2526: }
2527: } else {
2528: $coownersoff = ' checked="checked" ';
2529: $coownerson = ' ';
2530: }
1.3 raeburn 2531: if (exists($settings->{'sender_domain'})) {
2532: $defdom = $settings->{'sender_domain'};
2533: }
1.14 raeburn 2534: } else {
2535: if ($autorun) {
2536: $runon = ' checked="checked" ';
2537: $runoff = ' ';
2538: } else {
2539: $runoff = ' checked="checked" ';
2540: $runon = ' ';
2541: }
1.3 raeburn 2542: }
2543: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2544: my $notif_sender;
2545: if (ref($settings) eq 'HASH') {
2546: $notif_sender = $settings->{'sender_uname'};
2547: }
1.3 raeburn 2548: my $datatable='<tr class="LC_odd_row">'.
2549: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2550: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2551: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2552: $runon.' value="1" />'.&mt('Yes').'</label> '.
2553: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2554: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2555: '</tr><tr>'.
2556: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2557: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2558: &mt('username').': '.
2559: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2560: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2561: ': '.$domform.'</span></td></tr>'.
2562: '<tr class="LC_odd_row">'.
2563: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2564: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2565: '<input type="radio" name="autoassign_coowners"'.
2566: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2567: '<label><input type="radio" name="autoassign_coowners"'.
2568: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2569: '</tr>';
2570: $$rowtotal += 3;
1.3 raeburn 2571: return $datatable;
2572: }
2573:
2574: sub print_autoupdate {
1.30 raeburn 2575: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2576: my $datatable;
2577: if ($position eq 'top') {
2578: my $updateon = ' ';
2579: my $updateoff = ' checked="checked" ';
2580: my $classlistson = ' ';
2581: my $classlistsoff = ' checked="checked" ';
2582: if (ref($settings) eq 'HASH') {
2583: if ($settings->{'run'} eq '1') {
2584: $updateon = $updateoff;
2585: $updateoff = ' ';
2586: }
2587: if ($settings->{'classlists'} eq '1') {
2588: $classlistson = $classlistsoff;
2589: $classlistsoff = ' ';
2590: }
2591: }
2592: my %title = (
2593: run => 'Auto-update active?',
2594: classlists => 'Update information in classlists?',
2595: );
2596: $datatable = '<tr class="LC_odd_row">'.
2597: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2598: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2599: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2600: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2601: '<label><input type="radio" name="autoupdate_run"'.
2602: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2603: '</tr><tr>'.
2604: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2605: '<td class="LC_right_item"><span class="LC_nobreak">'.
2606: '<label><input type="radio" name="classlists"'.
2607: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2608: '<label><input type="radio" name="classlists"'.
2609: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2610: '</tr>';
1.30 raeburn 2611: $$rowtotal += 2;
1.131 raeburn 2612: } elsif ($position eq 'middle') {
2613: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2614: my $numinrow = 3;
2615: my $locknamesettings;
2616: $datatable .= &insttypes_row($settings,$types,$usertypes,
2617: $dom,$numinrow,$othertitle,
2618: 'lockablenames');
2619: $$rowtotal ++;
1.3 raeburn 2620: } else {
1.44 raeburn 2621: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2622: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2623: 'permanentemail','id');
1.33 raeburn 2624: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2625: my $numrows = 0;
1.26 raeburn 2626: if (ref($types) eq 'ARRAY') {
2627: if (@{$types} > 0) {
2628: $datatable =
2629: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2630: \@fields,$types,\$numrows);
1.30 raeburn 2631: $$rowtotal += @{$types};
1.26 raeburn 2632: }
1.3 raeburn 2633: }
2634: $datatable .=
2635: &usertype_update_row($settings,{'default' => $othertitle},
2636: \%fieldtitles,\@fields,['default'],
2637: \$numrows);
1.30 raeburn 2638: $$rowtotal ++;
1.3 raeburn 2639: }
2640: return $datatable;
2641: }
2642:
1.125 raeburn 2643: sub print_autocreate {
2644: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2645: my (%createon,%createoff,%currhash);
1.125 raeburn 2646: my @types = ('xml','req');
2647: if (ref($settings) eq 'HASH') {
2648: foreach my $item (@types) {
2649: $createoff{$item} = ' checked="checked" ';
2650: $createon{$item} = ' ';
2651: if (exists($settings->{$item})) {
2652: if ($settings->{$item}) {
2653: $createon{$item} = ' checked="checked" ';
2654: $createoff{$item} = ' ';
2655: }
2656: }
2657: }
1.210 raeburn 2658: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2659: $currhash{$settings->{'xmldc'}} = 1;
2660: }
1.125 raeburn 2661: } else {
2662: foreach my $item (@types) {
2663: $createoff{$item} = ' checked="checked" ';
2664: $createon{$item} = ' ';
2665: }
2666: }
2667: $$rowtotal += 2;
1.191 raeburn 2668: my $numinrow = 2;
1.125 raeburn 2669: my $datatable='<tr class="LC_odd_row">'.
2670: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2671: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2672: '<input type="radio" name="autocreate_xml"'.
2673: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2674: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2675: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2676: '</td></tr><tr>'.
2677: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2678: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2679: '<input type="radio" name="autocreate_req"'.
2680: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2681: '<label><input type="radio" name="autocreate_req"'.
2682: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2683: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2684: 'autocreate_xmldc',%currhash);
1.247 raeburn 2685: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2686: if ($numdc > 1) {
1.247 raeburn 2687: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2688: '</td><td class="LC_left_item">';
1.125 raeburn 2689: } else {
1.247 raeburn 2690: $datatable .= &mt('Course creation processed as:').
2691: '</td><td class="LC_right_item">';
1.125 raeburn 2692: }
1.247 raeburn 2693: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2694: $$rowtotal += $rows;
1.125 raeburn 2695: return $datatable;
2696: }
2697:
1.23 raeburn 2698: sub print_directorysrch {
1.30 raeburn 2699: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2700: my $srchon = ' ';
2701: my $srchoff = ' checked="checked" ';
1.25 raeburn 2702: my ($exacton,$containson,$beginson);
1.24 raeburn 2703: my $localon = ' ';
2704: my $localoff = ' checked="checked" ';
1.23 raeburn 2705: if (ref($settings) eq 'HASH') {
2706: if ($settings->{'available'} eq '1') {
2707: $srchon = $srchoff;
2708: $srchoff = ' ';
2709: }
1.24 raeburn 2710: if ($settings->{'localonly'} eq '1') {
2711: $localon = $localoff;
2712: $localoff = ' ';
2713: }
1.25 raeburn 2714: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2715: foreach my $type (@{$settings->{'searchtypes'}}) {
2716: if ($type eq 'exact') {
2717: $exacton = ' checked="checked" ';
2718: } elsif ($type eq 'contains') {
2719: $containson = ' checked="checked" ';
2720: } elsif ($type eq 'begins') {
2721: $beginson = ' checked="checked" ';
2722: }
2723: }
2724: } else {
2725: if ($settings->{'searchtypes'} eq 'exact') {
2726: $exacton = ' checked="checked" ';
2727: } elsif ($settings->{'searchtypes'} eq 'contains') {
2728: $containson = ' checked="checked" ';
2729: } elsif ($settings->{'searchtypes'} eq 'specify') {
2730: $exacton = ' checked="checked" ';
2731: $containson = ' checked="checked" ';
2732: }
1.23 raeburn 2733: }
2734: }
2735: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2736: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2737:
2738: my $numinrow = 4;
1.26 raeburn 2739: my $cansrchrow = 0;
1.23 raeburn 2740: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2741: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2742: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2743: '<input type="radio" name="dirsrch_available"'.
2744: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2745: '<label><input type="radio" name="dirsrch_available"'.
2746: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2747: '</tr><tr>'.
1.30 raeburn 2748: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2749: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2750: '<input type="radio" name="dirsrch_localonly"'.
2751: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2752: '<label><input type="radio" name="dirsrch_localonly"'.
2753: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2754: '</tr>';
1.30 raeburn 2755: $$rowtotal += 2;
1.26 raeburn 2756: if (ref($usertypes) eq 'HASH') {
2757: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2758: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2759: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2760: $cansrchrow = 1;
2761: }
2762: }
2763: if ($cansrchrow) {
1.30 raeburn 2764: $$rowtotal ++;
1.26 raeburn 2765: $datatable .= '<tr>';
2766: } else {
2767: $datatable .= '<tr class="LC_odd_row">';
2768: }
1.30 raeburn 2769: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2770: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2771: foreach my $title (@{$titleorder}) {
2772: if (defined($searchtitles->{$title})) {
2773: my $check = ' ';
1.93 raeburn 2774: if (ref($settings) eq 'HASH') {
1.39 raeburn 2775: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2776: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2777: $check = ' checked="checked" ';
2778: }
1.25 raeburn 2779: }
2780: }
2781: $datatable .= '<td class="LC_left_item">'.
2782: '<span class="LC_nobreak"><label>'.
2783: '<input type="checkbox" name="searchby" '.
2784: 'value="'.$title.'"'.$check.'/>'.
2785: $searchtitles->{$title}.'</label></span></td>';
2786: }
2787: }
1.26 raeburn 2788: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2789: $$rowtotal ++;
1.26 raeburn 2790: if ($cansrchrow) {
2791: $datatable .= '<tr class="LC_odd_row">';
2792: } else {
2793: $datatable .= '<tr>';
2794: }
1.30 raeburn 2795: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2796: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2797: '<span class="LC_nobreak"><label>'.
2798: '<input type="checkbox" name="searchtypes" '.
2799: $exacton.' value="exact" />'.&mt('Exact match').
2800: '</label> '.
2801: '<label><input type="checkbox" name="searchtypes" '.
2802: $beginson.' value="begins" />'.&mt('Begins with').
2803: '</label> '.
2804: '<label><input type="checkbox" name="searchtypes" '.
2805: $containson.' value="contains" />'.&mt('Contains').
2806: '</label></span></td></tr>';
1.30 raeburn 2807: $$rowtotal ++;
1.25 raeburn 2808: return $datatable;
2809: }
2810:
1.28 raeburn 2811: sub print_contacts {
1.30 raeburn 2812: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2813: my $datatable;
2814: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2815: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2816: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2817: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2818: foreach my $type (@mailings) {
2819: $otheremails{$type} = '';
2820: }
1.134 raeburn 2821: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2822: if (ref($settings) eq 'HASH') {
2823: foreach my $item (@contacts) {
2824: if (exists($settings->{$item})) {
2825: $to{$item} = $settings->{$item};
2826: }
2827: }
2828: foreach my $type (@mailings) {
2829: if (exists($settings->{$type})) {
2830: if (ref($settings->{$type}) eq 'HASH') {
2831: foreach my $item (@contacts) {
2832: if ($settings->{$type}{$item}) {
2833: $checked{$type}{$item} = ' checked="checked" ';
2834: }
2835: }
2836: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2837: if ($type eq 'helpdeskmail') {
2838: $bccemails{$type} = $settings->{$type}{'bcc'};
2839: }
1.28 raeburn 2840: }
1.89 raeburn 2841: } elsif ($type eq 'lonstatusmail') {
2842: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2843: }
2844: }
2845: } else {
2846: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2847: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2848: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2849: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2850: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2851: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2852: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2853: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2854: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2855: }
2856: my ($titles,$short_titles) = &contact_titles();
2857: my $rownum = 0;
2858: my $css_class;
2859: foreach my $item (@contacts) {
1.69 raeburn 2860: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2861: $datatable .= '<tr'.$css_class.'>'.
2862: '<td><span class="LC_nobreak">'.$titles->{$item}.
2863: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2864: '<input type="text" name="'.$item.'" value="'.
2865: $to{$item}.'" /></td></tr>';
1.203 raeburn 2866: $rownum ++;
1.28 raeburn 2867: }
2868: foreach my $type (@mailings) {
1.69 raeburn 2869: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2870: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2871: '<td><span class="LC_nobreak">'.
2872: $titles->{$type}.': </span></td>'.
1.28 raeburn 2873: '<td class="LC_left_item">'.
2874: '<span class="LC_nobreak">';
2875: foreach my $item (@contacts) {
2876: $datatable .= '<label>'.
2877: '<input type="checkbox" name="'.$type.'"'.
2878: $checked{$type}{$item}.
2879: ' value="'.$item.'" />'.$short_titles->{$item}.
2880: '</label> ';
2881: }
2882: $datatable .= '</span><br />'.&mt('Others').': '.
2883: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2884: 'value="'.$otheremails{$type}.'" />';
2885: if ($type eq 'helpdeskmail') {
1.136 raeburn 2886: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2887: '<input type="text" name="'.$type.'_bcc" '.
2888: 'value="'.$bccemails{$type}.'" />';
2889: }
2890: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2891: $rownum ++;
1.28 raeburn 2892: }
1.203 raeburn 2893: my %choices;
2894: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2895: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2896: &mt('LON-CAPA core group - MSU'),600,500));
2897: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2898: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2899: &mt('LON-CAPA core group - MSU'),600,500));
2900: my @toggles = ('reporterrors','reportupdates');
2901: my %defaultchecked = ('reporterrors' => 'on',
2902: 'reportupdates' => 'on');
2903: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2904: \%choices,$rownum);
2905: $datatable .= $reports;
1.30 raeburn 2906: $$rowtotal += $rownum;
1.28 raeburn 2907: return $datatable;
2908: }
2909:
1.118 jms 2910: sub print_helpsettings {
1.168 raeburn 2911: my ($dom,$confname,$settings,$rowtotal) = @_;
2912: my ($datatable,$itemcount);
1.166 raeburn 2913: $itemcount = 1;
1.168 raeburn 2914: my (%choices,%defaultchecked,@toggles);
2915: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2916: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2917: &mt('LON-CAPA bug tracker'),600,500));
2918: %defaultchecked = ('submitbugs' => 'on');
2919: @toggles = ('submitbugs',);
1.166 raeburn 2920:
1.168 raeburn 2921: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2922: \%choices,$itemcount);
1.166 raeburn 2923: return $datatable;
1.121 raeburn 2924: }
2925:
2926: sub radiobutton_prefs {
1.192 raeburn 2927: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 2928: $additional,$align) = @_;
1.121 raeburn 2929: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2930: (ref($choices) eq 'HASH'));
2931:
1.170 raeburn 2932: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2933:
2934: foreach my $item (@{$toggles}) {
2935: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2936: $checkedon{$item} = ' checked="checked" ';
2937: $checkedoff{$item} = ' ';
1.121 raeburn 2938: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2939: $checkedoff{$item} = ' checked="checked" ';
2940: $checkedon{$item} = ' ';
2941: }
2942: }
2943: if (ref($settings) eq 'HASH') {
1.121 raeburn 2944: foreach my $item (@{$toggles}) {
1.118 jms 2945: if ($settings->{$item} eq '1') {
2946: $checkedon{$item} = ' checked="checked" ';
2947: $checkedoff{$item} = ' ';
2948: } elsif ($settings->{$item} eq '0') {
2949: $checkedoff{$item} = ' checked="checked" ';
2950: $checkedon{$item} = ' ';
2951: }
2952: }
1.121 raeburn 2953: }
1.192 raeburn 2954: if ($onclick) {
2955: $onclick = ' onclick="'.$onclick.'"';
2956: }
1.121 raeburn 2957: foreach my $item (@{$toggles}) {
1.118 jms 2958: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2959: $datatable .=
1.192 raeburn 2960: '<tr'.$css_class.'><td valign="top">'.
2961: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 2962: '</span></td>';
2963: if ($align eq 'left') {
2964: $datatable .= '<td class="LC_left_item">';
2965: } else {
2966: $datatable .= '<td class="LC_right_item">';
2967: }
2968: $datatable .=
2969: '<span class="LC_nobreak">'.
1.118 jms 2970: '<label><input type="radio" name="'.
1.192 raeburn 2971: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2972: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2973: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2974: '</span>'.$additional.
2975: '</td>'.
1.118 jms 2976: '</tr>';
2977: $itemcount ++;
1.121 raeburn 2978: }
2979: return ($datatable,$itemcount);
2980: }
2981:
1.267 raeburn 2982: sub print_ltitools {
2983: my ($dom,$settings,$rowtotal) = @_;
2984: my $rownum = 0;
2985: my $css_class;
2986: my $itemcount = 1;
2987: my $maxnum = 0;
2988: my %ordered;
2989: if (ref($settings) eq 'HASH') {
2990: foreach my $item (keys(%{$settings})) {
2991: if (ref($settings->{$item}) eq 'HASH') {
2992: my $num = $settings->{$item}{'order'};
2993: $ordered{$num} = $item;
2994: }
2995: }
2996: }
2997: my $confname = $dom.'-domainconfig';
2998: my $switchserver = &check_switchserver($dom,$confname);
2999: my $maxnum = scalar(keys(%ordered));
3000: my $datatable = <itools_javascript($settings);
3001: my %lt = <itools_names();
3002: my @courseroles = ('cc','in','ta','ep','st');
3003: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3004: my @fields = ('fullname','firstname','lastname','email','user','roles');
3005: if (keys(%ordered)) {
3006: my @items = sort { $a <=> $b } keys(%ordered);
3007: for (my $i=0; $i<@items; $i++) {
3008: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3009: my $item = $ordered{$items[$i]};
3010: my ($title,$key,$secret,$url,$imgsrc,$version);
3011: if (ref($settings->{$item}) eq 'HASH') {
3012: $title = $settings->{$item}->{'title'};
3013: $url = $settings->{$item}->{'url'};
3014: $key = $settings->{$item}->{'key'};
3015: $secret = $settings->{$item}->{'secret'};
3016: my $image = $settings->{$item}->{'image'};
3017: if ($image ne '') {
3018: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3019: }
3020: }
3021: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3022: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3023: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3024: for (my $k=0; $k<=$maxnum; $k++) {
3025: my $vpos = $k+1;
3026: my $selstr;
3027: if ($k == $i) {
3028: $selstr = ' selected="selected" ';
3029: }
3030: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3031: }
3032: $datatable .= '</select>'.(' 'x2).
3033: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3034: &mt('Delete?').'</label></span></td>'.
3035: '<td colspan="2">'.
3036: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3037: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3038: (' 'x2).
3039: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3040: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3041: (' 'x2).
3042: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3043: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3044: '<br /><br />'.
3045: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3046: ' value="'.$url.'" /></span>'.
3047: (' 'x2).
3048: '<span class="LC_nobreak">'.$lt{'key'}.
3049: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3050: (' 'x2).
3051: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3052: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3053: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
3054: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3055: '</fieldset>'.
3056: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3057: '<span class="LC_nobreak">'.&mt('Display target:');
3058: my %currdisp;
3059: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3060: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3061: $currdisp{'window'} = ' checked="checked"';
3062: } else {
3063: $currdisp{'iframe'} = ' checked="checked"';
3064: }
3065: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3066: $currdisp{'width'} = $1;
3067: }
3068: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3069: $currdisp{'height'} = $1;
3070: }
3071: } else {
3072: $currdisp{'iframe'} = ' checked="checked"';
3073: }
3074: foreach my $disp ('iframe','window') {
3075: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3076: $lt{$disp}.'</label>'.(' 'x2);
3077: }
3078: $datatable .= (' 'x4);
3079: foreach my $dimen ('width','height') {
3080: $datatable .= '<label>'.$lt{$dimen}.' '.
3081: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3082: (' 'x2);
3083: }
3084: $datatable .= '<br />';
3085: foreach my $extra ('passback','roster') {
3086: my $checkedon = '';
3087: my $checkedoff = ' checked="checked"';
3088: if ($settings->{$item}->{$extra}) {
3089: $checkedon = $checkedoff;
3090: $checkedoff = '';
3091: }
3092: $datatable .= $lt{$extra}.' '.
3093: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3094: &mt('Yes').'</label>'.(' 'x2).
3095: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3096: &mt('No').'</label>'.(' 'x4);
3097: }
3098: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3099: if ($imgsrc) {
3100: $datatable .= $imgsrc.
3101: '<label><input type="checkbox" name="ltitools_image_del"'.
3102: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3103: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3104: } else {
3105: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3106: }
3107: if ($switchserver) {
3108: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3109: } else {
3110: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3111: }
3112: $datatable .= '</span></fieldset>';
3113: my (%checkedfields,%rolemaps);
3114: if (ref($settings->{$item}) eq 'HASH') {
3115: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3116: %checkedfields = %{$settings->{$item}->{'fields'}};
3117: }
3118: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3119: %rolemaps = %{$settings->{$item}->{'roles'}};
3120: $checkedfields{'roles'} = 1;
3121: }
3122: }
3123: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3124: '<span class="LC_nobreak">';
3125: foreach my $field (@fields) {
3126: my $checked;
3127: if ($checkedfields{$field}) {
3128: $checked = ' checked="checked"';
3129: }
3130: $datatable .= '<label>'.
3131: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3132: $lt{$field}.'</label>'.(' ' x2);
3133: }
3134: $datatable .= '</span></fieldset>'.
3135: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3136: foreach my $role (@courseroles) {
3137: my ($selected,$selectnone);
3138: if (!$rolemaps{$role}) {
3139: $selectnone = ' selected="selected"';
3140: }
3141: $datatable .= '<td align="center">'.
3142: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3143: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3144: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3145: foreach my $ltirole (@ltiroles) {
3146: unless ($selectnone) {
3147: if ($rolemaps{$role} eq $ltirole) {
3148: $selected = ' selected="selected"';
3149: } else {
3150: $selected = '';
3151: }
3152: }
3153: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3154: }
3155: $datatable .= '</select></td>';
3156: }
3157: $datatable .= '</tr></table></fieldset>'.
3158: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3159: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3160: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3161: my %custom = %{$settings->{$item}->{'custom'}};
3162: if (keys(%custom) > 0) {
3163: foreach my $key (sort(keys(%custom))) {
3164: $datatable .= '<tr><td><span class="LC_nobreak">'.
3165: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3166: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3167: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3168: ' value="'.$custom{$key}.'" /></td></tr>';
3169: }
3170: }
3171: }
3172: $datatable .= '<tr><td><span class="LC_nobreak">'.
3173: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3174: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3175: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3176: $datatable .= '</table></fieldset></td></tr>'."\n";
3177: $itemcount ++;
3178: }
3179: }
3180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3181: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3182: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3183: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3184: '<select name="ltitools_add_pos"'.$chgstr.'>';
3185: for (my $k=0; $k<$maxnum+1; $k++) {
3186: my $vpos = $k+1;
3187: my $selstr;
3188: if ($k == $maxnum) {
3189: $selstr = ' selected="selected" ';
3190: }
3191: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3192: }
3193: $datatable .= '</select> '."\n".
3194: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3195: '<td colspan="2">'.
3196: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3197: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3198: (' 'x2).
3199: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3200: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3201: (' 'x2).
3202: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3203: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3204: '<br />'.
3205: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3206: (' 'x2).
3207: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3208: (' 'x2).
3209: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3210: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
3211: '</fieldset>'.
3212: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3213: '<span class="LC_nobreak">'.&mt('Display target:');
3214: my %defaultdisp;
3215: $defaultdisp{'iframe'} = ' checked="checked"';
3216: foreach my $disp ('iframe','window') {
3217: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3218: $lt{$disp}.'</label>'.(' 'x2);
3219: }
3220: $datatable .= (' 'x4);
3221: foreach my $dimen ('width','height') {
3222: $datatable .= '<label>'.$lt{$dimen}.' '.
3223: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3224: (' 'x2);
3225: }
3226: $datatable .= '<br />';
3227: foreach my $extra ('passback','roster') {
3228: $datatable .= $lt{$extra}.' '.
3229: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3230: &mt('Yes').'</label>'.(' 'x2).
3231: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3232: &mt('No').'</label>'.(' 'x4);
3233: }
3234: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3235: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3236: if ($switchserver) {
3237: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3238: } else {
3239: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3240: }
3241: $datatable .= '</span></fieldset>'.
3242: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3243: '<span class="LC_nobreak">';
3244: foreach my $field (@fields) {
3245: $datatable .= '<label>'.
3246: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3247: $lt{$field}.'</label>'.(' ' x2);
3248: }
3249: $datatable .= '</span></fieldset>'.
3250: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3251: foreach my $role (@courseroles) {
3252: my ($checked,$checkednone);
3253: $datatable .= '<td align="center">'.
3254: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3255: '<select name="ltitools_add_roles_'.$role.'">'.
3256: '<option value="" selected="selected">'.&mt('Select').'</option>';
3257: foreach my $ltirole (@ltiroles) {
3258: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3259: }
3260: $datatable .= '</select></td>';
3261: }
3262: $datatable .= '</tr></table></fieldset>'.
3263: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3264: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3265: '<tr><td><span class="LC_nobreak">'.
3266: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3267: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3268: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3269: '</table></fieldset></td></tr>'."\n".
3270: '</td>'."\n".
3271: '</tr>'."\n";
3272: $itemcount ++;
3273: return $datatable;
3274: }
3275:
3276: sub ltitools_names {
3277: my %lt = &Apache::lonlocal::texthash(
3278: 'title' => 'Title',
3279: 'version' => 'Version',
3280: 'msgtype' => 'Message Type',
3281: 'url' => 'URL',
3282: 'key' => 'Key',
3283: 'secret' => 'Secret',
3284: 'icon' => 'Icon',
3285: 'user' => 'Username:domain',
3286: 'fullname' => 'Full Name',
3287: 'firstname' => 'First Name',
3288: 'lastname' => 'Last Name',
3289: 'email' => 'E-mail',
3290: 'roles' => 'Role',
3291: 'window' => 'Window/Tab',
3292: 'iframe' => 'iFrame',
3293: 'height' => 'Height',
3294: 'width' => 'Width',
3295: 'passback' => 'Tool can return grades:',
3296: 'roster' => 'Tool can retrieve roster:',
3297: );
3298: return %lt;
3299: }
3300:
1.121 raeburn 3301: sub print_coursedefaults {
1.139 raeburn 3302: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 3303: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3304: my $itemcount = 1;
1.192 raeburn 3305: my %choices = &Apache::lonlocal::texthash (
3306: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 3307: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 3308: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3309: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 3310: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3311: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3312: postsubmit => 'Disable submit button/keypress following student submission',
1.264 raeburn 3313: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.192 raeburn 3314: );
1.198 raeburn 3315: my %staticdefaults = (
3316: anonsurvey_threshold => 10,
3317: uploadquota => 500,
1.257 raeburn 3318: postsubmit => 60,
1.198 raeburn 3319: );
1.139 raeburn 3320: if ($position eq 'top') {
1.257 raeburn 3321: %defaultchecked = (
3322: 'canuse_pdfforms' => 'off',
3323: 'uselcmath' => 'on',
3324: 'usejsme' => 'on',
1.264 raeburn 3325: 'canclone' => 'none',
1.257 raeburn 3326: );
3327: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 3328: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 3329: \%choices,$itemcount);
1.264 raeburn 3330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3331: $datatable .=
3332: '<tr'.$css_class.'><td valign="top">'.
3333: '<span class="LC_nobreak">'.$choices{'canclone'}.
3334: '</span></td><td class="LC_left_item">';
3335: my $currcanclone = 'none';
3336: my $onclick;
3337: my @cloneoptions = ('none','domain');
3338: my %clonetitles = (
3339: none => 'No additional course requesters',
3340: domain => "Any course requester in course's domain",
3341: instcode => 'Course requests for official courses ...',
3342: );
3343: my (%codedefaults,@code_order,@posscodes);
3344: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3345: \@code_order) eq 'ok') {
3346: if (@code_order > 0) {
3347: push(@cloneoptions,'instcode');
3348: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3349: }
3350: }
3351: if (ref($settings) eq 'HASH') {
3352: if ($settings->{'canclone'}) {
3353: if (ref($settings->{'canclone'}) eq 'HASH') {
3354: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3355: if (@code_order > 0) {
3356: $currcanclone = 'instcode';
3357: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3358: }
3359: }
3360: } elsif ($settings->{'canclone'} eq 'domain') {
3361: $currcanclone = $settings->{'canclone'};
3362: }
3363: }
3364: }
3365: foreach my $option (@cloneoptions) {
3366: my ($checked,$additional);
3367: if ($currcanclone eq $option) {
3368: $checked = ' checked="checked"';
3369: }
3370: if ($option eq 'instcode') {
3371: if (@code_order) {
3372: my $show = 'none';
3373: if ($checked) {
3374: $show = 'block';
3375: }
3376: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3377: &mt('Institutional codes for new and cloned course have identical:').
3378: '<br />';
3379: foreach my $item (@code_order) {
3380: my $codechk;
3381: if ($checked) {
3382: if (grep(/^\Q$item\E$/,@posscodes)) {
3383: $codechk = ' checked="checked"';
3384: }
3385: }
3386: $additional .= '<label>'.
3387: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3388: $item.'</label>';
3389: }
3390: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3391: }
3392: }
3393: $datatable .=
3394: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3395: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3396: '</label> '.$additional.'</span><br />';
3397: }
3398: $datatable .= '</td>'.
3399: '</tr>';
3400: $itemcount ++;
1.139 raeburn 3401: } else {
3402: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.257 raeburn 3403: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.192 raeburn 3404: my $currusecredits = 0;
1.257 raeburn 3405: my $postsubmitclient = 1;
1.271 ! raeburn 3406: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 3407: if (ref($settings) eq 'HASH') {
3408: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 3409: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3410: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3411: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3412: }
3413: }
1.192 raeburn 3414: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 3415: foreach my $type (@types) {
3416: next if ($type eq 'community');
3417: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3418: if ($defcredits{$type} ne '') {
3419: $currusecredits = 1;
3420: }
3421: }
3422: }
3423: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3424: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3425: $postsubmitclient = 0;
3426: foreach my $type (@types) {
3427: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3428: }
3429: } else {
3430: foreach my $type (@types) {
3431: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3432: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3433: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3434: } else {
3435: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3436: }
3437: } else {
3438: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3439: }
3440: }
3441: }
3442: } else {
3443: foreach my $type (@types) {
3444: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 3445: }
3446: }
1.258 raeburn 3447: } else {
3448: foreach my $type (@types) {
3449: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3450: }
1.139 raeburn 3451: }
3452: if (!$currdefresponder) {
1.198 raeburn 3453: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3454: } elsif ($currdefresponder < 1) {
3455: $currdefresponder = 1;
3456: }
1.198 raeburn 3457: foreach my $type (@types) {
3458: if ($curruploadquota{$type} eq '') {
3459: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3460: }
3461: }
1.139 raeburn 3462: $datatable .=
1.192 raeburn 3463: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3464: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3465: '</span></td>'.
3466: '<td class="LC_right_item"><span class="LC_nobreak">'.
3467: '<input type="text" name="anonsurvey_threshold"'.
3468: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 3469: '</td></tr>'."\n";
3470: $itemcount ++;
3471: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3472: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3473: $choices{'uploadquota'}.
3474: '</span></td>'.
3475: '<td align="right" class="LC_right_item">'.
3476: '<table><tr>';
1.198 raeburn 3477: foreach my $type (@types) {
3478: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3479: '<input type="text" name="uploadquota_'.$type.'"'.
3480: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3481: }
3482: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 3483: $itemcount ++;
1.236 raeburn 3484: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 3485: my $display = 'none';
1.192 raeburn 3486: if ($currusecredits) {
3487: $display = 'block';
3488: }
3489: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 3490: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3491: foreach my $type (@types) {
3492: next if ($type eq 'community');
3493: $additional .= '<td align="center">'.&mt($type).'<br />'.
3494: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 3495: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 3496: }
3497: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 3498: %defaultchecked = ('coursecredits' => 'off');
3499: @toggles = ('coursecredits');
3500: my $current = {
3501: 'coursecredits' => $currusecredits,
3502: };
3503: (my $table,$itemcount) =
3504: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 3505: \%choices,$itemcount,$onclick,$additional,'left');
3506: $datatable .= $table;
3507: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3508: my $display = 'none';
3509: if ($postsubmitclient) {
3510: $display = 'block';
3511: }
3512: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 3513: &mt('Number of seconds submit is disabled').'<br />'.
3514: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3515: '<table><tr>';
1.257 raeburn 3516: foreach my $type (@types) {
3517: $additional .= '<td align="center">'.&mt($type).'<br />'.
3518: '<input type="text" name="'.$type.'_timeout" value="'.
3519: $deftimeout{$type}.'" size="5" /></td>';
3520: }
3521: $additional .= '</tr></table></div>'."\n";
3522: %defaultchecked = ('postsubmit' => 'on');
3523: @toggles = ('postsubmit');
3524: my $current = {
3525: 'postsubmit' => $postsubmitclient,
3526: };
3527: ($table,$itemcount) =
3528: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3529: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 3530: $datatable .= $table;
1.139 raeburn 3531: }
1.192 raeburn 3532: $$rowtotal += $itemcount;
1.121 raeburn 3533: return $datatable;
1.118 jms 3534: }
3535:
1.231 raeburn 3536: sub print_selfenrollment {
3537: my ($position,$dom,$settings,$rowtotal) = @_;
3538: my ($css_class,$datatable);
3539: my $itemcount = 1;
1.271 ! raeburn 3540: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 3541: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 3542: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3543: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 3544: my @rows;
3545: my $key;
3546: if ($position eq 'top') {
3547: $key = 'admin';
3548: if (ref($rowsref) eq 'ARRAY') {
3549: @rows = @{$rowsref};
3550: }
3551: } elsif ($position eq 'middle') {
3552: $key = 'default';
3553: @rows = ('types','registered','approval','limit');
3554: }
3555: foreach my $row (@rows) {
3556: if (defined($titlesref->{$row})) {
3557: $itemcount ++;
3558: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3559: $datatable .= '<tr'.$css_class.'>'.
3560: '<td>'.$titlesref->{$row}.'</td>'.
3561: '<td class="LC_left_item">'.
3562: '<table><tr>';
3563: my (%current,%currentcap);
3564: if (ref($settings) eq 'HASH') {
3565: if (ref($settings->{$key}) eq 'HASH') {
3566: foreach my $type (@types) {
3567: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3568: $current{$type} = $settings->{$key}->{$type}->{$row};
3569: }
3570: if (($row eq 'limit') && ($key eq 'default')) {
3571: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3572: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3573: }
3574: }
3575: }
3576: }
3577: }
3578: my %roles = (
3579: '0' => &Apache::lonnet::plaintext('dc'),
3580: );
3581:
3582: foreach my $type (@types) {
3583: unless (($row eq 'registered') && ($key eq 'default')) {
3584: $datatable .= '<th>'.&mt($type).'</th>';
3585: }
3586: }
3587: unless (($row eq 'registered') && ($key eq 'default')) {
3588: $datatable .= '</tr><tr>';
3589: }
3590: foreach my $type (@types) {
3591: if ($type eq 'community') {
3592: $roles{'1'} = &mt('Community personnel');
3593: } else {
3594: $roles{'1'} = &mt('Course personnel');
3595: }
3596: $datatable .= '<td style="vertical-align: top">';
3597: if ($position eq 'top') {
3598: my %checked;
3599: if ($current{$type} eq '0') {
3600: $checked{'0'} = ' checked="checked"';
3601: } else {
3602: $checked{'1'} = ' checked="checked"';
3603: }
3604: foreach my $role ('1','0') {
3605: $datatable .= '<span class="LC_nobreak"><label>'.
3606: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3607: 'value="'.$role.'"'.$checked{$role}.' />'.
3608: $roles{$role}.'</label></span> ';
3609: }
3610: } else {
3611: if ($row eq 'types') {
3612: my %checked;
3613: if ($current{$type} =~ /^(all|dom)$/) {
3614: $checked{$1} = ' checked="checked"';
3615: } else {
3616: $checked{''} = ' checked="checked"';
3617: }
3618: foreach my $val ('','dom','all') {
3619: $datatable .= '<span class="LC_nobreak"><label>'.
3620: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3621: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3622: }
3623: } elsif ($row eq 'registered') {
3624: my %checked;
3625: if ($current{$type} eq '1') {
3626: $checked{'1'} = ' checked="checked"';
3627: } else {
3628: $checked{'0'} = ' checked="checked"';
3629: }
3630: foreach my $val ('0','1') {
3631: $datatable .= '<span class="LC_nobreak"><label>'.
3632: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3633: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3634: }
3635: } elsif ($row eq 'approval') {
3636: my %checked;
3637: if ($current{$type} =~ /^([12])$/) {
3638: $checked{$1} = ' checked="checked"';
3639: } else {
3640: $checked{'0'} = ' checked="checked"';
3641: }
3642: for my $val (0..2) {
3643: $datatable .= '<span class="LC_nobreak"><label>'.
3644: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3645: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3646: }
3647: } elsif ($row eq 'limit') {
3648: my %checked;
3649: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3650: $checked{$1} = ' checked="checked"';
3651: } else {
3652: $checked{'none'} = ' checked="checked"';
3653: }
3654: my $cap;
3655: if ($currentcap{$type} =~ /^\d+$/) {
3656: $cap = $currentcap{$type};
3657: }
3658: foreach my $val ('none','allstudents','selfenrolled') {
3659: $datatable .= '<span class="LC_nobreak"><label>'.
3660: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3661: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3662: }
3663: $datatable .= '<br />'.
3664: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3665: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3666: '</span>';
3667: }
3668: }
3669: $datatable .= '</td>';
3670: }
3671: $datatable .= '</tr>';
3672: }
3673: $datatable .= '</table></td></tr>';
3674: }
3675: } elsif ($position eq 'bottom') {
1.235 raeburn 3676: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3677: }
3678: $$rowtotal += $itemcount;
3679: return $datatable;
3680: }
3681:
3682: sub print_validation_rows {
3683: my ($caller,$dom,$settings,$rowtotal) = @_;
3684: my ($itemsref,$namesref,$fieldsref);
3685: if ($caller eq 'selfenroll') {
3686: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3687: } elsif ($caller eq 'requestcourses') {
3688: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3689: }
3690: my %currvalidation;
3691: if (ref($settings) eq 'HASH') {
3692: if (ref($settings->{'validation'}) eq 'HASH') {
3693: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 3694: }
1.235 raeburn 3695: }
3696: my $datatable;
3697: my $itemcount = 0;
3698: foreach my $item (@{$itemsref}) {
3699: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3700: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3701: $namesref->{$item}.
3702: '</span></td>'.
3703: '<td class="LC_left_item">';
3704: if (($item eq 'url') || ($item eq 'button')) {
3705: $datatable .= '<span class="LC_nobreak">'.
3706: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3707: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3708: } elsif ($item eq 'fields') {
3709: my @currfields;
3710: if (ref($currvalidation{$item}) eq 'ARRAY') {
3711: @currfields = @{$currvalidation{$item}};
3712: }
3713: foreach my $field (@{$fieldsref}) {
3714: my $check = '';
3715: if (grep(/^\Q$field\E$/,@currfields)) {
3716: $check = ' checked="checked"';
3717: }
3718: $datatable .= '<span class="LC_nobreak"><label>'.
3719: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3720: ' value="'.$field.'"'.$check.' />'.$field.
3721: '</label></span> ';
3722: }
3723: } elsif ($item eq 'markup') {
3724: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3725: $currvalidation{$item}.
1.231 raeburn 3726: '</textarea>';
1.235 raeburn 3727: }
3728: $datatable .= '</td></tr>'."\n";
3729: if (ref($rowtotal)) {
1.231 raeburn 3730: $itemcount ++;
3731: }
3732: }
1.235 raeburn 3733: if ($caller eq 'requestcourses') {
3734: my %currhash;
1.248 raeburn 3735: if (ref($settings) eq 'HASH') {
3736: if (ref($settings->{'validation'}) eq 'HASH') {
3737: if ($settings->{'validation'}{'dc'} ne '') {
3738: $currhash{$settings->{'validation'}{'dc'}} = 1;
3739: }
1.235 raeburn 3740: }
3741: }
3742: my $numinrow = 2;
3743: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3744: 'validationdc',%currhash);
1.247 raeburn 3745: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3746: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 3747: if ($numdc > 1) {
1.247 raeburn 3748: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 3749: } else {
1.247 raeburn 3750: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 3751: }
1.247 raeburn 3752: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 3753: $itemcount ++;
3754: }
3755: if (ref($rowtotal)) {
3756: $$rowtotal += $itemcount;
3757: }
1.231 raeburn 3758: return $datatable;
3759: }
3760:
1.137 raeburn 3761: sub print_usersessions {
3762: my ($position,$dom,$settings,$rowtotal) = @_;
3763: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3764: my (%by_ip,%by_location,@intdoms);
3765: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3766:
3767: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3768: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3769: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3770: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3771: my $itemcount = 1;
3772: if ($position eq 'top') {
1.152 raeburn 3773: if (keys(%serverhomes) > 1) {
1.145 raeburn 3774: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 3775: my $curroffloadnow;
3776: if (ref($settings) eq 'HASH') {
3777: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3778: $curroffloadnow = $settings->{'offloadnow'};
3779: }
3780: }
3781: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3782: } else {
1.140 raeburn 3783: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3784: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3785: }
1.137 raeburn 3786: } else {
1.145 raeburn 3787: if (keys(%by_location) == 0) {
3788: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3789: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3790: } else {
3791: my %lt = &usersession_titles();
3792: my $numinrow = 5;
3793: my $prefix;
3794: my @types;
3795: if ($position eq 'bottom') {
3796: $prefix = 'remote';
3797: @types = ('version','excludedomain','includedomain');
3798: } else {
3799: $prefix = 'hosted';
3800: @types = ('excludedomain','includedomain');
3801: }
3802: my (%current,%checkedon,%checkedoff);
3803: my @lcversions = &Apache::lonnet::all_loncaparevs();
3804: my @locations = sort(keys(%by_location));
3805: foreach my $type (@types) {
3806: $checkedon{$type} = '';
3807: $checkedoff{$type} = ' checked="checked"';
3808: }
3809: if (ref($settings) eq 'HASH') {
3810: if (ref($settings->{$prefix}) eq 'HASH') {
3811: foreach my $key (keys(%{$settings->{$prefix}})) {
3812: $current{$key} = $settings->{$prefix}{$key};
3813: if ($key eq 'version') {
3814: if ($current{$key} ne '') {
3815: $checkedon{$key} = ' checked="checked"';
3816: $checkedoff{$key} = '';
3817: }
3818: } elsif (ref($current{$key}) eq 'ARRAY') {
3819: $checkedon{$key} = ' checked="checked"';
3820: $checkedoff{$key} = '';
3821: }
1.137 raeburn 3822: }
3823: }
3824: }
1.145 raeburn 3825: foreach my $type (@types) {
3826: next if ($type ne 'version' && !@locations);
3827: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3828: $datatable .= '<tr'.$css_class.'>
3829: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
3830: <span class="LC_nobreak">
3831: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
3832: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
3833: if ($type eq 'version') {
3834: my $selector = '<select name="'.$prefix.'_version">';
3835: foreach my $version (@lcversions) {
3836: my $selected = '';
3837: if ($current{'version'} eq $version) {
3838: $selected = ' selected="selected"';
3839: }
3840: $selector .= ' <option value="'.$version.'"'.
3841: $selected.'>'.$version.'</option>';
3842: }
3843: $selector .= '</select> ';
3844: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
3845: } else {
3846: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
3847: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
3848: ' />'.(' 'x2).
3849: '<input type="button" value="'.&mt('uncheck all').'" '.
3850: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
3851: "\n".
3852: '</div><div><table>';
3853: my $rem;
3854: for (my $i=0; $i<@locations; $i++) {
3855: my ($showloc,$value,$checkedtype);
3856: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
3857: my $ip = $by_location{$locations[$i]}->[0];
3858: if (ref($by_ip{$ip}) eq 'ARRAY') {
3859: $value = join(':',@{$by_ip{$ip}});
3860: $showloc = join(', ',@{$by_ip{$ip}});
3861: if (ref($current{$type}) eq 'ARRAY') {
3862: foreach my $loc (@{$by_ip{$ip}}) {
3863: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
3864: $checkedtype = ' checked="checked"';
3865: last;
3866: }
3867: }
1.138 raeburn 3868: }
3869: }
3870: }
1.145 raeburn 3871: $rem = $i%($numinrow);
3872: if ($rem == 0) {
3873: if ($i > 0) {
3874: $datatable .= '</tr>';
3875: }
3876: $datatable .= '<tr>';
3877: }
3878: $datatable .= '<td class="LC_left_item">'.
3879: '<span class="LC_nobreak"><label>'.
3880: '<input type="checkbox" name="'.$prefix.'_'.$type.
3881: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
3882: '</label></span></td>';
1.137 raeburn 3883: }
1.145 raeburn 3884: $rem = @locations%($numinrow);
3885: my $colsleft = $numinrow - $rem;
3886: if ($colsleft > 1 ) {
3887: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3888: ' </td>';
3889: } elsif ($colsleft == 1) {
3890: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 3891: }
1.145 raeburn 3892: $datatable .= '</tr></table>';
1.137 raeburn 3893: }
1.145 raeburn 3894: $datatable .= '</td></tr>';
3895: $itemcount ++;
1.137 raeburn 3896: }
3897: }
3898: }
3899: $$rowtotal += $itemcount;
3900: return $datatable;
3901: }
3902:
1.138 raeburn 3903: sub build_location_hashes {
3904: my ($intdoms,$by_ip,$by_location) = @_;
3905: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
3906: (ref($by_location) eq 'HASH'));
3907: my %iphost = &Apache::lonnet::get_iphost();
3908: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
3909: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
3910: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
3911: foreach my $id (@{$iphost{$primary_ip}}) {
3912: my $intdom = &Apache::lonnet::internet_dom($id);
3913: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
3914: push(@{$intdoms},$intdom);
3915: }
3916: }
3917: }
3918: foreach my $ip (keys(%iphost)) {
3919: if (ref($iphost{$ip}) eq 'ARRAY') {
3920: foreach my $id (@{$iphost{$ip}}) {
3921: my $location = &Apache::lonnet::internet_dom($id);
3922: if ($location) {
3923: next if (grep(/^\Q$location\E$/,@{$intdoms}));
3924: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3925: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
3926: push(@{$by_ip->{$ip}},$location);
3927: }
3928: } else {
3929: $by_ip->{$ip} = [$location];
3930: }
3931: }
3932: }
3933: }
3934: }
3935: foreach my $ip (sort(keys(%{$by_ip}))) {
3936: if (ref($by_ip->{$ip}) eq 'ARRAY') {
3937: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
3938: my $first = $by_ip->{$ip}->[0];
3939: if (ref($by_location->{$first}) eq 'ARRAY') {
3940: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
3941: push(@{$by_location->{$first}},$ip);
3942: }
3943: } else {
3944: $by_location->{$first} = [$ip];
3945: }
3946: }
3947: }
3948: return;
3949: }
3950:
1.145 raeburn 3951: sub current_offloads_to {
3952: my ($dom,$settings,$servers) = @_;
3953: my (%spareid,%otherdomconfigs);
1.152 raeburn 3954: if (ref($servers) eq 'HASH') {
1.145 raeburn 3955: foreach my $lonhost (sort(keys(%{$servers}))) {
3956: my $gotspares;
1.152 raeburn 3957: if (ref($settings) eq 'HASH') {
3958: if (ref($settings->{'spares'}) eq 'HASH') {
3959: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
3960: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
3961: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
3962: $gotspares = 1;
3963: }
1.145 raeburn 3964: }
3965: }
3966: unless ($gotspares) {
3967: my $gotspares;
3968: my $serverhomeID =
3969: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
3970: my $serverhomedom =
3971: &Apache::lonnet::host_domain($serverhomeID);
3972: if ($serverhomedom ne $dom) {
3973: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
3974: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3975: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3976: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3977: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3978: $gotspares = 1;
3979: }
3980: }
3981: } else {
3982: $otherdomconfigs{$serverhomedom} =
3983: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
3984: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
3985: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
3986: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
3987: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
3988: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
3989: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
3990: $gotspares = 1;
3991: }
3992: }
3993: }
3994: }
3995: }
3996: }
3997: }
3998: unless ($gotspares) {
3999: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4000: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4001: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4002: } else {
4003: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4004: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4005: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4006: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4007: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4008: } else {
1.150 raeburn 4009: my %what = (
4010: spareid => 1,
4011: );
4012: my ($result,$returnhash) =
4013: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4014: if ($result eq 'ok') {
4015: if (ref($returnhash) eq 'HASH') {
4016: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4017: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4018: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4019: }
4020: }
1.145 raeburn 4021: }
4022: }
4023: }
4024: }
4025: }
4026: }
4027: return %spareid;
4028: }
4029:
4030: sub spares_row {
1.261 raeburn 4031: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4032: my $css_class;
4033: my $numinrow = 4;
4034: my $itemcount = 1;
4035: my $datatable;
1.152 raeburn 4036: my %typetitles = &sparestype_titles();
4037: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4038: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4039: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4040: my ($othercontrol,$serverdom);
4041: if ($serverhome ne $server) {
4042: $serverdom = &Apache::lonnet::host_domain($serverhome);
4043: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4044: } else {
4045: $serverdom = &Apache::lonnet::host_domain($server);
4046: if ($serverdom ne $dom) {
4047: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4048: }
4049: }
4050: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4051: my $checkednow;
4052: if (ref($curroffloadnow) eq 'HASH') {
4053: if ($curroffloadnow->{$server}) {
4054: $checkednow = ' checked="checked"';
4055: }
4056: }
1.145 raeburn 4057: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4058: $datatable .= '<tr'.$css_class.'>
4059: <td rowspan="2">
1.183 bisitz 4060: <span class="LC_nobreak">'.
4061: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4062: ,'<b>'.$server.'</b>').'</span><br />'.
4063: '<span class="LC_nobreak">'."\n".
4064: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4065: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4066: "\n";
1.145 raeburn 4067: my (%current,%canselect);
1.152 raeburn 4068: my @choices =
4069: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4070: foreach my $type ('primary','default') {
4071: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4072: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4073: my @spares = @{$spareid->{$server}{$type}};
4074: if (@spares > 0) {
1.152 raeburn 4075: if ($othercontrol) {
4076: $current{$type} = join(', ',@spares);
4077: } else {
4078: $current{$type} .= '<table>';
4079: my $numspares = scalar(@spares);
4080: for (my $i=0; $i<@spares; $i++) {
4081: my $rem = $i%($numinrow);
4082: if ($rem == 0) {
4083: if ($i > 0) {
4084: $current{$type} .= '</tr>';
4085: }
4086: $current{$type} .= '<tr>';
1.145 raeburn 4087: }
1.152 raeburn 4088: $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'".');" /> '.
4089: $spareid->{$server}{$type}[$i].
4090: '</label></td>'."\n";
4091: }
4092: my $rem = @spares%($numinrow);
4093: my $colsleft = $numinrow - $rem;
4094: if ($colsleft > 1 ) {
4095: $current{$type} .= '<td colspan="'.$colsleft.
4096: '" class="LC_left_item">'.
4097: ' </td>';
4098: } elsif ($colsleft == 1) {
4099: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4100: }
1.152 raeburn 4101: $current{$type} .= '</tr></table>';
1.150 raeburn 4102: }
1.145 raeburn 4103: }
4104: }
4105: if ($current{$type} eq '') {
4106: $current{$type} = &mt('None specified');
4107: }
1.152 raeburn 4108: if ($othercontrol) {
4109: if ($type eq 'primary') {
4110: $canselect{$type} = $othercontrol;
4111: }
4112: } else {
4113: $canselect{$type} =
4114: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4115: '<select name="newspare_'.$type.'_'.$server.'" '.
4116: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4117: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4118: if (@choices > 0) {
4119: foreach my $lonhost (@choices) {
4120: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4121: }
4122: }
4123: $canselect{$type} .= '</select>'."\n";
4124: }
4125: } else {
4126: $current{$type} = &mt('Could not be determined');
4127: if ($type eq 'primary') {
4128: $canselect{$type} = $othercontrol;
4129: }
1.145 raeburn 4130: }
1.152 raeburn 4131: if ($type eq 'default') {
4132: $datatable .= '<tr'.$css_class.'>';
4133: }
4134: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4135: '<td>'.$current{$type}.'</td>'."\n".
4136: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4137: }
4138: $itemcount ++;
4139: }
4140: }
4141: $$rowtotal += $itemcount;
4142: return $datatable;
4143: }
4144:
1.152 raeburn 4145: sub possible_newspares {
4146: my ($server,$currspares,$serverhomes,$altids) = @_;
4147: my $serverhostname = &Apache::lonnet::hostname($server);
4148: my %excluded;
4149: if ($serverhostname ne '') {
4150: %excluded = (
4151: $serverhostname => 1,
4152: );
4153: }
4154: if (ref($currspares) eq 'HASH') {
4155: foreach my $type (keys(%{$currspares})) {
4156: if (ref($currspares->{$type}) eq 'ARRAY') {
4157: if (@{$currspares->{$type}} > 0) {
4158: foreach my $curr (@{$currspares->{$type}}) {
4159: my $hostname = &Apache::lonnet::hostname($curr);
4160: $excluded{$hostname} = 1;
4161: }
4162: }
4163: }
4164: }
4165: }
4166: my @choices;
4167: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4168: if (keys(%{$serverhomes}) > 1) {
4169: foreach my $name (sort(keys(%{$serverhomes}))) {
4170: unless ($excluded{$name}) {
4171: if (exists($altids->{$serverhomes->{$name}})) {
4172: push(@choices,$altids->{$serverhomes->{$name}});
4173: } else {
4174: push(@choices,$serverhomes->{$name});
1.145 raeburn 4175: }
4176: }
4177: }
4178: }
4179: }
1.152 raeburn 4180: return sort(@choices);
1.145 raeburn 4181: }
4182:
1.150 raeburn 4183: sub print_loadbalancing {
4184: my ($dom,$settings,$rowtotal) = @_;
4185: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4186: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4187: my $numinrow = 1;
4188: my $datatable;
4189: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 4190: my (%currbalancer,%currtargets,%currrules,%existing);
4191: if (ref($settings) eq 'HASH') {
4192: %existing = %{$settings};
4193: }
4194: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4195: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4196: \%currtargets,\%currrules);
1.150 raeburn 4197: } else {
4198: return;
4199: }
4200: my ($othertitle,$usertypes,$types) =
4201: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 4202: my $rownum = 8;
1.150 raeburn 4203: if (ref($types) eq 'ARRAY') {
4204: $rownum += scalar(@{$types});
4205: }
1.171 raeburn 4206: my @css_class = ('LC_odd_row','LC_even_row');
4207: my $balnum = 0;
4208: my $islast;
4209: my (@toshow,$disabledtext);
4210: if (keys(%currbalancer) > 0) {
4211: @toshow = sort(keys(%currbalancer));
4212: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4213: push(@toshow,'');
4214: }
4215: } else {
4216: @toshow = ('');
4217: $disabledtext = &mt('No existing load balancer');
4218: }
4219: foreach my $lonhost (@toshow) {
4220: if ($balnum == scalar(@toshow)-1) {
4221: $islast = 1;
4222: } else {
4223: $islast = 0;
4224: }
4225: my $cssidx = $balnum%2;
4226: my $targets_div_style = 'display: none';
4227: my $disabled_div_style = 'display: block';
4228: my $homedom_div_style = 'display: none';
4229: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4230: '<td rowspan="'.$rownum.'" valign="top">'.
4231: '<p>';
4232: if ($lonhost eq '') {
1.210 raeburn 4233: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 4234: if (keys(%currbalancer) > 0) {
4235: $datatable .= &mt('Add balancer:');
4236: } else {
4237: $datatable .= &mt('Enable balancer:');
4238: }
4239: $datatable .= ' '.
4240: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4241: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4242: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4243: '<option value="" selected="selected">'.&mt('None').
4244: '</option>'."\n";
4245: foreach my $server (sort(keys(%servers))) {
4246: next if ($currbalancer{$server});
4247: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4248: }
1.210 raeburn 4249: $datatable .=
1.171 raeburn 4250: '</select>'."\n".
4251: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4252: } else {
4253: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4254: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4255: &mt('Stop balancing').'</label>'.
4256: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4257: $targets_div_style = 'display: block';
4258: $disabled_div_style = 'display: none';
4259: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4260: $homedom_div_style = 'display: block';
4261: }
4262: }
4263: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4264: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4265: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4266: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4267: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4268: my @sparestypes = ('primary','default');
4269: my %typetitles = &sparestype_titles();
4270: foreach my $sparetype (@sparestypes) {
4271: my $targettable;
4272: for (my $i=0; $i<$numspares; $i++) {
4273: my $checked;
4274: if (ref($currtargets{$lonhost}) eq 'HASH') {
4275: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4276: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4277: $checked = ' checked="checked"';
4278: }
4279: }
4280: }
4281: my ($chkboxval,$disabled);
4282: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4283: $chkboxval = $spares[$i];
4284: }
4285: if (exists($currbalancer{$spares[$i]})) {
4286: $disabled = ' disabled="disabled"';
4287: }
1.210 raeburn 4288: $targettable .=
1.253 raeburn 4289: '<td><span class="LC_nobreak"><label>'.
4290: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 4291: $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 4292: '</span></label></span></td>';
1.171 raeburn 4293: my $rem = $i%($numinrow);
4294: if ($rem == 0) {
4295: if (($i > 0) && ($i < $numspares-1)) {
4296: $targettable .= '</tr>';
4297: }
4298: if ($i < $numspares-1) {
4299: $targettable .= '<tr>';
1.150 raeburn 4300: }
4301: }
4302: }
1.171 raeburn 4303: if ($targettable ne '') {
4304: my $rem = $numspares%($numinrow);
4305: my $colsleft = $numinrow - $rem;
4306: if ($colsleft > 1 ) {
4307: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4308: ' </td>';
4309: } elsif ($colsleft == 1) {
4310: $targettable .= '<td class="LC_left_item"> </td>';
4311: }
4312: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4313: '<table><tr>'.$targettable.'</tr></table><br />';
4314: }
4315: }
4316: $datatable .= '</div></td></tr>'.
4317: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4318: $othertitle,$usertypes,$types,\%servers,
4319: \%currbalancer,$lonhost,
4320: $targets_div_style,$homedom_div_style,
4321: $css_class[$cssidx],$balnum,$islast);
4322: $$rowtotal += $rownum;
4323: $balnum ++;
4324: }
4325: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4326: return $datatable;
4327: }
4328:
4329: sub get_loadbalancers_config {
4330: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4331: return unless ((ref($servers) eq 'HASH') &&
4332: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4333: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4334: if (keys(%{$existing}) > 0) {
4335: my $oldlonhost;
4336: foreach my $key (sort(keys(%{$existing}))) {
4337: if ($key eq 'lonhost') {
4338: $oldlonhost = $existing->{'lonhost'};
4339: $currbalancer->{$oldlonhost} = 1;
4340: } elsif ($key eq 'targets') {
4341: if ($oldlonhost) {
4342: $currtargets->{$oldlonhost} = $existing->{'targets'};
4343: }
4344: } elsif ($key eq 'rules') {
4345: if ($oldlonhost) {
4346: $currrules->{$oldlonhost} = $existing->{'rules'};
4347: }
4348: } elsif (ref($existing->{$key}) eq 'HASH') {
4349: $currbalancer->{$key} = 1;
4350: $currtargets->{$key} = $existing->{$key}{'targets'};
4351: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4352: }
4353: }
1.171 raeburn 4354: } else {
4355: my ($balancerref,$targetsref) =
4356: &Apache::lonnet::get_lonbalancer_config($servers);
4357: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4358: foreach my $server (sort(keys(%{$balancerref}))) {
4359: $currbalancer->{$server} = 1;
4360: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4361: }
4362: }
4363: }
1.171 raeburn 4364: return;
1.150 raeburn 4365: }
4366:
4367: sub loadbalancing_rules {
4368: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 4369: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4370: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4371: my $output;
1.171 raeburn 4372: my $num = 0;
1.210 raeburn 4373: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4374: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4375: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4376: foreach my $type (@{$alltypes}) {
1.171 raeburn 4377: $num ++;
1.150 raeburn 4378: my $current;
4379: if (ref($currrules) eq 'HASH') {
4380: $current = $currrules->{$type};
4381: }
1.253 raeburn 4382: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 4383: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4384: $current = '';
4385: }
4386: }
4387: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 4388: $servers,$currbalancer,$lonhost,$dom,
4389: $targets_div_style,$homedom_div_style,
4390: $css_class,$balnum,$num,$islast);
1.150 raeburn 4391: }
4392: }
4393: return $output;
4394: }
4395:
4396: sub loadbalancing_titles {
4397: my ($dom,$intdom,$usertypes,$types) = @_;
4398: my %othertypes = (
4399: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4400: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4401: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4402: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 4403: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4404: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4405: );
1.209 raeburn 4406: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4407: if (ref($types) eq 'ARRAY') {
4408: unshift(@alltypes,@{$types},'default');
4409: }
4410: my %titles;
4411: foreach my $type (@alltypes) {
4412: if ($type =~ /^_LC_/) {
4413: $titles{$type} = $othertypes{$type};
4414: } elsif ($type eq 'default') {
4415: $titles{$type} = &mt('All users from [_1]',$dom);
4416: if (ref($types) eq 'ARRAY') {
4417: if (@{$types} > 0) {
4418: $titles{$type} = &mt('Other users from [_1]',$dom);
4419: }
4420: }
4421: } elsif (ref($usertypes) eq 'HASH') {
4422: $titles{$type} = $usertypes->{$type};
4423: }
4424: }
4425: return (\@alltypes,\%othertypes,\%titles);
4426: }
4427:
4428: sub loadbalance_rule_row {
1.171 raeburn 4429: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4430: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 4431: my @rulenames;
1.150 raeburn 4432: my %ruletitles = &offloadtype_text();
1.209 raeburn 4433: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 4434: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4435: } else {
1.209 raeburn 4436: @rulenames = ('default','homeserver');
4437: if ($type eq '_LC_external') {
4438: push(@rulenames,'externalbalancer');
4439: } else {
4440: push(@rulenames,'specific');
4441: }
4442: push(@rulenames,'none');
1.150 raeburn 4443: }
4444: my $style = $targets_div_style;
1.253 raeburn 4445: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4446: $style = $homedom_div_style;
4447: }
1.171 raeburn 4448: my $space;
4449: if ($islast && $num == 1) {
4450: $space = '<div display="inline-block"> </div>';
4451: }
1.210 raeburn 4452: my $output =
1.171 raeburn 4453: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4454: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4455: '<td valaign="top">'.$space.
4456: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4457: for (my $i=0; $i<@rulenames; $i++) {
4458: my $rule = $rulenames[$i];
4459: my ($checked,$extra);
4460: if ($rulenames[$i] eq 'default') {
4461: $rule = '';
4462: }
4463: if ($rulenames[$i] eq 'specific') {
4464: if (ref($servers) eq 'HASH') {
4465: my $default;
4466: if (($current ne '') && (exists($servers->{$current}))) {
4467: $checked = ' checked="checked"';
4468: }
4469: unless ($checked) {
4470: $default = ' selected="selected"';
4471: }
1.210 raeburn 4472: $extra =
1.171 raeburn 4473: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4474: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4475: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4476: '<option value=""'.$default.'></option>'."\n";
4477: foreach my $server (sort(keys(%{$servers}))) {
4478: if (ref($currbalancer) eq 'HASH') {
4479: next if (exists($currbalancer->{$server}));
4480: }
1.150 raeburn 4481: my $selected;
1.171 raeburn 4482: if ($server eq $current) {
1.150 raeburn 4483: $selected = ' selected="selected"';
4484: }
1.171 raeburn 4485: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4486: }
4487: $extra .= '</select>';
4488: }
4489: } elsif ($rule eq $current) {
4490: $checked = ' checked="checked"';
4491: }
4492: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 4493: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4494: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4495: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 4496: ')"'.$checked.' /> ';
4497: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
4498: $output .= $ruletitles{'particular'};
4499: } else {
4500: $output .= $ruletitles{$rulenames[$i]};
4501: }
4502: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4503: }
4504: $output .= '</div></td></tr>'."\n";
4505: return $output;
4506: }
4507:
4508: sub offloadtype_text {
4509: my %ruletitles = &Apache::lonlocal::texthash (
4510: 'default' => 'Offloads to default destinations',
4511: 'homeserver' => "Offloads to user's home server",
4512: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4513: 'specific' => 'Offloads to specific server',
1.161 raeburn 4514: 'none' => 'No offload',
1.209 raeburn 4515: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4516: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 4517: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4518: );
4519: return %ruletitles;
4520: }
4521:
4522: sub sparestype_titles {
4523: my %typestitles = &Apache::lonlocal::texthash (
4524: 'primary' => 'primary',
4525: 'default' => 'default',
4526: );
4527: return %typestitles;
4528: }
4529:
1.28 raeburn 4530: sub contact_titles {
4531: my %titles = &Apache::lonlocal::texthash (
4532: 'supportemail' => 'Support E-mail address',
1.69 raeburn 4533: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 4534: 'errormail' => 'Error reports to be e-mailed to',
4535: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 4536: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
4537: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 4538: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 4539: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 4540: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4541: );
4542: my %short_titles = &Apache::lonlocal::texthash (
4543: adminemail => 'Admin E-mail address',
4544: supportemail => 'Support E-mail',
4545: );
4546: return (\%titles,\%short_titles);
4547: }
4548:
1.72 raeburn 4549: sub tool_titles {
4550: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 4551: aboutme => 'Personal web page',
1.86 raeburn 4552: blog => 'Blog',
1.162 raeburn 4553: webdav => 'WebDAV',
1.86 raeburn 4554: portfolio => 'Portfolio',
1.88 bisitz 4555: official => 'Official courses (with institutional codes)',
4556: unofficial => 'Unofficial courses',
1.98 raeburn 4557: community => 'Communities',
1.216 raeburn 4558: textbook => 'Textbook courses',
1.271 ! raeburn 4559: placement => 'Placement tests',
1.86 raeburn 4560: );
1.72 raeburn 4561: return %titles;
4562: }
4563:
1.101 raeburn 4564: sub courserequest_titles {
4565: my %titles = &Apache::lonlocal::texthash (
4566: official => 'Official',
4567: unofficial => 'Unofficial',
4568: community => 'Communities',
1.216 raeburn 4569: textbook => 'Textbook',
1.271 ! raeburn 4570: placement => 'Placement tests',
1.101 raeburn 4571: norequest => 'Not allowed',
1.104 raeburn 4572: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4573: validate => 'With validation',
4574: autolimit => 'Numerical limit',
1.103 raeburn 4575: unlimited => '(blank for unlimited)',
1.101 raeburn 4576: );
4577: return %titles;
4578: }
4579:
1.163 raeburn 4580: sub authorrequest_titles {
4581: my %titles = &Apache::lonlocal::texthash (
4582: norequest => 'Not allowed',
4583: approval => 'Approval by Dom. Coord.',
4584: automatic => 'Automatic approval',
4585: );
4586: return %titles;
1.210 raeburn 4587: }
1.163 raeburn 4588:
1.101 raeburn 4589: sub courserequest_conditions {
4590: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4591: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 4592: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4593: );
4594: return %conditions;
4595: }
4596:
4597:
1.27 raeburn 4598: sub print_usercreation {
1.30 raeburn 4599: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4600: my $numinrow = 4;
1.28 raeburn 4601: my $datatable;
4602: if ($position eq 'top') {
1.30 raeburn 4603: $$rowtotal ++;
1.34 raeburn 4604: my $rowcount = 0;
1.32 raeburn 4605: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4606: if (ref($rules) eq 'HASH') {
4607: if (keys(%{$rules}) > 0) {
1.32 raeburn 4608: $datatable .= &user_formats_row('username',$settings,$rules,
4609: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4610: $$rowtotal ++;
1.32 raeburn 4611: $rowcount ++;
4612: }
4613: }
4614: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4615: if (ref($idrules) eq 'HASH') {
4616: if (keys(%{$idrules}) > 0) {
4617: $datatable .= &user_formats_row('id',$settings,$idrules,
4618: $idruleorder,$numinrow,$rowcount);
4619: $$rowtotal ++;
4620: $rowcount ++;
1.28 raeburn 4621: }
4622: }
1.39 raeburn 4623: if ($rowcount == 0) {
4624: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4625: $$rowtotal ++;
4626: $rowcount ++;
4627: }
1.34 raeburn 4628: } elsif ($position eq 'middle') {
1.224 raeburn 4629: my @creators = ('author','course','requestcrs');
1.37 raeburn 4630: my ($rules,$ruleorder) =
4631: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4632: my %lt = &usercreation_types();
4633: my %checked;
4634: if (ref($settings) eq 'HASH') {
4635: if (ref($settings->{'cancreate'}) eq 'HASH') {
4636: foreach my $item (@creators) {
4637: $checked{$item} = $settings->{'cancreate'}{$item};
4638: }
4639: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4640: foreach my $item (@creators) {
4641: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4642: $checked{$item} = 'none';
4643: }
4644: }
4645: }
4646: }
4647: my $rownum = 0;
4648: foreach my $item (@creators) {
4649: $rownum ++;
1.224 raeburn 4650: if ($checked{$item} eq '') {
4651: $checked{$item} = 'any';
1.34 raeburn 4652: }
4653: my $css_class;
4654: if ($rownum%2) {
4655: $css_class = '';
4656: } else {
4657: $css_class = ' class="LC_odd_row" ';
4658: }
4659: $datatable .= '<tr'.$css_class.'>'.
4660: '<td><span class="LC_nobreak">'.$lt{$item}.
4661: '</span></td><td align="right">';
1.224 raeburn 4662: my @options = ('any');
4663: if (ref($rules) eq 'HASH') {
4664: if (keys(%{$rules}) > 0) {
4665: push(@options,('official','unofficial'));
1.37 raeburn 4666: }
4667: }
1.224 raeburn 4668: push(@options,'none');
1.37 raeburn 4669: foreach my $option (@options) {
1.50 raeburn 4670: my $type = 'radio';
1.34 raeburn 4671: my $check = ' ';
1.224 raeburn 4672: if ($checked{$item} eq $option) {
4673: $check = ' checked="checked" ';
1.34 raeburn 4674: }
4675: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4676: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4677: $item.'" value="'.$option.'"'.$check.'/> '.
4678: $lt{$option}.'</label> </span>';
4679: }
4680: $datatable .= '</td></tr>';
4681: }
1.28 raeburn 4682: } else {
4683: my @contexts = ('author','course','domain');
4684: my @authtypes = ('int','krb4','krb5','loc');
4685: my %checked;
4686: if (ref($settings) eq 'HASH') {
4687: if (ref($settings->{'authtypes'}) eq 'HASH') {
4688: foreach my $item (@contexts) {
4689: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4690: foreach my $auth (@authtypes) {
4691: if ($settings->{'authtypes'}{$item}{$auth}) {
4692: $checked{$item}{$auth} = ' checked="checked" ';
4693: }
4694: }
4695: }
4696: }
1.27 raeburn 4697: }
1.35 raeburn 4698: } else {
4699: foreach my $item (@contexts) {
1.36 raeburn 4700: foreach my $auth (@authtypes) {
1.35 raeburn 4701: $checked{$item}{$auth} = ' checked="checked" ';
4702: }
4703: }
1.27 raeburn 4704: }
1.28 raeburn 4705: my %title = &context_names();
4706: my %authname = &authtype_names();
4707: my $rownum = 0;
4708: my $css_class;
4709: foreach my $item (@contexts) {
4710: if ($rownum%2) {
4711: $css_class = '';
4712: } else {
4713: $css_class = ' class="LC_odd_row" ';
4714: }
1.30 raeburn 4715: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4716: '<td>'.$title{$item}.
4717: '</td><td class="LC_left_item">'.
4718: '<span class="LC_nobreak">';
4719: foreach my $auth (@authtypes) {
4720: $datatable .= '<label>'.
4721: '<input type="checkbox" name="'.$item.'_auth" '.
4722: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4723: $authname{$auth}.'</label> ';
4724: }
4725: $datatable .= '</span></td></tr>';
4726: $rownum ++;
1.27 raeburn 4727: }
1.30 raeburn 4728: $$rowtotal += $rownum;
1.27 raeburn 4729: }
4730: return $datatable;
4731: }
4732:
1.224 raeburn 4733: sub print_selfcreation {
4734: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 4735: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 4736: if (ref($settings) eq 'HASH') {
4737: if (ref($settings->{'cancreate'}) eq 'HASH') {
4738: $createsettings = $settings->{'cancreate'};
1.236 raeburn 4739: if (ref($createsettings) eq 'HASH') {
4740: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4741: @selfcreate = @{$createsettings->{'selfcreate'}};
4742: } elsif ($createsettings->{'selfcreate'} ne '') {
4743: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4744: @selfcreate = ('email','login','sso');
4745: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4746: @selfcreate = ($createsettings->{'selfcreate'});
4747: }
4748: }
4749: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
4750: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 4751: }
4752: }
4753: }
4754: }
4755: my %radiohash;
4756: my $numinrow = 4;
4757: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
4758: if ($position eq 'top') {
4759: my %choices = &Apache::lonlocal::texthash (
4760: cancreate_login => 'Institutional Login',
4761: cancreate_sso => 'Institutional Single Sign On',
4762: );
4763: my @toggles = sort(keys(%choices));
4764: my %defaultchecked = (
4765: 'cancreate_login' => 'off',
4766: 'cancreate_sso' => 'off',
4767: );
1.228 raeburn 4768: my ($onclick,$itemcount);
1.224 raeburn 4769: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
4770: \%choices,$itemcount,$onclick);
1.228 raeburn 4771: $$rowtotal += $itemcount;
4772:
1.224 raeburn 4773: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4774:
4775: if (ref($usertypes) eq 'HASH') {
4776: if (keys(%{$usertypes}) > 0) {
4777: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
4778: $dom,$numinrow,$othertitle,
1.228 raeburn 4779: 'statustocreate',$$rowtotal);
1.224 raeburn 4780: $$rowtotal ++;
4781: }
4782: }
1.240 raeburn 4783: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
4784: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4785: $fieldtitles{'inststatus'} = &mt('Institutional status');
4786: my $rem;
4787: my $numperrow = 2;
4788: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
4789: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 4790: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 4791: '<td class="LC_left_item">'."\n".
4792: '<table><tr><td>'."\n";
4793: for (my $i=0; $i<@fields; $i++) {
4794: $rem = $i%($numperrow);
4795: if ($rem == 0) {
4796: if ($i > 0) {
4797: $datatable .= '</tr>';
4798: }
4799: $datatable .= '<tr>';
4800: }
4801: my $currval;
1.248 raeburn 4802: if (ref($createsettings) eq 'HASH') {
4803: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
4804: $currval = $createsettings->{'shibenv'}{$fields[$i]};
4805: }
1.240 raeburn 4806: }
4807: $datatable .= '<td class="LC_left_item">'.
4808: '<span class="LC_nobreak">'.
4809: '<input type="text" name="shibenv_'.$fields[$i].'" '.
4810: 'value="'.$currval.'" size="10" /> '.
4811: $fieldtitles{$fields[$i]}.'</span></td>';
4812: }
4813: my $colsleft = $numperrow - $rem;
4814: if ($colsleft > 1 ) {
4815: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4816: ' </td>';
4817: } elsif ($colsleft == 1) {
4818: $datatable .= '<td class="LC_left_item"> </td>';
4819: }
4820: $datatable .= '</tr></table></td></tr>';
4821: $$rowtotal ++;
1.224 raeburn 4822: } elsif ($position eq 'middle') {
4823: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
4824: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4825: $usertypes->{'default'} = $othertitle;
4826: if (ref($types) eq 'ARRAY') {
4827: push(@{$types},'default');
4828: $usertypes->{'default'} = $othertitle;
4829: foreach my $status (@{$types}) {
4830: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 4831: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 4832: $$rowtotal ++;
1.224 raeburn 4833: }
4834: }
4835: } else {
1.236 raeburn 4836: my %choices = &Apache::lonlocal::texthash (
4837: cancreate_email => 'E-mail address as username',
4838: );
4839: my @toggles = sort(keys(%choices));
4840: my %defaultchecked = (
4841: 'cancreate_email' => 'off',
4842: );
4843: my $itemcount = 0;
4844: my $display = 'none';
4845: if (grep(/^\Qemail\E$/,@selfcreate)) {
4846: $display = 'block';
4847: }
4848: my $onclick = "toggleDisplay(this.form,'emailoptions');";
4849: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
4850: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4851: my $usertypes = {};
4852: my $order = [];
4853: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
4854: $usertypes = $domdefaults{'inststatustypes'};
4855: $order = $domdefaults{'inststatusguest'};
4856: }
4857: if (ref($order) eq 'ARRAY') {
4858: push(@{$order},'default');
4859: if (@{$order} > 1) {
4860: $usertypes->{'default'} = &mt('Other users');
4861: $additional .= '<table><tr>';
4862: foreach my $status (@{$order}) {
4863: $additional .= '<th>'.$usertypes->{$status}.'</th>';
4864: }
4865: $additional .= '</tr><tr>';
4866: foreach my $status (@{$order}) {
4867: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 4868: }
1.236 raeburn 4869: $additional .= '</tr></table>';
1.224 raeburn 4870: } else {
1.236 raeburn 4871: $usertypes->{'default'} = &mt('All users');
4872: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 4873: }
4874: }
1.236 raeburn 4875: $additional .= '</div>'."\n";
4876:
4877: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 4878: \%choices,$$rowtotal,$onclick,$additional);
4879: $$rowtotal ++;
1.236 raeburn 4880: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 4881: $$rowtotal ++;
1.224 raeburn 4882: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 4883: $numinrow = 1;
1.236 raeburn 4884: if (ref($order) eq 'ARRAY') {
4885: foreach my $status (@{$order}) {
1.228 raeburn 4886: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
4887: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
4888: $$rowtotal ++;
4889: }
4890: }
1.224 raeburn 4891: my ($emailrules,$emailruleorder) =
4892: &Apache::lonnet::inst_userrules($dom,'email');
4893: if (ref($emailrules) eq 'HASH') {
4894: if (keys(%{$emailrules}) > 0) {
4895: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 4896: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 4897: $$rowtotal ++;
4898: }
4899: }
1.228 raeburn 4900: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 4901: }
4902: return $datatable;
4903: }
4904:
1.236 raeburn 4905: sub email_as_username {
4906: my ($rowtotal,$processing,$type) = @_;
4907: my %choices =
4908: &Apache::lonlocal::texthash (
4909: automatic => 'Automatic approval',
4910: approval => 'Queued for approval',
4911: );
4912: my $output;
4913: foreach my $option ('automatic','approval') {
4914: my $checked;
4915: if (ref($processing) eq 'HASH') {
4916: if ($type eq '') {
4917: if (!exists($processing->{'default'})) {
4918: if ($option eq 'automatic') {
4919: $checked = ' checked="checked"';
4920: }
4921: } else {
4922: if ($processing->{'default'} eq $option) {
4923: $checked = ' checked="checked"';
4924: }
4925: }
4926: } else {
4927: if (!exists($processing->{$type})) {
4928: if ($option eq 'automatic') {
4929: $checked = ' checked="checked"';
4930: }
4931: } else {
4932: if ($processing->{$type} eq $option) {
4933: $checked = ' checked="checked"';
4934: }
4935: }
4936: }
4937: } elsif ($option eq 'automatic') {
4938: $checked = ' checked="checked"';
4939: }
4940: my $name = 'cancreate_emailprocess';
4941: if (($type ne '') && ($type ne 'default')) {
4942: $name .= '_'.$type;
4943: }
4944: $output .= '<span class="LC_nobreak"><label>'.
4945: '<input type="radio" name="'.$name.'"'.
4946: $checked.' value="'.$option.'" />'.
4947: $choices{$option}.'</label></span>';
4948: if ($type eq '') {
4949: $output .= ' ';
4950: } else {
4951: $output .= '<br />';
4952: }
4953: }
4954: $$rowtotal ++;
4955: return $output;
4956: }
4957:
1.165 raeburn 4958: sub captcha_choice {
1.169 raeburn 4959: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 4960: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
4961: $vertext,$currver);
1.165 raeburn 4962: my %lt = &captcha_phrases();
4963: $keyentry = 'hidden';
4964: if ($context eq 'cancreate') {
1.224 raeburn 4965: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 4966: } elsif ($context eq 'login') {
4967: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 4968: }
4969: if (ref($settings) eq 'HASH') {
4970: if ($settings->{'captcha'}) {
4971: $checked{$settings->{'captcha'}} = ' checked="checked"';
4972: } else {
4973: $checked{'original'} = ' checked="checked"';
4974: }
4975: if ($settings->{'captcha'} eq 'recaptcha') {
4976: $pubtext = $lt{'pub'};
4977: $privtext = $lt{'priv'};
4978: $keyentry = 'text';
1.269 raeburn 4979: $vertext = $lt{'ver'};
4980: $currver = $settings->{'recaptchaversion'};
4981: if ($currver ne '2') {
4982: $currver = 1;
4983: }
1.165 raeburn 4984: }
4985: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
4986: $currpub = $settings->{'recaptchakeys'}{'public'};
4987: $currpriv = $settings->{'recaptchakeys'}{'private'};
4988: }
4989: } else {
4990: $checked{'original'} = ' checked="checked"';
4991: }
1.169 raeburn 4992: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4993: my $output = '<tr'.$css_class.'>'.
4994: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 4995: '<table><tr><td>'."\n";
4996: foreach my $option ('original','recaptcha','notused') {
4997: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
4998: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
4999: $lt{$option}.'</label></span>';
5000: unless ($option eq 'notused') {
5001: $output .= (' 'x2)."\n";
5002: }
5003: }
5004: #
5005: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5006: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5007: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5008: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5009: #
1.165 raeburn 5010: $output .= '</td></tr>'."\n".
5011: '<tr><td>'."\n".
5012: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5013: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5014: $currpub.'" size="40" /></span><br />'."\n".
5015: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5016: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5017: $currpriv.'" size="40" /></span><br />'.
5018: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5019: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5020: $currver.'" size="3" /></span><br />'.
5021: '</td></tr></table>'."\n".
1.165 raeburn 5022: '</td></tr>';
5023: return $output;
5024: }
5025:
1.32 raeburn 5026: sub user_formats_row {
5027: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5028: my $output;
5029: my %text = (
5030: 'username' => 'new usernames',
5031: 'id' => 'IDs',
1.45 raeburn 5032: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5033: );
5034: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5035: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5036: '<td><span class="LC_nobreak">';
5037: if ($type eq 'email') {
5038: $output .= &mt("Formats disallowed for $text{$type}: ");
5039: } else {
5040: $output .= &mt("Format rules to check for $text{$type}: ");
5041: }
5042: $output .= '</span></td>'.
5043: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5044: my $rem;
5045: if (ref($ruleorder) eq 'ARRAY') {
5046: for (my $i=0; $i<@{$ruleorder}; $i++) {
5047: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5048: my $rem = $i%($numinrow);
5049: if ($rem == 0) {
5050: if ($i > 0) {
5051: $output .= '</tr>';
5052: }
5053: $output .= '<tr>';
5054: }
5055: my $check = ' ';
1.39 raeburn 5056: if (ref($settings) eq 'HASH') {
5057: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5058: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5059: $check = ' checked="checked" ';
5060: }
1.27 raeburn 5061: }
5062: }
5063: $output .= '<td class="LC_left_item">'.
5064: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5065: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5066: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5067: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5068: }
5069: }
5070: $rem = @{$ruleorder}%($numinrow);
5071: }
5072: my $colsleft = $numinrow - $rem;
5073: if ($colsleft > 1 ) {
5074: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5075: ' </td>';
5076: } elsif ($colsleft == 1) {
5077: $output .= '<td class="LC_left_item"> </td>';
5078: }
5079: $output .= '</tr></table></td></tr>';
5080: return $output;
5081: }
5082:
1.34 raeburn 5083: sub usercreation_types {
5084: my %lt = &Apache::lonlocal::texthash (
5085: author => 'When adding a co-author',
5086: course => 'When adding a user to a course',
1.100 raeburn 5087: requestcrs => 'When requesting a course',
1.34 raeburn 5088: any => 'Any',
5089: official => 'Institutional only ',
5090: unofficial => 'Non-institutional only',
5091: none => 'None',
5092: );
5093: return %lt;
1.48 raeburn 5094: }
1.34 raeburn 5095:
1.224 raeburn 5096: sub selfcreation_types {
5097: my %lt = &Apache::lonlocal::texthash (
5098: selfcreate => 'User creates own account',
5099: any => 'Any',
5100: official => 'Institutional only ',
5101: unofficial => 'Non-institutional only',
5102: email => 'E-mail address',
5103: login => 'Institutional Login',
5104: sso => 'SSO',
5105: );
5106: }
5107:
1.28 raeburn 5108: sub authtype_names {
5109: my %lt = &Apache::lonlocal::texthash(
5110: int => 'Internal',
5111: krb4 => 'Kerberos 4',
5112: krb5 => 'Kerberos 5',
5113: loc => 'Local',
5114: );
5115: return %lt;
5116: }
5117:
5118: sub context_names {
5119: my %context_title = &Apache::lonlocal::texthash(
5120: author => 'Creating users when an Author',
5121: course => 'Creating users when in a course',
5122: domain => 'Creating users when a Domain Coordinator',
5123: );
5124: return %context_title;
5125: }
5126:
1.33 raeburn 5127: sub print_usermodification {
5128: my ($position,$dom,$settings,$rowtotal) = @_;
5129: my $numinrow = 4;
5130: my ($context,$datatable,$rowcount);
5131: if ($position eq 'top') {
5132: $rowcount = 0;
5133: $context = 'author';
5134: foreach my $role ('ca','aa') {
5135: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5136: $numinrow,$rowcount);
5137: $$rowtotal ++;
5138: $rowcount ++;
5139: }
1.230 raeburn 5140: } elsif ($position eq 'bottom') {
1.33 raeburn 5141: $context = 'course';
5142: $rowcount = 0;
5143: foreach my $role ('st','ep','ta','in','cr') {
5144: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5145: $numinrow,$rowcount);
5146: $$rowtotal ++;
5147: $rowcount ++;
5148: }
5149: }
5150: return $datatable;
5151: }
5152:
1.43 raeburn 5153: sub print_defaults {
1.236 raeburn 5154: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5155: my $rownum = 0;
5156: my ($datatable,$css_class);
1.236 raeburn 5157: if ($position eq 'top') {
5158: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5159: 'datelocale_def','portal_def');
5160: my %defaults;
5161: if (ref($settings) eq 'HASH') {
5162: %defaults = %{$settings};
1.43 raeburn 5163: } else {
1.236 raeburn 5164: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5165: foreach my $item (@items) {
5166: $defaults{$item} = $domdefaults{$item};
5167: }
1.43 raeburn 5168: }
1.236 raeburn 5169: my $titles = &defaults_titles($dom);
5170: foreach my $item (@items) {
5171: if ($rownum%2) {
5172: $css_class = '';
5173: } else {
5174: $css_class = ' class="LC_odd_row" ';
5175: }
5176: $datatable .= '<tr'.$css_class.'>'.
5177: '<td><span class="LC_nobreak">'.$titles->{$item}.
5178: '</span></td><td class="LC_right_item" colspan="3">';
5179: if ($item eq 'auth_def') {
5180: my @authtypes = ('internal','krb4','krb5','localauth');
5181: my %shortauth = (
5182: internal => 'int',
5183: krb4 => 'krb4',
5184: krb5 => 'krb5',
5185: localauth => 'loc'
5186: );
5187: my %authnames = &authtype_names();
5188: foreach my $auth (@authtypes) {
5189: my $checked = ' ';
5190: if ($defaults{$item} eq $auth) {
5191: $checked = ' checked="checked" ';
5192: }
5193: $datatable .= '<label><input type="radio" name="'.$item.
5194: '" value="'.$auth.'"'.$checked.'/>'.
5195: $authnames{$shortauth{$auth}}.'</label> ';
5196: }
5197: } elsif ($item eq 'timezone_def') {
5198: my $includeempty = 1;
5199: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5200: } elsif ($item eq 'datelocale_def') {
5201: my $includeempty = 1;
5202: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5203: } elsif ($item eq 'lang_def') {
1.263 raeburn 5204: my $includeempty = 1;
5205: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 5206: } else {
5207: my $size;
5208: if ($item eq 'portal_def') {
5209: $size = ' size="25"';
5210: }
5211: $datatable .= '<input type="text" name="'.$item.'" value="'.
5212: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 5213: }
1.236 raeburn 5214: $datatable .= '</td></tr>';
5215: $rownum ++;
5216: }
5217: } else {
5218: my (%defaults);
5219: if (ref($settings) eq 'HASH') {
5220: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5221: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5222: my $maxnum = @{$settings->{'inststatusorder'}};
5223: for (my $i=0; $i<$maxnum; $i++) {
5224: $css_class = $rownum%2?' class="LC_odd_row"':'';
5225: my $item = $settings->{'inststatusorder'}->[$i];
5226: my $title = $settings->{'inststatustypes'}->{$item};
5227: my $guestok;
5228: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5229: $guestok = 1;
5230: }
5231: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5232: $datatable .= '<tr'.$css_class.'>'.
5233: '<td><span class="LC_nobreak">'.
5234: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5235: for (my $k=0; $k<=$maxnum; $k++) {
5236: my $vpos = $k+1;
5237: my $selstr;
5238: if ($k == $i) {
5239: $selstr = ' selected="selected" ';
5240: }
5241: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5242: }
5243: my ($checkedon,$checkedoff);
5244: $checkedoff = ' checked="checked"';
5245: if ($guestok) {
5246: $checkedon = $checkedoff;
5247: $checkedoff = '';
5248: }
5249: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5250: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5251: &mt('delete').'</span></td>'.
5252: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5253: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5254: '</span></td>'.
5255: '<td class="LC_right_item"><span class="LC_nobreak">'.
5256: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5257: &mt('Yes').'</label>'.(' 'x2).
5258: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5259: &mt('No').'</label></span></td></tr>';
5260: }
5261: $css_class = $rownum%2?' class="LC_odd_row"':'';
5262: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5263: $datatable .= '<tr '.$css_class.'>'.
5264: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5265: for (my $k=0; $k<=$maxnum; $k++) {
5266: my $vpos = $k+1;
5267: my $selstr;
5268: if ($k == $maxnum) {
5269: $selstr = ' selected="selected" ';
5270: }
5271: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5272: }
5273: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 5274: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 5275: ' '.&mt('(new)').
5276: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5277: &mt('Name displayed:').
5278: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5279: '<td class="LC_right_item"><span class="LC_nobreak">'.
5280: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5281: &mt('Yes').'</label>'.(' 'x2).
5282: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5283: &mt('No').'</label></span></td></tr>';
5284: '</tr>'."\n";
5285: $rownum ++;
1.141 raeburn 5286: }
1.43 raeburn 5287: }
5288: }
5289: $$rowtotal += $rownum;
5290: return $datatable;
5291: }
5292:
1.168 raeburn 5293: sub get_languages_hash {
5294: my %langchoices;
5295: foreach my $id (&Apache::loncommon::languageids()) {
5296: my $code = &Apache::loncommon::supportedlanguagecode($id);
5297: if ($code ne '') {
5298: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5299: }
5300: }
5301: return %langchoices;
5302: }
5303:
1.43 raeburn 5304: sub defaults_titles {
1.141 raeburn 5305: my ($dom) = @_;
1.43 raeburn 5306: my %titles = &Apache::lonlocal::texthash (
5307: 'auth_def' => 'Default authentication type',
5308: 'auth_arg_def' => 'Default authentication argument',
5309: 'lang_def' => 'Default language',
1.54 raeburn 5310: 'timezone_def' => 'Default timezone',
1.68 raeburn 5311: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5312: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 5313: );
1.141 raeburn 5314: if ($dom) {
5315: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5316: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5317: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5318: $protocol = 'http' if ($protocol ne 'https');
5319: if ($uint_dom) {
5320: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5321: $uint_dom);
5322: }
5323: }
1.43 raeburn 5324: return (\%titles);
5325: }
5326:
1.46 raeburn 5327: sub print_scantronformat {
5328: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5329: my $itemcount = 1;
1.60 raeburn 5330: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5331: %confhash);
1.46 raeburn 5332: my $switchserver = &check_switchserver($dom,$confname);
5333: my %lt = &Apache::lonlocal::texthash (
1.95 www 5334: default => 'Default bubblesheet format file error',
5335: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5336: );
5337: my %scantronfiles = (
5338: default => 'default.tab',
5339: custom => 'custom.tab',
5340: );
5341: foreach my $key (keys(%scantronfiles)) {
5342: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5343: .$scantronfiles{$key};
5344: }
5345: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5346: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5347: if (!$switchserver) {
5348: my $servadm = $r->dir_config('lonAdmEMail');
5349: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5350: if ($configuserok eq 'ok') {
5351: if ($author_ok eq 'ok') {
5352: my %legacyfile = (
5353: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5354: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5355: );
5356: my %md5chk;
5357: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5358: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5359: chomp($md5chk{$type});
1.46 raeburn 5360: }
5361: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5362: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5363: ($scantronurls{$type},my $error) =
1.46 raeburn 5364: &legacy_scantronformat($r,$dom,$confname,
5365: $type,$legacyfile{$type},
5366: $scantronurls{$type},
5367: $scantronfiles{$type});
1.60 raeburn 5368: if ($error ne '') {
5369: $error{$type} = $error;
5370: }
5371: }
5372: if (keys(%error) == 0) {
5373: $is_custom = 1;
5374: $confhash{'scantron'}{'scantronformat'} =
5375: $scantronurls{'custom'};
5376: my $putresult =
5377: &Apache::lonnet::put_dom('configuration',
5378: \%confhash,$dom);
5379: if ($putresult ne 'ok') {
5380: $error{'custom'} =
5381: '<span class="LC_error">'.
5382: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5383: }
1.46 raeburn 5384: }
5385: } else {
1.60 raeburn 5386: ($scantronurls{'default'},my $error) =
1.46 raeburn 5387: &legacy_scantronformat($r,$dom,$confname,
5388: 'default',$legacyfile{'default'},
5389: $scantronurls{'default'},
5390: $scantronfiles{'default'});
1.60 raeburn 5391: if ($error eq '') {
5392: $confhash{'scantron'}{'scantronformat'} = '';
5393: my $putresult =
5394: &Apache::lonnet::put_dom('configuration',
5395: \%confhash,$dom);
5396: if ($putresult ne 'ok') {
5397: $error{'default'} =
5398: '<span class="LC_error">'.
5399: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5400: }
5401: } else {
5402: $error{'default'} = $error;
5403: }
1.46 raeburn 5404: }
5405: }
5406: }
5407: } else {
1.95 www 5408: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5409: }
5410: }
5411: if (ref($settings) eq 'HASH') {
5412: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5413: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5414: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5415: $scantronurl = '';
5416: } else {
5417: $scantronurl = $settings->{'scantronformat'};
5418: }
5419: $is_custom = 1;
5420: } else {
5421: $scantronurl = $scantronurls{'default'};
5422: }
5423: } else {
1.60 raeburn 5424: if ($is_custom) {
5425: $scantronurl = $scantronurls{'custom'};
5426: } else {
5427: $scantronurl = $scantronurls{'default'};
5428: }
1.46 raeburn 5429: }
5430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5431: $datatable .= '<tr'.$css_class.'>';
5432: if (!$is_custom) {
1.65 raeburn 5433: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5434: '<span class="LC_nobreak">';
1.46 raeburn 5435: if ($scantronurl) {
1.199 raeburn 5436: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5437: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5438: } else {
5439: $datatable = &mt('File unavailable for display');
5440: }
1.65 raeburn 5441: $datatable .= '</span></td>';
1.60 raeburn 5442: if (keys(%error) == 0) {
5443: $datatable .= '<td valign="bottom">';
5444: if (!$switchserver) {
5445: $datatable .= &mt('Upload:').'<br />';
5446: }
5447: } else {
5448: my $errorstr;
5449: foreach my $key (sort(keys(%error))) {
5450: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5451: }
5452: $datatable .= '<td>'.$errorstr;
5453: }
1.46 raeburn 5454: } else {
5455: if (keys(%error) > 0) {
5456: my $errorstr;
5457: foreach my $key (sort(keys(%error))) {
5458: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5459: }
1.60 raeburn 5460: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5461: } elsif ($scantronurl) {
1.199 raeburn 5462: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
5463: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5464: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 5465: $link.
5466: '<label><input type="checkbox" name="scantronformat_del"'.
5467: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5468: '<td><span class="LC_nobreak"> '.
5469: &mt('Replace:').'</span><br />';
1.46 raeburn 5470: }
5471: }
5472: if (keys(%error) == 0) {
5473: if ($switchserver) {
5474: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5475: } else {
1.65 raeburn 5476: $datatable .='<span class="LC_nobreak"> '.
5477: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5478: }
5479: }
5480: $datatable .= '</td></tr>';
5481: $$rowtotal ++;
5482: return $datatable;
5483: }
5484:
5485: sub legacy_scantronformat {
5486: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5487: my ($url,$error);
5488: my @statinfo = &Apache::lonnet::stat_file($newurl);
5489: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5490: (my $result,$url) =
5491: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5492: '','',$newfile);
5493: if ($result ne 'ok') {
1.130 raeburn 5494: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5495: }
5496: }
5497: return ($url,$error);
5498: }
1.43 raeburn 5499:
1.49 raeburn 5500: sub print_coursecategories {
1.57 raeburn 5501: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5502: my $datatable;
5503: if ($position eq 'top') {
1.238 raeburn 5504: my (%checked);
5505: my @catitems = ('unauth','auth');
5506: my @cattypes = ('std','domonly','codesrch','none');
5507: $checked{'unauth'} = 'std';
5508: $checked{'auth'} = 'std';
5509: if (ref($settings) eq 'HASH') {
5510: foreach my $type (@cattypes) {
5511: if ($type eq $settings->{'unauth'}) {
5512: $checked{'unauth'} = $type;
5513: }
5514: if ($type eq $settings->{'auth'}) {
5515: $checked{'auth'} = $type;
5516: }
5517: }
5518: }
5519: my %lt = &Apache::lonlocal::texthash (
5520: unauth => 'Catalog type for unauthenticated users',
5521: auth => 'Catalog type for authenticated users',
5522: none => 'No catalog',
5523: std => 'Standard catalog',
5524: domonly => 'Domain-only catalog',
5525: codesrch => "Code search form",
5526: );
5527: my $itemcount = 0;
5528: foreach my $item (@catitems) {
5529: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5530: $datatable .= '<tr '.$css_class.'>'.
5531: '<td>'.$lt{$item}.'</td>'.
5532: '<td class="LC_right_item"><span class="LC_nobreak">';
5533: foreach my $type (@cattypes) {
5534: my $ischecked;
5535: if ($checked{$item} eq $type) {
5536: $ischecked=' checked="checked"';
5537: }
5538: $datatable .= '<label>'.
5539: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5540: ' />'.$lt{$type}.'</label> ';
5541: }
5542: $datatable .= '</td></tr>';
5543: $itemcount ++;
5544: }
5545: $$rowtotal += $itemcount;
5546: } elsif ($position eq 'middle') {
1.57 raeburn 5547: my $toggle_cats_crs = ' ';
5548: my $toggle_cats_dom = ' checked="checked" ';
5549: my $can_cat_crs = ' ';
5550: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5551: my $toggle_catscomm_comm = ' ';
5552: my $toggle_catscomm_dom = ' checked="checked" ';
5553: my $can_catcomm_comm = ' ';
5554: my $can_catcomm_dom = ' checked="checked" ';
5555:
1.57 raeburn 5556: if (ref($settings) eq 'HASH') {
5557: if ($settings->{'togglecats'} eq 'crs') {
5558: $toggle_cats_crs = $toggle_cats_dom;
5559: $toggle_cats_dom = ' ';
5560: }
5561: if ($settings->{'categorize'} eq 'crs') {
5562: $can_cat_crs = $can_cat_dom;
5563: $can_cat_dom = ' ';
5564: }
1.120 raeburn 5565: if ($settings->{'togglecatscomm'} eq 'comm') {
5566: $toggle_catscomm_comm = $toggle_catscomm_dom;
5567: $toggle_catscomm_dom = ' ';
5568: }
5569: if ($settings->{'categorizecomm'} eq 'comm') {
5570: $can_catcomm_comm = $can_catcomm_dom;
5571: $can_catcomm_dom = ' ';
5572: }
1.57 raeburn 5573: }
5574: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5575: togglecats => 'Show/Hide a course in catalog',
5576: togglecatscomm => 'Show/Hide a community in catalog',
5577: categorize => 'Assign a category to a course',
5578: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5579: );
5580: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5581: dom => 'Set in Domain',
5582: crs => 'Set in Course',
5583: comm => 'Set in Community',
1.57 raeburn 5584: );
5585: $datatable = '<tr class="LC_odd_row">'.
5586: '<td>'.$title{'togglecats'}.'</td>'.
5587: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5588: '<input type="radio" name="togglecats"'.
5589: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5590: '<label><input type="radio" name="togglecats"'.
5591: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5592: '</tr><tr>'.
5593: '<td>'.$title{'categorize'}.'</td>'.
5594: '<td class="LC_right_item"><span class="LC_nobreak">'.
5595: '<label><input type="radio" name="categorize"'.
5596: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5597: '<label><input type="radio" name="categorize"'.
5598: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5599: '</tr><tr class="LC_odd_row">'.
5600: '<td>'.$title{'togglecatscomm'}.'</td>'.
5601: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5602: '<input type="radio" name="togglecatscomm"'.
5603: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5604: '<label><input type="radio" name="togglecatscomm"'.
5605: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5606: '</tr><tr>'.
5607: '<td>'.$title{'categorizecomm'}.'</td>'.
5608: '<td class="LC_right_item"><span class="LC_nobreak">'.
5609: '<label><input type="radio" name="categorizecomm"'.
5610: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5611: '<label><input type="radio" name="categorizecomm"'.
5612: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5613: '</tr>';
1.120 raeburn 5614: $$rowtotal += 4;
1.57 raeburn 5615: } else {
5616: my $css_class;
5617: my $itemcount = 1;
5618: my $cathash;
5619: if (ref($settings) eq 'HASH') {
5620: $cathash = $settings->{'cats'};
5621: }
5622: if (ref($cathash) eq 'HASH') {
5623: my (@cats,@trails,%allitems,%idx,@jsarray);
5624: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5625: \%allitems,\%idx,\@jsarray);
5626: my $maxdepth = scalar(@cats);
5627: my $colattrib = '';
5628: if ($maxdepth > 2) {
5629: $colattrib = ' colspan="2" ';
5630: }
5631: my @path;
5632: if (@cats > 0) {
5633: if (ref($cats[0]) eq 'ARRAY') {
5634: my $numtop = @{$cats[0]};
5635: my $maxnum = $numtop;
1.120 raeburn 5636: my %default_names = (
5637: instcode => &mt('Official courses'),
5638: communities => &mt('Communities'),
5639: );
5640:
5641: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5642: ($cathash->{'instcode::0'} eq '') ||
5643: (!grep(/^communities$/,@{$cats[0]})) ||
5644: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5645: $maxnum ++;
5646: }
5647: my $lastidx;
5648: for (my $i=0; $i<$numtop; $i++) {
5649: my $parent = $cats[0][$i];
5650: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5651: my $item = &escape($parent).'::0';
5652: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5653: $lastidx = $idx{$item};
5654: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5655: .'<select name="'.$item.'"'.$chgstr.'>';
5656: for (my $k=0; $k<=$maxnum; $k++) {
5657: my $vpos = $k+1;
5658: my $selstr;
5659: if ($k == $i) {
5660: $selstr = ' selected="selected" ';
5661: }
5662: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5663: }
1.214 raeburn 5664: $datatable .= '</select></span></td><td>';
1.120 raeburn 5665: if ($parent eq 'instcode' || $parent eq 'communities') {
5666: $datatable .= '<span class="LC_nobreak">'
5667: .$default_names{$parent}.'</span>';
5668: if ($parent eq 'instcode') {
5669: $datatable .= '<br /><span class="LC_nobreak">('
5670: .&mt('with institutional codes')
5671: .')</span></td><td'.$colattrib.'>';
5672: } else {
5673: $datatable .= '<table><tr><td>';
5674: }
5675: $datatable .= '<span class="LC_nobreak">'
5676: .'<label><input type="radio" name="'
5677: .$parent.'" value="1" checked="checked" />'
5678: .&mt('Display').'</label>';
5679: if ($parent eq 'instcode') {
5680: $datatable .= ' ';
5681: } else {
5682: $datatable .= '</span></td></tr><tr><td>'
5683: .'<span class="LC_nobreak">';
5684: }
5685: $datatable .= '<label><input type="radio" name="'
5686: .$parent.'" value="0" />'
5687: .&mt('Do not display').'</label></span>';
5688: if ($parent eq 'communities') {
5689: $datatable .= '</td></tr></table>';
5690: }
5691: $datatable .= '</td>';
1.57 raeburn 5692: } else {
5693: $datatable .= $parent
1.214 raeburn 5694: .' <span class="LC_nobreak"><label>'
5695: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 5696: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
5697: }
5698: my $depth = 1;
5699: push(@path,$parent);
5700: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
5701: pop(@path);
5702: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
5703: $itemcount ++;
5704: }
1.48 raeburn 5705: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 5706: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
5707: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 5708: for (my $k=0; $k<=$maxnum; $k++) {
5709: my $vpos = $k+1;
5710: my $selstr;
1.57 raeburn 5711: if ($k == $numtop) {
1.48 raeburn 5712: $selstr = ' selected="selected" ';
5713: }
5714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5715: }
1.59 bisitz 5716: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 5717: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
5718: .'</tr>'."\n";
1.48 raeburn 5719: $itemcount ++;
1.120 raeburn 5720: foreach my $default ('instcode','communities') {
5721: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
5722: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5723: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
5724: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
5725: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
5726: for (my $k=0; $k<=$maxnum; $k++) {
5727: my $vpos = $k+1;
5728: my $selstr;
5729: if ($k == $maxnum) {
5730: $selstr = ' selected="selected" ';
5731: }
5732: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 5733: }
1.120 raeburn 5734: $datatable .= '</select></span></td>'.
5735: '<td><span class="LC_nobreak">'.
5736: $default_names{$default}.'</span>';
5737: if ($default eq 'instcode') {
5738: $datatable .= '<br /><span class="LC_nobreak">('
5739: .&mt('with institutional codes').')</span>';
5740: }
5741: $datatable .= '</td>'
5742: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
5743: .&mt('Display').'</label> '
5744: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
5745: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 5746: }
5747: }
5748: }
1.57 raeburn 5749: } else {
5750: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 5751: }
5752: } else {
1.238 raeburn 5753: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 5754: .&initialize_categories($itemcount);
1.48 raeburn 5755: }
1.57 raeburn 5756: $$rowtotal += $itemcount;
1.48 raeburn 5757: }
5758: return $datatable;
5759: }
5760:
1.69 raeburn 5761: sub print_serverstatuses {
5762: my ($dom,$settings,$rowtotal) = @_;
5763: my $datatable;
5764: my @pages = &serverstatus_pages();
5765: my (%namedaccess,%machineaccess);
5766: foreach my $type (@pages) {
5767: $namedaccess{$type} = '';
5768: $machineaccess{$type}= '';
5769: }
5770: if (ref($settings) eq 'HASH') {
5771: foreach my $type (@pages) {
5772: if (exists($settings->{$type})) {
5773: if (ref($settings->{$type}) eq 'HASH') {
5774: foreach my $key (keys(%{$settings->{$type}})) {
5775: if ($key eq 'namedusers') {
5776: $namedaccess{$type} = $settings->{$type}->{$key};
5777: } elsif ($key eq 'machines') {
5778: $machineaccess{$type} = $settings->{$type}->{$key};
5779: }
5780: }
5781: }
5782: }
5783: }
5784: }
1.81 raeburn 5785: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5786: my $rownum = 0;
5787: my $css_class;
5788: foreach my $type (@pages) {
5789: $rownum ++;
5790: $css_class = $rownum%2?' class="LC_odd_row"':'';
5791: $datatable .= '<tr'.$css_class.'>'.
5792: '<td><span class="LC_nobreak">'.
5793: $titles->{$type}.'</span></td>'.
5794: '<td class="LC_left_item">'.
5795: '<input type="text" name="'.$type.'_namedusers" '.
5796: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
5797: '<td class="LC_right_item">'.
5798: '<span class="LC_nobreak">'.
5799: '<input type="text" name="'.$type.'_machines" '.
5800: 'value="'.$machineaccess{$type}.'" size="10" />'.
5801: '</td></tr>'."\n";
5802: }
5803: $$rowtotal += $rownum;
5804: return $datatable;
5805: }
5806:
5807: sub serverstatus_pages {
5808: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 5809: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221 raeburn 5810: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.262 raeburn 5811: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 5812: }
5813:
1.236 raeburn 5814: sub defaults_javascript {
5815: my ($settings) = @_;
1.248 raeburn 5816: return unless (ref($settings) eq 'HASH');
1.236 raeburn 5817: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
5818: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
5819: if ($maxnum eq '') {
5820: $maxnum = 0;
5821: }
5822: $maxnum ++;
1.249 raeburn 5823: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 5824: return <<"ENDSCRIPT";
5825: <script type="text/javascript">
5826: // <![CDATA[
5827: function reorderTypes(form,caller) {
5828: var changedVal;
5829: $jstext
5830: var newpos = 'addinststatus_pos';
5831: var current = new Array;
5832: var maxh = $maxnum;
5833: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5834: var oldVal;
5835: if (caller == newpos) {
5836: changedVal = newitemVal;
5837: } else {
5838: var curritem = 'inststatus_pos_'+caller;
5839: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
5840: current[newitemVal] = newpos;
5841: }
5842: for (var i=0; i<inststatuses.length; i++) {
5843: if (inststatuses[i] != caller) {
5844: var elementName = 'inststatus_pos_'+inststatuses[i];
5845: if (form.elements[elementName]) {
5846: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5847: current[currVal] = elementName;
5848: }
5849: }
5850: }
5851: for (var j=0; j<maxh; j++) {
5852: if (current[j] == undefined) {
5853: oldVal = j;
5854: }
5855: }
5856: if (oldVal < changedVal) {
5857: for (var k=oldVal+1; k<=changedVal ; k++) {
5858: var elementName = current[k];
5859: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5860: }
5861: } else {
5862: for (var k=changedVal; k<oldVal; k++) {
5863: var elementName = current[k];
5864: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5865: }
5866: }
5867: return;
5868: }
5869:
5870: // ]]>
5871: </script>
5872:
5873: ENDSCRIPT
5874: }
5875: }
5876:
1.49 raeburn 5877: sub coursecategories_javascript {
5878: my ($settings) = @_;
1.57 raeburn 5879: my ($output,$jstext,$cathash);
1.49 raeburn 5880: if (ref($settings) eq 'HASH') {
1.57 raeburn 5881: $cathash = $settings->{'cats'};
5882: }
5883: if (ref($cathash) eq 'HASH') {
1.49 raeburn 5884: my (@cats,@jsarray,%idx);
1.57 raeburn 5885: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 5886: if (@jsarray > 0) {
5887: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
5888: for (my $i=0; $i<@jsarray; $i++) {
5889: if (ref($jsarray[$i]) eq 'ARRAY') {
5890: my $catstr = join('","',@{$jsarray[$i]});
5891: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
5892: }
5893: }
5894: }
5895: } else {
5896: $jstext = ' var categories = Array(1);'."\n".
5897: ' categories[0] = Array("instcode_pos");'."\n";
5898: }
1.237 bisitz 5899: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
5900: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.265 damieng 5901: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
5902: &js_escape(\$instcode_reserved);
5903: &js_escape(\$communities_reserved);
5904: &js_escape(\$choose_again);
1.49 raeburn 5905: $output = <<"ENDSCRIPT";
5906: <script type="text/javascript">
1.109 raeburn 5907: // <![CDATA[
1.49 raeburn 5908: function reorderCats(form,parent,item,idx) {
5909: var changedVal;
5910: $jstext
5911: var newpos = 'addcategory_pos';
5912: if (parent == '') {
5913: var has_instcode = 0;
5914: var maxtop = categories[idx].length;
5915: for (var j=0; j<maxtop; j++) {
5916: if (categories[idx][j] == 'instcode::0') {
5917: has_instcode == 1;
5918: }
5919: }
5920: if (has_instcode == 0) {
5921: categories[idx][maxtop] = 'instcode_pos';
5922: }
5923: } else {
5924: newpos += '_'+parent;
5925: }
5926: var maxh = 1 + categories[idx].length;
5927: var current = new Array;
5928: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5929: if (item == newpos) {
5930: changedVal = newitemVal;
5931: } else {
5932: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5933: current[newitemVal] = newpos;
5934: }
5935: for (var i=0; i<categories[idx].length; i++) {
5936: var elementName = categories[idx][i];
5937: if (elementName != item) {
5938: if (form.elements[elementName]) {
5939: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5940: current[currVal] = elementName;
5941: }
5942: }
5943: }
5944: var oldVal;
5945: for (var j=0; j<maxh; j++) {
5946: if (current[j] == undefined) {
5947: oldVal = j;
5948: }
5949: }
5950: if (oldVal < changedVal) {
5951: for (var k=oldVal+1; k<=changedVal ; k++) {
5952: var elementName = current[k];
5953: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5954: }
5955: } else {
5956: for (var k=changedVal; k<oldVal; k++) {
5957: var elementName = current[k];
5958: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5959: }
5960: }
5961: return;
5962: }
1.120 raeburn 5963:
5964: function categoryCheck(form) {
5965: if (form.elements['addcategory_name'].value == 'instcode') {
5966: alert('$instcode_reserved\\n$choose_again');
5967: return false;
5968: }
5969: if (form.elements['addcategory_name'].value == 'communities') {
5970: alert('$communities_reserved\\n$choose_again');
5971: return false;
5972: }
5973: return true;
5974: }
5975:
1.109 raeburn 5976: // ]]>
1.49 raeburn 5977: </script>
5978:
5979: ENDSCRIPT
5980: return $output;
5981: }
5982:
1.48 raeburn 5983: sub initialize_categories {
5984: my ($itemcount) = @_;
1.120 raeburn 5985: my ($datatable,$css_class,$chgstr);
5986: my %default_names = (
5987: instcode => 'Official courses (with institutional codes)',
5988: communities => 'Communities',
5989: );
5990: my $select0 = ' selected="selected"';
5991: my $select1 = '';
5992: foreach my $default ('instcode','communities') {
5993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5994: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
5995: if ($default eq 'communities') {
5996: $select1 = $select0;
5997: $select0 = '';
5998: }
5999: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6000: .'<select name="'.$default.'_pos">'
6001: .'<option value="0"'.$select0.'>1</option>'
6002: .'<option value="1"'.$select1.'>2</option>'
6003: .'<option value="2">3</option></select> '
6004: .$default_names{$default}
6005: .'</span></td><td><span class="LC_nobreak">'
6006: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6007: .&mt('Display').'</label> <label>'
6008: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6009: .'</label></span></td></tr>';
1.120 raeburn 6010: $itemcount ++;
6011: }
1.48 raeburn 6012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6013: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6014: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6015: .'<select name="addcategory_pos"'.$chgstr.'>'
6016: .'<option value="0">1</option>'
6017: .'<option value="1">2</option>'
6018: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6019: .&mt('Add category').'</td><td>'.&mt('Name:')
6020: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6021: return $datatable;
6022: }
6023:
6024: sub build_category_rows {
1.49 raeburn 6025: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6026: my ($text,$name,$item,$chgstr);
1.48 raeburn 6027: if (ref($cats) eq 'ARRAY') {
6028: my $maxdepth = scalar(@{$cats});
6029: if (ref($cats->[$depth]) eq 'HASH') {
6030: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6031: my $numchildren = @{$cats->[$depth]{$parent}};
6032: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 6033: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6034: my ($idxnum,$parent_name,$parent_item);
6035: my $higher = $depth - 1;
6036: if ($higher == 0) {
6037: $parent_name = &escape($parent).'::'.$higher;
6038: } else {
6039: if (ref($path) eq 'ARRAY') {
6040: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6041: }
6042: }
6043: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6044: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6045: if ($j < $numchildren) {
1.48 raeburn 6046: $name = $cats->[$depth]{$parent}[$j];
6047: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6048: $idxnum = $idx->{$item};
6049: } else {
6050: $name = $parent_name;
6051: $item = $parent_item;
1.48 raeburn 6052: }
1.49 raeburn 6053: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6054: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6055: for (my $i=0; $i<=$numchildren; $i++) {
6056: my $vpos = $i+1;
6057: my $selstr;
6058: if ($j == $i) {
6059: $selstr = ' selected="selected" ';
6060: }
6061: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6062: }
6063: $text .= '</select> ';
6064: if ($j < $numchildren) {
6065: my $deeper = $depth+1;
6066: $text .= $name.' '
6067: .'<label><input type="checkbox" name="deletecategory" value="'
6068: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6069: if(ref($path) eq 'ARRAY') {
6070: push(@{$path},$name);
1.49 raeburn 6071: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6072: pop(@{$path});
6073: }
6074: } else {
1.59 bisitz 6075: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6076: if ($j == $numchildren) {
6077: $text .= $name;
6078: } else {
6079: $text .= $item;
6080: }
6081: $text .= '" value="" />';
6082: }
6083: $text .= '</td></tr>';
6084: }
6085: $text .= '</table></td>';
6086: } else {
6087: my $higher = $depth-1;
6088: if ($higher == 0) {
6089: $name = &escape($parent).'::'.$higher;
6090: } else {
6091: if (ref($path) eq 'ARRAY') {
6092: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6093: }
6094: }
6095: my $colspan;
6096: if ($parent ne 'instcode') {
6097: $colspan = $maxdepth - $depth - 1;
6098: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6099: }
6100: }
6101: }
6102: }
6103: return $text;
6104: }
6105:
1.33 raeburn 6106: sub modifiable_userdata_row {
1.228 raeburn 6107: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6108: my ($role,$rolename,$statustype);
6109: $role = $item;
1.224 raeburn 6110: if ($context eq 'cancreate') {
1.228 raeburn 6111: if ($item =~ /^emailusername_(.+)$/) {
6112: $statustype = $1;
6113: $role = 'emailusername';
6114: if (ref($usertypes) eq 'HASH') {
6115: if ($usertypes->{$statustype}) {
6116: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6117: } else {
6118: $rolename = &mt('Data provided by user');
6119: }
6120: }
1.224 raeburn 6121: }
6122: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6123: if (ref($usertypes) eq 'HASH') {
6124: $rolename = $usertypes->{$role};
6125: } else {
6126: $rolename = $role;
6127: }
1.33 raeburn 6128: } else {
1.63 raeburn 6129: if ($role eq 'cr') {
6130: $rolename = &mt('Custom role');
6131: } else {
6132: $rolename = &Apache::lonnet::plaintext($role);
6133: }
1.33 raeburn 6134: }
1.224 raeburn 6135: my (@fields,%fieldtitles);
6136: if (ref($fieldsref) eq 'ARRAY') {
6137: @fields = @{$fieldsref};
6138: } else {
6139: @fields = ('lastname','firstname','middlename','generation',
6140: 'permanentemail','id');
6141: }
6142: if ((ref($titlesref) eq 'HASH')) {
6143: %fieldtitles = %{$titlesref};
6144: } else {
6145: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6146: }
1.33 raeburn 6147: my $output;
6148: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6149: $output = '<tr '.$css_class.'>'.
6150: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6151: '<td class="LC_left_item" colspan="2"><table>';
6152: my $rem;
6153: my %checks;
6154: if (ref($settings) eq 'HASH') {
6155: if (ref($settings->{$context}) eq 'HASH') {
6156: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 6157: my $hashref = $settings->{$context}->{$role};
6158: if ($role eq 'emailusername') {
6159: if ($statustype) {
6160: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6161: $hashref = $settings->{$context}->{$role}->{$statustype};
6162: if (ref($hashref) eq 'HASH') {
6163: foreach my $field (@fields) {
6164: if ($hashref->{$field}) {
6165: $checks{$field} = $hashref->{$field};
6166: }
6167: }
6168: }
6169: }
6170: }
6171: } else {
6172: if (ref($hashref) eq 'HASH') {
6173: foreach my $field (@fields) {
6174: if ($hashref->{$field}) {
6175: $checks{$field} = ' checked="checked" ';
6176: }
6177: }
1.33 raeburn 6178: }
6179: }
6180: }
6181: }
6182: }
1.228 raeburn 6183:
1.33 raeburn 6184: for (my $i=0; $i<@fields; $i++) {
6185: my $rem = $i%($numinrow);
6186: if ($rem == 0) {
6187: if ($i > 0) {
6188: $output .= '</tr>';
6189: }
6190: $output .= '<tr>';
6191: }
6192: my $check = ' ';
1.228 raeburn 6193: unless ($role eq 'emailusername') {
6194: if (exists($checks{$fields[$i]})) {
6195: $check = $checks{$fields[$i]}
6196: } else {
6197: if ($role eq 'st') {
6198: if (ref($settings) ne 'HASH') {
6199: $check = ' checked="checked" ';
6200: }
1.33 raeburn 6201: }
6202: }
6203: }
6204: $output .= '<td class="LC_left_item">'.
1.228 raeburn 6205: '<span class="LC_nobreak">';
6206: if ($role eq 'emailusername') {
6207: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6208: $checks{$fields[$i]} = 'omit';
6209: }
6210: foreach my $option ('required','optional','omit') {
6211: my $checked='';
6212: if ($checks{$fields[$i]} eq $option) {
6213: $checked='checked="checked" ';
6214: }
6215: $output .= '<label>'.
6216: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6217: &mt($option).'</label>'.(' ' x2);
6218: }
6219: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6220: } else {
6221: $output .= '<label>'.
6222: '<input type="checkbox" name="canmodify_'.$role.'" '.
6223: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6224: '</label>';
6225: }
6226: $output .= '</span></td>';
1.33 raeburn 6227: $rem = @fields%($numinrow);
6228: }
6229: my $colsleft = $numinrow - $rem;
6230: if ($colsleft > 1 ) {
6231: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6232: ' </td>';
6233: } elsif ($colsleft == 1) {
6234: $output .= '<td class="LC_left_item"> </td>';
6235: }
6236: $output .= '</tr></table></td></tr>';
6237: return $output;
6238: }
1.28 raeburn 6239:
1.93 raeburn 6240: sub insttypes_row {
1.224 raeburn 6241: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6242: my %lt = &Apache::lonlocal::texthash (
6243: cansearch => 'Users allowed to search',
6244: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6245: lockablenames => 'User preference to lock name',
1.93 raeburn 6246: );
6247: my $showdom;
6248: if ($context eq 'cansearch') {
6249: $showdom = ' ('.$dom.')';
6250: }
1.165 raeburn 6251: my $class = 'LC_left_item';
6252: if ($context eq 'statustocreate') {
6253: $class = 'LC_right_item';
6254: }
1.224 raeburn 6255: my $css_class = ' class="LC_odd_row"';
6256: if ($rownum ne '') {
6257: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6258: }
6259: my $output = '<tr'.$css_class.'>'.
6260: '<td>'.$lt{$context}.$showdom.
6261: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6262: my $rem;
6263: if (ref($types) eq 'ARRAY') {
6264: for (my $i=0; $i<@{$types}; $i++) {
6265: if (defined($usertypes->{$types->[$i]})) {
6266: my $rem = $i%($numinrow);
6267: if ($rem == 0) {
6268: if ($i > 0) {
6269: $output .= '</tr>';
6270: }
6271: $output .= '<tr>';
1.23 raeburn 6272: }
1.26 raeburn 6273: my $check = ' ';
1.99 raeburn 6274: if (ref($settings) eq 'HASH') {
6275: if (ref($settings->{$context}) eq 'ARRAY') {
6276: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6277: $check = ' checked="checked" ';
6278: }
6279: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6280: $check = ' checked="checked" ';
6281: }
1.23 raeburn 6282: }
1.26 raeburn 6283: $output .= '<td class="LC_left_item">'.
6284: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6285: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6286: 'value="'.$types->[$i].'"'.$check.'/>'.
6287: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6288: }
6289: }
1.26 raeburn 6290: $rem = @{$types}%($numinrow);
1.23 raeburn 6291: }
6292: my $colsleft = $numinrow - $rem;
1.131 raeburn 6293: if (($rem == 0) && (@{$types} > 0)) {
6294: $output .= '<tr>';
6295: }
1.23 raeburn 6296: if ($colsleft > 1) {
1.25 raeburn 6297: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6298: } else {
1.25 raeburn 6299: $output .= '<td class="LC_left_item">';
1.23 raeburn 6300: }
6301: my $defcheck = ' ';
1.99 raeburn 6302: if (ref($settings) eq 'HASH') {
6303: if (ref($settings->{$context}) eq 'ARRAY') {
6304: if (grep(/^default$/,@{$settings->{$context}})) {
6305: $defcheck = ' checked="checked" ';
6306: }
6307: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6308: $defcheck = ' checked="checked" ';
6309: }
1.23 raeburn 6310: }
1.25 raeburn 6311: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6312: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6313: 'value="default"'.$defcheck.'/>'.
6314: $othertitle.'</label></span></td>'.
6315: '</tr></table></td></tr>';
6316: return $output;
1.23 raeburn 6317: }
6318:
6319: sub sorted_searchtitles {
6320: my %searchtitles = &Apache::lonlocal::texthash(
6321: 'uname' => 'username',
6322: 'lastname' => 'last name',
6323: 'lastfirst' => 'last name, first name',
6324: );
6325: my @titleorder = ('uname','lastname','lastfirst');
6326: return (\%searchtitles,\@titleorder);
6327: }
6328:
1.25 raeburn 6329: sub sorted_searchtypes {
6330: my %srchtypes_desc = (
6331: exact => 'is exact match',
6332: contains => 'contains ..',
6333: begins => 'begins with ..',
6334: );
6335: my @srchtypeorder = ('exact','begins','contains');
6336: return (\%srchtypes_desc,\@srchtypeorder);
6337: }
6338:
1.3 raeburn 6339: sub usertype_update_row {
6340: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6341: my $datatable;
6342: my $numinrow = 4;
6343: foreach my $type (@{$types}) {
6344: if (defined($usertypes->{$type})) {
6345: $$rownums ++;
6346: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6347: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6348: '</td><td class="LC_left_item"><table>';
6349: for (my $i=0; $i<@{$fields}; $i++) {
6350: my $rem = $i%($numinrow);
6351: if ($rem == 0) {
6352: if ($i > 0) {
6353: $datatable .= '</tr>';
6354: }
6355: $datatable .= '<tr>';
6356: }
6357: my $check = ' ';
1.39 raeburn 6358: if (ref($settings) eq 'HASH') {
6359: if (ref($settings->{'fields'}) eq 'HASH') {
6360: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6361: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6362: $check = ' checked="checked" ';
6363: }
1.3 raeburn 6364: }
6365: }
6366: }
6367:
6368: if ($i == @{$fields}-1) {
6369: my $colsleft = $numinrow - $rem;
6370: if ($colsleft > 1) {
6371: $datatable .= '<td colspan="'.$colsleft.'">';
6372: } else {
6373: $datatable .= '<td>';
6374: }
6375: } else {
6376: $datatable .= '<td>';
6377: }
1.8 raeburn 6378: $datatable .= '<span class="LC_nobreak"><label>'.
6379: '<input type="checkbox" name="updateable_'.$type.
6380: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6381: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6382: }
6383: $datatable .= '</tr></table></td></tr>';
6384: }
6385: }
6386: return $datatable;
1.1 raeburn 6387: }
6388:
6389: sub modify_login {
1.205 raeburn 6390: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 6391: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6392: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6393: %title = ( coursecatalog => 'Display course catalog',
6394: adminmail => 'Display administrator E-mail address',
1.188 raeburn 6395: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 6396: newuser => 'Link for visitors to create a user account',
6397: loginheader => 'Log-in box header');
6398: @offon = ('off','on');
1.112 raeburn 6399: if (ref($domconfig{login}) eq 'HASH') {
6400: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6401: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6402: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6403: }
6404: }
6405: }
1.9 raeburn 6406: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6407: \%domconfig,\%loginhash);
1.188 raeburn 6408: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6409: foreach my $item (@toggles) {
6410: $loginhash{login}{$item} = $env{'form.'.$item};
6411: }
1.41 raeburn 6412: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6413: if (ref($colchanges{'login'}) eq 'HASH') {
6414: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6415: \%loginhash);
6416: }
1.110 raeburn 6417:
1.149 raeburn 6418: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 6419: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6420: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6421: if (keys(%servers) > 1) {
6422: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6423: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6424: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6425: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6426: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6427: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6428: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6429: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6430: $changes{'loginvia'}{$lonhost} = 1;
6431: } else {
6432: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6433: $changes{'loginvia'}{$lonhost} = 1;
6434: }
6435: } else {
6436: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6437: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6438: $changes{'loginvia'}{$lonhost} = 1;
6439: }
6440: }
6441: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6442: foreach my $item (@loginvia_attribs) {
6443: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6444: }
6445: } else {
6446: foreach my $item (@loginvia_attribs) {
6447: my $new = $env{'form.'.$lonhost.'_'.$item};
6448: if (($item eq 'serverpath') && ($new eq 'custom')) {
6449: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6450: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6451: $new = '/';
6452: }
6453: }
6454: if (($item eq 'custompath') &&
6455: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6456: $new = '';
6457: }
6458: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6459: $changes{'loginvia'}{$lonhost} = 1;
6460: }
6461: if ($item eq 'exempt') {
1.256 raeburn 6462: $new = &check_exempt_addresses($new);
1.128 raeburn 6463: }
6464: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6465: }
6466: }
1.112 raeburn 6467: } else {
1.128 raeburn 6468: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6469: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6470: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6471: foreach my $item (@loginvia_attribs) {
6472: my $new = $env{'form.'.$lonhost.'_'.$item};
6473: if (($item eq 'serverpath') && ($new eq 'custom')) {
6474: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6475: $new = '/';
6476: }
6477: }
6478: if (($item eq 'custompath') &&
6479: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6480: $new = '';
6481: }
6482: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6483: }
1.110 raeburn 6484: }
6485: }
6486: }
6487: }
1.119 raeburn 6488:
1.168 raeburn 6489: my $servadm = $r->dir_config('lonAdmEMail');
6490: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6491: if (ref($domconfig{'login'}) eq 'HASH') {
6492: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6493: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6494: if ($lang eq 'nolang') {
6495: push(@currlangs,$lang);
6496: } elsif (defined($langchoices{$lang})) {
6497: push(@currlangs,$lang);
6498: } else {
6499: next;
6500: }
6501: }
6502: }
6503: }
6504: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6505: if (@currlangs > 0) {
6506: foreach my $lang (@currlangs) {
6507: if (grep(/^\Q$lang\E$/,@delurls)) {
6508: $changes{'helpurl'}{$lang} = 1;
6509: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6510: $changes{'helpurl'}{$lang} = 1;
6511: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6512: push(@newlangs,$lang);
6513: } else {
6514: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6515: }
6516: }
6517: }
6518: unless (grep(/^nolang$/,@currlangs)) {
6519: if ($env{'form.loginhelpurl_nolang.filename'}) {
6520: $changes{'helpurl'}{'nolang'} = 1;
6521: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6522: push(@newlangs,'nolang');
6523: }
6524: }
6525: if ($env{'form.loginhelpurl_add_lang'}) {
6526: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6527: ($env{'form.loginhelpurl_add_file.filename'})) {
6528: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6529: $addedfile = $env{'form.loginhelpurl_add_lang'};
6530: }
6531: }
6532: if ((@newlangs > 0) || ($addedfile)) {
6533: my $error;
6534: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6535: if ($configuserok eq 'ok') {
6536: if ($switchserver) {
6537: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6538: } elsif ($author_ok eq 'ok') {
6539: my @allnew = @newlangs;
6540: if ($addedfile ne '') {
6541: push(@allnew,$addedfile);
6542: }
6543: foreach my $lang (@allnew) {
6544: my $formelem = 'loginhelpurl_'.$lang;
6545: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6546: $formelem = 'loginhelpurl_add_file';
6547: }
6548: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6549: "help/$lang",'','',$newfile{$lang});
6550: if ($result eq 'ok') {
6551: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6552: $changes{'helpurl'}{$lang} = 1;
6553: } else {
6554: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6555: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 6556: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 6557: (!grep(/^\Q$lang\E$/,@delurls))) {
6558: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6559: }
6560: }
6561: }
6562: } else {
6563: $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);
6564: }
6565: } else {
6566: $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);
6567: }
6568: if ($error) {
6569: &Apache::lonnet::logthis($error);
6570: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6571: }
6572: }
1.256 raeburn 6573:
6574: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6575: if (ref($domconfig{'login'}) eq 'HASH') {
6576: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6577: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6578: if ($domservers{$lonhost}) {
6579: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6580: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 6581: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 6582: }
6583: }
6584: }
6585: }
6586: }
6587: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6588: foreach my $lonhost (sort(keys(%domservers))) {
6589: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6590: $changes{'headtag'}{$lonhost} = 1;
6591: } else {
6592: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6593: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6594: }
6595: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6596: push(@newhosts,$lonhost);
6597: } elsif ($currheadtagurls{$lonhost}) {
6598: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6599: if ($currexempt{$lonhost}) {
6600: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6601: $changes{'headtag'}{$lonhost} = 1;
6602: }
6603: } elsif ($possexempt{$lonhost}) {
6604: $changes{'headtag'}{$lonhost} = 1;
6605: }
6606: if ($possexempt{$lonhost}) {
6607: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6608: }
6609: }
6610: }
6611: }
6612: if (@newhosts) {
6613: my $error;
6614: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6615: if ($configuserok eq 'ok') {
6616: if ($switchserver) {
6617: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6618: } elsif ($author_ok eq 'ok') {
6619: foreach my $lonhost (@newhosts) {
6620: my $formelem = 'loginheadtag_'.$lonhost;
6621: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6622: "login/headtag/$lonhost",'','',
6623: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6624: if ($result eq 'ok') {
6625: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6626: $changes{'headtag'}{$lonhost} = 1;
6627: if ($possexempt{$lonhost}) {
6628: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6629: }
6630: } else {
6631: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6632: $newheadtagurls{$lonhost},$result);
6633: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6634: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
6635: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
6636: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
6637: }
6638: }
6639: }
6640: } else {
6641: $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);
6642: }
6643: } else {
6644: $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);
6645: }
6646: if ($error) {
6647: &Apache::lonnet::logthis($error);
6648: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6649: }
6650: }
1.169 raeburn 6651: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 6652:
6653: my $defaulthelpfile = '/adm/loginproblems.html';
6654: my $defaulttext = &mt('Default in use');
6655:
1.1 raeburn 6656: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
6657: $dom);
6658: if ($putresult eq 'ok') {
1.188 raeburn 6659: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6660: my %defaultchecked = (
6661: 'coursecatalog' => 'on',
1.188 raeburn 6662: 'helpdesk' => 'on',
1.42 raeburn 6663: 'adminmail' => 'off',
1.43 raeburn 6664: 'newuser' => 'off',
1.42 raeburn 6665: );
1.55 raeburn 6666: if (ref($domconfig{'login'}) eq 'HASH') {
6667: foreach my $item (@toggles) {
6668: if ($defaultchecked{$item} eq 'on') {
6669: if (($domconfig{'login'}{$item} eq '0') &&
6670: ($env{'form.'.$item} eq '1')) {
6671: $changes{$item} = 1;
6672: } elsif (($domconfig{'login'}{$item} eq '' ||
6673: $domconfig{'login'}{$item} eq '1') &&
6674: ($env{'form.'.$item} eq '0')) {
6675: $changes{$item} = 1;
6676: }
6677: } elsif ($defaultchecked{$item} eq 'off') {
6678: if (($domconfig{'login'}{$item} eq '1') &&
6679: ($env{'form.'.$item} eq '0')) {
6680: $changes{$item} = 1;
6681: } elsif (($domconfig{'login'}{$item} eq '' ||
6682: $domconfig{'login'}{$item} eq '0') &&
6683: ($env{'form.'.$item} eq '1')) {
6684: $changes{$item} = 1;
6685: }
1.42 raeburn 6686: }
6687: }
1.41 raeburn 6688: }
1.6 raeburn 6689: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 6690: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6691: if (ref($lastactref) eq 'HASH') {
6692: $lastactref->{'domainconfig'} = 1;
6693: }
1.1 raeburn 6694: $resulttext = &mt('Changes made:').'<ul>';
6695: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 6696: if ($item eq 'loginvia') {
1.112 raeburn 6697: if (ref($changes{$item}) eq 'HASH') {
6698: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
6699: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 6700: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
6701: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
6702: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
6703: $protocol = 'http' if ($protocol ne 'https');
6704: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
6705:
6706: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
6707: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
6708: } else {
6709: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
6710: }
6711: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
6712: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
6713: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
6714: }
6715: $resulttext .= '</li>';
6716: } else {
6717: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
6718: }
1.112 raeburn 6719: } else {
1.128 raeburn 6720: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 6721: }
6722: }
1.128 raeburn 6723: $resulttext .= '</ul></li>';
1.112 raeburn 6724: }
1.168 raeburn 6725: } elsif ($item eq 'helpurl') {
6726: if (ref($changes{$item}) eq 'HASH') {
6727: foreach my $lang (sort(keys(%{$changes{$item}}))) {
6728: if (grep(/^\Q$lang\E$/,@delurls)) {
6729: my ($chg,$link);
6730: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
6731: if ($lang eq 'nolang') {
6732: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
6733: } else {
6734: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
6735: }
6736: $resulttext .= '<li>'.$chg.'</li>';
6737: } else {
6738: my $chg;
6739: if ($lang eq 'nolang') {
6740: $chg = &mt('custom log-in help file for no preferred language');
6741: } else {
6742: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
6743: }
6744: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
6745: $loginhash{'login'}{'helpurl'}{$lang}.
6746: '?inhibitmenu=yes',$chg,600,500).
6747: '</li>';
6748: }
6749: }
6750: }
1.256 raeburn 6751: } elsif ($item eq 'headtag') {
6752: if (ref($changes{$item}) eq 'HASH') {
6753: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
6754: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6755: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
6756: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6757: $resulttext .= '<li><a href="'.
6758: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
6759: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
6760: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
6761: if ($possexempt{$lonhost}) {
6762: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
6763: } else {
6764: $resulttext .= &mt('included for any client IP');
6765: }
6766: $resulttext .= '</li>';
6767: }
6768: }
6769: }
1.169 raeburn 6770: } elsif ($item eq 'captcha') {
6771: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 6772: my $chgtxt;
1.169 raeburn 6773: if ($loginhash{'login'}{$item} eq 'notused') {
6774: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
6775: } else {
6776: my %captchas = &captcha_phrases();
6777: if ($captchas{$loginhash{'login'}{$item}}) {
6778: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
6779: } else {
6780: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
6781: }
6782: }
6783: $resulttext .= '<li>'.$chgtxt.'</li>';
6784: }
6785: } elsif ($item eq 'recaptchakeys') {
6786: if (ref($loginhash{'login'}) eq 'HASH') {
6787: my ($privkey,$pubkey);
6788: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
6789: $pubkey = $loginhash{'login'}{$item}{'public'};
6790: $privkey = $loginhash{'login'}{$item}{'private'};
6791: }
6792: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
6793: if (!$pubkey) {
6794: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
6795: } else {
6796: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6797: }
6798: if (!$privkey) {
6799: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
6800: } else {
1.251 raeburn 6801: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 6802: }
6803: $chgtxt .= '</ul>';
6804: $resulttext .= '<li>'.$chgtxt.'</li>';
6805: }
1.269 raeburn 6806: } elsif ($item eq 'recaptchaversion') {
6807: if (ref($loginhash{'login'}) eq 'HASH') {
6808: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 6809: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 6810: '</li>';
6811: }
6812: }
1.41 raeburn 6813: } else {
6814: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6815: }
1.1 raeburn 6816: }
1.6 raeburn 6817: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 6818: } else {
6819: $resulttext = &mt('No changes made to log-in page settings');
6820: }
6821: } else {
1.11 albertel 6822: $resulttext = '<span class="LC_error">'.
6823: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6824: }
1.6 raeburn 6825: if ($errors) {
1.9 raeburn 6826: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 6827: $errors.'</ul>';
6828: }
6829: return $resulttext;
6830: }
6831:
1.256 raeburn 6832:
6833: sub check_exempt_addresses {
6834: my ($iplist) = @_;
6835: $iplist =~ s/^\s+//;
6836: $iplist =~ s/\s+$//;
6837: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
6838: my (@okips,$new);
6839: foreach my $ip (@poss_ips) {
6840: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
6841: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
6842: push(@okips,$ip);
6843: }
6844: }
6845: }
6846: if (@okips > 0) {
6847: $new = join(',',@okips);
6848: } else {
6849: $new = '';
6850: }
6851: return $new;
6852: }
6853:
1.6 raeburn 6854: sub color_font_choices {
6855: my %choices =
6856: &Apache::lonlocal::texthash (
6857: img => "Header",
6858: bgs => "Background colors",
6859: links => "Link colors",
1.55 raeburn 6860: images => "Images",
1.6 raeburn 6861: font => "Font color",
1.201 raeburn 6862: fontmenu => "Font menu",
1.76 raeburn 6863: pgbg => "Page",
1.6 raeburn 6864: tabbg => "Header",
6865: sidebg => "Border",
6866: link => "Link",
6867: alink => "Active link",
6868: vlink => "Visited link",
6869: );
6870: return %choices;
6871: }
6872:
6873: sub modify_rolecolors {
1.205 raeburn 6874: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 6875: my ($resulttext,%rolehash);
6876: $rolehash{'rolecolors'} = {};
1.55 raeburn 6877: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
6878: if ($domconfig{'rolecolors'} eq '') {
6879: $domconfig{'rolecolors'} = {};
6880: }
6881: }
1.9 raeburn 6882: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 6883: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
6884: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
6885: $dom);
6886: if ($putresult eq 'ok') {
6887: if (keys(%changes) > 0) {
1.41 raeburn 6888: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 6889: if (ref($lastactref) eq 'HASH') {
6890: $lastactref->{'domainconfig'} = 1;
6891: }
1.6 raeburn 6892: $resulttext = &display_colorchgs($dom,\%changes,$roles,
6893: $rolehash{'rolecolors'});
6894: } else {
6895: $resulttext = &mt('No changes made to default color schemes');
6896: }
6897: } else {
1.11 albertel 6898: $resulttext = '<span class="LC_error">'.
6899: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 6900: }
6901: if ($errors) {
6902: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6903: $errors.'</ul>';
6904: }
6905: return $resulttext;
6906: }
6907:
6908: sub modify_colors {
1.9 raeburn 6909: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 6910: my (%changes,%choices);
1.51 raeburn 6911: my @bgs;
1.6 raeburn 6912: my @links = ('link','alink','vlink');
1.41 raeburn 6913: my @logintext;
1.6 raeburn 6914: my @images;
6915: my $servadm = $r->dir_config('lonAdmEMail');
6916: my $errors;
1.200 raeburn 6917: my %defaults;
1.6 raeburn 6918: foreach my $role (@{$roles}) {
6919: if ($role eq 'login') {
1.12 raeburn 6920: %choices = &login_choices();
1.41 raeburn 6921: @logintext = ('textcol','bgcol');
1.12 raeburn 6922: } else {
6923: %choices = &color_font_choices();
6924: }
6925: if ($role eq 'login') {
1.41 raeburn 6926: @images = ('img','logo','domlogo','login');
1.51 raeburn 6927: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 6928: } else {
6929: @images = ('img');
1.200 raeburn 6930: @bgs = ('pgbg','tabbg','sidebg');
6931: }
6932: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
6933: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
6934: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
6935: }
6936: if ($role eq 'login') {
6937: foreach my $item (@logintext) {
1.234 raeburn 6938: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6939: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6940: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6941: }
6942: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 6943: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6944: }
6945: }
6946: } else {
1.234 raeburn 6947: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
6948: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
6949: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
6950: }
6951: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 6952: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
6953: }
1.6 raeburn 6954: }
1.200 raeburn 6955: foreach my $item (@bgs) {
1.234 raeburn 6956: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6957: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6958: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6959: }
6960: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 6961: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6962: }
6963: }
6964: foreach my $item (@links) {
1.234 raeburn 6965: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
6966: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
6967: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
6968: }
6969: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 6970: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
6971: }
1.6 raeburn 6972: }
1.46 raeburn 6973: my ($configuserok,$author_ok,$switchserver) =
6974: &config_check($dom,$confname,$servadm);
1.9 raeburn 6975: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 6976: if (ref($domconfig->{$role}) ne 'HASH') {
6977: $domconfig->{$role} = {};
6978: }
1.8 raeburn 6979: foreach my $img (@images) {
1.70 raeburn 6980: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
6981: if (defined($env{'form.login_showlogo_'.$img})) {
6982: $confhash->{$role}{'showlogo'}{$img} = 1;
6983: } else {
6984: $confhash->{$role}{'showlogo'}{$img} = 0;
6985: }
6986: }
1.18 albertel 6987: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
6988: && !defined($domconfig->{$role}{$img})
6989: && !$env{'form.'.$role.'_del_'.$img}
6990: && $env{'form.'.$role.'_import_'.$img}) {
6991: # import the old configured image from the .tab setting
6992: # if they haven't provided a new one
6993: $domconfig->{$role}{$img} =
6994: $env{'form.'.$role.'_import_'.$img};
6995: }
1.6 raeburn 6996: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 6997: my $error;
1.6 raeburn 6998: if ($configuserok eq 'ok') {
1.9 raeburn 6999: if ($switchserver) {
1.12 raeburn 7000: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7001: } else {
7002: if ($author_ok eq 'ok') {
7003: my ($result,$logourl) =
7004: &publishlogo($r,'upload',$role.'_'.$img,
7005: $dom,$confname,$img,$width,$height);
7006: if ($result eq 'ok') {
7007: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7008: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7009: } else {
1.12 raeburn 7010: $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 7011: }
7012: } else {
1.46 raeburn 7013: $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 7014: }
7015: }
7016: } else {
1.46 raeburn 7017: $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 7018: }
7019: if ($error) {
1.8 raeburn 7020: &Apache::lonnet::logthis($error);
1.11 albertel 7021: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7022: }
7023: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7024: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7025: my $error;
7026: if ($configuserok eq 'ok') {
7027: # is confname an author?
7028: if ($switchserver eq '') {
7029: if ($author_ok eq 'ok') {
7030: my ($result,$logourl) =
7031: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7032: $dom,$confname,$img,$width,$height);
7033: if ($result eq 'ok') {
7034: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7035: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7036: }
7037: }
7038: }
7039: }
1.6 raeburn 7040: }
7041: }
7042: }
7043: if (ref($domconfig) eq 'HASH') {
7044: if (ref($domconfig->{$role}) eq 'HASH') {
7045: foreach my $img (@images) {
7046: if ($domconfig->{$role}{$img} ne '') {
7047: if ($env{'form.'.$role.'_del_'.$img}) {
7048: $confhash->{$role}{$img} = '';
1.12 raeburn 7049: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7050: } else {
1.9 raeburn 7051: if ($confhash->{$role}{$img} eq '') {
7052: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7053: }
1.6 raeburn 7054: }
7055: } else {
7056: if ($env{'form.'.$role.'_del_'.$img}) {
7057: $confhash->{$role}{$img} = '';
1.12 raeburn 7058: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7059: }
7060: }
1.70 raeburn 7061: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7062: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7063: if ($confhash->{$role}{'showlogo'}{$img} ne
7064: $domconfig->{$role}{'showlogo'}{$img}) {
7065: $changes{$role}{'showlogo'}{$img} = 1;
7066: }
7067: } else {
7068: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7069: $changes{$role}{'showlogo'}{$img} = 1;
7070: }
7071: }
7072: }
7073: }
1.6 raeburn 7074: if ($domconfig->{$role}{'font'} ne '') {
7075: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7076: $changes{$role}{'font'} = 1;
7077: }
7078: } else {
7079: if ($confhash->{$role}{'font'}) {
7080: $changes{$role}{'font'} = 1;
7081: }
7082: }
1.107 raeburn 7083: if ($role ne 'login') {
7084: if ($domconfig->{$role}{'fontmenu'} ne '') {
7085: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7086: $changes{$role}{'fontmenu'} = 1;
7087: }
7088: } else {
7089: if ($confhash->{$role}{'fontmenu'}) {
7090: $changes{$role}{'fontmenu'} = 1;
7091: }
1.97 tempelho 7092: }
7093: }
1.6 raeburn 7094: foreach my $item (@bgs) {
7095: if ($domconfig->{$role}{$item} ne '') {
7096: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7097: $changes{$role}{'bgs'}{$item} = 1;
7098: }
7099: } else {
7100: if ($confhash->{$role}{$item}) {
7101: $changes{$role}{'bgs'}{$item} = 1;
7102: }
7103: }
7104: }
7105: foreach my $item (@links) {
7106: if ($domconfig->{$role}{$item} ne '') {
7107: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7108: $changes{$role}{'links'}{$item} = 1;
7109: }
7110: } else {
7111: if ($confhash->{$role}{$item}) {
7112: $changes{$role}{'links'}{$item} = 1;
7113: }
7114: }
7115: }
1.41 raeburn 7116: foreach my $item (@logintext) {
7117: if ($domconfig->{$role}{$item} ne '') {
7118: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7119: $changes{$role}{'logintext'}{$item} = 1;
7120: }
7121: } else {
7122: if ($confhash->{$role}{$item}) {
7123: $changes{$role}{'logintext'}{$item} = 1;
7124: }
7125: }
7126: }
1.6 raeburn 7127: } else {
7128: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7129: \@logintext,$confhash,\%changes);
1.6 raeburn 7130: }
7131: } else {
7132: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7133: \@logintext,$confhash,\%changes);
1.6 raeburn 7134: }
7135: }
7136: return ($errors,%changes);
7137: }
7138:
1.46 raeburn 7139: sub config_check {
7140: my ($dom,$confname,$servadm) = @_;
7141: my ($configuserok,$author_ok,$switchserver,%currroles);
7142: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7143: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7144: $confname,$servadm);
7145: if ($configuserok eq 'ok') {
7146: $switchserver = &check_switchserver($dom,$confname);
7147: if ($switchserver eq '') {
7148: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7149: }
7150: }
7151: return ($configuserok,$author_ok,$switchserver);
7152: }
7153:
1.6 raeburn 7154: sub default_change_checker {
1.41 raeburn 7155: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7156: foreach my $item (@{$links}) {
7157: if ($confhash->{$role}{$item}) {
7158: $changes->{$role}{'links'}{$item} = 1;
7159: }
7160: }
7161: foreach my $item (@{$bgs}) {
7162: if ($confhash->{$role}{$item}) {
7163: $changes->{$role}{'bgs'}{$item} = 1;
7164: }
7165: }
1.41 raeburn 7166: foreach my $item (@{$logintext}) {
7167: if ($confhash->{$role}{$item}) {
7168: $changes->{$role}{'logintext'}{$item} = 1;
7169: }
7170: }
1.6 raeburn 7171: foreach my $img (@{$images}) {
7172: if ($env{'form.'.$role.'_del_'.$img}) {
7173: $confhash->{$role}{$img} = '';
1.12 raeburn 7174: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7175: }
1.70 raeburn 7176: if ($role eq 'login') {
7177: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7178: $changes->{$role}{'showlogo'}{$img} = 1;
7179: }
7180: }
1.6 raeburn 7181: }
7182: if ($confhash->{$role}{'font'}) {
7183: $changes->{$role}{'font'} = 1;
7184: }
1.48 raeburn 7185: }
1.6 raeburn 7186:
7187: sub display_colorchgs {
7188: my ($dom,$changes,$roles,$confhash) = @_;
7189: my (%choices,$resulttext);
7190: if (!grep(/^login$/,@{$roles})) {
7191: $resulttext = &mt('Changes made:').'<br />';
7192: }
7193: foreach my $role (@{$roles}) {
7194: if ($role eq 'login') {
7195: %choices = &login_choices();
7196: } else {
7197: %choices = &color_font_choices();
7198: }
7199: if (ref($changes->{$role}) eq 'HASH') {
7200: if ($role ne 'login') {
7201: $resulttext .= '<h4>'.&mt($role).'</h4>';
7202: }
7203: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7204: if ($role ne 'login') {
7205: $resulttext .= '<ul>';
7206: }
7207: if (ref($changes->{$role}{$key}) eq 'HASH') {
7208: if ($role ne 'login') {
7209: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7210: }
7211: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7212: if (($role eq 'login') && ($key eq 'showlogo')) {
7213: if ($confhash->{$role}{$key}{$item}) {
7214: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7215: } else {
7216: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7217: }
7218: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7219: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7220: } else {
1.12 raeburn 7221: my $newitem = $confhash->{$role}{$item};
7222: if ($key eq 'images') {
7223: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7224: }
7225: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7226: }
7227: }
7228: if ($role ne 'login') {
7229: $resulttext .= '</ul></li>';
7230: }
7231: } else {
7232: if ($confhash->{$role}{$key} eq '') {
7233: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7234: } else {
7235: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7236: }
7237: }
7238: if ($role ne 'login') {
7239: $resulttext .= '</ul>';
7240: }
7241: }
7242: }
7243: }
1.3 raeburn 7244: return $resulttext;
1.1 raeburn 7245: }
7246:
1.9 raeburn 7247: sub thumb_dimensions {
7248: return ('200','50');
7249: }
7250:
1.16 raeburn 7251: sub check_dimensions {
7252: my ($inputfile) = @_;
7253: my ($fullwidth,$fullheight);
7254: if ($inputfile =~ m|^[/\w.\-]+$|) {
7255: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7256: my $imageinfo = <PIPE>;
7257: if (!close(PIPE)) {
7258: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7259: }
7260: chomp($imageinfo);
7261: my ($fullsize) =
1.21 raeburn 7262: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7263: if ($fullsize) {
7264: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7265: }
7266: }
7267: }
7268: return ($fullwidth,$fullheight);
7269: }
7270:
1.9 raeburn 7271: sub check_configuser {
7272: my ($uhome,$dom,$confname,$servadm) = @_;
7273: my ($configuserok,%currroles);
7274: if ($uhome eq 'no_host') {
7275: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7276: my $configpass = &LONCAPA::Enrollment::create_password();
7277: $configuserok =
7278: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7279: $configpass,'','','','','',undef,$servadm);
7280: } else {
7281: $configuserok = 'ok';
7282: %currroles =
7283: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7284: }
7285: return ($configuserok,%currroles);
7286: }
7287:
7288: sub check_authorstatus {
7289: my ($dom,$confname,%currroles) = @_;
7290: my $author_ok;
1.40 raeburn 7291: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7292: my $start = time;
7293: my $end = 0;
7294: $author_ok =
7295: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7296: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7297: } else {
7298: $author_ok = 'ok';
7299: }
7300: return $author_ok;
7301: }
7302:
7303: sub publishlogo {
1.46 raeburn 7304: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 7305: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 7306: if ($action eq 'upload') {
7307: $fname=$env{'form.'.$formname.'.filename'};
7308: chop($env{'form.'.$formname});
7309: } else {
7310: ($fname) = ($formname =~ /([^\/]+)$/);
7311: }
1.46 raeburn 7312: if ($savefileas ne '') {
7313: $fname = $savefileas;
7314: }
1.9 raeburn 7315: $fname=&Apache::lonnet::clean_filename($fname);
7316: # See if there is anything left
7317: unless ($fname) { return ('error: no uploaded file'); }
7318: $fname="$subdir/$fname";
1.210 raeburn 7319: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 7320: my $filepath="$docroot/priv";
7321: my $relpath = "$dom/$confname";
1.9 raeburn 7322: my ($fnamepath,$file,$fetchthumb);
7323: $file=$fname;
7324: if ($fname=~m|/|) {
7325: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7326: }
1.164 raeburn 7327: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7328: my $count;
1.164 raeburn 7329: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7330: $filepath.="/$parts[$count]";
7331: if ((-e $filepath)!=1) {
7332: mkdir($filepath,02770);
7333: }
7334: }
7335: # Check for bad extension and disallow upload
7336: if ($file=~/\.(\w+)$/ &&
7337: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7338: $output =
1.207 bisitz 7339: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7340: } elsif ($file=~/\.(\w+)$/ &&
7341: !defined(&Apache::loncommon::fileembstyle($1))) {
7342: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7343: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 7344: $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 7345: } elsif (-d "$filepath/$file") {
1.195 bisitz 7346: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7347: } else {
7348: my $source = $filepath.'/'.$file;
7349: my $logfile;
7350: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 7351: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7352: }
7353: print $logfile
7354: "\n================= Publish ".localtime()." ================\n".
7355: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7356: # Save the file
7357: if (!open(FH,'>'.$source)) {
7358: &Apache::lonnet::logthis('Failed to create '.$source);
7359: return (&mt('Failed to create file'));
7360: }
7361: if ($action eq 'upload') {
7362: if (!print FH ($env{'form.'.$formname})) {
7363: &Apache::lonnet::logthis('Failed to write to '.$source);
7364: return (&mt('Failed to write file'));
7365: }
7366: } else {
7367: my $original = &Apache::lonnet::filelocation('',$formname);
7368: if(!copy($original,$source)) {
7369: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7370: return (&mt('Failed to write file'));
7371: }
7372: }
7373: close(FH);
7374: chmod(0660, $source); # Permissions to rw-rw---.
7375:
7376: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7377: my $copyfile=$targetdir.'/'.$file;
7378:
7379: my @parts=split(/\//,$targetdir);
7380: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7381: for (my $count=5;$count<=$#parts;$count++) {
7382: $path.="/$parts[$count]";
7383: if (!-e $path) {
7384: print $logfile "\nCreating directory ".$path;
7385: mkdir($path,02770);
7386: }
7387: }
7388: my $versionresult;
7389: if (-e $copyfile) {
7390: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7391: } else {
7392: $versionresult = 'ok';
7393: }
7394: if ($versionresult eq 'ok') {
7395: if (copy($source,$copyfile)) {
7396: print $logfile "\nCopied original source to ".$copyfile."\n";
7397: $output = 'ok';
7398: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7399: push(@{$modified_urls},[$copyfile,$source]);
7400: my $metaoutput =
7401: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7402: unless ($registered_cleanup) {
7403: my $handlers = $r->get_handlers('PerlCleanupHandler');
7404: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7405: $registered_cleanup=1;
7406: }
1.9 raeburn 7407: } else {
7408: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7409: $output = &mt('Failed to copy file to RES space').", $!";
7410: }
7411: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7412: my $inputfile = $filepath.'/'.$file;
7413: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7414: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7415: if ($fullwidth ne '' && $fullheight ne '') {
7416: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7417: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7418: system("convert -sample $thumbsize $inputfile $outfile");
7419: chmod(0660, $filepath.'/tn-'.$file);
7420: if (-e $outfile) {
7421: my $copyfile=$targetdir.'/tn-'.$file;
7422: if (copy($outfile,$copyfile)) {
7423: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7424: my $thumb_metaoutput =
7425: &write_metadata($dom,$confname,$formname,
7426: $targetdir,'tn-'.$file,$logfile);
7427: push(@{$modified_urls},[$copyfile,$outfile]);
7428: unless ($registered_cleanup) {
7429: my $handlers = $r->get_handlers('PerlCleanupHandler');
7430: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7431: $registered_cleanup=1;
7432: }
1.267 raeburn 7433: $madethumb = 1;
1.16 raeburn 7434: } else {
7435: print $logfile "\nUnable to write ".$copyfile.
7436: ':'.$!."\n";
7437: }
7438: }
1.9 raeburn 7439: }
7440: }
7441: }
7442: } else {
7443: $output = $versionresult;
7444: }
7445: }
1.267 raeburn 7446: return ($output,$logourl,$madethumb);
1.9 raeburn 7447: }
7448:
7449: sub logo_versioning {
7450: my ($targetdir,$file,$logfile) = @_;
7451: my $target = $targetdir.'/'.$file;
7452: my ($maxversion,$fn,$extn,$output);
7453: $maxversion = 0;
7454: if ($file =~ /^(.+)\.(\w+)$/) {
7455: $fn=$1;
7456: $extn=$2;
7457: }
7458: opendir(DIR,$targetdir);
7459: while (my $filename=readdir(DIR)) {
7460: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7461: $maxversion=($1>$maxversion)?$1:$maxversion;
7462: }
7463: }
7464: $maxversion++;
7465: print $logfile "\nCreating old version ".$maxversion."\n";
7466: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7467: if (copy($target,$copyfile)) {
7468: print $logfile "Copied old target to ".$copyfile."\n";
7469: $copyfile=$copyfile.'.meta';
7470: if (copy($target.'.meta',$copyfile)) {
7471: print $logfile "Copied old target metadata to ".$copyfile."\n";
7472: $output = 'ok';
7473: } else {
7474: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7475: $output = &mt('Failed to copy old meta').", $!, ";
7476: }
7477: } else {
7478: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7479: $output = &mt('Failed to copy old target').", $!, ";
7480: }
7481: return $output;
7482: }
7483:
7484: sub write_metadata {
7485: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7486: my (%metadatafields,%metadatakeys,$output);
7487: $metadatafields{'title'}=$formname;
7488: $metadatafields{'creationdate'}=time;
7489: $metadatafields{'lastrevisiondate'}=time;
7490: $metadatafields{'copyright'}='public';
7491: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7492: $env{'user.domain'};
7493: $metadatafields{'authorspace'}=$confname.':'.$dom;
7494: $metadatafields{'domain'}=$dom;
7495: {
7496: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7497: my $mfh;
1.155 raeburn 7498: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 7499: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7500: unless ($_=~/\./) {
7501: my $unikey=$_;
7502: $unikey=~/^([A-Za-z]+)/;
7503: my $tag=$1;
7504: $tag=~tr/A-Z/a-z/;
7505: print $mfh "\n\<$tag";
7506: foreach (split(/\,/,$metadatakeys{$unikey})) {
7507: my $value=$metadatafields{$unikey.'.'.$_};
7508: $value=~s/\"/\'\'/g;
7509: print $mfh ' '.$_.'="'.$value.'"';
7510: }
7511: print $mfh '>'.
7512: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7513: .'</'.$tag.'>';
7514: }
7515: }
7516: $output = 'ok';
7517: print $logfile "\nWrote metadata";
7518: close($mfh);
7519: } else {
7520: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7521: $output = &mt('Could not write metadata');
7522: }
7523: }
1.155 raeburn 7524: return $output;
7525: }
7526:
7527: sub notifysubscribed {
7528: foreach my $targetsource (@{$modified_urls}){
7529: next unless (ref($targetsource) eq 'ARRAY');
7530: my ($target,$source)=@{$targetsource};
7531: if ($source ne '') {
7532: if (open(my $logfh,'>>'.$source.'.log')) {
7533: print $logfh "\nCleanup phase: Notifications\n";
7534: my @subscribed=&subscribed_hosts($target);
7535: foreach my $subhost (@subscribed) {
7536: print $logfh "\nNotifying host ".$subhost.':';
7537: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7538: print $logfh $reply;
7539: }
7540: my @subscribedmeta=&subscribed_hosts("$target.meta");
7541: foreach my $subhost (@subscribedmeta) {
7542: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7543: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7544: $subhost);
7545: print $logfh $reply;
7546: }
7547: print $logfh "\n============ Done ============\n";
1.160 raeburn 7548: close($logfh);
1.155 raeburn 7549: }
7550: }
7551: }
7552: return OK;
7553: }
7554:
7555: sub subscribed_hosts {
7556: my ($target) = @_;
7557: my @subscribed;
7558: if (open(my $fh,"<$target.subscription")) {
7559: while (my $subline=<$fh>) {
7560: if ($subline =~ /^($match_lonid):/) {
7561: my $host = $1;
7562: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7563: unless (grep(/^\Q$host\E$/,@subscribed)) {
7564: push(@subscribed,$host);
7565: }
7566: }
7567: }
7568: }
7569: }
7570: return @subscribed;
1.9 raeburn 7571: }
7572:
7573: sub check_switchserver {
7574: my ($dom,$confname) = @_;
7575: my ($allowed,$switchserver);
7576: my $home = &Apache::lonnet::homeserver($confname,$dom);
7577: if ($home eq 'no_host') {
7578: $home = &Apache::lonnet::domain($dom,'primary');
7579: }
7580: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7581: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7582: if (!$allowed) {
1.180 raeburn 7583: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7584: }
7585: return $switchserver;
7586: }
7587:
1.1 raeburn 7588: sub modify_quotas {
1.216 raeburn 7589: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7590: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 7591: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 7592: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7593: $validationfieldsref);
1.86 raeburn 7594: if ($action eq 'quotas') {
7595: $context = 'tools';
1.163 raeburn 7596: } else {
1.86 raeburn 7597: $context = $action;
7598: }
7599: if ($context eq 'requestcourses') {
1.271 ! raeburn 7600: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 7601: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7602: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7603: %titles = &courserequest_titles();
7604: $toolregexp = join('|',@usertools);
7605: %conditions = &courserequest_conditions();
1.216 raeburn 7606: $confname = $dom.'-domainconfig';
7607: my $servadm = $r->dir_config('lonAdmEMail');
7608: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 7609: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7610: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 7611: } elsif ($context eq 'requestauthor') {
7612: @usertools = ('author');
7613: %titles = &authorrequest_titles();
1.86 raeburn 7614: } else {
1.162 raeburn 7615: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7616: %titles = &tool_titles();
1.86 raeburn 7617: }
1.212 raeburn 7618: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7619: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7620: foreach my $key (keys(%env)) {
1.101 raeburn 7621: if ($context eq 'requestcourses') {
7622: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7623: my $item = $1;
7624: my $type = $2;
7625: if ($type =~ /^limit_(.+)/) {
7626: $limithash{$item}{$1} = $env{$key};
7627: } else {
7628: $confhash{$item}{$type} = $env{$key};
7629: }
7630: }
1.163 raeburn 7631: } elsif ($context eq 'requestauthor') {
7632: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7633: $confhash{$1} = $env{$key};
7634: }
1.101 raeburn 7635: } else {
1.86 raeburn 7636: if ($key =~ /^form\.quota_(.+)$/) {
7637: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 7638: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
7639: $confhash{'authorquota'}{$1} = $env{$key};
7640: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 7641: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
7642: }
1.72 raeburn 7643: }
7644: }
1.163 raeburn 7645: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 7646: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 7647: @approvalnotify = sort(@approvalnotify);
7648: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 ! raeburn 7649: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 7650: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
7651: foreach my $type (@hasuniquecode) {
7652: if (grep(/^\Q$type\E$/,@crstypes)) {
7653: $confhash{'uniquecode'}{$type} = 1;
7654: }
1.216 raeburn 7655: }
1.242 raeburn 7656: my (%newbook,%allpos);
1.216 raeburn 7657: if ($context eq 'requestcourses') {
1.242 raeburn 7658: foreach my $type ('textbooks','templates') {
7659: @{$allpos{$type}} = ();
7660: my $invalid;
7661: if ($type eq 'textbooks') {
7662: $invalid = &mt('Invalid LON-CAPA course for textbook');
7663: } else {
7664: $invalid = &mt('Invalid LON-CAPA course for template');
7665: }
7666: if ($env{'form.'.$type.'_addbook'}) {
7667: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
7668: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
7669: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
7670: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
7671: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
7672: } else {
7673: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
7674: my $position = $env{'form.'.$type.'_addbook_pos'};
7675: $position =~ s/\D+//g;
7676: if ($position ne '') {
7677: $allpos{$type}[$position] = $newbook{$type};
7678: }
1.216 raeburn 7679: }
1.242 raeburn 7680: } else {
7681: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 7682: }
7683: }
1.242 raeburn 7684: }
1.216 raeburn 7685: }
1.102 raeburn 7686: if (ref($domconfig{$action}) eq 'HASH') {
7687: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
7688: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
7689: $changes{'notify'}{'approval'} = 1;
7690: }
7691: } else {
1.144 raeburn 7692: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7693: $changes{'notify'}{'approval'} = 1;
7694: }
7695: }
1.218 raeburn 7696: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
7697: if (ref($confhash{'uniquecode'}) eq 'HASH') {
7698: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
7699: unless ($confhash{'uniquecode'}{$crstype}) {
7700: $changes{'uniquecode'} = 1;
7701: }
7702: }
7703: unless ($changes{'uniquecode'}) {
7704: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
7705: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
7706: $changes{'uniquecode'} = 1;
7707: }
7708: }
7709: }
7710: } else {
7711: $changes{'uniquecode'} = 1;
7712: }
7713: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
7714: $changes{'uniquecode'} = 1;
1.216 raeburn 7715: }
7716: if ($context eq 'requestcourses') {
1.242 raeburn 7717: foreach my $type ('textbooks','templates') {
7718: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7719: my %deletions;
7720: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
7721: if (@todelete) {
7722: map { $deletions{$_} = 1; } @todelete;
7723: }
7724: my %imgdeletions;
7725: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
7726: if (@todeleteimages) {
7727: map { $imgdeletions{$_} = 1; } @todeleteimages;
7728: }
7729: my $maxnum = $env{'form.'.$type.'_maxnum'};
7730: for (my $i=0; $i<=$maxnum; $i++) {
7731: my $itemid = $env{'form.'.$type.'_id_'.$i};
7732: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
7733: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
7734: if ($deletions{$key}) {
7735: if ($domconfig{$action}{$type}{$key}{'image'}) {
7736: #FIXME need to obsolete item in RES space
7737: }
7738: next;
7739: } else {
7740: my $newpos = $env{'form.'.$itemid};
7741: $newpos =~ s/\D+//g;
1.243 raeburn 7742: foreach my $item ('subject','title','publisher','author') {
7743: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7744: ($type eq 'templates'));
1.242 raeburn 7745: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
7746: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
7747: $changes{$type}{$key} = 1;
7748: }
7749: }
7750: $allpos{$type}[$newpos] = $key;
7751: }
7752: if ($imgdeletions{$key}) {
7753: $changes{$type}{$key} = 1;
1.216 raeburn 7754: #FIXME need to obsolete item in RES space
1.242 raeburn 7755: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
7756: my ($cdom,$cnum) = split(/_/,$key);
7757: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
7758: $cdom,$cnum,$type,$configuserok,
7759: $switchserver,$author_ok);
7760: if ($imgurl) {
7761: $confhash{$type}{$key}{'image'} = $imgurl;
7762: $changes{$type}{$key} = 1;
1.216 raeburn 7763: }
1.242 raeburn 7764: if ($error) {
7765: &Apache::lonnet::logthis($error);
7766: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7767: }
7768: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
7769: $confhash{$type}{$key}{'image'} =
7770: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 7771: }
7772: }
7773: }
7774: }
7775: }
7776: }
1.102 raeburn 7777: } else {
1.144 raeburn 7778: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 7779: $changes{'notify'}{'approval'} = 1;
7780: }
1.218 raeburn 7781: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 7782: $changes{'uniquecode'} = 1;
7783: }
7784: }
7785: if ($context eq 'requestcourses') {
1.242 raeburn 7786: foreach my $type ('textbooks','templates') {
7787: if ($newbook{$type}) {
7788: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 7789: foreach my $item ('subject','title','publisher','author') {
7790: next if ((($item eq 'author') || ($item eq 'publisher')) &&
7791: ($type eq 'template'));
1.242 raeburn 7792: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
7793: if ($env{'form.'.$type.'_addbook_'.$item}) {
7794: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
7795: }
7796: }
7797: if ($type eq 'textbooks') {
7798: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
7799: my ($cdom,$cnum) = split(/_/,$newbook{$type});
7800: my ($imageurl,$error) =
7801: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
7802: $configuserok,$switchserver,$author_ok);
7803: if ($imageurl) {
7804: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
7805: }
7806: if ($error) {
7807: &Apache::lonnet::logthis($error);
7808: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7809: }
7810: }
1.216 raeburn 7811: }
7812: }
1.242 raeburn 7813: if (@{$allpos{$type}} > 0) {
7814: my $idx = 0;
7815: foreach my $item (@{$allpos{$type}}) {
7816: if ($item ne '') {
7817: $confhash{$type}{$item}{'order'} = $idx;
7818: if (ref($domconfig{$action}) eq 'HASH') {
7819: if (ref($domconfig{$action}{$type}) eq 'HASH') {
7820: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
7821: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
7822: $changes{$type}{$item} = 1;
7823: }
1.216 raeburn 7824: }
7825: }
7826: }
1.242 raeburn 7827: $idx ++;
1.216 raeburn 7828: }
7829: }
7830: }
7831: }
1.235 raeburn 7832: if (ref($validationitemsref) eq 'ARRAY') {
7833: foreach my $item (@{$validationitemsref}) {
7834: if ($item eq 'fields') {
7835: my @changed;
7836: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
7837: if (@{$confhash{'validation'}{$item}} > 0) {
7838: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
7839: }
1.266 raeburn 7840: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7841: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7842: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
7843: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
7844: $domconfig{'requestcourses'}{'validation'}{$item});
7845: } else {
7846: @changed = @{$confhash{'validation'}{$item}};
7847: }
1.235 raeburn 7848: } else {
7849: @changed = @{$confhash{'validation'}{$item}};
7850: }
7851: } else {
7852: @changed = @{$confhash{'validation'}{$item}};
7853: }
7854: if (@changed) {
7855: if ($confhash{'validation'}{$item}) {
7856: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
7857: } else {
7858: $changes{'validation'}{$item} = &mt('None');
7859: }
7860: }
7861: } else {
7862: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
7863: if ($item eq 'markup') {
7864: if ($env{'form.requestcourses_validation_'.$item}) {
7865: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
7866: }
7867: }
1.266 raeburn 7868: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7869: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7870: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
7871: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7872: }
7873: } else {
7874: if ($confhash{'validation'}{$item} ne '') {
7875: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7876: }
1.235 raeburn 7877: }
7878: } else {
7879: if ($confhash{'validation'}{$item} ne '') {
7880: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
7881: }
7882: }
7883: }
7884: }
7885: }
7886: if ($env{'form.validationdc'}) {
7887: my $newval = $env{'form.validationdc'};
7888: my %domcoords = &get_active_dcs($dom);
7889: if (exists($domcoords{$newval})) {
7890: $confhash{'validation'}{'dc'} = $newval;
7891: }
7892: }
7893: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 7894: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7895: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7896: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7897: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
7898: if ($confhash{'validation'}{'dc'} eq '') {
7899: $changes{'validation'}{'dc'} = &mt('None');
7900: } else {
7901: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7902: }
1.235 raeburn 7903: }
1.266 raeburn 7904: } elsif ($confhash{'validation'}{'dc'} ne '') {
7905: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 7906: }
7907: } elsif ($confhash{'validation'}{'dc'} ne '') {
7908: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
7909: }
7910: } elsif ($confhash{'validation'}{'dc'} ne '') {
7911: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266 raeburn 7912: }
7913: } else {
7914: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
7915: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
7916: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
7917: $changes{'validation'}{'dc'} = &mt('None');
7918: }
7919: }
1.235 raeburn 7920: }
7921: }
1.102 raeburn 7922: }
7923: } else {
1.86 raeburn 7924: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 7925: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 7926: }
1.72 raeburn 7927: foreach my $item (@usertools) {
7928: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 7929: my $unset;
1.101 raeburn 7930: if ($context eq 'requestcourses') {
1.104 raeburn 7931: $unset = '0';
7932: if ($type eq '_LC_adv') {
7933: $unset = '';
7934: }
1.101 raeburn 7935: if ($confhash{$item}{$type} eq 'autolimit') {
7936: $confhash{$item}{$type} .= '=';
7937: unless ($limithash{$item}{$type} =~ /\D/) {
7938: $confhash{$item}{$type} .= $limithash{$item}{$type};
7939: }
7940: }
1.163 raeburn 7941: } elsif ($context eq 'requestauthor') {
7942: $unset = '0';
7943: if ($type eq '_LC_adv') {
7944: $unset = '';
7945: }
1.72 raeburn 7946: } else {
1.101 raeburn 7947: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
7948: $confhash{$item}{$type} = 1;
7949: } else {
7950: $confhash{$item}{$type} = 0;
7951: }
1.72 raeburn 7952: }
1.86 raeburn 7953: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 7954: if ($action eq 'requestauthor') {
7955: if ($domconfig{$action}{$type} ne $confhash{$type}) {
7956: $changes{$type} = 1;
7957: }
7958: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 7959: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
7960: $changes{$item}{$type} = 1;
7961: }
7962: } else {
7963: if ($context eq 'requestcourses') {
1.104 raeburn 7964: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 7965: $changes{$item}{$type} = 1;
7966: }
7967: } else {
7968: if (!$confhash{$item}{$type}) {
7969: $changes{$item}{$type} = 1;
7970: }
7971: }
7972: }
7973: } else {
7974: if ($context eq 'requestcourses') {
1.104 raeburn 7975: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 7976: $changes{$item}{$type} = 1;
7977: }
1.163 raeburn 7978: } elsif ($context eq 'requestauthor') {
7979: if ($confhash{$type} ne $unset) {
7980: $changes{$type} = 1;
7981: }
1.72 raeburn 7982: } else {
7983: if (!$confhash{$item}{$type}) {
7984: $changes{$item}{$type} = 1;
7985: }
7986: }
7987: }
1.1 raeburn 7988: }
7989: }
1.163 raeburn 7990: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 7991: if (ref($domconfig{'quotas'}) eq 'HASH') {
7992: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
7993: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
7994: if (exists($confhash{'defaultquota'}{$key})) {
7995: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
7996: $changes{'defaultquota'}{$key} = 1;
7997: }
7998: } else {
7999: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8000: }
8001: }
1.86 raeburn 8002: } else {
8003: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8004: if (exists($confhash{'defaultquota'}{$key})) {
8005: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8006: $changes{'defaultquota'}{$key} = 1;
8007: }
8008: } else {
8009: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8010: }
1.1 raeburn 8011: }
8012: }
1.197 raeburn 8013: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8014: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8015: if (exists($confhash{'authorquota'}{$key})) {
8016: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8017: $changes{'authorquota'}{$key} = 1;
8018: }
8019: } else {
8020: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8021: }
8022: }
8023: }
1.1 raeburn 8024: }
1.86 raeburn 8025: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8026: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8027: if (ref($domconfig{'quotas'}) eq 'HASH') {
8028: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8029: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8030: $changes{'defaultquota'}{$key} = 1;
8031: }
8032: } else {
8033: if (!exists($domconfig{'quotas'}{$key})) {
8034: $changes{'defaultquota'}{$key} = 1;
8035: }
1.72 raeburn 8036: }
8037: } else {
1.86 raeburn 8038: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8039: }
1.1 raeburn 8040: }
8041: }
1.197 raeburn 8042: if (ref($confhash{'authorquota'}) eq 'HASH') {
8043: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8044: if (ref($domconfig{'quotas'}) eq 'HASH') {
8045: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8046: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8047: $changes{'authorquota'}{$key} = 1;
8048: }
8049: } else {
8050: $changes{'authorquota'}{$key} = 1;
8051: }
8052: } else {
8053: $changes{'authorquota'}{$key} = 1;
8054: }
8055: }
8056: }
1.1 raeburn 8057: }
1.72 raeburn 8058:
1.163 raeburn 8059: if ($context eq 'requestauthor') {
8060: $domdefaults{'requestauthor'} = \%confhash;
8061: } else {
8062: foreach my $key (keys(%confhash)) {
1.242 raeburn 8063: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 8064: $domdefaults{$key} = $confhash{$key};
8065: }
1.163 raeburn 8066: }
1.72 raeburn 8067: }
1.163 raeburn 8068:
1.1 raeburn 8069: my %quotahash = (
1.86 raeburn 8070: $action => { %confhash }
1.1 raeburn 8071: );
8072: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8073: $dom);
8074: if ($putresult eq 'ok') {
8075: if (keys(%changes) > 0) {
1.72 raeburn 8076: my $cachetime = 24*60*60;
8077: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 8078: if (ref($lastactref) eq 'HASH') {
8079: $lastactref->{'domdefaults'} = 1;
8080: }
1.1 raeburn 8081: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 8082: unless (($context eq 'requestcourses') ||
1.163 raeburn 8083: ($context eq 'requestauthor')) {
1.86 raeburn 8084: if (ref($changes{'defaultquota'}) eq 'HASH') {
8085: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8086: foreach my $type (@{$types},'default') {
8087: if (defined($changes{'defaultquota'}{$type})) {
8088: my $typetitle = $usertypes->{$type};
8089: if ($type eq 'default') {
8090: $typetitle = $othertitle;
8091: }
1.213 raeburn 8092: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8093: }
8094: }
1.86 raeburn 8095: $resulttext .= '</ul></li>';
1.72 raeburn 8096: }
1.197 raeburn 8097: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 8098: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 8099: foreach my $type (@{$types},'default') {
8100: if (defined($changes{'authorquota'}{$type})) {
8101: my $typetitle = $usertypes->{$type};
8102: if ($type eq 'default') {
8103: $typetitle = $othertitle;
8104: }
1.213 raeburn 8105: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 8106: }
8107: }
8108: $resulttext .= '</ul></li>';
8109: }
1.72 raeburn 8110: }
1.80 raeburn 8111: my %newenv;
1.72 raeburn 8112: foreach my $item (@usertools) {
1.163 raeburn 8113: my (%haschgs,%inconf);
8114: if ($context eq 'requestauthor') {
8115: %haschgs = %changes;
1.210 raeburn 8116: %inconf = %confhash;
1.163 raeburn 8117: } else {
8118: if (ref($changes{$item}) eq 'HASH') {
8119: %haschgs = %{$changes{$item}};
8120: }
8121: if (ref($confhash{$item}) eq 'HASH') {
8122: %inconf = %{$confhash{$item}};
8123: }
8124: }
8125: if (keys(%haschgs) > 0) {
1.80 raeburn 8126: my $newacc =
8127: &Apache::lonnet::usertools_access($env{'user.name'},
8128: $env{'user.domain'},
1.86 raeburn 8129: $item,'reload',$context);
1.210 raeburn 8130: if (($context eq 'requestcourses') ||
1.163 raeburn 8131: ($context eq 'requestauthor')) {
1.108 raeburn 8132: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8133: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8134: }
8135: } else {
8136: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8137: $newenv{'environment.availabletools.'.$item} = $newacc;
8138: }
1.80 raeburn 8139: }
1.163 raeburn 8140: unless ($context eq 'requestauthor') {
8141: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8142: }
1.72 raeburn 8143: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 8144: if ($haschgs{$type}) {
1.72 raeburn 8145: my $typetitle = $usertypes->{$type};
8146: if ($type eq 'default') {
8147: $typetitle = $othertitle;
8148: } elsif ($type eq '_LC_adv') {
8149: $typetitle = 'LON-CAPA Advanced Users';
8150: }
1.163 raeburn 8151: if ($inconf{$type}) {
1.101 raeburn 8152: if ($context eq 'requestcourses') {
8153: my $cond;
1.163 raeburn 8154: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8155: if ($1 eq '') {
8156: $cond = &mt('(Automatic processing of any request).');
8157: } else {
8158: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8159: }
8160: } else {
1.163 raeburn 8161: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8162: }
8163: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 8164: } elsif ($context eq 'requestauthor') {
8165: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8166: $titles{$inconf{$type}},$typetitle);
8167:
1.101 raeburn 8168: } else {
8169: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8170: }
1.72 raeburn 8171: } else {
1.104 raeburn 8172: if ($type eq '_LC_adv') {
1.163 raeburn 8173: if ($inconf{$type} eq '0') {
1.104 raeburn 8174: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8175: } else {
8176: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8177: }
8178: } else {
8179: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8180: }
1.72 raeburn 8181: }
8182: }
1.26 raeburn 8183: }
1.163 raeburn 8184: unless ($context eq 'requestauthor') {
8185: $resulttext .= '</ul></li>';
8186: }
1.26 raeburn 8187: }
1.1 raeburn 8188: }
1.163 raeburn 8189: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8190: if (ref($changes{'notify'}) eq 'HASH') {
8191: if ($changes{'notify'}{'approval'}) {
8192: if (ref($confhash{'notify'}) eq 'HASH') {
8193: if ($confhash{'notify'}{'approval'}) {
8194: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8195: } else {
1.163 raeburn 8196: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8197: }
8198: }
8199: }
8200: }
8201: }
1.216 raeburn 8202: if ($action eq 'requestcourses') {
8203: my @offon = ('off','on');
8204: if ($changes{'uniquecode'}) {
1.218 raeburn 8205: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8206: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8207: $resulttext .= '<li>'.
8208: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8209: '</li>';
8210: } else {
8211: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8212: '</li>';
8213: }
1.216 raeburn 8214: }
1.242 raeburn 8215: foreach my $type ('textbooks','templates') {
8216: if (ref($changes{$type}) eq 'HASH') {
8217: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8218: foreach my $key (sort(keys(%{$changes{$type}}))) {
8219: my %coursehash = &Apache::lonnet::coursedescription($key);
8220: my $coursetitle = $coursehash{'description'};
8221: my $position = $confhash{$type}{$key}{'order'} + 1;
8222: $resulttext .= '<li>';
1.243 raeburn 8223: foreach my $item ('subject','title','publisher','author') {
8224: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8225: ($type eq 'templates'));
1.242 raeburn 8226: my $name = $item.':';
8227: $name =~ s/^(\w)/\U$1/;
8228: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8229: }
8230: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8231: if ($type eq 'textbooks') {
8232: if ($confhash{$type}{$key}{'image'}) {
8233: $resulttext .= ' '.&mt('Image: [_1]',
8234: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8235: ' alt="Textbook cover" />').'<br />';
8236: }
8237: }
8238: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 8239: }
1.242 raeburn 8240: $resulttext .= '</ul></li>';
1.216 raeburn 8241: }
8242: }
1.235 raeburn 8243: if (ref($changes{'validation'}) eq 'HASH') {
8244: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8245: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8246: foreach my $item (@{$validationitemsref}) {
8247: if (exists($changes{'validation'}{$item})) {
8248: if ($item eq 'markup') {
8249: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8250: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8251: } else {
8252: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8253: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8254: }
8255: }
8256: }
8257: if (exists($changes{'validation'}{'dc'})) {
8258: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8259: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8260: }
8261: }
8262: }
1.216 raeburn 8263: }
1.1 raeburn 8264: $resulttext .= '</ul>';
1.80 raeburn 8265: if (keys(%newenv)) {
8266: &Apache::lonnet::appenv(\%newenv);
8267: }
1.1 raeburn 8268: } else {
1.86 raeburn 8269: if ($context eq 'requestcourses') {
8270: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 8271: } elsif ($context eq 'requestauthor') {
8272: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8273: } else {
1.90 weissno 8274: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8275: }
1.1 raeburn 8276: }
8277: } else {
1.11 albertel 8278: $resulttext = '<span class="LC_error">'.
8279: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8280: }
1.216 raeburn 8281: if ($errors) {
8282: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8283: '<ul>'.$errors.'</ul></p>';
8284: }
1.3 raeburn 8285: return $resulttext;
1.1 raeburn 8286: }
8287:
1.216 raeburn 8288: sub process_textbook_image {
1.242 raeburn 8289: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 8290: my $filename = $env{'form.'.$caller.'.filename'};
8291: my ($error,$url);
8292: my ($width,$height) = (50,50);
8293: if ($configuserok eq 'ok') {
8294: if ($switchserver) {
8295: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8296: $switchserver);
8297: } elsif ($author_ok eq 'ok') {
8298: my ($result,$imageurl) =
8299: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 8300: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 8301: if ($result eq 'ok') {
8302: $url = $imageurl;
8303: } else {
8304: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8305: }
8306: } else {
8307: $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);
8308: }
8309: } else {
8310: $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);
8311: }
8312: return ($url,$error);
8313: }
8314:
1.267 raeburn 8315: sub modify_ltitools {
8316: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
8317: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8318: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
8319: my $confname = $dom.'-domainconfig';
8320: my $servadm = $r->dir_config('lonAdmEMail');
8321: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8322: my (%posslti,%possfield);
8323: my @courseroles = ('cc','in','ta','ep','st');
8324: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
8325: map { $posslti{$_} = 1; } @ltiroles;
8326: my @allfields = ('fullname','firstname','lastname','email','user','roles');
8327: map { $possfield{$_} = 1; } @allfields;
8328: my %lt = <itools_names();
8329: if ($env{'form.ltitools_add'}) {
8330: my $title = $env{'form.ltitools_add_title'};
8331: $title =~ s/(`)/'/g;
8332: ($newid,my $error) = &get_ltitools_id($dom,$title);
8333: if ($newid) {
8334: my $position = $env{'form.ltitools_add_pos'};
8335: $position =~ s/\D+//g;
8336: if ($position ne '') {
8337: $allpos[$position] = $newid;
8338: }
8339: $changes{$newid} = 1;
8340: foreach my $item ('title','url','key','secret') {
8341: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
8342: if ($env{'form.ltitools_add_'.$item}) {
8343: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
8344: }
8345: }
8346: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
8347: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
8348: }
8349: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
8350: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
8351: }
8352: foreach my $item ('width','height') {
8353: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
8354: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
8355: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
8356: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
8357: }
8358: }
8359: if ($env{'form.ltitools_add_target'} eq 'window') {
8360: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
8361: } else {
8362: $confhash{$newid}{'display'}{'target'} = 'iframe';
8363: }
8364: foreach my $item ('passback','roster') {
8365: if ($env{'form.ltitools_add_'.$item}) {
8366: $confhash{$newid}{$item} = 1;
8367: }
8368: }
8369: if ($env{'form.ltitools_add_image.filename'} ne '') {
8370: my ($imageurl,$error) =
8371: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
8372: $configuserok,$switchserver,$author_ok);
8373: if ($imageurl) {
8374: $confhash{$newid}{'image'} = $imageurl;
8375: }
8376: if ($error) {
8377: &Apache::lonnet::logthis($error);
8378: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8379: }
8380: }
8381: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
8382: foreach my $field (@fields) {
8383: if ($possfield{$field}) {
8384: if ($field eq 'roles') {
8385: foreach my $role (@courseroles) {
8386: my $choice = $env{'form.ltitools_add_roles_'.$role};
8387: if (($choice ne '') && ($posslti{$choice})) {
8388: $confhash{$newid}{'roles'}{$role} = $choice;
8389: if ($role eq 'cc') {
8390: $confhash{$newid}{'roles'}{'co'} = $choice;
8391: }
8392: }
8393: }
8394: } else {
8395: $confhash{$newid}{'fields'}{$field} = 1;
8396: }
8397: }
8398: }
8399: if ($env{'form.ltitools_add_custom'}) {
8400: my $name = $env{'form.ltitools_add_custom_name'};
8401: my $value = $env{'form.ltitools_add_custom_value'};
8402: $value =~ s/(`)/'/g;
8403: $name =~ s/(`)/'/g;
8404: $confhash{$newid}{'custom'}{$name} = $value;
8405: }
8406: } else {
8407: my $error = &mt('Failed to acquire unique ID for new external tool');
8408: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8409: }
8410: }
8411: if (ref($domconfig{$action}) eq 'HASH') {
8412: my %deletions;
8413: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
8414: if (@todelete) {
8415: map { $deletions{$_} = 1; } @todelete;
8416: }
8417: my %customadds;
8418: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
8419: if (@newcustom) {
8420: map { $customadds{$_} = 1; } @newcustom;
8421: }
8422: my %imgdeletions;
8423: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
8424: if (@todeleteimages) {
8425: map { $imgdeletions{$_} = 1; } @todeleteimages;
8426: }
8427: my $maxnum = $env{'form.ltitools_maxnum'};
8428: for (my $i=0; $i<=$maxnum; $i++) {
8429: my $itemid = $env{'form.ltitools_id_'.$i};
8430: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8431: if ($deletions{$itemid}) {
8432: if ($domconfig{$action}{$itemid}{'image'}) {
8433: #FIXME need to obsolete item in RES space
8434: }
8435: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
8436: next;
8437: } else {
8438: my $newpos = $env{'form.ltitools_'.$itemid};
8439: $newpos =~ s/\D+//g;
8440: foreach my $item ('title','url','key','secret') {
8441: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
8442: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
8443: $changes{$itemid} = 1;
8444: }
8445: }
8446: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
8447: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
8448: }
8449: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
8450: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
8451: }
8452: foreach my $size ('width','height') {
8453: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
8454: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
8455: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
8456: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
8457: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8458: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
8459: $changes{$itemid} = 1;
8460: }
8461: } else {
8462: $changes{$itemid} = 1;
8463: }
8464: }
8465: }
8466: if ($env{'form.ltitools_target_'.$i} eq 'window') {
8467: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
8468: } else {
8469: $confhash{$itemid}{'display'}{'target'} = 'iframe';
8470: }
8471: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
8472: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
8473: $changes{$itemid} = 1;
8474: }
8475: } else {
8476: $changes{$itemid} = 1;
8477: }
8478: foreach my $extra ('passback','roster') {
8479: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
8480: $confhash{$itemid}{$extra} = 1;
8481: }
8482: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
8483: $changes{$itemid} = 1;
8484: }
8485: }
8486: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
8487: foreach my $field (@fields) {
8488: if ($possfield{$field}) {
8489: if ($field eq 'roles') {
8490: foreach my $role (@courseroles) {
8491: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
8492: if (($choice ne '') && ($posslti{$choice})) {
8493: $confhash{$itemid}{'roles'}{$role} = $choice;
8494: if ($role eq 'cc') {
8495: $confhash{$itemid}{'roles'}{'co'} = $choice;
8496: }
8497: }
8498: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
8499: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
8500: $changes{$itemid} = 1;
8501: }
8502: } elsif ($confhash{$itemid}{'roles'}{$role}) {
8503: $changes{$itemid} = 1;
8504: }
8505: }
8506: } else {
8507: $confhash{$itemid}{'fields'}{$field} = 1;
8508: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
8509: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
8510: $changes{$itemid} = 1;
8511: }
8512: } else {
8513: $changes{$itemid} = 1;
8514: }
8515: }
8516: }
8517: }
8518: $allpos[$newpos] = $itemid;
8519: }
8520: if ($imgdeletions{$itemid}) {
8521: $changes{$itemid} = 1;
8522: #FIXME need to obsolete item in RES space
8523: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
8524: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
8525: $itemid,$configuserok,$switchserver,
8526: $author_ok);
8527: if ($imgurl) {
8528: $confhash{$itemid}{'image'} = $imgurl;
8529: $changes{$itemid} = 1;
8530: }
8531: if ($error) {
8532: &Apache::lonnet::logthis($error);
8533: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8534: }
8535: } elsif ($domconfig{$action}{$itemid}{'image'}) {
8536: $confhash{$itemid}{'image'} =
8537: $domconfig{$action}{$itemid}{'image'};
8538: }
8539: if ($customadds{$i}) {
8540: my $name = $env{'form.ltitools_custom_name_'.$i};
8541: $name =~ s/(`)/'/g;
8542: $name =~ s/^\s+//;
8543: $name =~ s/\s+$//;
8544: my $value = $env{'form.ltitools_custom_value_'.$i};
8545: $value =~ s/(`)/'/g;
8546: $value =~ s/^\s+//;
8547: $value =~ s/\s+$//;
8548: if ($name ne '') {
8549: $confhash{$itemid}{'custom'}{$name} = $value;
8550: $changes{$itemid} = 1;
8551: }
8552: }
8553: my %customdels;
8554: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
8555: if (@customdeletions) {
8556: $changes{$itemid} = 1;
8557: }
8558: map { $customdels{$_} = 1; } @customdeletions;
8559: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
8560: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
8561: unless ($customdels{$key}) {
8562: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
8563: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
8564: }
8565: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
8566: $changes{$itemid} = 1;
8567: }
8568: }
8569: }
8570: }
8571: unless ($changes{$itemid}) {
8572: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
8573: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
8574: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
8575: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
8576: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
8577: $changes{$itemid} = 1;
8578: last;
8579: }
8580: }
8581: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
8582: $changes{$itemid} = 1;
8583: }
8584: }
8585: last if ($changes{$itemid});
8586: }
8587: }
8588: }
8589: }
8590: }
8591: if (@allpos > 0) {
8592: my $idx = 0;
8593: foreach my $itemid (@allpos) {
8594: if ($itemid ne '') {
8595: $confhash{$itemid}{'order'} = $idx;
8596: if (ref($domconfig{$action}) eq 'HASH') {
8597: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
8598: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
8599: $changes{$itemid} = 1;
8600: }
8601: }
8602: }
8603: $idx ++;
8604: }
8605: }
8606: }
8607: my %ltitoolshash = (
8608: $action => { %confhash }
8609: );
8610: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
8611: $dom);
8612: if ($putresult eq 'ok') {
8613: if (keys(%changes) > 0) {
8614: my $cachetime = 24*60*60;
8615: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
8616: if (ref($lastactref) eq 'HASH') {
8617: $lastactref->{'ltitools'} = 1;
8618: }
8619: $resulttext = &mt('Changes made:').'<ul>';
8620: my %bynum;
8621: foreach my $itemid (sort(keys(%changes))) {
8622: my $position = $confhash{$itemid}{'order'};
8623: $bynum{$position} = $itemid;
8624: }
8625: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
8626: my $itemid = $bynum{$pos};
8627: if (ref($confhash{$itemid}) ne 'HASH') {
8628: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
8629: } else {
8630: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
8631: if ($confhash{$itemid}{'image'}) {
8632: $resulttext .= ' '.
8633: '<img src="'.$confhash{$itemid}{'image'}.'"'.
8634: ' alt="'.&mt('Tool Provider icon').'" />';
8635: }
8636: $resulttext .= '</li><ul>';
8637: my $position = $pos + 1;
8638: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
8639: foreach my $item ('version','msgtype','url','key') {
8640: if ($confhash{$itemid}{$item} ne '') {
8641: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
8642: }
8643: }
8644: if ($confhash{$itemid}{'secret'} ne '') {
8645: $resulttext .= '<li>'.$lt{'secret'}.': ';
8646: my $num = length($confhash{$itemid}{'secret'});
8647: $resulttext .= ('*'x$num).'</li>';
8648: }
8649: foreach my $item ('passback','roster') {
8650: $resulttext .= '<li>'.$lt{$item}.' ';
8651: if ($confhash{$itemid}{$item}) {
8652: $resulttext .= &mt('Yes');
8653: } else {
8654: $resulttext .= &mt('No');
8655: }
8656: $resulttext .= '</li>';
8657: }
8658: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
8659: my $displaylist;
8660: if ($confhash{$itemid}{'display'}{'target'}) {
8661: $displaylist = &mt('Display target').': '.
8662: $confhash{$itemid}{'display'}{'target'}.',';
8663: }
8664: foreach my $size ('width','height') {
8665: if ($confhash{$itemid}{'display'}{$size}) {
8666: $displaylist .= (' 'x2).$lt{$size}.': '.
8667: $confhash{$itemid}{'display'}{$size}.',';
8668: }
8669: }
8670: if ($displaylist) {
8671: $displaylist =~ s/,$//;
8672: $resulttext .= '<li>'.$displaylist.'</li>';
8673: }
8674: }
8675: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
8676: my $fieldlist;
8677: foreach my $field (@allfields) {
8678: if ($confhash{$itemid}{'fields'}{$field}) {
8679: $fieldlist .= (' 'x2).$lt{$field}.',';
8680: }
8681: }
8682: if ($fieldlist) {
8683: $fieldlist =~ s/,$//;
8684: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
8685: }
8686: }
8687: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
8688: my $rolemaps;
8689: foreach my $role (@courseroles) {
8690: if ($confhash{$itemid}{'roles'}{$role}) {
8691: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
8692: $confhash{$itemid}{'roles'}{$role}.',';
8693: }
8694: }
8695: if ($rolemaps) {
8696: $rolemaps =~ s/,$//;
8697: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
8698: }
8699: }
8700: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
8701: my $customlist;
8702: if (keys(%{$confhash{$itemid}{'custom'}})) {
8703: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
8704: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
8705: }
8706: }
8707: if ($customlist) {
8708: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
8709: }
8710: }
8711: $resulttext .= '</ul></li>';
8712: }
8713: }
8714: $resulttext .= '</ul>';
8715: } else {
8716: $resulttext = &mt('No changes made.');
8717: }
8718: } else {
8719: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
8720: }
8721: if ($errors) {
8722: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8723: $errors.'</ul>';
8724: }
8725: return $resulttext;
8726: }
8727:
8728: sub process_ltitools_image {
8729: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
8730: my $filename = $env{'form.'.$caller.'.filename'};
8731: my ($error,$url);
8732: my ($width,$height) = (21,21);
8733: if ($configuserok eq 'ok') {
8734: if ($switchserver) {
8735: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
8736: $switchserver);
8737: } elsif ($author_ok eq 'ok') {
8738: my ($result,$imageurl,$madethumb) =
8739: &publishlogo($r,'upload',$caller,$dom,$confname,
8740: "ltitools/$itemid/icon",$width,$height);
8741: if ($result eq 'ok') {
8742: if ($madethumb) {
8743: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
8744: my $imagethumb = "$path/tn-".$imagefile;
8745: $url = $imagethumb;
8746: } else {
8747: $url = $imageurl;
8748: }
8749: } else {
8750: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8751: }
8752: } else {
8753: $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);
8754: }
8755: } else {
8756: $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);
8757: }
8758: return ($url,$error);
8759: }
8760:
8761: sub get_ltitools_id {
8762: my ($cdom,$title) = @_;
8763: # get lock on ltitools db
8764: my $lockhash = {
8765: lock => $env{'user.name'}.
8766: ':'.$env{'user.domain'},
8767: };
8768: my $tries = 0;
8769: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8770: my ($id,$error);
8771:
8772: while (($gotlock ne 'ok') && ($tries<10)) {
8773: $tries ++;
8774: sleep (0.1);
8775: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
8776: }
8777: if ($gotlock eq 'ok') {
8778: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
8779: if ($currids{'lock'}) {
8780: delete($currids{'lock'});
8781: if (keys(%currids)) {
8782: my @curr = sort { $a <=> $b } keys(%currids);
8783: if ($curr[-1] =~ /^\d+$/) {
8784: $id = 1 + $curr[-1];
8785: }
8786: } else {
8787: $id = 1;
8788: }
8789: if ($id) {
8790: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
8791: $error = 'nostore';
8792: }
8793: } else {
8794: $error = 'nonumber';
8795: }
8796: }
8797: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
8798: } else {
8799: $error = 'nolock';
8800: }
8801: return ($id,$error);
8802: }
8803:
1.3 raeburn 8804: sub modify_autoenroll {
1.205 raeburn 8805: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8806: my ($resulttext,%changes);
8807: my %currautoenroll;
8808: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8809: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8810: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8811: }
8812: }
8813: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8814: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8815: sender => 'Sender for notification messages',
8816: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 8817: my @offon = ('off','on');
1.17 raeburn 8818: my $sender_uname = $env{'form.sender_uname'};
8819: my $sender_domain = $env{'form.sender_domain'};
8820: if ($sender_domain eq '') {
8821: $sender_uname = '';
8822: } elsif ($sender_uname eq '') {
8823: $sender_domain = '';
8824: }
1.129 raeburn 8825: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 8826: my %autoenrollhash = (
1.129 raeburn 8827: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8828: 'sender_uname' => $sender_uname,
8829: 'sender_domain' => $sender_domain,
8830: 'co-owners' => $coowners,
1.1 raeburn 8831: }
8832: );
1.4 raeburn 8833: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8834: $dom);
1.1 raeburn 8835: if ($putresult eq 'ok') {
8836: if (exists($currautoenroll{'run'})) {
8837: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8838: $changes{'run'} = 1;
8839: }
8840: } elsif ($autorun) {
8841: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8842: $changes{'run'} = 1;
1.1 raeburn 8843: }
8844: }
1.17 raeburn 8845: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8846: $changes{'sender'} = 1;
8847: }
1.17 raeburn 8848: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8849: $changes{'sender'} = 1;
8850: }
1.129 raeburn 8851: if ($currautoenroll{'co-owners'} ne '') {
8852: if ($currautoenroll{'co-owners'} ne $coowners) {
8853: $changes{'coowners'} = 1;
8854: }
8855: } elsif ($coowners) {
8856: $changes{'coowners'} = 1;
8857: }
1.1 raeburn 8858: if (keys(%changes) > 0) {
8859: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8860: if ($changes{'run'}) {
1.1 raeburn 8861: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8862: }
8863: if ($changes{'sender'}) {
1.17 raeburn 8864: if ($sender_uname eq '' || $sender_domain eq '') {
8865: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8866: } else {
8867: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8868: }
1.1 raeburn 8869: }
1.129 raeburn 8870: if ($changes{'coowners'}) {
8871: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8872: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8873: if (ref($lastactref) eq 'HASH') {
8874: $lastactref->{'domainconfig'} = 1;
8875: }
1.129 raeburn 8876: }
1.1 raeburn 8877: $resulttext .= '</ul>';
8878: } else {
8879: $resulttext = &mt('No changes made to auto-enrollment settings');
8880: }
8881: } else {
1.11 albertel 8882: $resulttext = '<span class="LC_error">'.
8883: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8884: }
1.3 raeburn 8885: return $resulttext;
1.1 raeburn 8886: }
8887:
8888: sub modify_autoupdate {
1.3 raeburn 8889: my ($dom,%domconfig) = @_;
1.1 raeburn 8890: my ($resulttext,%currautoupdate,%fields,%changes);
8891: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8892: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8893: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8894: }
8895: }
8896: my @offon = ('off','on');
8897: my %title = &Apache::lonlocal::texthash (
8898: run => 'Auto-update:',
8899: classlists => 'Updates to user information in classlists?'
8900: );
1.44 raeburn 8901: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8902: my %fieldtitles = &Apache::lonlocal::texthash (
8903: id => 'Student/Employee ID',
1.20 raeburn 8904: permanentemail => 'E-mail address',
1.1 raeburn 8905: lastname => 'Last Name',
8906: firstname => 'First Name',
8907: middlename => 'Middle Name',
1.132 raeburn 8908: generation => 'Generation',
1.1 raeburn 8909: );
1.142 raeburn 8910: $othertitle = &mt('All users');
1.1 raeburn 8911: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8912: $othertitle = &mt('Other users');
1.1 raeburn 8913: }
8914: foreach my $key (keys(%env)) {
8915: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8916: my ($usertype,$item) = ($1,$2);
8917: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8918: if ($usertype eq 'default') {
8919: push(@{$fields{$1}},$2);
8920: } elsif (ref($types) eq 'ARRAY') {
8921: if (grep(/^\Q$usertype\E$/,@{$types})) {
8922: push(@{$fields{$1}},$2);
8923: }
8924: }
8925: }
1.1 raeburn 8926: }
8927: }
1.131 raeburn 8928: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8929: @lockablenames = sort(@lockablenames);
8930: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8931: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8932: if (@changed) {
8933: $changes{'lockablenames'} = 1;
8934: }
8935: } else {
8936: if (@lockablenames) {
8937: $changes{'lockablenames'} = 1;
8938: }
8939: }
1.1 raeburn 8940: my %updatehash = (
8941: autoupdate => { run => $env{'form.autoupdate_run'},
8942: classlists => $env{'form.classlists'},
8943: fields => {%fields},
1.131 raeburn 8944: lockablenames => \@lockablenames,
1.1 raeburn 8945: }
8946: );
8947: foreach my $key (keys(%currautoupdate)) {
8948: if (($key eq 'run') || ($key eq 'classlists')) {
8949: if (exists($updatehash{autoupdate}{$key})) {
8950: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8951: $changes{$key} = 1;
8952: }
8953: }
8954: } elsif ($key eq 'fields') {
8955: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8956: foreach my $item (@{$types},'default') {
1.1 raeburn 8957: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8958: my $change = 0;
8959: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8960: if (!exists($fields{$item})) {
8961: $change = 1;
1.132 raeburn 8962: last;
1.1 raeburn 8963: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8964: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8965: $change = 1;
1.132 raeburn 8966: last;
1.1 raeburn 8967: }
8968: }
8969: }
8970: if ($change) {
8971: push(@{$changes{$key}},$item);
8972: }
1.26 raeburn 8973: }
1.1 raeburn 8974: }
8975: }
1.131 raeburn 8976: } elsif ($key eq 'lockablenames') {
8977: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8978: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8979: if (@changed) {
8980: $changes{'lockablenames'} = 1;
8981: }
8982: } else {
8983: if (@lockablenames) {
8984: $changes{'lockablenames'} = 1;
8985: }
8986: }
8987: }
8988: }
8989: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8990: if (@lockablenames) {
8991: $changes{'lockablenames'} = 1;
1.1 raeburn 8992: }
8993: }
1.26 raeburn 8994: foreach my $item (@{$types},'default') {
8995: if (defined($fields{$item})) {
8996: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8997: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8998: my $change = 0;
8999: if (ref($fields{$item}) eq 'ARRAY') {
9000: foreach my $type (@{$fields{$item}}) {
9001: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9002: $change = 1;
9003: last;
9004: }
9005: }
9006: }
9007: if ($change) {
9008: push(@{$changes{'fields'}},$item);
9009: }
9010: } else {
1.26 raeburn 9011: push(@{$changes{'fields'}},$item);
9012: }
9013: } else {
9014: push(@{$changes{'fields'}},$item);
1.1 raeburn 9015: }
9016: }
9017: }
9018: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9019: $dom);
9020: if ($putresult eq 'ok') {
9021: if (keys(%changes) > 0) {
9022: $resulttext = &mt('Changes made:').'<ul>';
9023: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9024: if ($key eq 'lockablenames') {
9025: $resulttext .= '<li>';
9026: if (@lockablenames) {
9027: $usertypes->{'default'} = $othertitle;
9028: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9029: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9030: } else {
9031: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9032: }
9033: $resulttext .= '</li>';
9034: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9035: foreach my $item (@{$changes{$key}}) {
9036: my @newvalues;
9037: foreach my $type (@{$fields{$item}}) {
9038: push(@newvalues,$fieldtitles{$type});
9039: }
1.3 raeburn 9040: my $newvaluestr;
9041: if (@newvalues > 0) {
9042: $newvaluestr = join(', ',@newvalues);
9043: } else {
9044: $newvaluestr = &mt('none');
1.6 raeburn 9045: }
1.1 raeburn 9046: if ($item eq 'default') {
1.26 raeburn 9047: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9048: } else {
1.26 raeburn 9049: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9050: }
9051: }
9052: } else {
9053: my $newvalue;
9054: if ($key eq 'run') {
9055: $newvalue = $offon[$env{'form.autoupdate_run'}];
9056: } else {
9057: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9058: }
1.1 raeburn 9059: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9060: }
9061: }
9062: $resulttext .= '</ul>';
9063: } else {
1.3 raeburn 9064: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9065: }
9066: } else {
1.11 albertel 9067: $resulttext = '<span class="LC_error">'.
9068: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9069: }
1.3 raeburn 9070: return $resulttext;
1.1 raeburn 9071: }
9072:
1.125 raeburn 9073: sub modify_autocreate {
9074: my ($dom,%domconfig) = @_;
9075: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9076: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9077: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9078: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9079: }
9080: }
9081: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9082: req => 'Auto-creation of validated requests for official courses',
9083: xmldc => 'Identity of course creator of courses from XML files',
9084: );
9085: my @types = ('xml','req');
9086: foreach my $item (@types) {
9087: $newvals{$item} = $env{'form.autocreate_'.$item};
9088: $newvals{$item} =~ s/\D//g;
9089: $newvals{$item} = 0 if ($newvals{$item} eq '');
9090: }
9091: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
9092: my %domcoords = &get_active_dcs($dom);
9093: unless (exists($domcoords{$newvals{'xmldc'}})) {
9094: $newvals{'xmldc'} = '';
9095: }
9096: %autocreatehash = (
9097: autocreate => { xml => $newvals{'xml'},
9098: req => $newvals{'req'},
9099: }
9100: );
9101: if ($newvals{'xmldc'} ne '') {
9102: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9103: }
9104: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9105: $dom);
9106: if ($putresult eq 'ok') {
9107: my @items = @types;
9108: if ($newvals{'xml'}) {
9109: push(@items,'xmldc');
9110: }
9111: foreach my $item (@items) {
9112: if (exists($currautocreate{$item})) {
9113: if ($currautocreate{$item} ne $newvals{$item}) {
9114: $changes{$item} = 1;
9115: }
9116: } elsif ($newvals{$item}) {
9117: $changes{$item} = 1;
9118: }
9119: }
9120: if (keys(%changes) > 0) {
9121: my @offon = ('off','on');
9122: $resulttext = &mt('Changes made:').'<ul>';
9123: foreach my $item (@types) {
9124: if ($changes{$item}) {
9125: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 9126: $resulttext .= '<li>'.
9127: &mt("$title{$item} set to [_1]$newtxt [_2]",
9128: '<b>','</b>').
9129: '</li>';
1.125 raeburn 9130: }
9131: }
9132: if ($changes{'xmldc'}) {
9133: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9134: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 9135: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9136: }
9137: $resulttext .= '</ul>';
9138: } else {
9139: $resulttext = &mt('No changes made to auto-creation settings');
9140: }
9141: } else {
9142: $resulttext = '<span class="LC_error">'.
9143: &mt('An error occurred: [_1]',$putresult).'</span>';
9144: }
9145: return $resulttext;
9146: }
9147:
1.23 raeburn 9148: sub modify_directorysrch {
9149: my ($dom,%domconfig) = @_;
9150: my ($resulttext,%changes);
9151: my %currdirsrch;
9152: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9153: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9154: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9155: }
9156: }
9157: my %title = ( available => 'Directory search available',
1.24 raeburn 9158: localonly => 'Other domains can search',
1.23 raeburn 9159: searchby => 'Search types',
9160: searchtypes => 'Search latitude');
9161: my @offon = ('off','on');
1.24 raeburn 9162: my @otherdoms = ('Yes','No');
1.23 raeburn 9163:
1.25 raeburn 9164: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9165: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9166: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9167:
1.44 raeburn 9168: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9169: if (keys(%{$usertypes}) == 0) {
9170: @cansearch = ('default');
9171: } else {
9172: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9173: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9174: if (!grep(/^\Q$type\E$/,@cansearch)) {
9175: push(@{$changes{'cansearch'}},$type);
9176: }
1.23 raeburn 9177: }
1.26 raeburn 9178: foreach my $type (@cansearch) {
9179: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9180: push(@{$changes{'cansearch'}},$type);
9181: }
1.23 raeburn 9182: }
1.26 raeburn 9183: } else {
9184: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9185: }
9186: }
9187:
9188: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9189: foreach my $by (@{$currdirsrch{'searchby'}}) {
9190: if (!grep(/^\Q$by\E$/,@searchby)) {
9191: push(@{$changes{'searchby'}},$by);
9192: }
9193: }
9194: foreach my $by (@searchby) {
9195: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9196: push(@{$changes{'searchby'}},$by);
9197: }
9198: }
9199: } else {
9200: push(@{$changes{'searchby'}},@searchby);
9201: }
1.25 raeburn 9202:
9203: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9204: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9205: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9206: push(@{$changes{'searchtypes'}},$type);
9207: }
9208: }
9209: foreach my $type (@searchtypes) {
9210: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9211: push(@{$changes{'searchtypes'}},$type);
9212: }
9213: }
9214: } else {
9215: if (exists($currdirsrch{'searchtypes'})) {
9216: foreach my $type (@searchtypes) {
9217: if ($type ne $currdirsrch{'searchtypes'}) {
9218: push(@{$changes{'searchtypes'}},$type);
9219: }
9220: }
9221: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9222: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9223: }
9224: } else {
9225: push(@{$changes{'searchtypes'}},@searchtypes);
9226: }
9227: }
9228:
1.23 raeburn 9229: my %dirsrch_hash = (
9230: directorysrch => { available => $env{'form.dirsrch_available'},
9231: cansearch => \@cansearch,
1.24 raeburn 9232: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 9233: searchby => \@searchby,
1.25 raeburn 9234: searchtypes => \@searchtypes,
1.23 raeburn 9235: }
9236: );
9237: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9238: $dom);
9239: if ($putresult eq 'ok') {
9240: if (exists($currdirsrch{'available'})) {
9241: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9242: $changes{'available'} = 1;
9243: }
9244: } else {
9245: if ($env{'form.dirsrch_available'} eq '1') {
9246: $changes{'available'} = 1;
9247: }
9248: }
1.24 raeburn 9249: if (exists($currdirsrch{'localonly'})) {
9250: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
9251: $changes{'localonly'} = 1;
9252: }
9253: } else {
9254: if ($env{'form.dirsrch_localonly'} eq '1') {
9255: $changes{'localonly'} = 1;
9256: }
9257: }
1.23 raeburn 9258: if (keys(%changes) > 0) {
9259: $resulttext = &mt('Changes made:').'<ul>';
9260: if ($changes{'available'}) {
9261: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9262: }
1.24 raeburn 9263: if ($changes{'localonly'}) {
9264: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
9265: }
9266:
1.23 raeburn 9267: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9268: my $chgtext;
1.26 raeburn 9269: if (ref($usertypes) eq 'HASH') {
9270: if (keys(%{$usertypes}) > 0) {
9271: foreach my $type (@{$types}) {
9272: if (grep(/^\Q$type\E$/,@cansearch)) {
9273: $chgtext .= $usertypes->{$type}.'; ';
9274: }
9275: }
9276: if (grep(/^default$/,@cansearch)) {
9277: $chgtext .= $othertitle;
9278: } else {
9279: $chgtext =~ s/\; $//;
9280: }
1.210 raeburn 9281: $resulttext .=
1.178 raeburn 9282: '<li>'.
9283: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9284: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9285: '</li>';
1.23 raeburn 9286: }
9287: }
9288: }
9289: if (ref($changes{'searchby'}) eq 'ARRAY') {
9290: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9291: my $chgtext;
9292: foreach my $type (@{$titleorder}) {
9293: if (grep(/^\Q$type\E$/,@searchby)) {
9294: if (defined($searchtitles->{$type})) {
9295: $chgtext .= $searchtitles->{$type}.'; ';
9296: }
9297: }
9298: }
9299: $chgtext =~ s/\; $//;
9300: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9301: }
1.25 raeburn 9302: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9303: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9304: my $chgtext;
9305: foreach my $type (@{$srchtypeorder}) {
9306: if (grep(/^\Q$type\E$/,@searchtypes)) {
9307: if (defined($srchtypes_desc->{$type})) {
9308: $chgtext .= $srchtypes_desc->{$type}.'; ';
9309: }
9310: }
9311: }
9312: $chgtext =~ s/\; $//;
1.178 raeburn 9313: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9314: }
9315: $resulttext .= '</ul>';
9316: } else {
9317: $resulttext = &mt('No changes made to institution directory search settings');
9318: }
9319: } else {
9320: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9321: &mt('An error occurred: [_1]',$putresult).'</span>';
9322: }
9323: return $resulttext;
9324: }
9325:
1.28 raeburn 9326: sub modify_contacts {
1.205 raeburn 9327: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9328: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9329: if (ref($domconfig{'contacts'}) eq 'HASH') {
9330: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9331: $currsetting{$key} = $domconfig{'contacts'}{$key};
9332: }
9333: }
1.134 raeburn 9334: my (%others,%to,%bcc);
1.28 raeburn 9335: my @contacts = ('supportemail','adminemail');
1.102 raeburn 9336: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 9337: 'requestsmail','updatesmail','idconflictsmail');
9338: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 9339: foreach my $type (@mailings) {
9340: @{$newsetting{$type}} =
9341: &Apache::loncommon::get_env_multiple('form.'.$type);
9342: foreach my $item (@contacts) {
9343: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9344: $contacts_hash{contacts}{$type}{$item} = 1;
9345: } else {
9346: $contacts_hash{contacts}{$type}{$item} = 0;
9347: }
9348: }
9349: $others{$type} = $env{'form.'.$type.'_others'};
9350: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 9351: if ($type eq 'helpdeskmail') {
9352: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9353: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
9354: }
1.28 raeburn 9355: }
9356: foreach my $item (@contacts) {
9357: $to{$item} = $env{'form.'.$item};
9358: $contacts_hash{'contacts'}{$item} = $to{$item};
9359: }
1.203 raeburn 9360: foreach my $item (@toggles) {
9361: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9362: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9363: }
9364: }
1.28 raeburn 9365: if (keys(%currsetting) > 0) {
9366: foreach my $item (@contacts) {
9367: if ($to{$item} ne $currsetting{$item}) {
9368: $changes{$item} = 1;
9369: }
9370: }
9371: foreach my $type (@mailings) {
9372: foreach my $item (@contacts) {
9373: if (ref($currsetting{$type}) eq 'HASH') {
9374: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9375: push(@{$changes{$type}},$item);
9376: }
9377: } else {
9378: push(@{$changes{$type}},@{$newsetting{$type}});
9379: }
9380: }
9381: if ($others{$type} ne $currsetting{$type}{'others'}) {
9382: push(@{$changes{$type}},'others');
9383: }
1.134 raeburn 9384: if ($type eq 'helpdeskmail') {
9385: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9386: push(@{$changes{$type}},'bcc');
9387: }
9388: }
1.28 raeburn 9389: }
9390: } else {
9391: my %default;
9392: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9393: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9394: $default{'errormail'} = 'adminemail';
9395: $default{'packagesmail'} = 'adminemail';
9396: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 9397: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9398: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 9399: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9400: foreach my $item (@contacts) {
9401: if ($to{$item} ne $default{$item}) {
9402: $changes{$item} = 1;
1.203 raeburn 9403: }
1.28 raeburn 9404: }
9405: foreach my $type (@mailings) {
9406: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9407:
9408: push(@{$changes{$type}},@{$newsetting{$type}});
9409: }
9410: if ($others{$type} ne '') {
9411: push(@{$changes{$type}},'others');
1.134 raeburn 9412: }
9413: if ($type eq 'helpdeskmail') {
9414: if ($bcc{$type} ne '') {
9415: push(@{$changes{$type}},'bcc');
9416: }
9417: }
1.28 raeburn 9418: }
9419: }
1.203 raeburn 9420: foreach my $item (@toggles) {
9421: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9422: $changes{$item} = 1;
9423: } elsif ((!$env{'form.'.$item}) &&
9424: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9425: $changes{$item} = 1;
9426: }
9427: }
1.28 raeburn 9428: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9429: $dom);
9430: if ($putresult eq 'ok') {
9431: if (keys(%changes) > 0) {
1.205 raeburn 9432: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9433: if (ref($lastactref) eq 'HASH') {
9434: $lastactref->{'domainconfig'} = 1;
9435: }
1.28 raeburn 9436: my ($titles,$short_titles) = &contact_titles();
9437: $resulttext = &mt('Changes made:').'<ul>';
9438: foreach my $item (@contacts) {
9439: if ($changes{$item}) {
9440: $resulttext .= '<li>'.$titles->{$item}.
9441: &mt(' set to: ').
9442: '<span class="LC_cusr_emph">'.
9443: $to{$item}.'</span></li>';
9444: }
9445: }
9446: foreach my $type (@mailings) {
9447: if (ref($changes{$type}) eq 'ARRAY') {
9448: $resulttext .= '<li>'.$titles->{$type}.': ';
9449: my @text;
9450: foreach my $item (@{$newsetting{$type}}) {
9451: push(@text,$short_titles->{$item});
9452: }
9453: if ($others{$type} ne '') {
9454: push(@text,$others{$type});
9455: }
9456: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 9457: join(', ',@text).'</span>';
9458: if ($type eq 'helpdeskmail') {
9459: if ($bcc{$type} ne '') {
9460: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9461: }
9462: }
9463: $resulttext .= '</li>';
1.28 raeburn 9464: }
9465: }
1.203 raeburn 9466: my @offon = ('off','on');
9467: if ($changes{'reporterrors'}) {
9468: $resulttext .= '<li>'.
9469: &mt('E-mail error reports to [_1] set to "'.
9470: $offon[$env{'form.reporterrors'}].'".',
9471: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9472: &mt('LON-CAPA core group - MSU'),600,500)).
9473: '</li>';
9474: }
9475: if ($changes{'reportupdates'}) {
9476: $resulttext .= '<li>'.
9477: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9478: $offon[$env{'form.reportupdates'}].'".',
9479: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9480: &mt('LON-CAPA core group - MSU'),600,500)).
9481: '</li>';
9482: }
1.28 raeburn 9483: $resulttext .= '</ul>';
9484: } else {
1.34 raeburn 9485: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 9486: }
9487: } else {
9488: $resulttext = '<span class="LC_error">'.
9489: &mt('An error occurred: [_1].',$putresult).'</span>';
9490: }
9491: return $resulttext;
9492: }
9493:
9494: sub modify_usercreation {
1.27 raeburn 9495: my ($dom,%domconfig) = @_;
1.224 raeburn 9496: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9497: my $warningmsg;
1.27 raeburn 9498: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9499: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 9500: if ($key eq 'cancreate') {
9501: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9502: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9503: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 9504: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9505: ($item eq 'recaptchaversion')) {
1.224 raeburn 9506: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9507: } else {
9508: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9509: }
9510: }
9511: }
9512: } elsif ($key eq 'email_rule') {
9513: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9514: } else {
9515: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9516: }
1.27 raeburn 9517: }
9518: }
9519: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 9520: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 9521: my @contexts = ('author','course','requestcrs');
1.34 raeburn 9522: foreach my $item(@contexts) {
1.224 raeburn 9523: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9524: }
1.34 raeburn 9525: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9526: foreach my $item (@contexts) {
1.224 raeburn 9527: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9528: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9529: }
1.27 raeburn 9530: }
1.34 raeburn 9531: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9532: foreach my $item (@contexts) {
1.43 raeburn 9533: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9534: if ($cancreate{$item} ne 'any') {
9535: push(@{$changes{'cancreate'}},$item);
9536: }
9537: } else {
9538: if ($cancreate{$item} ne 'none') {
9539: push(@{$changes{'cancreate'}},$item);
9540: }
1.27 raeburn 9541: }
9542: }
9543: } else {
1.43 raeburn 9544: foreach my $item (@contexts) {
1.34 raeburn 9545: push(@{$changes{'cancreate'}},$item);
9546: }
1.27 raeburn 9547: }
1.34 raeburn 9548:
1.27 raeburn 9549: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9550: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9551: if (!grep(/^\Q$type\E$/,@username_rule)) {
9552: push(@{$changes{'username_rule'}},$type);
9553: }
9554: }
9555: foreach my $type (@username_rule) {
9556: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9557: push(@{$changes{'username_rule'}},$type);
9558: }
9559: }
9560: } else {
9561: push(@{$changes{'username_rule'}},@username_rule);
9562: }
9563:
1.32 raeburn 9564: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9565: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9566: if (!grep(/^\Q$type\E$/,@id_rule)) {
9567: push(@{$changes{'id_rule'}},$type);
9568: }
9569: }
9570: foreach my $type (@id_rule) {
9571: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9572: push(@{$changes{'id_rule'}},$type);
9573: }
9574: }
9575: } else {
9576: push(@{$changes{'id_rule'}},@id_rule);
9577: }
9578:
1.43 raeburn 9579: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9580: my @authtypes = ('int','krb4','krb5','loc');
9581: my %authhash;
1.43 raeburn 9582: foreach my $item (@authen_contexts) {
1.28 raeburn 9583: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9584: foreach my $auth (@authtypes) {
9585: if (grep(/^\Q$auth\E$/,@authallowed)) {
9586: $authhash{$item}{$auth} = 1;
9587: } else {
9588: $authhash{$item}{$auth} = 0;
9589: }
9590: }
9591: }
9592: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9593: foreach my $item (@authen_contexts) {
1.28 raeburn 9594: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9595: foreach my $auth (@authtypes) {
9596: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9597: push(@{$changes{'authtypes'}},$item);
9598: last;
9599: }
9600: }
9601: }
9602: }
9603: } else {
1.43 raeburn 9604: foreach my $item (@authen_contexts) {
1.28 raeburn 9605: push(@{$changes{'authtypes'}},$item);
9606: }
9607: }
9608:
1.224 raeburn 9609: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9610: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9611: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9612: $save_usercreate{'id_rule'} = \@id_rule;
9613: $save_usercreate{'username_rule'} = \@username_rule,
9614: $save_usercreate{'authtypes'} = \%authhash;
9615:
1.27 raeburn 9616: my %usercreation_hash = (
1.224 raeburn 9617: usercreation => \%save_usercreate,
9618: );
1.27 raeburn 9619:
9620: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9621: $dom);
1.50 raeburn 9622:
1.224 raeburn 9623: if ($putresult eq 'ok') {
9624: if (keys(%changes) > 0) {
9625: $resulttext = &mt('Changes made:').'<ul>';
9626: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9627: my %lt = &usercreation_types();
9628: foreach my $type (@{$changes{'cancreate'}}) {
9629: my $chgtext = $lt{$type}.', ';
9630: if ($cancreate{$type} eq 'none') {
9631: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9632: } elsif ($cancreate{$type} eq 'any') {
9633: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9634: } elsif ($cancreate{$type} eq 'official') {
9635: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9636: } elsif ($cancreate{$type} eq 'unofficial') {
9637: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9638: }
9639: $resulttext .= '<li>'.$chgtext.'</li>';
9640: }
9641: }
9642: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9643: my ($rules,$ruleorder) =
9644: &Apache::lonnet::inst_userrules($dom,'username');
9645: my $chgtext = '<ul>';
9646: foreach my $type (@username_rule) {
9647: if (ref($rules->{$type}) eq 'HASH') {
9648: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9649: }
9650: }
9651: $chgtext .= '</ul>';
9652: if (@username_rule > 0) {
9653: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9654: } else {
9655: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9656: }
9657: }
9658: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9659: my ($idrules,$idruleorder) =
9660: &Apache::lonnet::inst_userrules($dom,'id');
9661: my $chgtext = '<ul>';
9662: foreach my $type (@id_rule) {
9663: if (ref($idrules->{$type}) eq 'HASH') {
9664: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9665: }
9666: }
9667: $chgtext .= '</ul>';
9668: if (@id_rule > 0) {
9669: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9670: } else {
9671: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9672: }
9673: }
9674: my %authname = &authtype_names();
9675: my %context_title = &context_names();
9676: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9677: my $chgtext = '<ul>';
9678: foreach my $type (@{$changes{'authtypes'}}) {
9679: my @allowed;
9680: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9681: foreach my $auth (@authtypes) {
9682: if ($authhash{$type}{$auth}) {
9683: push(@allowed,$authname{$auth});
9684: }
9685: }
9686: if (@allowed > 0) {
9687: $chgtext .= join(', ',@allowed).'</li>';
9688: } else {
9689: $chgtext .= &mt('none').'</li>';
9690: }
9691: }
9692: $chgtext .= '</ul>';
9693: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9694: $resulttext .= '</li>';
9695: }
9696: $resulttext .= '</ul>';
9697: } else {
9698: $resulttext = &mt('No changes made to user creation settings');
9699: }
9700: } else {
9701: $resulttext = '<span class="LC_error">'.
9702: &mt('An error occurred: [_1]',$putresult).'</span>';
9703: }
9704: if ($warningmsg ne '') {
9705: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9706: }
9707: return $resulttext;
9708: }
9709:
9710: sub modify_selfcreation {
9711: my ($dom,%domconfig) = @_;
9712: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9713: my (%save_usercreate,%save_usermodify);
1.228 raeburn 9714: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9715: if (ref($types) eq 'ARRAY') {
9716: $usertypes->{'default'} = $othertitle;
9717: push(@{$types},'default');
9718: }
1.224 raeburn 9719: #
9720: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9721: #
9722: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9723: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9724: if ($key eq 'cancreate') {
9725: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9726: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9727: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9728: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 9729: ($item eq 'recaptchaversion') ||
1.236 raeburn 9730: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 9731: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 9732: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9733: } else {
9734: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9735: }
9736: }
9737: }
9738: } elsif ($key eq 'email_rule') {
9739: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9740: } else {
9741: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9742: }
9743: }
9744: }
9745: #
9746: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9747: #
9748: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9749: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9750: if ($key eq 'selfcreate') {
9751: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9752: } else {
9753: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9754: }
9755: }
9756: }
9757:
9758: my @contexts = ('selfcreate');
9759: @{$cancreate{'selfcreate'}} = ();
9760: %{$cancreate{'emailusername'}} = ();
9761: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 9762: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 9763: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9764: my %selfcreatetypes = (
9765: sso => 'users authenticated by institutional single sign on',
9766: login => 'users authenticated by institutional log-in',
1.236 raeburn 9767: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9768: );
1.224 raeburn 9769: #
9770: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9771: # is permitted.
9772: #
1.236 raeburn 9773:
9774: my @statuses;
9775: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9776: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9777: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9778: }
9779: }
9780: push(@statuses,'default');
9781:
1.228 raeburn 9782: foreach my $item ('login','sso','email') {
1.224 raeburn 9783: if ($item eq 'email') {
1.236 raeburn 9784: if ($env{'form.cancreate_email'}) {
1.224 raeburn 9785: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 9786: push(@contexts,'selfcreateprocessing');
9787: foreach my $type (@statuses) {
9788: if ($type eq 'default') {
9789: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9790: } else {
9791: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9792: }
9793: }
1.224 raeburn 9794: }
9795: } else {
9796: if ($env{'form.cancreate_'.$item}) {
9797: push(@{$cancreate{'selfcreate'}},$item);
9798: }
9799: }
9800: }
9801: my (@email_rule,%userinfo,%savecaptcha);
9802: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9803: #
1.228 raeburn 9804: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9805: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 9806: #
1.236 raeburn 9807:
1.244 raeburn 9808: if ($env{'form.cancreate_email'}) {
1.228 raeburn 9809: push(@contexts,'emailusername');
9810: if (ref($types) eq 'ARRAY') {
9811: foreach my $type (@{$types}) {
9812: if (ref($infofields) eq 'ARRAY') {
9813: foreach my $field (@{$infofields}) {
9814: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9815: $cancreate{'emailusername'}{$type}{$field} = $1;
9816: }
9817: }
1.224 raeburn 9818: }
9819: }
9820: }
9821: #
9822: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9823: # queued requests for self-creation of account using e-mail address as username
9824: #
9825:
9826: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9827: @approvalnotify = sort(@approvalnotify);
9828: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9829: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9830: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9831: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9832: push(@{$changes{'cancreate'}},'notify');
9833: }
9834: } else {
9835: if ($cancreate{'notify'}{'approval'}) {
9836: push(@{$changes{'cancreate'}},'notify');
9837: }
9838: }
9839: } elsif ($cancreate{'notify'}{'approval'}) {
9840: push(@{$changes{'cancreate'}},'notify');
9841: }
9842:
9843: #
9844: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9845: #
9846: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9847: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9848: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9849: if (@{$curr_usercreation{'email_rule'}} > 0) {
9850: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9851: if (!grep(/^\Q$type\E$/,@email_rule)) {
9852: push(@{$changes{'email_rule'}},$type);
9853: }
9854: }
9855: }
9856: if (@email_rule > 0) {
9857: foreach my $type (@email_rule) {
9858: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9859: push(@{$changes{'email_rule'}},$type);
9860: }
9861: }
9862: }
9863: } elsif (@email_rule > 0) {
9864: push(@{$changes{'email_rule'}},@email_rule);
9865: }
9866: }
9867: #
1.236 raeburn 9868: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 9869: # institutional log-in.
9870: #
9871: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9872: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9873: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9874: ($domdefaults{'auth_def'} eq 'localauth'))) {
9875: $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.').' '.
9876: &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.');
9877: }
9878: }
9879: my @fields = ('lastname','firstname','middlename','generation',
9880: 'permanentemail','id');
1.240 raeburn 9881: my @shibfields = (@fields,'inststatus');
1.224 raeburn 9882: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9883: #
9884: # Where usernames may created for institutional log-in and/or institutional single sign on:
9885: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9886: # may self-create accounts
9887: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9888: # which the user may supply, if institutional data is unavailable.
9889: #
9890: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9891: if (ref($types) eq 'ARRAY') {
1.228 raeburn 9892: if (@{$types} > 1) {
1.224 raeburn 9893: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9894: push(@contexts,'statustocreate');
9895: } else {
9896: undef($cancreate{'statustocreate'});
9897: }
9898: foreach my $type (@{$types}) {
9899: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9900: foreach my $field (@fields) {
9901: if (grep(/^\Q$field\E$/,@modifiable)) {
9902: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9903: } else {
9904: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9905: }
9906: }
9907: }
9908: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9909: foreach my $type (@{$types}) {
9910: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9911: foreach my $field (@fields) {
9912: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9913: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9914: push(@{$changes{'selfcreate'}},$type);
9915: last;
9916: }
9917: }
9918: }
9919: }
9920: } else {
9921: foreach my $type (@{$types}) {
9922: push(@{$changes{'selfcreate'}},$type);
9923: }
9924: }
9925: }
1.240 raeburn 9926: foreach my $field (@shibfields) {
9927: if ($env{'form.shibenv_'.$field} ne '') {
9928: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9929: }
9930: }
9931: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9932: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9933: foreach my $field (@shibfields) {
9934: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9935: push(@{$changes{'cancreate'}},'shibenv');
9936: }
9937: }
9938: } else {
9939: foreach my $field (@shibfields) {
9940: if ($env{'form.shibenv_'.$field}) {
9941: push(@{$changes{'cancreate'}},'shibenv');
9942: last;
9943: }
9944: }
9945: }
9946: }
1.224 raeburn 9947: }
9948: foreach my $item (@contexts) {
9949: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
9950: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
9951: if (ref($cancreate{$item}) eq 'ARRAY') {
9952: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
9953: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9954: push(@{$changes{'cancreate'}},$item);
9955: }
9956: }
9957: }
9958: }
9959: if (ref($cancreate{$item}) eq 'ARRAY') {
9960: foreach my $type (@{$cancreate{$item}}) {
9961: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
9962: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9963: push(@{$changes{'cancreate'}},$item);
9964: }
9965: }
9966: }
9967: }
9968: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
9969: if (ref($cancreate{$item}) eq 'HASH') {
9970: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 9971: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
9972: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
9973: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
9974: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9975: push(@{$changes{'cancreate'}},$item);
9976: }
9977: }
9978: }
1.236 raeburn 9979: } elsif ($item eq 'selfcreateprocessing') {
9980: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
9981: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9982: push(@{$changes{'cancreate'}},$item);
9983: }
9984: }
1.228 raeburn 9985: } else {
9986: if (!$cancreate{$item}{$curr}) {
9987: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9988: push(@{$changes{'cancreate'}},$item);
9989: }
1.224 raeburn 9990: }
9991: }
9992: }
9993: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 9994: if (ref($cancreate{$item}{$field}) eq 'HASH') {
9995: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
9996: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
9997: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
9998: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
9999: push(@{$changes{'cancreate'}},$item);
10000: }
10001: }
10002: } else {
10003: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10004: push(@{$changes{'cancreate'}},$item);
10005: }
10006: }
10007: }
1.236 raeburn 10008: } elsif ($item eq 'selfcreateprocessing') {
10009: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10010: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10011: push(@{$changes{'cancreate'}},$item);
10012: }
10013: }
1.228 raeburn 10014: } else {
10015: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10016: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10017: push(@{$changes{'cancreate'}},$item);
10018: }
1.224 raeburn 10019: }
10020: }
10021: }
10022: }
10023: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10024: if (ref($cancreate{$item}) eq 'ARRAY') {
10025: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10026: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10027: push(@{$changes{'cancreate'}},$item);
10028: }
10029: }
10030: } elsif (ref($cancreate{$item}) eq 'HASH') {
10031: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10032: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10033: push(@{$changes{'cancreate'}},$item);
10034: }
10035: }
10036: }
10037: } elsif ($item eq 'emailusername') {
1.228 raeburn 10038: if (ref($cancreate{$item}) eq 'HASH') {
10039: foreach my $type (keys(%{$cancreate{$item}})) {
10040: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10041: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10042: if ($cancreate{$item}{$type}{$field}) {
10043: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10044: push(@{$changes{'cancreate'}},$item);
10045: }
10046: last;
10047: }
10048: }
10049: }
10050: }
1.224 raeburn 10051: }
10052: }
10053: }
10054: #
10055: # Populate %save_usercreate hash with updates to self-creation configuration.
10056: #
10057: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10058: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 10059: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 10060: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10061: if (ref($cancreate{'notify'}) eq 'HASH') {
10062: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10063: }
1.236 raeburn 10064: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10065: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10066: }
1.224 raeburn 10067: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10068: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10069: }
1.240 raeburn 10070: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10071: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10072: }
1.224 raeburn 10073: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10074: $save_usercreate{'emailrule'} = \@email_rule;
10075:
10076: my %userconfig_hash = (
10077: usercreation => \%save_usercreate,
10078: usermodification => \%save_usermodify,
10079: );
10080: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10081: $dom);
10082: #
10083: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10084: #
1.27 raeburn 10085: if ($putresult eq 'ok') {
10086: if (keys(%changes) > 0) {
10087: $resulttext = &mt('Changes made:').'<ul>';
10088: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 10089: my %lt = &selfcreation_types();
1.34 raeburn 10090: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10091: my $chgtext;
1.45 raeburn 10092: if ($type eq 'selfcreate') {
1.50 raeburn 10093: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 10094: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10095: } else {
1.224 raeburn 10096: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10097: '<ul>';
1.50 raeburn 10098: foreach my $case (@{$cancreate{$type}}) {
10099: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10100: }
10101: $chgtext .= '</ul>';
1.100 raeburn 10102: if (ref($cancreate{$type}) eq 'ARRAY') {
10103: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10104: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10105: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 10106: $chgtext .= '<br />'.
10107: '<span class="LC_warning">'.
10108: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10109: '</span>';
1.100 raeburn 10110: }
10111: }
10112: }
10113: }
1.43 raeburn 10114: }
1.240 raeburn 10115: } elsif ($type eq 'shibenv') {
10116: if (keys(%{$cancreate{$type}}) == 0) {
10117: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10118: } else {
10119: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10120: '<ul>';
10121: foreach my $field (@shibfields) {
10122: next if ($cancreate{$type}{$field} eq '');
10123: if ($field eq 'inststatus') {
10124: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10125: } else {
10126: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10127: }
10128: }
10129: $chgtext .= '</ul>';
10130: }
1.93 raeburn 10131: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10132: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10133: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10134: if (@{$cancreate{'selfcreate'}} > 0) {
10135: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10136: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10137: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10138: $chgtext .= '<br />'.
10139: '<span class="LC_warning">'.
10140: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10141: '</span>';
10142: }
1.96 raeburn 10143: } elsif (ref($usertypes) eq 'HASH') {
10144: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10145: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10146: } else {
10147: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10148: }
10149: $chgtext .= '<ul>';
10150: foreach my $case (@{$cancreate{$type}}) {
10151: if ($case eq 'default') {
10152: $chgtext .= '<li>'.$othertitle.'</li>';
10153: } else {
10154: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10155: }
10156: }
1.100 raeburn 10157: $chgtext .= '</ul>';
10158: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 10159: $chgtext .= '<br /><span class="LC_warning">'.
10160: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10161: '</span>';
1.100 raeburn 10162: }
10163: }
10164: } else {
10165: if (@{$cancreate{$type}} == 0) {
10166: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10167: } else {
10168: $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 10169: }
10170: }
10171: }
1.236 raeburn 10172: } elsif ($type eq 'selfcreateprocessing') {
10173: my %choices = &Apache::lonlocal::texthash (
10174: automatic => 'Automatic approval',
10175: approval => 'Queued for approval',
10176: );
10177: if (@statuses > 1) {
10178: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10179: '<ul>';
10180: foreach my $type (@statuses) {
10181: if ($type eq 'default') {
10182: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10183: } else {
10184: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10185: }
10186: }
10187: $chgtext .= '</ul>';
10188: } else {
10189: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10190: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10191: }
1.165 raeburn 10192: } elsif ($type eq 'captcha') {
1.224 raeburn 10193: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 10194: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10195: } else {
10196: my %captchas = &captcha_phrases();
1.224 raeburn 10197: if ($captchas{$savecaptcha{$type}}) {
10198: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 10199: } else {
1.210 raeburn 10200: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 10201: }
10202: }
10203: } elsif ($type eq 'recaptchakeys') {
10204: my ($privkey,$pubkey);
1.224 raeburn 10205: if (ref($savecaptcha{$type}) eq 'HASH') {
10206: $pubkey = $savecaptcha{$type}{'public'};
10207: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 10208: }
10209: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10210: if (!$pubkey) {
10211: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10212: } else {
10213: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10214: }
10215: if (!$privkey) {
10216: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10217: } else {
10218: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10219: }
10220: $chgtext .= '</ul>';
1.269 raeburn 10221: } elsif ($type eq 'recaptchaversion') {
10222: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 10223: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 10224: }
1.224 raeburn 10225: } elsif ($type eq 'emailusername') {
10226: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 10227: if (ref($types) eq 'ARRAY') {
10228: foreach my $type (@{$types}) {
10229: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10230: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 10231: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 10232: '<ul>';
10233: foreach my $field (@{$infofields}) {
10234: if ($cancreate{'emailusername'}{$type}{$field}) {
10235: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10236: }
10237: }
1.245 raeburn 10238: $chgtext .= '</ul>';
10239: } else {
10240: $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 10241: }
10242: } else {
1.245 raeburn 10243: $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 10244: }
10245: }
10246: }
10247: }
10248: } elsif ($type eq 'notify') {
10249: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10250: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10251: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10252: if ($cancreate{'notify'}{'approval'}) {
10253: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10254: }
10255: }
1.43 raeburn 10256: }
1.34 raeburn 10257: }
1.224 raeburn 10258: if ($chgtext) {
10259: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10260: }
10261: }
10262: }
1.43 raeburn 10263: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10264: my ($emailrules,$emailruleorder) =
10265: &Apache::lonnet::inst_userrules($dom,'email');
10266: my $chgtext = '<ul>';
10267: foreach my $type (@email_rule) {
10268: if (ref($emailrules->{$type}) eq 'HASH') {
10269: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10270: }
10271: }
10272: $chgtext .= '</ul>';
10273: if (@email_rule > 0) {
1.224 raeburn 10274: $resulttext .= '<li>'.
10275: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10276: $chgtext.
10277: '</li>';
1.43 raeburn 10278: } else {
1.224 raeburn 10279: $resulttext .= '<li>'.
10280: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10281: '</li>';
1.43 raeburn 10282: }
10283: }
1.224 raeburn 10284: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10285: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10286: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10287: foreach my $type (@{$changes{'selfcreate'}}) {
10288: my $typename = $type;
10289: if (ref($usertypes) eq 'HASH') {
10290: if ($usertypes->{$type} ne '') {
10291: $typename = $usertypes->{$type};
10292: }
10293: }
10294: my @modifiable;
10295: $resulttext .= '<li>'.
10296: &mt('Self-creation of account by users with status: [_1]',
10297: '<span class="LC_cusr_emph">'.$typename.'</span>').
10298: ' - '.&mt('modifiable fields (if institutional data blank): ');
10299: foreach my $field (@fields) {
10300: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10301: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 10302: }
10303: }
1.224 raeburn 10304: if (@modifiable > 0) {
10305: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10306: } else {
1.224 raeburn 10307: $resulttext .= &mt('none');
1.43 raeburn 10308: }
1.224 raeburn 10309: $resulttext .= '</li>';
1.28 raeburn 10310: }
1.224 raeburn 10311: $resulttext .= '</ul></li>';
1.28 raeburn 10312: }
1.27 raeburn 10313: $resulttext .= '</ul>';
10314: } else {
1.224 raeburn 10315: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10316: }
10317: } else {
10318: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10319: &mt('An error occurred: [_1]',$putresult).'</span>';
10320: }
1.43 raeburn 10321: if ($warningmsg ne '') {
10322: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10323: }
1.23 raeburn 10324: return $resulttext;
10325: }
10326:
1.165 raeburn 10327: sub process_captcha {
10328: my ($container,$changes,$newsettings,$current) = @_;
10329: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10330: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10331: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10332: $newsettings->{'captcha'} = 'original';
10333: }
10334: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 10335: if ($container eq 'cancreate') {
1.169 raeburn 10336: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10337: push(@{$changes->{'cancreate'}},'captcha');
10338: } elsif (!defined($changes->{'cancreate'})) {
10339: $changes->{'cancreate'} = ['captcha'];
10340: }
10341: } else {
10342: $changes->{'captcha'} = 1;
1.165 raeburn 10343: }
10344: }
1.269 raeburn 10345: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 10346: if ($newsettings->{'captcha'} eq 'recaptcha') {
10347: $newpub = $env{'form.'.$container.'_recaptchapub'};
10348: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 10349: $newpub =~ s/[^\w\-]//g;
10350: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 10351: $newsettings->{'recaptchakeys'} = {
10352: public => $newpub,
10353: private => $newpriv,
10354: };
1.269 raeburn 10355: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10356: $newversion =~ s/\D//g;
10357: if ($newversion ne '2') {
10358: $newversion = 1;
10359: }
10360: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 10361: }
10362: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10363: $currpub = $current->{'recaptchakeys'}{'public'};
10364: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 10365: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10366: $newsettings->{'recaptchakeys'} = {
10367: public => '',
10368: private => '',
10369: }
10370: }
1.165 raeburn 10371: }
1.269 raeburn 10372: if ($current->{'captcha'} eq 'recaptcha') {
10373: $currversion = $current->{'recaptchaversion'};
10374: if ($currversion ne '2') {
10375: $currversion = 1;
10376: }
10377: }
10378: if ($currversion ne $newversion) {
10379: if ($container eq 'cancreate') {
10380: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10381: push(@{$changes->{'cancreate'}},'recaptchaversion');
10382: } elsif (!defined($changes->{'cancreate'})) {
10383: $changes->{'cancreate'} = ['recaptchaversion'];
10384: }
10385: } else {
10386: $changes->{'recaptchaversion'} = 1;
10387: }
10388: }
1.165 raeburn 10389: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 10390: if ($container eq 'cancreate') {
10391: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10392: push(@{$changes->{'cancreate'}},'recaptchakeys');
10393: } elsif (!defined($changes->{'cancreate'})) {
10394: $changes->{'cancreate'} = ['recaptchakeys'];
10395: }
10396: } else {
1.210 raeburn 10397: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 10398: }
10399: }
10400: return;
10401: }
10402:
1.33 raeburn 10403: sub modify_usermodification {
10404: my ($dom,%domconfig) = @_;
1.224 raeburn 10405: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10406: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10407: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 10408: if ($key eq 'selfcreate') {
10409: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10410: } else {
10411: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10412: }
1.33 raeburn 10413: }
10414: }
1.224 raeburn 10415: my @contexts = ('author','course');
1.33 raeburn 10416: my %context_title = (
10417: author => 'In author context',
10418: course => 'In course context',
10419: );
10420: my @fields = ('lastname','firstname','middlename','generation',
10421: 'permanentemail','id');
10422: my %roles = (
10423: author => ['ca','aa'],
10424: course => ['st','ep','ta','in','cr'],
10425: );
10426: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10427: foreach my $context (@contexts) {
10428: foreach my $role (@{$roles{$context}}) {
10429: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10430: foreach my $item (@fields) {
10431: if (grep(/^\Q$item\E$/,@modifiable)) {
10432: $modifyhash{$context}{$role}{$item} = 1;
10433: } else {
10434: $modifyhash{$context}{$role}{$item} = 0;
10435: }
10436: }
10437: }
10438: if (ref($curr_usermodification{$context}) eq 'HASH') {
10439: foreach my $role (@{$roles{$context}}) {
10440: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10441: foreach my $field (@fields) {
10442: if ($modifyhash{$context}{$role}{$field} ne
10443: $curr_usermodification{$context}{$role}{$field}) {
10444: push(@{$changes{$context}},$role);
10445: last;
10446: }
10447: }
10448: }
10449: }
10450: } else {
10451: foreach my $context (@contexts) {
10452: foreach my $role (@{$roles{$context}}) {
10453: push(@{$changes{$context}},$role);
10454: }
10455: }
10456: }
10457: }
10458: my %usermodification_hash = (
10459: usermodification => \%modifyhash,
10460: );
10461: my $putresult = &Apache::lonnet::put_dom('configuration',
10462: \%usermodification_hash,$dom);
10463: if ($putresult eq 'ok') {
10464: if (keys(%changes) > 0) {
10465: $resulttext = &mt('Changes made: ').'<ul>';
10466: foreach my $context (@contexts) {
10467: if (ref($changes{$context}) eq 'ARRAY') {
10468: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10469: if (ref($changes{$context}) eq 'ARRAY') {
10470: foreach my $role (@{$changes{$context}}) {
10471: my $rolename;
1.224 raeburn 10472: if ($role eq 'cr') {
10473: $rolename = &mt('Custom');
1.33 raeburn 10474: } else {
1.224 raeburn 10475: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10476: }
10477: my @modifiable;
1.224 raeburn 10478: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10479: foreach my $field (@fields) {
10480: if ($modifyhash{$context}{$role}{$field}) {
10481: push(@modifiable,$fieldtitles{$field});
10482: }
10483: }
10484: if (@modifiable > 0) {
10485: $resulttext .= join(', ',@modifiable);
10486: } else {
10487: $resulttext .= &mt('none');
10488: }
10489: $resulttext .= '</li>';
10490: }
10491: $resulttext .= '</ul></li>';
10492: }
10493: }
10494: }
10495: $resulttext .= '</ul>';
10496: } else {
10497: $resulttext = &mt('No changes made to user modification settings');
10498: }
10499: } else {
10500: $resulttext = '<span class="LC_error">'.
10501: &mt('An error occurred: [_1]',$putresult).'</span>';
10502: }
10503: return $resulttext;
10504: }
10505:
1.43 raeburn 10506: sub modify_defaults {
1.212 raeburn 10507: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10508: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 10509: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 10510: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 10511: my @authtypes = ('internal','krb4','krb5','localauth');
10512: foreach my $item (@items) {
10513: $newvalues{$item} = $env{'form.'.$item};
10514: if ($item eq 'auth_def') {
10515: if ($newvalues{$item} ne '') {
10516: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10517: push(@errors,$item);
10518: }
10519: }
10520: } elsif ($item eq 'lang_def') {
10521: if ($newvalues{$item} ne '') {
10522: if ($newvalues{$item} =~ /^(\w+)/) {
10523: my $langcode = $1;
1.103 raeburn 10524: if ($langcode ne 'x_chef') {
10525: if (code2language($langcode) eq '') {
10526: push(@errors,$item);
10527: }
1.43 raeburn 10528: }
10529: } else {
10530: push(@errors,$item);
10531: }
10532: }
1.54 raeburn 10533: } elsif ($item eq 'timezone_def') {
10534: if ($newvalues{$item} ne '') {
1.62 raeburn 10535: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10536: push(@errors,$item);
10537: }
10538: }
1.68 raeburn 10539: } elsif ($item eq 'datelocale_def') {
10540: if ($newvalues{$item} ne '') {
10541: my @datelocale_ids = DateTime::Locale->ids();
10542: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10543: push(@errors,$item);
10544: }
10545: }
1.141 raeburn 10546: } elsif ($item eq 'portal_def') {
10547: if ($newvalues{$item} ne '') {
10548: 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])\/?$/) {
10549: push(@errors,$item);
10550: }
10551: }
1.43 raeburn 10552: }
10553: if (grep(/^\Q$item\E$/,@errors)) {
10554: $newvalues{$item} = $domdefaults{$item};
10555: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10556: $changes{$item} = 1;
10557: }
1.72 raeburn 10558: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10559: }
10560: my %defaults_hash = (
1.72 raeburn 10561: defaults => \%newvalues,
10562: );
1.43 raeburn 10563: my $title = &defaults_titles();
1.236 raeburn 10564:
10565: my $currinststatus;
10566: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10567: $currinststatus = $domconfig{'inststatus'};
10568: } else {
10569: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10570: $currinststatus = {
10571: inststatustypes => $usertypes,
10572: inststatusorder => $types,
10573: inststatusguest => [],
10574: };
10575: }
10576: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10577: my @allpos;
10578: my %guests;
10579: my %alltypes;
10580: my ($currtitles,$currguests,$currorder);
10581: if (ref($currinststatus) eq 'HASH') {
10582: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10583: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10584: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10585: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10586: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10587: }
10588: }
10589: unless (grep(/^\Q$type\E$/,@todelete)) {
10590: my $position = $env{'form.inststatus_pos_'.$type};
10591: $position =~ s/\D+//g;
10592: $allpos[$position] = $type;
10593: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10594: $alltypes{$type} =~ s/`//g;
10595: if ($env{'form.inststatus_guest_'.$type}) {
10596: $guests{$type} = 1;
10597: }
10598: }
10599: }
10600: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10601: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10602: }
10603: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10604: $currtitles =~ s/,$//;
10605: }
10606: }
10607: if ($env{'form.addinststatus'}) {
10608: my $newtype = $env{'form.addinststatus'};
10609: $newtype =~ s/\W//g;
10610: unless (exists($alltypes{$newtype})) {
10611: if ($env{'form.addinststatus_guest'}) {
10612: $guests{$newtype} = 1;
10613: }
10614: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10615: $alltypes{$newtype} =~ s/`//g;
10616: my $position = $env{'form.addinststatus_pos'};
10617: $position =~ s/\D+//g;
10618: if ($position ne '') {
10619: $allpos[$position] = $newtype;
10620: }
10621: }
10622: }
10623: my (@orderedstatus,@orderedguests);
10624: foreach my $type (@allpos) {
10625: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10626: push(@orderedstatus,$type);
10627: if ($guests{$type}) {
10628: push(@orderedguests,$type);
10629: }
10630: }
10631: }
10632: foreach my $type (keys(%alltypes)) {
10633: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10634: delete($alltypes{$type});
10635: }
10636: }
10637: $defaults_hash{'inststatus'} = {
10638: inststatustypes => \%alltypes,
10639: inststatusorder => \@orderedstatus,
10640: inststatusguest => \@orderedguests,
10641: };
10642: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10643: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10644: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10645: }
10646: }
10647: if ($currorder ne join(',',@orderedstatus)) {
10648: $changes{'inststatus'}{'inststatusorder'} = 1;
10649: }
10650: if ($currguests ne join(',',@orderedguests)) {
10651: $changes{'inststatus'}{'inststatusguest'} = 1;
10652: }
10653: my $newtitles;
10654: foreach my $item (@orderedstatus) {
10655: $newtitles .= $alltypes{$item}.',';
10656: }
10657: $newtitles =~ s/,$//;
10658: if ($currtitles ne $newtitles) {
10659: $changes{'inststatus'}{'inststatustypes'} = 1;
10660: }
1.43 raeburn 10661: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10662: $dom);
10663: if ($putresult eq 'ok') {
10664: if (keys(%changes) > 0) {
10665: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 10666: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10667: 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";
10668: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 10669: if ($item eq 'inststatus') {
10670: if (ref($changes{'inststatus'}) eq 'HASH') {
10671: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10672: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10673: foreach my $type (@orderedstatus) {
10674: $resulttext .= $alltypes{$type}.', ';
10675: }
10676: $resulttext =~ s/, $//;
10677: $resulttext .= '</li>';
10678: }
10679: if ($changes{'inststatus'}{'inststatusguest'}) {
10680: $resulttext .= '<li>';
10681: if (@orderedguests) {
10682: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10683: foreach my $type (@orderedguests) {
10684: $resulttext .= $alltypes{$type}.', ';
10685: }
10686: $resulttext =~ s/, $//;
10687: } else {
10688: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10689: }
10690: $resulttext .= '</li>';
10691: }
10692: }
10693: } else {
10694: my $value = $env{'form.'.$item};
10695: if ($value eq '') {
10696: $value = &mt('none');
10697: } elsif ($item eq 'auth_def') {
10698: my %authnames = &authtype_names();
10699: my %shortauth = (
10700: internal => 'int',
10701: krb4 => 'krb4',
10702: krb5 => 'krb5',
10703: localauth => 'loc',
10704: );
10705: $value = $authnames{$shortauth{$value}};
10706: }
10707: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10708: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10709: }
10710: }
10711: $resulttext .= '</ul>';
10712: $mailmsgtext .= "\n";
10713: my $cachetime = 24*60*60;
1.72 raeburn 10714: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 10715: if (ref($lastactref) eq 'HASH') {
10716: $lastactref->{'domdefaults'} = 1;
10717: }
1.68 raeburn 10718: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 10719: my $notify = 1;
10720: if (ref($domconfig{'contacts'}) eq 'HASH') {
10721: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10722: $notify = 0;
10723: }
10724: }
10725: if ($notify) {
10726: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10727: "LON-CAPA Domain Settings Change - $dom",
10728: $mailmsgtext);
10729: }
1.54 raeburn 10730: }
1.43 raeburn 10731: } else {
1.54 raeburn 10732: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10733: }
10734: } else {
10735: $resulttext = '<span class="LC_error">'.
10736: &mt('An error occurred: [_1]',$putresult).'</span>';
10737: }
10738: if (@errors > 0) {
10739: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10740: foreach my $item (@errors) {
10741: $resulttext .= ' "'.$title->{$item}.'",';
10742: }
10743: $resulttext =~ s/,$//;
10744: }
10745: return $resulttext;
10746: }
10747:
1.46 raeburn 10748: sub modify_scantron {
1.205 raeburn 10749: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10750: my ($resulttext,%confhash,%changes,$errors);
10751: my $custom = 'custom.tab';
10752: my $default = 'default.tab';
10753: my $servadm = $r->dir_config('lonAdmEMail');
10754: my ($configuserok,$author_ok,$switchserver) =
10755: &config_check($dom,$confname,$servadm);
10756: if ($env{'form.scantronformat.filename'} ne '') {
10757: my $error;
10758: if ($configuserok eq 'ok') {
10759: if ($switchserver) {
1.130 raeburn 10760: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10761: } else {
10762: if ($author_ok eq 'ok') {
10763: my ($result,$scantronurl) =
10764: &publishlogo($r,'upload','scantronformat',$dom,
10765: $confname,'scantron','','',$custom);
10766: if ($result eq 'ok') {
10767: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10768: $changes{'scantronformat'} = 1;
1.46 raeburn 10769: } else {
10770: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10771: }
10772: } else {
10773: $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);
10774: }
10775: }
10776: } else {
10777: $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);
10778: }
10779: if ($error) {
10780: &Apache::lonnet::logthis($error);
10781: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10782: }
10783: }
1.48 raeburn 10784: if (ref($domconfig{'scantron'}) eq 'HASH') {
10785: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10786: if ($env{'form.scantronformat_del'}) {
10787: $confhash{'scantron'}{'scantronformat'} = '';
10788: $changes{'scantronformat'} = 1;
1.46 raeburn 10789: }
10790: }
10791: }
10792: if (keys(%confhash) > 0) {
10793: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10794: $dom);
10795: if ($putresult eq 'ok') {
10796: if (keys(%changes) > 0) {
1.48 raeburn 10797: if (ref($confhash{'scantron'}) eq 'HASH') {
10798: $resulttext = &mt('Changes made:').'<ul>';
10799: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10800: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10801: } else {
1.130 raeburn 10802: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10803: }
1.48 raeburn 10804: $resulttext .= '</ul>';
10805: } else {
1.130 raeburn 10806: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10807: }
10808: $resulttext .= '</ul>';
10809: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10810: if (ref($lastactref) eq 'HASH') {
10811: $lastactref->{'domainconfig'} = 1;
10812: }
1.46 raeburn 10813: } else {
1.130 raeburn 10814: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10815: }
10816: } else {
10817: $resulttext = '<span class="LC_error">'.
10818: &mt('An error occurred: [_1]',$putresult).'</span>';
10819: }
10820: } else {
1.130 raeburn 10821: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10822: }
10823: if ($errors) {
10824: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10825: $errors.'</ul>';
10826: }
10827: return $resulttext;
10828: }
10829:
1.48 raeburn 10830: sub modify_coursecategories {
1.239 raeburn 10831: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10832: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10833: $cathash);
1.48 raeburn 10834: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 10835: my @catitems = ('unauth','auth');
10836: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10837: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10838: $cathash = $domconfig{'coursecategories'}{'cats'};
10839: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10840: $changes{'togglecats'} = 1;
10841: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10842: }
10843: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10844: $changes{'categorize'} = 1;
10845: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10846: }
1.120 raeburn 10847: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10848: $changes{'togglecatscomm'} = 1;
10849: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10850: }
10851: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10852: $changes{'categorizecomm'} = 1;
10853: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10854: }
1.238 raeburn 10855: foreach my $item (@catitems) {
10856: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10857: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10858: $changes{$item} = 1;
10859: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10860: }
10861: }
10862: }
1.57 raeburn 10863: } else {
10864: $changes{'togglecats'} = 1;
10865: $changes{'categorize'} = 1;
1.124 raeburn 10866: $changes{'togglecatscomm'} = 1;
10867: $changes{'categorizecomm'} = 1;
1.87 raeburn 10868: $domconfig{'coursecategories'} = {
10869: togglecats => $env{'form.togglecats'},
10870: categorize => $env{'form.categorize'},
1.124 raeburn 10871: togglecatscomm => $env{'form.togglecatscomm'},
10872: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10873: };
1.238 raeburn 10874: foreach my $item (@catitems) {
10875: if ($env{'form.coursecat_'.$item} ne 'std') {
10876: $changes{$item} = 1;
10877: }
10878: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10879: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10880: }
10881: }
1.57 raeburn 10882: }
10883: if (ref($cathash) eq 'HASH') {
10884: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10885: push (@deletecategory,'instcode::0');
10886: }
1.120 raeburn 10887: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10888: push(@deletecategory,'communities::0');
10889: }
1.48 raeburn 10890: }
1.57 raeburn 10891: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10892: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10893: if (@deletecategory > 0) {
10894: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10895: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10896: foreach my $item (@deletecategory) {
1.57 raeburn 10897: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10898: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10899: $deletions{$item} = 1;
1.57 raeburn 10900: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10901: }
10902: }
10903: }
1.57 raeburn 10904: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 10905: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 10906: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 10907: $reorderings{$item} = 1;
1.57 raeburn 10908: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 10909: }
10910: if ($env{'form.addcategory_name_'.$item} ne '') {
10911: my $newcat = $env{'form.addcategory_name_'.$item};
10912: my $newdepth = $depth+1;
10913: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10914: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 10915: $adds{$newitem} = 1;
10916: }
10917: if ($env{'form.subcat_'.$item} ne '') {
10918: my $newcat = $env{'form.subcat_'.$item};
10919: my $newdepth = $depth+1;
10920: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 10921: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 10922: $adds{$newitem} = 1;
10923: }
10924: }
10925: }
10926: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 10927: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10928: my $newitem = 'instcode::0';
1.57 raeburn 10929: if ($cathash->{$newitem} eq '') {
10930: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10931: $adds{$newitem} = 1;
10932: }
10933: } else {
10934: my $newitem = 'instcode::0';
1.57 raeburn 10935: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 10936: $adds{$newitem} = 1;
10937: }
10938: }
1.120 raeburn 10939: if ($env{'form.communities'} eq '1') {
10940: if (ref($cathash) eq 'HASH') {
10941: my $newitem = 'communities::0';
10942: if ($cathash->{$newitem} eq '') {
10943: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10944: $adds{$newitem} = 1;
10945: }
10946: } else {
10947: my $newitem = 'communities::0';
10948: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
10949: $adds{$newitem} = 1;
10950: }
10951: }
1.48 raeburn 10952: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 10953: if (($env{'form.addcategory_name'} ne 'instcode') &&
10954: ($env{'form.addcategory_name'} ne 'communities')) {
10955: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
10956: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
10957: $adds{$newitem} = 1;
10958: }
1.48 raeburn 10959: }
1.57 raeburn 10960: my $putresult;
1.48 raeburn 10961: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10962: if (keys(%deletions) > 0) {
10963: foreach my $key (keys(%deletions)) {
10964: if ($predelallitems{$key} ne '') {
10965: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
10966: }
10967: }
10968: }
10969: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 10970: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 10971: if (ref($chkcats[0]) eq 'ARRAY') {
10972: my $depth = 0;
10973: my $chg = 0;
10974: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
10975: my $name = $chkcats[0][$i];
10976: my $item;
10977: if ($name eq '') {
10978: $chg ++;
10979: } else {
10980: $item = &escape($name).'::0';
10981: if ($chg) {
1.57 raeburn 10982: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 10983: }
10984: $depth ++;
1.57 raeburn 10985: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 10986: $depth --;
10987: }
10988: }
10989: }
1.57 raeburn 10990: }
10991: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
10992: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 10993: if ($putresult eq 'ok') {
1.57 raeburn 10994: my %title = (
1.120 raeburn 10995: togglecats => 'Show/Hide a course in catalog',
10996: categorize => 'Assign a category to a course',
10997: togglecatscomm => 'Show/Hide a community in catalog',
10998: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10999: );
11000: my %level = (
1.120 raeburn 11001: dom => 'set in Domain ("Modify Course/Community")',
11002: crs => 'set in Course ("Course Configuration")',
11003: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 11004: none => 'No catalog',
11005: std => 'Standard catalog',
11006: domonly => 'Domain-only catalog',
11007: codesrch => 'Code search form',
1.57 raeburn 11008: );
1.48 raeburn 11009: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11010: if ($changes{'togglecats'}) {
11011: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11012: }
11013: if ($changes{'categorize'}) {
11014: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11015: }
1.120 raeburn 11016: if ($changes{'togglecatscomm'}) {
11017: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11018: }
11019: if ($changes{'categorizecomm'}) {
11020: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11021: }
1.238 raeburn 11022: if ($changes{'unauth'}) {
11023: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11024: }
11025: if ($changes{'auth'}) {
11026: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11027: }
1.57 raeburn 11028: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11029: my $cathash;
11030: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11031: $cathash = $domconfig{'coursecategories'}{'cats'};
11032: } else {
11033: $cathash = {};
11034: }
11035: my (@cats,@trails,%allitems);
11036: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11037: if (keys(%deletions) > 0) {
11038: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11039: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11040: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11041: }
11042: $resulttext .= '</ul></li>';
11043: }
11044: if (keys(%reorderings) > 0) {
11045: my %sort_by_trail;
11046: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11047: foreach my $key (keys(%reorderings)) {
11048: if ($allitems{$key} ne '') {
11049: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11050: }
1.48 raeburn 11051: }
1.57 raeburn 11052: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11053: $resulttext .= '<li>'.$trails[$trail].'</li>';
11054: }
11055: $resulttext .= '</ul></li>';
1.48 raeburn 11056: }
1.57 raeburn 11057: if (keys(%adds) > 0) {
11058: my %sort_by_trail;
11059: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11060: foreach my $key (keys(%adds)) {
11061: if ($allitems{$key} ne '') {
11062: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11063: }
11064: }
11065: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11066: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11067: }
1.57 raeburn 11068: $resulttext .= '</ul></li>';
1.48 raeburn 11069: }
11070: }
11071: $resulttext .= '</ul>';
1.239 raeburn 11072: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 11073: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11074: if ($changes{'auth'}) {
11075: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11076: }
11077: if ($changes{'unauth'}) {
11078: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11079: }
11080: my $cachetime = 24*60*60;
11081: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 11082: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 11083: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 11084: }
11085: }
1.48 raeburn 11086: } else {
11087: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11088: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11089: }
11090: } else {
1.120 raeburn 11091: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11092: }
11093: return $resulttext;
11094: }
11095:
1.69 raeburn 11096: sub modify_serverstatuses {
11097: my ($dom,%domconfig) = @_;
11098: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11099: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11100: %currserverstatus = %{$domconfig{'serverstatuses'}};
11101: }
11102: my @pages = &serverstatus_pages();
11103: foreach my $type (@pages) {
11104: $newserverstatus{$type}{'namedusers'} = '';
11105: $newserverstatus{$type}{'machines'} = '';
11106: if (defined($env{'form.'.$type.'_namedusers'})) {
11107: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11108: my @okusers;
11109: foreach my $user (@users) {
11110: my ($uname,$udom) = split(/:/,$user);
11111: if (($udom =~ /^$match_domain$/) &&
11112: (&Apache::lonnet::domain($udom)) &&
11113: ($uname =~ /^$match_username$/)) {
11114: if (!grep(/^\Q$user\E/,@okusers)) {
11115: push(@okusers,$user);
11116: }
11117: }
11118: }
11119: if (@okusers > 0) {
11120: @okusers = sort(@okusers);
11121: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11122: }
11123: }
11124: if (defined($env{'form.'.$type.'_machines'})) {
11125: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11126: my @okmachines;
11127: foreach my $ip (@machines) {
11128: my @parts = split(/\./,$ip);
11129: next if (@parts < 4);
11130: my $badip = 0;
11131: for (my $i=0; $i<4; $i++) {
11132: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11133: $badip = 1;
11134: last;
11135: }
11136: }
11137: if (!$badip) {
11138: push(@okmachines,$ip);
11139: }
11140: }
11141: @okmachines = sort(@okmachines);
11142: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11143: }
11144: }
11145: my %serverstatushash = (
11146: serverstatuses => \%newserverstatus,
11147: );
11148: foreach my $type (@pages) {
1.83 raeburn 11149: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11150: my (@current,@new);
1.83 raeburn 11151: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11152: if ($currserverstatus{$type}{$setting} ne '') {
11153: @current = split(/,/,$currserverstatus{$type}{$setting});
11154: }
11155: }
11156: if ($newserverstatus{$type}{$setting} ne '') {
11157: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11158: }
11159: if (@current > 0) {
11160: if (@new > 0) {
11161: foreach my $item (@current) {
11162: if (!grep(/^\Q$item\E$/,@new)) {
11163: $changes{$type}{$setting} = 1;
1.82 raeburn 11164: last;
11165: }
11166: }
1.84 raeburn 11167: foreach my $item (@new) {
11168: if (!grep(/^\Q$item\E$/,@current)) {
11169: $changes{$type}{$setting} = 1;
11170: last;
1.82 raeburn 11171: }
11172: }
11173: } else {
1.83 raeburn 11174: $changes{$type}{$setting} = 1;
1.69 raeburn 11175: }
1.83 raeburn 11176: } elsif (@new > 0) {
11177: $changes{$type}{$setting} = 1;
1.69 raeburn 11178: }
11179: }
11180: }
11181: if (keys(%changes) > 0) {
1.81 raeburn 11182: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11183: my $putresult = &Apache::lonnet::put_dom('configuration',
11184: \%serverstatushash,$dom);
11185: if ($putresult eq 'ok') {
11186: $resulttext .= &mt('Changes made:').'<ul>';
11187: foreach my $type (@pages) {
1.84 raeburn 11188: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11189: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11190: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11191: if ($newserverstatus{$type}{'namedusers'} eq '') {
11192: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11193: } else {
11194: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11195: }
1.84 raeburn 11196: }
11197: if ($changes{$type}{'machines'}) {
1.69 raeburn 11198: if ($newserverstatus{$type}{'machines'} eq '') {
11199: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11200: } else {
11201: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11202: }
11203:
11204: }
11205: $resulttext .= '</ul></li>';
11206: }
11207: }
11208: $resulttext .= '</ul>';
11209: } else {
11210: $resulttext = '<span class="LC_error">'.
11211: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11212:
11213: }
11214: } else {
11215: $resulttext = &mt('No changes made to access to server status pages');
11216: }
11217: return $resulttext;
11218: }
11219:
1.118 jms 11220: sub modify_helpsettings {
1.122 jms 11221: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 11222: my ($resulttext,$errors,%changes,%helphash);
11223: my %defaultchecked = ('submitbugs' => 'on');
11224: my @offon = ('off','on');
1.118 jms 11225: my @toggles = ('submitbugs');
11226: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
11227: foreach my $item (@toggles) {
1.166 raeburn 11228: if ($defaultchecked{$item} eq 'on') {
11229: if ($domconfig{'helpsettings'}{$item} eq '') {
11230: if ($env{'form.'.$item} eq '0') {
11231: $changes{$item} = 1;
11232: }
11233: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11234: $changes{$item} = 1;
11235: }
11236: } elsif ($defaultchecked{$item} eq 'off') {
11237: if ($domconfig{'helpsettings'}{$item} eq '') {
11238: if ($env{'form.'.$item} eq '1') {
11239: $changes{$item} = 1;
11240: }
11241: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
11242: $changes{$item} = 1;
11243: }
11244: }
1.210 raeburn 11245: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 11246: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11247: }
11248: }
1.118 jms 11249: }
1.123 jms 11250: my $putresult;
11251: if (keys(%changes) > 0) {
1.166 raeburn 11252: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 11253: if ($putresult eq 'ok') {
1.166 raeburn 11254: $resulttext = &mt('Changes made:').'<ul>';
11255: foreach my $item (sort(keys(%changes))) {
11256: if ($item eq 'submitbugs') {
11257: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11258: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11259: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
11260: }
11261: }
11262: $resulttext .= '</ul>';
11263: } else {
11264: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 11265: $errors .= '<li><span class="LC_error">'.
11266: &mt('An error occurred storing the settings: [_1]',
11267: $putresult).'</span></li>';
1.166 raeburn 11268: }
1.118 jms 11269: }
11270: if ($errors) {
1.168 raeburn 11271: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 11272: $errors.'</ul>';
11273: }
11274: return $resulttext;
11275: }
11276:
1.121 raeburn 11277: sub modify_coursedefaults {
1.212 raeburn 11278: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11279: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 11280: my %defaultchecked = (
11281: 'canuse_pdfforms' => 'off',
11282: 'uselcmath' => 'on',
11283: 'usejsme' => 'on'
11284: );
11285: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 11286: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.271 ! raeburn 11287: 'uploadquota_community','uploadquota_textbook','uploadquota_placement');
! 11288: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 11289: my %staticdefaults = (
11290: anonsurvey_threshold => 10,
11291: uploadquota => 500,
1.257 raeburn 11292: postsubmit => 60,
1.198 raeburn 11293: );
1.121 raeburn 11294:
11295: $defaultshash{'coursedefaults'} = {};
11296:
11297: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11298: if ($domconfig{'coursedefaults'} eq '') {
11299: $domconfig{'coursedefaults'} = {};
11300: }
11301: }
11302:
11303: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11304: foreach my $item (@toggles) {
11305: if ($defaultchecked{$item} eq 'on') {
11306: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11307: ($env{'form.'.$item} eq '0')) {
11308: $changes{$item} = 1;
1.192 raeburn 11309: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11310: $changes{$item} = 1;
11311: }
11312: } elsif ($defaultchecked{$item} eq 'off') {
11313: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11314: ($env{'form.'.$item} eq '1')) {
11315: $changes{$item} = 1;
11316: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11317: $changes{$item} = 1;
11318: }
11319: }
11320: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11321: }
1.198 raeburn 11322: foreach my $item (@numbers) {
11323: my ($currdef,$newdef);
1.208 raeburn 11324: $newdef = $env{'form.'.$item};
1.198 raeburn 11325: if ($item eq 'anonsurvey_threshold') {
11326: $currdef = $domconfig{'coursedefaults'}{$item};
11327: $newdef =~ s/\D//g;
11328: if ($newdef eq '' || $newdef < 1) {
11329: $newdef = 1;
11330: }
11331: $defaultshash{'coursedefaults'}{$item} = $newdef;
11332: } else {
11333: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
11334: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11335: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
11336: }
11337: $newdef =~ s/[^\w.\-]//g;
11338: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
11339: }
11340: if ($currdef ne $newdef) {
11341: my $staticdef;
11342: if ($item eq 'anonsurvey_threshold') {
11343: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11344: $changes{$item} = 1;
11345: }
11346: } else {
11347: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
11348: $changes{'uploadquota'} = 1;
11349: }
11350: }
1.139 raeburn 11351: }
11352: }
1.264 raeburn 11353: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11354: my @currclonecode;
11355: if (ref($currclone) eq 'HASH') {
11356: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11357: @currclonecode = @{$currclone->{'instcode'}};
11358: }
11359: }
11360: my $newclone;
11361: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11362: $newclone = $env{'form.canclone'};
11363: }
11364: if ($newclone eq 'instcode') {
11365: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11366: my (%codedefaults,@code_order,@clonecode);
11367: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11368: \@code_order);
11369: foreach my $item (@code_order) {
11370: if (grep(/^\Q$item\E$/,@newcodes)) {
11371: push(@clonecode,$item);
11372: }
11373: }
11374: if (@clonecode) {
11375: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11376: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11377: if (@diffs) {
11378: $changes{'canclone'} = 1;
11379: }
11380: } else {
11381: $newclone eq '';
11382: }
11383: } elsif ($newclone ne '') {
11384: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11385: }
11386: if ($newclone ne $currclone) {
11387: $changes{'canclone'} = 1;
11388: }
1.257 raeburn 11389: my %credits;
11390: foreach my $type (@types) {
11391: unless ($type eq 'community') {
11392: $credits{$type} = $env{'form.'.$type.'_credits'};
11393: $credits{$type} =~ s/[^\d.]+//g;
11394: }
11395: }
11396: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11397: ($env{'form.coursecredits'} eq '1')) {
11398: $changes{'coursecredits'} = 1;
11399: foreach my $type (keys(%credits)) {
11400: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11401: }
11402: } else {
11403: if ($env{'form.coursecredits'} eq '1') {
11404: foreach my $type (@types) {
11405: unless ($type eq 'community') {
11406: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11407: $changes{'coursecredits'} = 1;
11408: }
11409: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11410: }
11411: }
11412: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11413: foreach my $type (@types) {
11414: unless ($type eq 'community') {
11415: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11416: $changes{'coursecredits'} = 1;
11417: last;
11418: }
11419: }
11420: }
11421: }
11422: }
11423: if ($env{'form.postsubmit'} eq '1') {
11424: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11425: my %currtimeout;
11426: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11427: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11428: $changes{'postsubmit'} = 1;
11429: }
11430: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11431: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11432: }
11433: } else {
11434: $changes{'postsubmit'} = 1;
11435: }
11436: foreach my $type (@types) {
11437: my $timeout = $env{'form.'.$type.'_timeout'};
11438: $timeout =~ s/\D//g;
11439: if ($timeout == $staticdefaults{'postsubmit'}) {
11440: $timeout = '';
11441: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11442: $timeout = '0';
11443: }
11444: unless ($timeout eq '') {
11445: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11446: }
11447: if (exists($currtimeout{$type})) {
11448: if ($timeout ne $currtimeout{$type}) {
11449: $changes{'postsubmit'} = 1;
11450: }
11451: } elsif ($timeout ne '') {
11452: $changes{'postsubmit'} = 1;
11453: }
11454: }
11455: } else {
11456: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11457: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11458: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11459: $changes{'postsubmit'} = 1;
11460: }
11461: } else {
11462: $changes{'postsubmit'} = 1;
11463: }
1.192 raeburn 11464: }
1.121 raeburn 11465: }
11466: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11467: $dom);
11468: if ($putresult eq 'ok') {
11469: if (keys(%changes) > 0) {
1.213 raeburn 11470: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 11471: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 11472: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
11473: ($changes{'canclone'})) {
1.257 raeburn 11474: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
11475: if ($changes{$item}) {
11476: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11477: }
11478: }
1.192 raeburn 11479: if ($changes{'coursecredits'}) {
11480: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 11481: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11482: $domdefaults{$type.'credits'} =
11483: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11484: }
11485: }
11486: }
11487: if ($changes{'postsubmit'}) {
11488: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11489: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11490: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11491: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11492: $domdefaults{$type.'postsubtimeout'} =
11493: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11494: }
11495: }
1.192 raeburn 11496: }
11497: }
1.198 raeburn 11498: if ($changes{'uploadquota'}) {
11499: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11500: foreach my $type (@types) {
11501: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11502: }
11503: }
11504: }
1.264 raeburn 11505: if ($changes{'canclone'}) {
11506: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11507: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11508: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11509: if (@clonecodes) {
11510: $domdefaults{'canclone'} = join('+',@clonecodes);
11511: }
11512: }
11513: } else {
11514: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11515: }
11516: }
1.121 raeburn 11517: my $cachetime = 24*60*60;
11518: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11519: if (ref($lastactref) eq 'HASH') {
11520: $lastactref->{'domdefaults'} = 1;
11521: }
1.121 raeburn 11522: }
11523: $resulttext = &mt('Changes made:').'<ul>';
11524: foreach my $item (sort(keys(%changes))) {
11525: if ($item eq 'canuse_pdfforms') {
11526: if ($env{'form.'.$item} eq '1') {
11527: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
11528: } else {
11529: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
11530: }
1.257 raeburn 11531: } elsif ($item eq 'uselcmath') {
11532: if ($env{'form.'.$item} eq '1') {
11533: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
11534: } else {
11535: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11536: }
11537: } elsif ($item eq 'usejsme') {
11538: if ($env{'form.'.$item} eq '1') {
11539: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11540: } else {
11541: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
11542: }
1.139 raeburn 11543: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 11544: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 11545: } elsif ($item eq 'uploadquota') {
11546: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11547: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11548: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11549: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 11550: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 ! raeburn 11551: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 11552: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11553: '</ul>'.
11554: '</li>';
11555: } else {
11556: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11557: }
1.257 raeburn 11558: } elsif ($item eq 'postsubmit') {
11559: if ($domdefaults{'postsubmit'} eq 'off') {
11560: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11561: } else {
11562: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11563: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11564: $resulttext .= &mt('durations:').'<ul>';
11565: foreach my $type (@types) {
11566: $resulttext .= '<li>';
11567: my $timeout;
11568: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11569: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11570: }
11571: my $display;
11572: if ($timeout eq '0') {
11573: $display = &mt('unlimited');
11574: } elsif ($timeout eq '') {
11575: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11576: } else {
11577: $display = &mt('[quant,_1,second]',$timeout);
11578: }
11579: if ($type eq 'community') {
11580: $resulttext .= &mt('Communities');
11581: } elsif ($type eq 'official') {
11582: $resulttext .= &mt('Official courses');
11583: } elsif ($type eq 'unofficial') {
11584: $resulttext .= &mt('Unofficial courses');
11585: } elsif ($type eq 'textbook') {
11586: $resulttext .= &mt('Textbook courses');
1.271 ! raeburn 11587: } elsif ($type eq 'placement') {
! 11588: $resulttext .= &mt('Placement tests');
1.257 raeburn 11589: }
11590: $resulttext .= ' -- '.$display.'</li>';
11591: }
11592: $resulttext .= '</ul>';
11593: }
11594: $resulttext .= '</li>';
11595: }
1.192 raeburn 11596: } elsif ($item eq 'coursecredits') {
11597: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11598: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 11599: ($domdefaults{'unofficialcredits'} eq '') &&
11600: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 11601: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11602: } else {
11603: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11604: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11605: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 11606: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 11607: '</ul>'.
11608: '</li>';
11609: }
11610: } else {
11611: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11612: }
1.264 raeburn 11613: } elsif ($item eq 'canclone') {
11614: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11615: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11616: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11617: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11618: }
11619: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11620: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11621: } else {
11622: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11623: }
1.140 raeburn 11624: }
1.121 raeburn 11625: }
11626: $resulttext .= '</ul>';
11627: } else {
11628: $resulttext = &mt('No changes made to course defaults');
11629: }
11630: } else {
11631: $resulttext = '<span class="LC_error">'.
11632: &mt('An error occurred: [_1]',$putresult).'</span>';
11633: }
11634: return $resulttext;
11635: }
11636:
1.231 raeburn 11637: sub modify_selfenrollment {
11638: my ($dom,$lastactref,%domconfig) = @_;
11639: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 ! raeburn 11640: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 11641: my %titles = &tool_titles();
1.232 raeburn 11642: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
11643: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 11644: $ordered{'default'} = ['types','registered','approval','limit'];
11645:
11646: my (%roles,%shown,%toplevel);
11647: $roles{'0'} = &Apache::lonnet::plaintext('dc');
11648:
11649: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
11650: if ($domconfig{'selfenrollment'} eq '') {
11651: $domconfig{'selfenrollment'} = {};
11652: }
11653: }
11654: %toplevel = (
11655: admin => 'Configuration Rights',
11656: default => 'Default settings',
11657: validation => 'Validation of self-enrollment requests',
11658: );
1.233 raeburn 11659: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 11660:
11661: if (ref($ordered{'admin'}) eq 'ARRAY') {
11662: foreach my $item (@{$ordered{'admin'}}) {
11663: foreach my $type (@types) {
11664: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
11665: $selfenrollhash{'admin'}{$type}{$item} = 1;
11666: } else {
11667: $selfenrollhash{'admin'}{$type}{$item} = 0;
11668: }
11669: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
11670: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
11671: if ($selfenrollhash{'admin'}{$type}{$item} ne
11672: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
11673: push(@{$changes{'admin'}{$type}},$item);
11674: }
11675: } else {
11676: if (!$selfenrollhash{'admin'}{$type}{$item}) {
11677: push(@{$changes{'admin'}{$type}},$item);
11678: }
11679: }
11680: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
11681: push(@{$changes{'admin'}{$type}},$item);
11682: }
11683: }
11684: }
11685: }
11686:
11687: foreach my $item (@{$ordered{'default'}}) {
11688: foreach my $type (@types) {
11689: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
11690: if ($item eq 'types') {
11691: unless (($value eq 'all') || ($value eq 'dom')) {
11692: $value = '';
11693: }
11694: } elsif ($item eq 'registered') {
11695: unless ($value eq '1') {
11696: $value = 0;
11697: }
11698: } elsif ($item eq 'approval') {
11699: unless ($value =~ /^[012]$/) {
11700: $value = 0;
11701: }
11702: } else {
11703: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11704: $value = 'none';
11705: }
11706: }
11707: $selfenrollhash{'default'}{$type}{$item} = $value;
11708: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
11709: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11710: if ($selfenrollhash{'default'}{$type}{$item} ne
11711: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
11712: push(@{$changes{'default'}{$type}},$item);
11713: }
11714: } else {
11715: push(@{$changes{'default'}{$type}},$item);
11716: }
11717: } else {
11718: push(@{$changes{'default'}{$type}},$item);
11719: }
11720: if ($item eq 'limit') {
11721: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
11722: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
11723: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
11724: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
11725: }
11726: } else {
11727: $selfenrollhash{'default'}{$type}{'cap'} = '';
11728: }
11729: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
11730: if ($selfenrollhash{'default'}{$type}{'cap'} ne
11731: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
11732: push(@{$changes{'default'}{$type}},'cap');
11733: }
11734: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
11735: push(@{$changes{'default'}{$type}},'cap');
11736: }
11737: }
11738: }
11739: }
11740:
11741: foreach my $item (@{$itemsref}) {
11742: if ($item eq 'fields') {
11743: my @changed;
11744: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
11745: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
11746: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
11747: }
11748: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11749: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
11750: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
11751: $domconfig{'selfenrollment'}{'validation'}{$item});
11752: } else {
11753: @changed = @{$selfenrollhash{'validation'}{$item}};
11754: }
11755: } else {
11756: @changed = @{$selfenrollhash{'validation'}{$item}};
11757: }
11758: if (@changed) {
11759: if ($selfenrollhash{'validation'}{$item}) {
11760: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
11761: } else {
11762: $changes{'validation'}{$item} = &mt('None');
11763: }
11764: }
11765: } else {
11766: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
11767: if ($item eq 'markup') {
11768: if ($env{'form.selfenroll_validation_'.$item}) {
11769: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11770: }
11771: }
11772: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
11773: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
11774: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
11775: }
11776: }
11777: }
11778: }
11779:
11780: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
11781: $dom);
11782: if ($putresult eq 'ok') {
11783: if (keys(%changes) > 0) {
11784: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11785: $resulttext = &mt('Changes made:').'<ul>';
11786: foreach my $key ('admin','default','validation') {
11787: if (ref($changes{$key}) eq 'HASH') {
11788: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
11789: if ($key eq 'validation') {
11790: foreach my $item (@{$itemsref}) {
11791: if (exists($changes{$key}{$item})) {
11792: if ($item eq 'markup') {
11793: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11794: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
11795: } else {
11796: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
11797: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
11798: }
11799: }
11800: }
11801: } else {
11802: foreach my $type (@types) {
11803: if ($type eq 'community') {
11804: $roles{'1'} = &mt('Community personnel');
11805: } else {
11806: $roles{'1'} = &mt('Course personnel');
11807: }
11808: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 11809: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11810: if ($key eq 'admin') {
11811: my @mgrdc = ();
11812: if (ref($ordered{$key}) eq 'ARRAY') {
11813: foreach my $item (@{$ordered{'admin'}}) {
11814: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
11815: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
11816: push(@mgrdc,$item);
11817: }
11818: }
11819: }
11820: if (@mgrdc) {
11821: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
11822: } else {
11823: delete($domdefaults{$type.'selfenrolladmdc'});
11824: }
11825: }
11826: } else {
11827: if (ref($ordered{$key}) eq 'ARRAY') {
11828: foreach my $item (@{$ordered{$key}}) {
11829: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11830: $domdefaults{$type.'selfenroll'.$item} =
11831: $selfenrollhash{$key}{$type}{$item};
11832: }
11833: }
11834: }
11835: }
11836: }
1.231 raeburn 11837: $resulttext .= '<li>'.$titles{$type}.'<ul>';
11838: foreach my $item (@{$ordered{$key}}) {
11839: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
11840: $resulttext .= '<li>';
11841: if ($key eq 'admin') {
11842: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
11843: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
11844: } else {
11845: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
11846: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
11847: }
11848: $resulttext .= '</li>';
11849: }
11850: }
11851: $resulttext .= '</ul></li>';
11852: }
11853: }
11854: $resulttext .= '</ul></li>';
11855: }
11856: }
1.232 raeburn 11857: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
11858: my $cachetime = 24*60*60;
11859: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11860: if (ref($lastactref) eq 'HASH') {
11861: $lastactref->{'domdefaults'} = 1;
11862: }
11863: }
1.231 raeburn 11864: }
11865: $resulttext .= '</ul>';
11866: } else {
11867: $resulttext = &mt('No changes made to self-enrollment settings');
11868: }
11869: } else {
11870: $resulttext = '<span class="LC_error">'.
11871: &mt('An error occurred: [_1]',$putresult).'</span>';
11872: }
11873: return $resulttext;
11874: }
11875:
1.137 raeburn 11876: sub modify_usersessions {
1.212 raeburn 11877: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 11878: my @hostingtypes = ('version','excludedomain','includedomain');
11879: my @offloadtypes = ('primary','default');
11880: my %types = (
11881: remote => \@hostingtypes,
11882: hosted => \@hostingtypes,
11883: spares => \@offloadtypes,
11884: );
11885: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 11886: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 11887: my (%by_ip,%by_location,@intdoms);
11888: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
11889: my @locations = sort(keys(%by_location));
1.137 raeburn 11890: my (%defaultshash,%changes);
11891: foreach my $prefix (@prefixes) {
11892: $defaultshash{'usersessions'}{$prefix} = {};
11893: }
1.212 raeburn 11894: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 11895: my $resulttext;
1.138 raeburn 11896: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 11897: foreach my $prefix (@prefixes) {
1.145 raeburn 11898: next if ($prefix eq 'spares');
11899: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 11900: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
11901: if ($type eq 'version') {
11902: my $value = $env{'form.'.$prefix.'_'.$type};
11903: my $okvalue;
11904: if ($value ne '') {
11905: if (grep(/^\Q$value\E$/,@lcversions)) {
11906: $okvalue = $value;
11907: }
11908: }
11909: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11910: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11911: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
11912: if ($inuse == 0) {
11913: $changes{$prefix}{$type} = 1;
11914: } else {
11915: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
11916: $changes{$prefix}{$type} = 1;
11917: }
11918: if ($okvalue ne '') {
11919: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11920: }
11921: }
11922: } else {
11923: if (($inuse == 1) && ($okvalue ne '')) {
11924: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11925: $changes{$prefix}{$type} = 1;
11926: }
11927: }
11928: } else {
11929: if (($inuse == 1) && ($okvalue ne '')) {
11930: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11931: $changes{$prefix}{$type} = 1;
11932: }
11933: }
11934: } else {
11935: if (($inuse == 1) && ($okvalue ne '')) {
11936: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
11937: $changes{$prefix}{$type} = 1;
11938: }
11939: }
11940: } else {
11941: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
11942: my @okvals;
11943: foreach my $val (@vals) {
1.138 raeburn 11944: if ($val =~ /:/) {
11945: my @items = split(/:/,$val);
11946: foreach my $item (@items) {
11947: if (ref($by_location{$item}) eq 'ARRAY') {
11948: push(@okvals,$item);
11949: }
11950: }
11951: } else {
11952: if (ref($by_location{$val}) eq 'ARRAY') {
11953: push(@okvals,$val);
11954: }
1.137 raeburn 11955: }
11956: }
11957: @okvals = sort(@okvals);
11958: if (ref($domconfig{'usersessions'}) eq 'HASH') {
11959: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
11960: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
11961: if ($inuse == 0) {
11962: $changes{$prefix}{$type} = 1;
11963: } else {
11964: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11965: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
11966: if (@changed > 0) {
11967: $changes{$prefix}{$type} = 1;
11968: }
11969: }
11970: } else {
11971: if ($inuse == 1) {
11972: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11973: $changes{$prefix}{$type} = 1;
11974: }
11975: }
11976: } else {
11977: if ($inuse == 1) {
11978: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11979: $changes{$prefix}{$type} = 1;
11980: }
11981: }
11982: } else {
11983: if ($inuse == 1) {
11984: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
11985: $changes{$prefix}{$type} = 1;
11986: }
11987: }
11988: }
11989: }
11990: }
1.145 raeburn 11991:
11992: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 11993: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 11994: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
11995: my $savespares;
11996:
11997: foreach my $lonhost (sort(keys(%servers))) {
11998: my $serverhomeID =
11999: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12000: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12001: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12002: my %spareschg;
12003: foreach my $type (@{$types{'spares'}}) {
12004: my @okspares;
12005: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12006: foreach my $server (@checked) {
1.152 raeburn 12007: if (&Apache::lonnet::hostname($server) ne '') {
12008: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12009: unless (grep(/^\Q$server\E$/,@okspares)) {
12010: push(@okspares,$server);
12011: }
1.145 raeburn 12012: }
12013: }
12014: }
12015: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12016: my $newspare;
1.152 raeburn 12017: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12018: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12019: $newspare = $new;
12020: }
12021: }
1.152 raeburn 12022: my @spares;
12023: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12024: @spares = sort(@okspares,$newspare);
12025: } else {
12026: @spares = sort(@okspares);
12027: }
12028: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12029: if (ref($spareid{$lonhost}) eq 'HASH') {
12030: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12031: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12032: if (@diffs > 0) {
12033: $spareschg{$type} = 1;
12034: }
12035: }
12036: }
12037: }
12038: if (keys(%spareschg) > 0) {
12039: $changes{'spares'}{$lonhost} = \%spareschg;
12040: }
12041: }
1.261 raeburn 12042: $defaultshash{'usersessions'}{'offloadnow'} = {};
12043: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12044: my @okoffload;
12045: if (@offloadnow) {
12046: foreach my $server (@offloadnow) {
12047: if (&Apache::lonnet::hostname($server) ne '') {
12048: unless (grep(/^\Q$server\E$/,@okoffload)) {
12049: push(@okoffload,$server);
12050: }
12051: }
12052: }
12053: if (@okoffload) {
12054: foreach my $lonhost (@okoffload) {
12055: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12056: }
12057: }
12058: }
1.145 raeburn 12059: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12060: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12061: if (ref($changes{'spares'}) eq 'HASH') {
12062: if (keys(%{$changes{'spares'}}) > 0) {
12063: $savespares = 1;
12064: }
12065: }
12066: } else {
12067: $savespares = 1;
12068: }
1.261 raeburn 12069: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12070: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12071: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12072: $changes{'offloadnow'} = 1;
12073: last;
12074: }
12075: }
12076: unless ($changes{'offloadnow'}) {
12077: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12078: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12079: $changes{'offloadnow'} = 1;
12080: last;
12081: }
12082: }
12083: }
12084: } elsif (@okoffload) {
12085: $changes{'offloadnow'} = 1;
12086: }
12087: } elsif (@okoffload) {
12088: $changes{'offloadnow'} = 1;
1.145 raeburn 12089: }
1.147 raeburn 12090: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12091: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12092: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12093: $dom);
12094: if ($putresult eq 'ok') {
12095: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12096: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12097: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12098: }
12099: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12100: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12101: }
1.261 raeburn 12102: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12103: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12104: }
1.137 raeburn 12105: }
12106: my $cachetime = 24*60*60;
12107: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12108: if (ref($lastactref) eq 'HASH') {
12109: $lastactref->{'domdefaults'} = 1;
12110: }
1.147 raeburn 12111: if (keys(%changes) > 0) {
12112: my %lt = &usersession_titles();
12113: $resulttext = &mt('Changes made:').'<ul>';
12114: foreach my $prefix (@prefixes) {
12115: if (ref($changes{$prefix}) eq 'HASH') {
12116: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12117: if ($prefix eq 'spares') {
12118: if (ref($changes{$prefix}) eq 'HASH') {
12119: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12120: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12121: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 12122: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12123: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12124: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12125: foreach my $type (@{$types{$prefix}}) {
12126: if ($changes{$prefix}{$lonhost}{$type}) {
12127: my $offloadto = &mt('None');
12128: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12129: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12130: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12131: }
1.145 raeburn 12132: }
1.147 raeburn 12133: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12134: }
1.137 raeburn 12135: }
12136: }
1.147 raeburn 12137: $resulttext .= '</li>';
1.137 raeburn 12138: }
12139: }
1.147 raeburn 12140: } else {
12141: foreach my $type (@{$types{$prefix}}) {
12142: if (defined($changes{$prefix}{$type})) {
12143: my $newvalue;
12144: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12145: if (ref($defaultshash{'usersessions'}{$prefix})) {
12146: if ($type eq 'version') {
12147: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12148: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12149: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12150: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12151: }
1.145 raeburn 12152: }
12153: }
12154: }
1.147 raeburn 12155: if ($newvalue eq '') {
12156: if ($type eq 'version') {
12157: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12158: } else {
12159: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12160: }
1.145 raeburn 12161: } else {
1.147 raeburn 12162: if ($type eq 'version') {
12163: $newvalue .= ' '.&mt('(or later)');
12164: }
12165: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12166: }
1.137 raeburn 12167: }
12168: }
12169: }
1.147 raeburn 12170: $resulttext .= '</ul>';
1.137 raeburn 12171: }
12172: }
1.261 raeburn 12173: if ($changes{'offloadnow'}) {
12174: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12175: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12176: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12177: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12178: $resulttext .= '<li>'.$lonhost.'</li>';
12179: }
12180: $resulttext .= '</ul>';
12181: } else {
12182: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12183: }
12184: } else {
12185: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12186: }
12187: }
1.147 raeburn 12188: $resulttext .= '</ul>';
12189: } else {
12190: $resulttext = $nochgmsg;
1.137 raeburn 12191: }
12192: } else {
12193: $resulttext = '<span class="LC_error">'.
12194: &mt('An error occurred: [_1]',$putresult).'</span>';
12195: }
12196: } else {
1.147 raeburn 12197: $resulttext = $nochgmsg;
1.137 raeburn 12198: }
12199: return $resulttext;
12200: }
12201:
1.150 raeburn 12202: sub modify_loadbalancing {
12203: my ($dom,%domconfig) = @_;
12204: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12205: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12206: my ($othertitle,$usertypes,$types) =
12207: &Apache::loncommon::sorted_inst_types($dom);
12208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 12209: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12210: my @sparestypes = ('primary','default');
12211: my %typetitles = &sparestype_titles();
12212: my $resulttext;
1.171 raeburn 12213: my (%currbalancer,%currtargets,%currrules,%existing);
12214: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12215: %existing = %{$domconfig{'loadbalancing'}};
12216: }
12217: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12218: \%currtargets,\%currrules);
12219: my ($saveloadbalancing,%defaultshash,%changes);
12220: my ($alltypes,$othertypes,$titles) =
12221: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12222: my %ruletitles = &offloadtype_text();
12223: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12224: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12225: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12226: if ($balancer eq '') {
12227: next;
12228: }
1.210 raeburn 12229: if (!exists($servers{$balancer})) {
1.171 raeburn 12230: if (exists($currbalancer{$balancer})) {
12231: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12232: }
1.171 raeburn 12233: next;
12234: }
12235: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12236: push(@{$changes{'delete'}},$balancer);
12237: next;
12238: }
12239: if (!exists($currbalancer{$balancer})) {
12240: push(@{$changes{'add'}},$balancer);
12241: }
12242: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12243: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12244: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12245: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12246: $saveloadbalancing = 1;
12247: }
12248: foreach my $sparetype (@sparestypes) {
12249: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12250: my @offloadto;
12251: foreach my $target (@targets) {
12252: if (($servers{$target}) && ($target ne $balancer)) {
12253: if ($sparetype eq 'default') {
12254: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12255: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12256: }
12257: }
1.171 raeburn 12258: unless(grep(/^\Q$target\E$/,@offloadto)) {
12259: push(@offloadto,$target);
12260: }
1.150 raeburn 12261: }
1.171 raeburn 12262: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12263: }
12264: }
1.171 raeburn 12265: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12266: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12267: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12268: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12269: if (@targetdiffs > 0) {
1.171 raeburn 12270: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12271: }
1.171 raeburn 12272: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12273: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12274: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12275: }
12276: }
12277: }
12278: } else {
1.171 raeburn 12279: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 12280: foreach my $sparetype (@sparestypes) {
1.171 raeburn 12281: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12282: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12283: $changes{'curr'}{$balancer}{'targets'} = 1;
12284: }
1.150 raeburn 12285: }
12286: }
1.210 raeburn 12287: }
1.150 raeburn 12288: }
12289: my $ishomedom;
1.171 raeburn 12290: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12291: $ishomedom = 1;
1.150 raeburn 12292: }
12293: if (ref($alltypes) eq 'ARRAY') {
12294: foreach my $type (@{$alltypes}) {
12295: my $rule;
1.210 raeburn 12296: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12297: (!$ishomedom)) {
1.171 raeburn 12298: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12299: }
12300: if ($rule eq 'specific') {
1.255 raeburn 12301: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12302: if (exists($servers{$specifiedhost})) {
12303: $rule = $specifiedhost;
12304: }
1.150 raeburn 12305: }
1.171 raeburn 12306: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12307: if (ref($currrules{$balancer}) eq 'HASH') {
12308: if ($rule ne $currrules{$balancer}{$type}) {
12309: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12310: }
12311: } elsif ($rule ne '') {
1.171 raeburn 12312: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12313: }
12314: }
12315: }
1.171 raeburn 12316: }
12317: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12318: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12319: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12320: $defaultshash{'loadbalancing'} = {};
12321: }
12322: my $putresult = &Apache::lonnet::put_dom('configuration',
12323: \%defaultshash,$dom);
12324: if ($putresult eq 'ok') {
12325: if (keys(%changes) > 0) {
1.252 raeburn 12326: my %toupdate;
1.171 raeburn 12327: if (ref($changes{'delete'}) eq 'ARRAY') {
12328: foreach my $balancer (sort(@{$changes{'delete'}})) {
12329: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 12330: $toupdate{$balancer} = 1;
1.150 raeburn 12331: }
1.171 raeburn 12332: }
12333: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 12334: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 12335: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 12336: $toupdate{$balancer} = 1;
1.171 raeburn 12337: }
12338: }
12339: if (ref($changes{'curr'}) eq 'HASH') {
12340: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 12341: $toupdate{$balancer} = 1;
1.171 raeburn 12342: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12343: if ($changes{'curr'}{$balancer}{'targets'}) {
12344: my %offloadstr;
12345: foreach my $sparetype (@sparestypes) {
12346: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12347: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12348: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12349: }
12350: }
1.150 raeburn 12351: }
1.171 raeburn 12352: if (keys(%offloadstr) == 0) {
12353: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12354: } else {
1.171 raeburn 12355: my $showoffload;
12356: foreach my $sparetype (@sparestypes) {
12357: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12358: if (defined($offloadstr{$sparetype})) {
12359: $showoffload .= $offloadstr{$sparetype};
12360: } else {
12361: $showoffload .= &mt('None');
12362: }
12363: $showoffload .= (' 'x3);
12364: }
12365: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12366: }
12367: }
12368: }
1.171 raeburn 12369: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12370: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12371: foreach my $type (@{$alltypes}) {
12372: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12373: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12374: my $balancetext;
12375: if ($rule eq '') {
12376: $balancetext = $ruletitles{'default'};
1.209 raeburn 12377: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254 raeburn 12378: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12379: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 12380: foreach my $sparetype (@sparestypes) {
12381: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12382: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12383: }
12384: }
1.253 raeburn 12385: foreach my $item (@{$alltypes}) {
12386: next if ($item =~ /^_LC_ipchange/);
12387: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12388: if ($hasrule eq 'homeserver') {
12389: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12390: } else {
12391: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12392: if ($servers{$hasrule}) {
12393: $toupdate{$hasrule} = 1;
12394: }
12395: }
12396: }
12397: }
1.254 raeburn 12398: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12399: $balancetext = $ruletitles{$rule};
12400: } else {
12401: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12402: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12403: if ($receiver) {
12404: $toupdate{$receiver};
12405: }
12406: }
12407: } else {
12408: $balancetext = $ruletitles{$rule};
1.252 raeburn 12409: }
1.171 raeburn 12410: } else {
12411: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12412: }
1.210 raeburn 12413: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12414: }
12415: }
12416: }
12417: }
1.252 raeburn 12418: if (keys(%toupdate)) {
12419: my %thismachine;
12420: my $updatedhere;
12421: my $cachetime = 60*60*24;
12422: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12423: foreach my $lonhost (keys(%toupdate)) {
12424: if ($thismachine{$lonhost}) {
12425: unless ($updatedhere) {
12426: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12427: $defaultshash{'loadbalancing'},
12428: $cachetime);
12429: $updatedhere = 1;
12430: }
12431: } else {
12432: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12433: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12434: }
12435: }
12436: }
1.150 raeburn 12437: }
1.171 raeburn 12438: }
12439: if ($resulttext ne '') {
12440: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12441: } else {
12442: $resulttext = $nochgmsg;
12443: }
12444: } else {
1.171 raeburn 12445: $resulttext = $nochgmsg;
1.150 raeburn 12446: }
12447: } else {
1.171 raeburn 12448: $resulttext = '<span class="LC_error">'.
12449: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12450: }
12451: } else {
1.171 raeburn 12452: $resulttext = $nochgmsg;
1.150 raeburn 12453: }
12454: return $resulttext;
12455: }
12456:
1.48 raeburn 12457: sub recurse_check {
12458: my ($chkcats,$categories,$depth,$name) = @_;
12459: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12460: my $chg = 0;
12461: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12462: my $category = $chkcats->[$depth]{$name}[$j];
12463: my $item;
12464: if ($category eq '') {
12465: $chg ++;
12466: } else {
12467: my $deeper = $depth + 1;
12468: $item = &escape($category).':'.&escape($name).':'.$depth;
12469: if ($chg) {
12470: $categories->{$item} -= $chg;
12471: }
12472: &recurse_check($chkcats,$categories,$deeper,$category);
12473: $deeper --;
12474: }
12475: }
12476: }
12477: return;
12478: }
12479:
12480: sub recurse_cat_deletes {
12481: my ($item,$coursecategories,$deletions) = @_;
12482: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12483: my $subdepth = $depth + 1;
12484: if (ref($coursecategories) eq 'HASH') {
12485: foreach my $subitem (keys(%{$coursecategories})) {
12486: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12487: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12488: delete($coursecategories->{$subitem});
12489: $deletions->{$subitem} = 1;
12490: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 12491: }
1.48 raeburn 12492: }
12493: }
12494: return;
12495: }
12496:
1.125 raeburn 12497: sub get_active_dcs {
12498: my ($dom) = @_;
1.191 raeburn 12499: my $now = time;
12500: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 12501: my %domcoords;
12502: my $numdcs = 0;
12503: foreach my $server (keys(%dompersonnel)) {
12504: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
12505: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 12506: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 12507: }
12508: }
12509: return %domcoords;
12510: }
12511:
12512: sub active_dc_picker {
1.191 raeburn 12513: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235 raeburn 12514: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 12515: my @domcoord = keys(%domcoords);
12516: if (keys(%currhash)) {
12517: foreach my $dc (keys(%currhash)) {
12518: unless (exists($domcoords{$dc})) {
12519: push(@domcoord,$dc);
12520: }
12521: }
12522: }
12523: @domcoord = sort(@domcoord);
1.210 raeburn 12524: my $numdcs = scalar(@domcoord);
1.191 raeburn 12525: my $rows = 0;
12526: my $table;
1.125 raeburn 12527: if ($numdcs > 1) {
1.191 raeburn 12528: $table = '<table>';
12529: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12530: my $rem = $i%($numinrow);
12531: if ($rem == 0) {
12532: if ($i > 0) {
1.191 raeburn 12533: $table .= '</tr>';
1.125 raeburn 12534: }
1.191 raeburn 12535: $table .= '<tr>';
12536: $rows ++;
1.125 raeburn 12537: }
1.191 raeburn 12538: my $check = '';
12539: if ($inputtype eq 'radio') {
12540: if (keys(%currhash) == 0) {
12541: if (!$i) {
12542: $check = ' checked="checked"';
12543: }
12544: } elsif (exists($currhash{$domcoord[$i]})) {
12545: $check = ' checked="checked"';
12546: }
12547: } else {
12548: if (exists($currhash{$domcoord[$i]})) {
12549: $check = ' checked="checked"';
1.125 raeburn 12550: }
12551: }
1.191 raeburn 12552: if ($i == @domcoord - 1) {
1.125 raeburn 12553: my $colsleft = $numinrow - $rem;
12554: if ($colsleft > 1) {
1.191 raeburn 12555: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12556: } else {
1.191 raeburn 12557: $table .= '<td class="LC_left_item">';
1.125 raeburn 12558: }
12559: } else {
1.191 raeburn 12560: $table .= '<td class="LC_left_item">';
12561: }
12562: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12563: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12564: $table .= '<span class="LC_nobreak"><label>'.
12565: '<input type="'.$inputtype.'" name="'.$name.'"'.
12566: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12567: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 12568: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 12569: }
1.219 raeburn 12570: $table .= '</label></span></td>';
1.191 raeburn 12571: }
12572: $table .= '</tr></table>';
12573: } elsif ($numdcs == 1) {
1.219 raeburn 12574: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12575: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 12576: if ($inputtype eq 'radio') {
1.247 raeburn 12577: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 12578: if ($user ne $dcname.':'.$dcdom) {
12579: $table .= ' ('.$dcname.':'.$dcdom.')';
12580: }
1.191 raeburn 12581: } else {
12582: my $check;
12583: if (exists($currhash{$domcoord[0]})) {
12584: $check = ' checked="checked"';
1.125 raeburn 12585: }
1.247 raeburn 12586: $table = '<span class="LC_nobreak"><label>'.
12587: '<input type="checkbox" name="'.$name.'" '.
12588: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 12589: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 12590: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 12591: }
1.220 raeburn 12592: $table .= '</label></span>';
1.191 raeburn 12593: $rows ++;
1.125 raeburn 12594: }
12595: }
1.191 raeburn 12596: return ($numdcs,$table,$rows);
1.125 raeburn 12597: }
12598:
1.137 raeburn 12599: sub usersession_titles {
12600: return &Apache::lonlocal::texthash(
12601: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12602: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12603: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12604: version => 'LON-CAPA version requirement',
1.138 raeburn 12605: excludedomain => 'Allow all, but exclude specific domains',
12606: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12607: primary => 'Primary (checked first)',
1.154 raeburn 12608: default => 'Default',
1.137 raeburn 12609: );
12610: }
12611:
1.152 raeburn 12612: sub id_for_thisdom {
12613: my (%servers) = @_;
12614: my %altids;
12615: foreach my $server (keys(%servers)) {
12616: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12617: if ($serverhome ne $server) {
12618: $altids{$serverhome} = $server;
12619: }
12620: }
12621: return %altids;
12622: }
12623:
1.150 raeburn 12624: sub count_servers {
12625: my ($currbalancer,%servers) = @_;
12626: my (@spares,$numspares);
12627: foreach my $lonhost (sort(keys(%servers))) {
12628: next if ($currbalancer eq $lonhost);
12629: push(@spares,$lonhost);
12630: }
12631: if ($currbalancer) {
12632: $numspares = scalar(@spares);
12633: } else {
12634: $numspares = scalar(@spares) - 1;
12635: }
12636: return ($numspares,@spares);
12637: }
12638:
12639: sub lonbalance_targets_js {
1.171 raeburn 12640: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 12641: my $select = &mt('Select');
12642: my ($alltargets,$allishome,$allinsttypes,@alltypes);
12643: if (ref($servers) eq 'HASH') {
12644: $alltargets = join("','",sort(keys(%{$servers})));
12645: my @homedoms;
12646: foreach my $server (sort(keys(%{$servers}))) {
12647: if (&Apache::lonnet::host_domain($server) eq $dom) {
12648: push(@homedoms,'1');
12649: } else {
12650: push(@homedoms,'0');
12651: }
12652: }
12653: $allishome = join("','",@homedoms);
12654: }
12655: if (ref($types) eq 'ARRAY') {
12656: if (@{$types} > 0) {
12657: @alltypes = @{$types};
12658: }
12659: }
12660: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
12661: $allinsttypes = join("','",@alltypes);
1.171 raeburn 12662: my (%currbalancer,%currtargets,%currrules,%existing);
12663: if (ref($settings) eq 'HASH') {
12664: %existing = %{$settings};
12665: }
12666: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
12667: \%currtargets,\%currrules);
1.210 raeburn 12668: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 12669: return <<"END";
12670:
12671: <script type="text/javascript">
12672: // <![CDATA[
12673:
1.171 raeburn 12674: currBalancers = new Array('$balancers');
12675:
12676: function toggleTargets(balnum) {
12677: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12678: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
12679: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
12680: var prevbalancer = prevhostitem.value;
12681: var baltotal = document.getElementById('loadbalancing_total').value;
12682: prevhostitem.value = balancer;
12683: if (prevbalancer != '') {
12684: var prevIdx = currBalancers.indexOf(prevbalancer);
12685: if (prevIdx != -1) {
12686: currBalancers.splice(prevIdx,1);
12687: }
12688: }
1.150 raeburn 12689: if (balancer == '') {
1.171 raeburn 12690: hideSpares(balnum);
1.150 raeburn 12691: } else {
1.171 raeburn 12692: var currIdx = currBalancers.indexOf(balancer);
12693: if (currIdx == -1) {
12694: currBalancers.push(balancer);
12695: }
1.150 raeburn 12696: var homedoms = new Array('$allishome');
1.171 raeburn 12697: var ishomedom = homedoms[lonhostitem.selectedIndex];
12698: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 12699: }
1.171 raeburn 12700: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 12701: return;
12702: }
12703:
1.171 raeburn 12704: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 12705: var alltargets = new Array('$alltargets');
12706: var insttypes = new Array('$allinsttypes');
1.151 raeburn 12707: var offloadtypes = new Array('primary','default');
12708:
1.171 raeburn 12709: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
12710: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 12711:
1.151 raeburn 12712: for (var i=0; i<offloadtypes.length; i++) {
12713: var count = 0;
12714: for (var j=0; j<alltargets.length; j++) {
12715: if (alltargets[j] != balancer) {
1.171 raeburn 12716: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
12717: item.value = alltargets[j];
12718: item.style.textAlign='left';
12719: item.style.textFace='normal';
12720: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
12721: if (currBalancers.indexOf(alltargets[j]) == -1) {
12722: item.disabled = '';
12723: } else {
12724: item.disabled = 'disabled';
12725: item.checked = false;
12726: }
1.151 raeburn 12727: count ++;
12728: }
1.150 raeburn 12729: }
12730: }
1.151 raeburn 12731: for (var k=0; k<insttypes.length; k++) {
12732: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 12733: if (ishomedom == 1) {
1.171 raeburn 12734: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12735: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12736: } else {
1.171 raeburn 12737: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12738: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 12739: }
12740: } else {
1.171 raeburn 12741: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
12742: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 12743: }
1.151 raeburn 12744: if ((insttypes[k] != '_LC_external') &&
12745: ((insttypes[k] != '_LC_internetdom') ||
12746: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 12747: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
12748: item.options.length = 0;
12749: item.options[0] = new Option("","",true,true);
1.210 raeburn 12750: var idx = 0;
1.151 raeburn 12751: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 12752: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
12753: idx ++;
12754: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 12755: }
12756: }
12757: }
12758: }
12759: return;
12760: }
12761:
1.171 raeburn 12762: function hideSpares(balnum) {
1.150 raeburn 12763: var alltargets = new Array('$alltargets');
12764: var insttypes = new Array('$allinsttypes');
12765: var offloadtypes = new Array('primary','default');
12766:
1.171 raeburn 12767: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
12768: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 12769:
12770: var total = alltargets.length - 1;
12771: for (var i=0; i<offloadtypes; i++) {
12772: for (var j=0; j<total; j++) {
1.171 raeburn 12773: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
12774: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
12775: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 12776: }
1.150 raeburn 12777: }
12778: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 12779: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
12780: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 12781: if (insttypes[k] != '_LC_external') {
1.171 raeburn 12782: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
12783: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 12784: }
12785: }
12786: return;
12787: }
12788:
1.171 raeburn 12789: function checkOffloads(item,balnum,type) {
1.150 raeburn 12790: var alltargets = new Array('$alltargets');
12791: var offloadtypes = new Array('primary','default');
12792: if (item.checked) {
12793: var total = alltargets.length - 1;
12794: var other;
12795: if (type == offloadtypes[0]) {
1.151 raeburn 12796: other = offloadtypes[1];
1.150 raeburn 12797: } else {
1.151 raeburn 12798: other = offloadtypes[0];
1.150 raeburn 12799: }
12800: for (var i=0; i<total; i++) {
1.171 raeburn 12801: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 12802: if (server == item.value) {
1.171 raeburn 12803: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
12804: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 12805: }
12806: }
12807: }
12808: }
12809: return;
12810: }
12811:
1.171 raeburn 12812: function singleServerToggle(balnum,type) {
12813: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 12814: if (offloadtoSelIdx == 0) {
1.171 raeburn 12815: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
12816: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12817:
12818: } else {
1.171 raeburn 12819: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
12820: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 12821: }
12822: return;
12823: }
12824:
1.171 raeburn 12825: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 12826: if (type == '_LC_external') {
1.171 raeburn 12827: return;
1.150 raeburn 12828: }
1.171 raeburn 12829: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 12830: for (var i=0; i<typesRules.length; i++) {
12831: if (formname.elements[typesRules[i]].checked) {
12832: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 12833: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
12834: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 12835: } else {
1.171 raeburn 12836: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
12837: }
12838: }
12839: }
12840: return;
12841: }
12842:
12843: function balancerDeleteChange(balnum) {
12844: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
12845: var baltotal = document.getElementById('loadbalancing_total').value;
12846: var addtarget;
12847: var removetarget;
12848: var action = 'delete';
12849: if (document.getElementById('loadbalancing_delete_'+balnum)) {
12850: var lonhost = hostitem.value;
12851: var currIdx = currBalancers.indexOf(lonhost);
12852: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
12853: if (currIdx != -1) {
12854: currBalancers.splice(currIdx,1);
12855: }
12856: addtarget = lonhost;
12857: } else {
12858: if (currIdx == -1) {
12859: currBalancers.push(lonhost);
12860: }
12861: removetarget = lonhost;
12862: action = 'undelete';
12863: }
12864: balancerChange(balnum,baltotal,action,addtarget,removetarget);
12865: }
12866: return;
12867: }
12868:
12869: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
12870: if (baltotal > 1) {
12871: var offloadtypes = new Array('primary','default');
12872: var alltargets = new Array('$alltargets');
12873: var insttypes = new Array('$allinsttypes');
12874: for (var i=0; i<baltotal; i++) {
12875: if (i != balnum) {
12876: for (var j=0; j<offloadtypes.length; j++) {
12877: var total = alltargets.length - 1;
12878: for (var k=0; k<total; k++) {
12879: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
12880: var server = serveritem.value;
12881: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12882: if (server == addtarget) {
12883: serveritem.disabled = '';
12884: }
12885: }
12886: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12887: if (server == removetarget) {
12888: serveritem.disabled = 'disabled';
12889: serveritem.checked = false;
12890: }
12891: }
12892: }
12893: }
12894: for (var j=0; j<insttypes.length; j++) {
12895: if (insttypes[j] != '_LC_external') {
12896: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
12897: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
12898: var currSel = singleserver.selectedIndex;
12899: var currVal = singleserver.options[currSel].value;
12900: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
12901: var numoptions = singleserver.options.length;
12902: var needsnew = 1;
12903: for (var k=0; k<numoptions; k++) {
12904: if (singleserver.options[k] == addtarget) {
12905: needsnew = 0;
12906: break;
12907: }
12908: }
12909: if (needsnew == 1) {
12910: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
12911: }
12912: }
12913: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
12914: singleserver.options.length = 0;
12915: if ((currVal) && (currVal != removetarget)) {
12916: singleserver.options[0] = new Option("","",false,false);
12917: } else {
12918: singleserver.options[0] = new Option("","",true,true);
12919: }
12920: var idx = 0;
12921: for (var m=0; m<alltargets.length; m++) {
12922: if (currBalancers.indexOf(alltargets[m]) == -1) {
12923: idx ++;
12924: if (currVal == alltargets[m]) {
12925: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
12926: } else {
12927: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
12928: }
12929: }
12930: }
12931: }
12932: }
12933: }
12934: }
1.150 raeburn 12935: }
12936: }
12937: }
12938: return;
12939: }
12940:
1.152 raeburn 12941: // ]]>
12942: </script>
12943:
12944: END
12945: }
12946:
12947: sub new_spares_js {
12948: my @sparestypes = ('primary','default');
12949: my $types = join("','",@sparestypes);
12950: my $select = &mt('Select');
12951: return <<"END";
12952:
12953: <script type="text/javascript">
12954: // <![CDATA[
12955:
12956: function updateNewSpares(formname,lonhost) {
12957: var types = new Array('$types');
12958: var include = new Array();
12959: var exclude = new Array();
12960: for (var i=0; i<types.length; i++) {
12961: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
12962: for (var j=0; j<spareboxes.length; j++) {
12963: if (formname.elements[spareboxes[j]].checked) {
12964: exclude.push(formname.elements[spareboxes[j]].value);
12965: } else {
12966: include.push(formname.elements[spareboxes[j]].value);
12967: }
12968: }
12969: }
12970: for (var i=0; i<types.length; i++) {
12971: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
12972: var selIdx = newSpare.selectedIndex;
12973: var currnew = newSpare.options[selIdx].value;
12974: var okSpares = new Array();
12975: for (var j=0; j<newSpare.options.length; j++) {
12976: var possible = newSpare.options[j].value;
12977: if (possible != '') {
12978: if (exclude.indexOf(possible) == -1) {
12979: okSpares.push(possible);
12980: } else {
12981: if (currnew == possible) {
12982: selIdx = 0;
12983: }
12984: }
12985: }
12986: }
12987: for (var k=0; k<include.length; k++) {
12988: if (okSpares.indexOf(include[k]) == -1) {
12989: okSpares.push(include[k]);
12990: }
12991: }
12992: okSpares.sort();
12993: newSpare.options.length = 0;
12994: if (selIdx == 0) {
12995: newSpare.options[0] = new Option("$select","",true,true);
12996: } else {
12997: newSpare.options[0] = new Option("$select","",false,false);
12998: }
12999: for (var m=0; m<okSpares.length; m++) {
13000: var idx = m+1;
13001: var selThis = 0;
13002: if (selIdx != 0) {
13003: if (okSpares[m] == currnew) {
13004: selThis = 1;
13005: }
13006: }
13007: if (selThis == 1) {
13008: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13009: } else {
13010: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13011: }
13012: }
13013: }
13014: return;
13015: }
13016:
13017: function checkNewSpares(lonhost,type) {
13018: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13019: var chosen = newSpare.options[newSpare.selectedIndex].value;
13020: if (chosen != '') {
13021: var othertype;
13022: var othernewSpare;
13023: if (type == 'primary') {
13024: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13025: }
13026: if (type == 'default') {
13027: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13028: }
13029: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13030: othernewSpare.selectedIndex = 0;
13031: }
13032: }
13033: return;
13034: }
13035:
13036: // ]]>
13037: </script>
13038:
13039: END
13040:
13041: }
13042:
13043: sub common_domprefs_js {
13044: return <<"END";
13045:
13046: <script type="text/javascript">
13047: // <![CDATA[
13048:
1.150 raeburn 13049: function getIndicesByName(formname,item) {
1.152 raeburn 13050: var group = new Array();
1.150 raeburn 13051: for (var i=0;i<formname.elements.length;i++) {
13052: if (formname.elements[i].name == item) {
1.152 raeburn 13053: group.push(formname.elements[i].id);
1.150 raeburn 13054: }
13055: }
1.152 raeburn 13056: return group;
1.150 raeburn 13057: }
13058:
13059: // ]]>
13060: </script>
13061:
13062: END
1.152 raeburn 13063:
1.150 raeburn 13064: }
13065:
1.165 raeburn 13066: sub recaptcha_js {
13067: my %lt = &captcha_phrases();
13068: return <<"END";
13069:
13070: <script type="text/javascript">
13071: // <![CDATA[
13072:
13073: function updateCaptcha(caller,context) {
13074: var privitem;
13075: var pubitem;
13076: var privtext;
13077: var pubtext;
1.269 raeburn 13078: var versionitem;
13079: var versiontext;
1.165 raeburn 13080: if (document.getElementById(context+'_recaptchapub')) {
13081: pubitem = document.getElementById(context+'_recaptchapub');
13082: } else {
13083: return;
13084: }
13085: if (document.getElementById(context+'_recaptchapriv')) {
13086: privitem = document.getElementById(context+'_recaptchapriv');
13087: } else {
13088: return;
13089: }
13090: if (document.getElementById(context+'_recaptchapubtxt')) {
13091: pubtext = document.getElementById(context+'_recaptchapubtxt');
13092: } else {
13093: return;
13094: }
13095: if (document.getElementById(context+'_recaptchaprivtxt')) {
13096: privtext = document.getElementById(context+'_recaptchaprivtxt');
13097: } else {
13098: return;
13099: }
1.269 raeburn 13100: if (document.getElementById(context+'_recaptchaversion')) {
13101: versionitem = document.getElementById(context+'_recaptchaversion');
13102: } else {
13103: return;
13104: }
13105: if (document.getElementById(context+'_recaptchavertxt')) {
13106: versiontext = document.getElementById(context+'_recaptchavertxt');
13107: } else {
13108: return;
13109: }
1.165 raeburn 13110: if (caller.checked) {
13111: if (caller.value == 'recaptcha') {
13112: pubitem.type = 'text';
13113: privitem.type = 'text';
13114: pubitem.size = '40';
13115: privitem.size = '40';
13116: pubtext.innerHTML = "$lt{'pub'}";
13117: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 13118: versionitem.type = 'text';
13119: versionitem.size = '3';
13120: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 13121: } else {
13122: pubitem.type = 'hidden';
13123: privitem.type = 'hidden';
1.269 raeburn 13124: versionitem.type = 'hidden';
1.165 raeburn 13125: pubtext.innerHTML = '';
13126: privtext.innerHTML = '';
1.269 raeburn 13127: versiontext.innerHTML = '';
1.165 raeburn 13128: }
13129: }
13130: return;
13131: }
13132:
13133: // ]]>
13134: </script>
13135:
13136: END
13137:
13138: }
13139:
1.236 raeburn 13140: sub toggle_display_js {
1.192 raeburn 13141: return <<"END";
13142:
13143: <script type="text/javascript">
13144: // <![CDATA[
13145:
1.236 raeburn 13146: function toggleDisplay(domForm,caller) {
13147: if (document.getElementById(caller)) {
13148: var divitem = document.getElementById(caller);
13149: var optionsElement = domForm.coursecredits;
1.264 raeburn 13150: var checkval = 1;
13151: var dispval = 'block';
1.236 raeburn 13152: if (caller == 'emailoptions') {
13153: optionsElement = domForm.cancreate_email;
13154: }
1.257 raeburn 13155: if (caller == 'studentsubmission') {
13156: optionsElement = domForm.postsubmit;
13157: }
1.264 raeburn 13158: if (caller == 'cloneinstcode') {
13159: optionsElement = domForm.canclone;
13160: checkval = 'instcode';
13161: }
1.236 raeburn 13162: if (optionsElement.length) {
1.192 raeburn 13163: var currval;
1.236 raeburn 13164: for (var i=0; i<optionsElement.length; i++) {
13165: if (optionsElement[i].checked) {
13166: currval = optionsElement[i].value;
1.192 raeburn 13167: }
13168: }
1.264 raeburn 13169: if (currval == checkval) {
13170: divitem.style.display = dispval;
1.192 raeburn 13171: } else {
1.236 raeburn 13172: divitem.style.display = 'none';
1.192 raeburn 13173: }
13174: }
13175: }
13176: return;
13177: }
13178:
13179: // ]]>
13180: </script>
13181:
13182: END
13183:
13184: }
13185:
1.165 raeburn 13186: sub captcha_phrases {
13187: return &Apache::lonlocal::texthash (
13188: priv => 'Private key',
13189: pub => 'Public key',
13190: original => 'original (CAPTCHA)',
13191: recaptcha => 'successor (ReCAPTCHA)',
13192: notused => 'unused',
1.269 raeburn 13193: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 13194: );
13195: }
13196:
1.205 raeburn 13197: sub devalidate_remote_domconfs {
1.212 raeburn 13198: my ($dom,$cachekeys) = @_;
13199: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 13200: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13201: my %thismachine;
13202: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 13203: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 13204: if (keys(%servers)) {
1.205 raeburn 13205: foreach my $server (keys(%servers)) {
13206: next if ($thismachine{$server});
1.212 raeburn 13207: my @cached;
13208: foreach my $name (@posscached) {
13209: if ($cachekeys->{$name}) {
13210: push(@cached,&escape($name).':'.&escape($dom));
13211: }
13212: }
13213: if (@cached) {
13214: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13215: }
1.205 raeburn 13216: }
13217: }
13218: return;
13219: }
13220:
1.3 raeburn 13221: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>